Commit 3a6a9beb authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fixed minor pep8 issues

parent 331eca85
......@@ -2,7 +2,7 @@
 
# Resource object code
#
# Created: Fri Jun 20 15:21:39 2014
# Created: Tue Jun 24 14:42:29 2014
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
......@@ -1699,9 +1699,10 @@ def newtype_gettype(root, ta_ast, context):
warnings = []
newtypename = ""
if (root.getChild(0).type != lexer.SORT):
warnings.append("Expected SORT in newtype identifier, got type:" + str(child.type))
warnings.append("Expected SORT in newtype identifier, got type:"
+ str(child.type))
return newtypename, errors, warnings
newtypename = root.getChild(0).getChild(0).text
return newtypename, errors, warnings
......@@ -1711,15 +1712,15 @@ def get_array_type(root):
typeSort = root.getChild(1).text
typeSortLine = root.getChild(1).getLine()
typeSortChar = root.getChild(1).getCharPositionInLine()
# Constructing ASN.1 AST subtype
newtype = type("SeqOf_type", (object,), {
"Line" : typeSortLine, "CharPositionInLine" : typeSortChar,
"Line" : typeSortLine, "CharPositionInLine" : typeSortChar,
"Kind" : "ReferenceType" , "ReferencedTypeName" : typeSort
})
return newtype
def get_struct_children(root):
''' Returns the fields of a STRUCT as a dictionary '''
children = {}
......@@ -1728,20 +1729,22 @@ def get_struct_children(root):
typename = ""
if (fieldlist.type != lexer.FIELDS):
return children
for field in fieldlist.getChildren():
if (field.type == lexer.FIELD):
fieldname = field.getChild(0).text
typename = field.getChild(1).getChild(0).text
line = field.getChild(0).getLine()
charpos = field.getChild(0).getCharPositionInLine()
children[fieldname] = type(str(fieldname), (object ,), {
"Optional": "False", "Line": line, "CharPositionInLine": charpos, "type": type(str(fieldname + "_type"), (object,), {
"Line": line, "CharPositionInLine": charpos, "kind": "ReferenceType", "ReferencedTypeName": typename
"Optional": "False", "Line": line,
"CharPositionInLine": charpos,
"type": type(str(fieldname + "_type"), (object,), {
"Line": line, "CharPositionInLine": charpos,
"kind": "ReferenceType", "ReferencedTypeName": typename
})
})
return children
def syntype(root, ta_ast, context):
......@@ -1751,32 +1754,36 @@ def syntype(root, ta_ast, context):
newtype = ""
reftype = ""
global DV
newtypename = root.getChild(0).getChild(0).text
reftypename = root.getChild(1).getChild(0).text
newtype = type(str(newtypename), (object,), {
"Line" : root.getChild(0).getLine(), "CharPositionInLine" : root.getChild(0).getCharPositionInLine(),
"Line" : root.getChild(0).getLine(),
"CharPositionInLine" : root.getChild(0).getCharPositionInLine(),
})
newtype.type = type(str(newtypename) + "_type", (object,), {
"Line" : root.getChild(1).getLine(), "CharPositionInLine" : root.getChild(1).getCharPositionInLine(),
"Line" : root.getChild(1).getLine(),
"CharPositionInLine" : root.getChild(1).getCharPositionInLine(),
"kind" : reftype + "Type"
})
DV.types[str(newtypename)] = newtype
LOG.debug("Found new SYNTYPE " + newtypename)
return errors, warnings
def newtype(root, ta_ast, context):
''' Parse a NEWTYPE definition and inject it in ASN1 AST'''
errors = []
warnings = []
global DV
newtypename, errors, warnings = newtype_gettype(root, ta_ast, context)
if (newtypename == ""):
return errors, warnings
newtype = type(str(newtypename), (object,), {"Line" : root.getLine(), "CharPositionInLine" : root.getCharPositionInLine()})
newtype = type(str(newtypename), (object,), {
"Line" : root.getLine(),
"CharPositionInLine" : root.getCharPositionInLine()})
if (root.getChild(1).type == lexer.ARRAY):
newtype.kind = "SequenceOfType"
......@@ -1806,16 +1813,16 @@ def synonym (root, ta_ast, context):
if not "SDL-Constants" in DV.asn1Modules:
DV.asn1Modules.append("SDL-Constants")
DV.exportedVariables["SDL-Constants"] = []
for child in root.getChildren():
if child.getChild(0).type == lexer.SORT:
DV.exportedVariables["SDL-Constants"].append(child.getChild(0).getChild(0).text)
DV.exportedVariables["SDL-Constants"].append(
child.getChild(0).getChild(0).text)
return errors, warnings
def text_area_content(root, ta_ast, context):
''' Content of a text area: DCL, NEWTYPES, SYNTYPES, SYNONYMS, operators, procedures '''
''' Content of a text area: DCL, NEWTYPES, SYNTYPES, SYNONYMS, operators,
procedures '''
errors = []
warnings = []
for child in root.getChildren():
......@@ -3088,10 +3095,11 @@ def pr_file(root):
ast = ogAST.AST()
global DV
# In case no ASN.1 files are parsed, the DV structure is pre-initialised
# In case no ASN.1 files are parsed, the DV structure is pre-initialised
# This to allow SDL types injection in ASN1 ASTs
DV = type("ASNParseTree", (object, ), {"types" : {}, "exportedVariables": {}, "asn1Modules": [] })
DV = type("ASNParseTree", (object, ),
{"types" : {}, "exportedVariables": {}, "asn1Modules": [] })
# Re-order the children of the AST to make sure system and use clauses
# are parsed before process definition - to get signal definitions
# and data typess references.
......@@ -3156,7 +3164,7 @@ def pr_file(root):
errors.extend(err)
warnings.extend(warn)
LOG.debug('all files: ' + str(ast.pr_files))
# Since SDL type declarations are injected in ASN.1 ast,
# The ASN.1 ASTs needs to be copied at the end of PR parsing process
# and not just after the ASN1 specific parsing
......
......@@ -267,8 +267,9 @@ content
| newtype_definition
| variable_definition
| synonym_definition)*
-> ^(TEXTAREA_CONTENT
fpar* procedure* variable_definition* syntype_definition* newtype_definition* timer_declaration* synonym_definition*);
-> ^(TEXTAREA_CONTENT fpar* procedure* variable_definition*
syntype_definition* newtype_definition* timer_declaration*
synonym_definition*);
timer_declaration
......@@ -278,39 +279,41 @@ timer_declaration
-> ^(TIMER timer_id+);
syntype_definition
: SYNTYPE syntype_name '=' parent_sort (CONSTANTS (range_condition (',' range_condition)* ))?
ENDSYNTYPE syntype_name? end
-> ^(SYNTYPE syntype_name parent_sort range_condition*);
syntype_name
: sort;
: SYNTYPE syntype_name '=' parent_sort
(CONSTANTS (range_condition (',' range_condition)* ))?
ENDSYNTYPE syntype_name? end
-> ^(SYNTYPE syntype_name parent_sort range_condition*);
syntype_name
: sort;
parent_sort
: sort;
: sort;
newtype_definition
: NEWTYPE type_name (array_definition|structure_definition)? ENDNEWTYPE type_name? end
-> ^(NEWTYPE type_name array_definition* structure_definition*);
: NEWTYPE type_name (array_definition|structure_definition)?
ENDNEWTYPE type_name? end
-> ^(NEWTYPE type_name array_definition* structure_definition*);
type_name
: sort;
: sort;
array_definition
: ARRAY '(' sort ',' sort ')'
-> ^(ARRAY sort sort);
: ARRAY '(' sort ',' sort ')'
-> ^(ARRAY sort sort);
structure_definition
: STRUCT field_list end
-> ^(STRUCT field_list);
: STRUCT field_list end
-> ^(STRUCT field_list);
field_list
: field_definition (end field_definition)*
-> ^(FIELDS field_definition+);
: field_definition (end field_definition)*
-> ^(FIELDS field_definition+);
field_definition
: field_name (',' field_name)* sort
-> ^(FIELD field_name+ sort);
: field_name (',' field_name)* sort
-> ^(FIELD field_name+ sort);
variable_definition
: DCL variables_of_sort
......@@ -318,16 +321,17 @@ variable_definition
end
-> ^(DCL variables_of_sort+);
synonym_definition
: internal_synonym_definition;
synonym_definition
: internal_synonym_definition;
internal_synonym_definition
: SYNONYM synonym_definition_item (',' synonym_definition_item)* end
-> ^(SYNONYM_LIST synonym_definition_item+);
: SYNONYM synonym_definition_item (',' synonym_definition_item)*
end
-> ^(SYNONYM_LIST synonym_definition_item+);
synonym_definition_item
: sort sort '=' ground_expression
-> ^(SYNONYM sort sort ground_expression);
: sort sort '=' ground_expression
-> ^(SYNONYM sort sort ground_expression);
variables_of_sort
: variable_id (',' variable_id)* sort (':=' ground_expression)?
......
This diff is collapsed.
This diff is collapsed.
......@@ -47,7 +47,7 @@ SDL_BLACKBOLD = ['\\b{word}\\b'.format(word=word) for word in (
'CHECKME', 'PROCEDURE', 'EXTERNAL', 'IN', 'OUT', 'TIMER',
'SET_TIMER', 'RESET_TIMER', 'VIA', 'ENTRY', 'EXIT',
'SYNTYPE', 'ENDSYNTYPE', 'CONSTANTS',
'NEWTYPE', 'ENDNEWTYPE', 'ARRAY', 'STRUCT', 'SYNONYM')]
'NEWTYPE', 'ENDNEWTYPE', 'ARRAY', 'STRUCT', 'SYNONYM')]
SDL_REDBOLD = ['\\b{word}\\b'.format(word=word) for word in (
'INPUT', 'OUTPUT', 'STATE', 'DECISION', 'NEXTSTATE',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment