Commit 30985150 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Enable USE Clause in textboxes

parent 0c2ff0b7
del dist\*.*
\python27\python setup_windows.py py2exe -b1 -c
copy asn1scc-put-in-dist\* dist
......@@ -692,6 +692,12 @@ class TextArea(object):
# fpar and timers are also listed, useful when using autocompletion
self.fpar = []
self.timers = []
# signals can be declared in a text area (structure: see System class)
self.signals = []
# USE construct can be declared in a text area (list of strings)
# asn1_files lists optional COMMENT strings of USE constructs
self.use_clauses = []
self.asn1_files = []
# inner procedures - useful to get autocompletion params
self.procedures = []
# optional hyperlink
......@@ -906,6 +912,7 @@ class System(object):
# 'signals': ['sig1', .. ]}]
self.channels = []
self.blocks = []
self.text_areas = []
class AST(object):
......
......@@ -148,6 +148,22 @@ type_name = lambda t: \
types = lambda: getattr(DV, 'types', {})
def set_global_DV(asn1_filenames):
''' Call ASN.1 parser and set the global dataview AST entry (DV) '''
global DV
try:
DV = parse_asn1(tuple(asn1_filenames),
ast_version=ASN1.UniqueEnumeratedNames,
flags=[ASN1.AstOnly])
except (ImportError, NameError) as err:
# Can happen if DataView.py is not there
LOG.error('Error loading ASN.1 model')
LOG.debug(str(err))
except TypeError as err:
LOG.debug(traceback.format_exc())
raise TypeError('ASN.1 compiler failed - {}'.format(str(err)))
def substring_range(substring):
''' Return the range of a substring '''
left, right = substring.value[1]['substring']
......@@ -1848,6 +1864,8 @@ def composite_state(root, parent=None, context=None):
comp.state_exitpoints.append(point.toString().lower())
elif child.type == lexer.TEXTAREA:
textarea, err, warn = text_area(child, context=comp)
if textarea.signals:
errors.append('Signals shall not be declared in a state')
errors.extend(err)
warnings.extend(warn)
comp.content.textAreas.append(textarea)
......@@ -1946,6 +1964,8 @@ def procedure_pre(root, parent=None, context=None):
proc.comment, _, ___ = end(child)
elif child.type == lexer.TEXTAREA:
textarea, err, warn = text_area(child, context=proc)
if textarea.signals:
errors.append('Signals shall not be declared in a procedure')
errors.extend(err)
warnings.extend(warn)
proc.content.textAreas.append(textarea)
......@@ -2276,6 +2296,23 @@ def text_area_content(root, ta_ast, context):
timers = [timer.text.lower() for timer in child.children]
context.timers.extend(timers)
ta_ast.timers = timers
elif child.type == lexer.SIGNAL:
sig, err, warn = signal(child)
errors.extend(err)
warnings.extend(warn)
ta_ast.signals.append(sig)
elif child.type == lexer.USE:
# USE clauses can contain a CIF comment with the ASN.1 filename
for each in child.getChildren():
use_cmt = ''
if each.type == lexer.ASN1:
errors.append('There shall be no CIF in text areas')
elif each.type == lexer.COMMENT:
# Comment: better way to specify ASN.1 filename
use_cmt, _, _ = end(each)
else:
ta_ast.use_clauses.append(each.text)
ta_ast.asn1_files.append(use_cmt)
else:
warnings.append(
'Unsupported construct in text area content, type: ' +
......@@ -2407,36 +2444,61 @@ def system_definition(root, parent):
# Store the name of the file where the system is defined
system.filename = node_filename(root)
system.ast = parent
asn1_files = []
signals, procedures, blocks = [], [], []
for child in root.getChildren():
if child.type == lexer.ID:
system.name = child.text
LOG.debug('System name: ' + system.name)
elif child.type == lexer.SIGNAL:
sig, err, warn = signal(child)
errors.extend(err)
warnings.extend(warn)
system.signals.append(sig)
LOG.debug('Found signal: ' + str(sig))
signals.append(child)
elif child.type == lexer.PROCEDURE:
LOG.debug('procedure declaration')
proc, err, warn = procedure(
child, parent=None, context=system)
errors.extend(err)
warnings.extend(warn)
system.procedures.append(proc)
LOG.debug('Added procedure: ' + proc.inputString)
procedures.append(child)
elif child.type == lexer.CHANNEL:
LOG.debug('channel declaration')
channel, _, _ = signalroute(child)
system.channels.append(channel)
elif child.type == lexer.BLOCK:
LOG.debug('block declaration')
block, err, warn = block_definition(child, parent=system)
blocks.append(child)
elif child.type == lexer.TEXTAREA:
# Text zone where signals can be declared
textarea, err, warn = text_area(child, context=system)
system.signals.extend(textarea.signals)
if textarea.variables:
errors.append('Variables shall be declared only in a process')
if textarea.fpar:
errors.append('FPAR shall be declared only in procedures')
if textarea.timers:
errors.append('Timers shall be declared only in a process')
# Update list of ASN.1 files - if any
asn1_files.extend(textarea.asn1_files)
errors.extend(err)
warnings.extend(warn)
system.text_areas.append(textarea)
else:
warnings.append('Unsupported construct in system: ' +
str(child.type))
if asn1_files:
# parse ASN.1 files before parsing the rest of the system
try:
set_global_DV(asn1_files)
except TypeError as err:
errors.append(str(err))
for each in signals:
sig, err, warn = signal(each)
errors.extend(err)
warnings.extend(warn)
system.signals.append(sig)
for each in procedures:
proc, err, warn = procedure(
each, parent=None, context=system)
errors.extend(err)
warnings.extend(warn)
system.procedures.append(proc)
for each in blocks:
block, err, warn = block_definition(each, parent=system)
errors.extend(err)
warnings.extend(warn)
return system, errors, warnings
......@@ -2476,6 +2538,8 @@ def process_definition(root, parent=None, context=None):
elif child.type == lexer.TEXTAREA:
# Text zone where variables and operators are declared
textarea, err, warn = text_area(child, context=process)
if textarea.signals:
errors.append('Signals shall not be declared in a process')
errors.extend(err)
warnings.extend(warn)
process.content.textAreas.append(textarea)
......@@ -3826,18 +3890,13 @@ def pr_file(root):
# for each in os.listdir('.'):
# if searchobj.match(each):
# print 'found', each
if ast.asn1_filenames:
try:
DV = parse_asn1(tuple(ast.asn1_filenames),
ast_version=ASN1.UniqueEnumeratedNames,
flags=[ASN1.AstOnly])
ast.asn1Modules = DV.asn1Modules
except (ImportError, NameError) as err:
# Can happen if DataView.py is not there
LOG.info('USE Clause did not contain ASN.1 filename')
LOG.debug(str(err))
set_global_DV(ast.asn1_filenames)
except TypeError as err:
LOG.debug(traceback.format_exc())
errors.append('ASN.1 compiler failed - {}'.format(str(err)))
errors.append(str(err))
ast.asn1Modules = DV.asn1Modules
for child in systems:
LOG.debug('found SYSTEM')
......
......@@ -151,7 +151,7 @@ system_definition
use_clause
: use_asn1?
USE package_name end
-> ^(USE use_asn1? package_name);
-> ^(USE use_asn1? end? package_name);
/* Entity in system:
......@@ -159,6 +159,7 @@ use_clause
*/
entity_in_system
: signal_declaration
| text_area
| procedure
| channel
| block_definition;
......@@ -1271,8 +1272,8 @@ ENDSYNTYPE : E N D S Y N T Y P E;
NEWTYPE : N E W T Y P E;
ENDNEWTYPE : E N D N E W T Y P E;
ARRAY : A R R A Y;
CONSTANTS : C O N S T A N T S;
STRUCT : S T R U C T;
CONSTANTS : C O N S T A N T S;
STRUCT : S T R U C T;
SYNONYM : S Y N O N Y M;
IMPORT : I M P O R T;
VIEW : V I E W;
......
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-10-19 08:49:52
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-10-23 14:32:25
import sys
from antlr3 import *
......@@ -449,8 +449,8 @@ class sdl92Lexer(Lexer):
_type = ASSIG_OP
_channel = DEFAULT_CHANNEL
# sdl92.g:1152:17: ( ':=' )
# sdl92.g:1152:25: ':='
# sdl92.g:1153:17: ( ':=' )
# sdl92.g:1153:25: ':='
pass
self.match(":=")
......@@ -474,8 +474,8 @@ class sdl92Lexer(Lexer):
_type = L_BRACKET
_channel = DEFAULT_CHANNEL
# sdl92.g:1153:17: ( '{' )
# sdl92.g:1153:25: '{'
# sdl92.g:1154:17: ( '{' )
# sdl92.g:1154:25: '{'
pass
self.match(123)
......@@ -499,8 +499,8 @@ class sdl92Lexer(Lexer):
_type = R_BRACKET
_channel = DEFAULT_CHANNEL
# sdl92.g:1154:17: ( '}' )
# sdl92.g:1154:25: '}'
# sdl92.g:1155:17: ( '}' )
# sdl92.g:1155:25: '}'
pass
self.match(125)
......@@ -524,8 +524,8 @@ class sdl92Lexer(Lexer):
_type = L_PAREN
_channel = DEFAULT_CHANNEL
# sdl92.g:1155:17: ( '(' )
# sdl92.g:1155:25: '('
# sdl92.g:1156:17: ( '(' )
# sdl92.g:1156:25: '('
pass
self.match(40)
......@@ -549,8 +549,8 @@ class sdl92Lexer(Lexer):
_type = R_PAREN
_channel = DEFAULT_CHANNEL
# sdl92.g:1156:17: ( ')' )
# sdl92.g:1156:25: ')'
# sdl92.g:1157:17: ( ')' )
# sdl92.g:1157:25: ')'
pass
self.match(41)
......@@ -574,8 +574,8 @@ class sdl92Lexer(Lexer):
_type = COMMA
_channel = DEFAULT_CHANNEL
# sdl92.g:1157:17: ( ',' )
# sdl92.g:1157:25: ','
# sdl92.g:1158:17: ( ',' )
# sdl92.g:1158:25: ','
pass
self.match(44)
......@@ -599,8 +599,8 @@ class sdl92Lexer(Lexer):
_type = SEMI
_channel = DEFAULT_CHANNEL
# sdl92.g:1158:17: ( ';' )
# sdl92.g:1158:25: ';'
# sdl92.g:1159:17: ( ';' )
# sdl92.g:1159:25: ';'
pass
self.match(59)
......@@ -624,8 +624,8 @@ class sdl92Lexer(Lexer):
_type = DASH
_channel = DEFAULT_CHANNEL
# sdl92.g:1159:17: ( '-' )
# sdl92.g:1159:25: '-'
# sdl92.g:1160:17: ( '-' )
# sdl92.g:1160:25: '-'
pass
self.match(45)
......@@ -649,8 +649,8 @@ class sdl92Lexer(Lexer):
_type = ANY
_channel = DEFAULT_CHANNEL
# sdl92.g:1160:17: ( A N Y )
# sdl92.g:1160:25: A N Y
# sdl92.g:1161:17: ( A N Y )
# sdl92.g:1161:25: A N Y
pass
self.mA()
self.mN()
......@@ -676,8 +676,8 @@ class sdl92Lexer(Lexer):
_type = ASTERISK
_channel = DEFAULT_CHANNEL
# sdl92.g:1161:17: ( '*' )
# sdl92.g:1161:25: '*'
# sdl92.g:1162:17: ( '*' )
# sdl92.g:1162:25: '*'
pass
self.match(42)
......@@ -701,8 +701,8 @@ class sdl92Lexer(Lexer):
_type = DCL
_channel = DEFAULT_CHANNEL
# sdl92.g:1162:17: ( D C L )
# sdl92.g:1162:25: D C L
# sdl92.g:1163:17: ( D C L )
# sdl92.g:1163:25: D C L
pass
self.mD()
self.mC()
......@@ -728,8 +728,8 @@ class sdl92Lexer(Lexer):
_type = END
_channel = DEFAULT_CHANNEL
# sdl92.g:1163:17: ( E N D )
# sdl92.g:1163:25: E N D
# sdl92.g:1164:17: ( E N D )
# sdl92.g:1164:25: E N D
pass
self.mE()
self.mN()
......@@ -755,8 +755,8 @@ class sdl92Lexer(Lexer):
_type = KEEP
_channel = DEFAULT_CHANNEL
# sdl92.g:1164:17: ( K E E P )
# sdl92.g:1164:25: K E E P
# sdl92.g:1165:17: ( K E E P )
# sdl92.g:1165:25: K E E P
pass
self.mK()
self.mE()
......@@ -783,8 +783,8 @@ class sdl92Lexer(Lexer):
_type = PARAMNAMES
_channel = DEFAULT_CHANNEL
# sdl92.g:1165:17: ( P A R A M N A M E S )
# sdl92.g:1165:25: P A R A M N A M E S
# sdl92.g:1166:17: ( P A R A M N A M E S )
# sdl92.g:1166:25: P A R A M N A M E S
pass
self.mP()
self.mA()
......@@ -817,8 +817,8 @@ class sdl92Lexer(Lexer):
_type = SPECIFIC
_channel = DEFAULT_CHANNEL
# sdl92.g:1166:17: ( S P E C I F I C )
# sdl92.g:1166:25: S P E C I F I C
# sdl92.g:1167:17: ( S P E C I F I C )
# sdl92.g:1167:25: S P E C I F I C
pass
self.mS()
self.mP()
......@@ -849,8 +849,8 @@ class sdl92Lexer(Lexer):
_type = GEODE
_channel = DEFAULT_CHANNEL
# sdl92.g:1167:17: ( G E O D E )
# sdl92.g:1167:25: G E O D E
# sdl92.g:1168:17: ( G E O D E )
# sdl92.g:1168:25: G E O D E
pass
self.mG()
self.mE()
......@@ -878,8 +878,8 @@ class sdl92Lexer(Lexer):
_type = HYPERLINK
_channel = DEFAULT_CHANNEL
# sdl92.g:1168:17: ( H Y P E R L I N K )
# sdl92.g:1168:25: H Y P E R L I N K
# sdl92.g:1169:17: ( H Y P E R L I N K )
# sdl92.g:1169:25: H Y P E R L I N K
pass
self.mH()
self.mY()
......@@ -911,8 +911,8 @@ class sdl92Lexer(Lexer):
_type = ENDTEXT
_channel = DEFAULT_CHANNEL
# sdl92.g:1169:17: ( E N D T E X T )
# sdl92.g:1169:25: E N D T E X T
# sdl92.g:1170:17: ( E N D T E X T )
# sdl92.g:1170:25: E N D T E X T
pass
self.mE()
self.mN()
......@@ -942,8 +942,8 @@ class sdl92Lexer(Lexer):
_type = RETURN
_channel = DEFAULT_CHANNEL
# sdl92.g:1170:17: ( R E T U R N )
# sdl92.g:1170:25: R E T U R N
# sdl92.g:1171:17: ( R E T U R N )
# sdl92.g:1171:25: R E T U R N
pass
self.mR()
self.mE()
......@@ -972,8 +972,8 @@ class sdl92Lexer(Lexer):
_type = TIMER
_channel = DEFAULT_CHANNEL
# sdl92.g:1171:17: ( T I M E R )
# sdl92.g:1171:25: T I M E R
# sdl92.g:1172:17: ( T I M E R )
# sdl92.g:1172:25: T I M E R
pass
self.mT()
self.mI()
......@@ -1001,8 +1001,8 @@ class sdl92Lexer(Lexer):
_type = PROCESS
_channel = DEFAULT_CHANNEL
# sdl92.g:1172:17: ( P R O C E S S )
# sdl92.g:1172:25: P R O C E S S
# sdl92.g:1173:17: ( P R O C E S S )
# sdl92.g:1173:25: P R O C E S S
pass
self.mP()
self.mR()
......@@ -1032,8 +1032,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCESS
_channel = DEFAULT_CHANNEL
# sdl92.g:1173:17: ( E N D P R O C E S S )
# sdl92.g:1173:25: E N D P R O C E S S
# sdl92.g:1174:17: ( E N D P R O C E S S )
# sdl92.g:1174:25: E N D P R O C E S S
pass
self.mE()
self.mN()
......@@ -1066,8 +1066,8 @@ class sdl92Lexer(Lexer):
_type = START
_channel = DEFAULT_CHANNEL
# sdl92.g:1174:17: ( S T A R T )
# sdl92.g:1174:25: S T A R T
# sdl92.g:1175:17: ( S T A R T )
# sdl92.g:1175:25: S T A R T
pass
self.mS()
self.mT()
......@@ -1095,8 +1095,8 @@ class sdl92Lexer(Lexer):
_type = STATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1175:17: ( S T A T E )
# sdl92.g:1175:25: S T A T E
# sdl92.g:1176:17: ( S T A T E )
# sdl92.g:1176:25: S T A T E
pass
self.mS()
self.mT()
......@@ -1124,8 +1124,8 @@ class sdl92Lexer(Lexer):
_type = TEXT
_channel = DEFAULT_CHANNEL
# sdl92.g:1176:17: ( T E X T )
# sdl92.g:1176:25: T E X T
# sdl92.g:1177:17: ( T E X T )
# sdl92.g:1177:25: T E X T
pass
self.mT()
self.mE()
......@@ -1152,8 +1152,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE
_channel = DEFAULT_CHANNEL
# sdl92.g:1177:17: ( P R O C E D U R E )
# sdl92.g:1177:25: P R O C E D U R E
# sdl92.g:1178:17: ( P R O C E D U R E )
# sdl92.g:1178:25: P R O C E D U R E
pass
self.mP()
self.mR()
......@@ -1185,8 +1185,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCEDURE
_channel = DEFAULT_CHANNEL
# sdl92.g:1178:17: ( E N D P R O C E D U R E )
# sdl92.g:1178:25: E N D P R O C E D U R E
# sdl92.g:1179:17: ( E N D P R O C E D U R E )
# sdl92.g:1179:25: E N D P R O C E D U R E
pass
self.mE()
self.mN()
......@@ -1221,8 +1221,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE_CALL
_channel = DEFAULT_CHANNEL
# sdl92.g:1179:17: ( P R O C E D U R E C A L L )
# sdl92.g:1179:25: P R O C E D U R E C A L L
# sdl92.g:1180:17: ( P R O C E D U R E C A L L )
# sdl92.g:1180:25: P R O C E D U R E C A L L
pass
self.mP()
self.mR()
......@@ -1258,8 +1258,8 @@ class sdl92Lexer(Lexer):
_type = ENDSTATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1180:17: ( E N D S T A T E )
# sdl92.g:1180:25: E N D S T A T E
# sdl92.g:1181:17: ( E N D S T A T E )
# sdl92.g:1181:25: E N D S T A T E
pass
self.mE()
self.mN()
......@@ -1290,8 +1290,8 @@ class sdl92Lexer(Lexer):
_type = INPUT
_channel = DEFAULT_CHANNEL
# sdl92.g:1181:17: ( I N P U T )
# sdl92.g:1181:25: I N P U T
# sdl92.g:1182:17: ( I N P U T )
# sdl92.g:1182:25: I N P U T
pass
self.mI()
self.mN()
......@@ -1319,8 +1319,8 @@ class sdl92Lexer(Lexer):
_type = PROVIDED
_channel = DEFAULT_CHANNEL
# sdl92.g:1182:17: ( P R O V I D E D )
# sdl92.g:1182:25: P R O V I D E D
# sdl92.g:1183:17: ( P R O V I D E D )
# sdl92.g:1183:25: P R O V I D E D
pass
self.mP()
self.mR()
......@@ -1351,8 +1351,8 @@ class sdl92Lexer(Lexer):
_type = PRIORITY
_channel = DEFAULT_CHANNEL
# sdl92.g:1183:17: ( P R I O R I T Y )
# sdl92.g:1183:25: P R I O R I T Y
# sdl92.g:1184:17: ( P R I O R I T Y )
# sdl92.g:1184:25: P R I O R I T Y
pass
self.mP()
self.mR()
......@@ -1383,8 +1383,8 @@ class sdl92Lexer(Lexer):
_type = SAVE
_channel = DEFAULT_CHANNEL
# sdl92.g:1184:17: ( S A V E )
# sdl92.g:1184:25: S A V E
# sdl92.g:1185:17: ( S A V E )
# sdl92.g:1185:25: S A V E
pass
self.mS()
self.mA()
......@@ -1411,8 +1411,8 @@ class sdl92Lexer(Lexer):
_type = NONE
_channel = DEFAULT_CHANNEL
# sdl92.g:1185:17: ( N O N E )
# sdl92.g:1185:25: N O N E
# sdl92.g:1186:17: ( N O N E )
# sdl92.g:1186:25: N O N E
pass
self.mN()
self.mO()
......@@ -1439,8 +1439,8 @@ class sdl92Lexer(Lexer):
_type = FOR
_channel = DEFAULT_CHANNEL
# sdl92.g:1192:17: ( F O R )
# sdl92.g:1192:25: F O R
# sdl92.g:1193:17: ( F O R )
# sdl92.g:1193:25: F O R
pass
self.mF()
self.mO()
......@@ -1466,8 +1466,8 @@ class sdl92Lexer(Lexer):
_type = ENDFOR
_channel = DEFAULT_CHANNEL
# sdl92.g:1193:17: ( E N D F O R )
# sdl92.g:1193:25: E N D F O R
# sdl92.g:1194:17: ( E N D F O R )
# sdl92.g:1194:25: E N D F O R
pass
self.mE()
self.mN()
......@@ -1496,8 +1496,8 @@ class sdl92Lexer(Lexer):
_type = RANGE
_channel = DEFAULT_CHANNEL
# sdl92.g:1194:17: ( R A N G E )
# sdl92.g:1194:25: R A N G E
# sdl92.g:1195:17: ( R A N G E )
# sdl92.g:1195:25: R A N G E
pass
self.mR()
self.mA()
......@@ -1525,8 +1525,8 @@ class sdl92Lexer(Lexer):
_type = NEXTSTATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1195:17: ( N E X T S T A T E )
# sdl92.g:1195:25: N E X T S T A T E
# sdl92.g:1196:17: ( N E X T S T A T E )
# sdl92.g:1196:25: N E X T S T A T E
pass
self.mN()
self.mE()
......@@ -1558,8 +1558,8 @@ class sdl92Lexer(Lexer):
_type = ANSWER
_channel = DEFAULT_CHANNEL
# sdl92.g:1196:17: ( A N S W E R )
# sdl92.g:1196:25: A N S W E R
# sdl92.g:1197:17: ( A N S W E R )
# sdl92.g:1197:25: A N S W E R
pass
self.mA()
self.mN()
......@@ -1588,8 +1588,8 @@ class sdl92Lexer(Lexer):
_type = COMMENT
_channel = DEFAULT_CHANNEL
# sdl92.g:1197:17: ( C O M M E N T )
# sdl92.g:1197:25: C O M M E N T
# sdl92.g:1198:17: ( C O M M E N T )