Commit 16388f61 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

[opengeode] Work on advanced autocompletion

parent 46a1f81e
......@@ -75,21 +75,21 @@ def _block(ast, scene):
def _process(ast, scene, **_):
''' Render a Process symbol (in a BLOCK diagram) '''
# Set autocompletion lists for input, output, state, types, variables:
try:
sdlSymbols.TextSymbol.completion_list = {
t.replace('-', '_') for t in ast.dataview}
except (AttributeError, TypeError):
LOG.debug('No dataview for filling types autocompletion list')
sdlSymbols.State.completion_list = {
state for state in ast.mapping if state != 'START'}
sdlSymbols.Input.completion_list = {
signal['name'] for signal in ast.input_signals}
sdlSymbols.Output.completion_list = {
signal['name'] for signal in ast.output_signals}
# try:
# sdlSymbols.TextSymbol.completion_list = {
# t.replace('-', '_') for t in ast.dataview}
# except (AttributeError, TypeError):
# LOG.debug('No dataview for filling types autocompletion list')
# sdlSymbols.State.completion_list = {
# state for state in ast.mapping if state != 'START'}
# sdlSymbols.Input.completion_list = {
# signal['name'] for signal in ast.input_signals}
# sdlSymbols.Output.completion_list = {
# signal['name'] for signal in ast.output_signals}
#sdlSymbols.Task.completion_list = set(ast.variables.keys())
sdlSymbols.ProcedureCall.completion_list = {
proc.inputString for proc in ast.procedures}
#
# sdlSymbols.ProcedureCall.completion_list = {
# proc.inputString for proc in ast.procedures}
symbol = sdlSymbols.Process(ast, ast)
add_to_scene(symbol, scene)
......
......@@ -924,8 +924,8 @@ class AST(object):
# Refs to the ASN.1 dataview AST (set with USE clauses)
self.dataview = None
self.asn1Modules = None
# Constants stored in the ASN.1 modules (type is unknown/unchecked)
self.asn1_constants = []
# ASN.1-defined constants (constants in Ada but variables in C)
self.asn1_constants = None
# List of System
self.systems = []
......
......@@ -385,14 +385,15 @@ def get_state_list(process_root):
return set(state_list)
def find_basic_type(a_type):
def find_basic_type(a_type, pool=None):
''' Return the ASN.1 basic type of a_type '''
basic_type = a_type or UNKNOWN_TYPE
pool = pool or types()
while basic_type.kind == 'ReferenceType':
# Find type with proper case in the data view
for typename in types().viewkeys():
for typename in pool.viewkeys():
if typename.lower() == basic_type.ReferencedTypeName.lower():
basic_type = types()[typename].type
basic_type = pool[typename].type
break
else:
raise TypeError('Type "' + type_name(basic_type) +
......@@ -812,7 +813,6 @@ def find_variable_type(var, context):
try:
for variable in context.fpar:
if variable['name'].lower() == var.lower():
LOG.debug(str(var) + ' is defined')
return variable['type']
except AttributeError:
# No FPAR section
......@@ -821,18 +821,15 @@ def find_variable_type(var, context):
for varname, (vartype, _) in all_visible_variables.viewitems():
# Case insensitive comparison with variables
if var.lower() == varname.lower():
LOG.debug(str(var) + ' is defined')
return vartype
for timer in chain(context.timers, context.global_timers):
if var.lower() == timer.lower():
LOG.debug(str(var) + ' is defined')
return TIMER
# check if is a ASN.1 constant
for varname, vartype in DV.variables.viewitems():
if var.lower() == varname.lower().replace('-', '_'):
LOG.debug(str(var) + ' is defined')
return vartype.type
LOG.debug('[find_variable] result: not found, raising exception')
......@@ -3787,9 +3784,6 @@ def pr_file(root):
ast_version=ASN1.UniqueEnumeratedNames,
flags=[ASN1.AstOnly])
ast.asn1Modules = DV.asn1Modules
# Add constants defined in the ASN.1 modules (for visibility)
for mod in ast.asn1Modules:
ast.asn1_constants.extend(DV.exportedVariables[mod])
except (ImportError, NameError) as err:
# Can happen if DataView.py is not there
LOG.info('USE Clause did not contain ASN.1 filename')
......@@ -3832,8 +3826,7 @@ def pr_file(root):
# The ASN.1 ASTs needs to be copied at the end of PR parsing process
# and not just after the ASN1 specific parsing
ast.dataview = types()
for mod in DV.exportedVariables:
ast.asn1_constants.extend(DV.exportedVariables[mod])
ast.asn1_constants = DV.variables
return ast, errors, warnings
......
......@@ -1392,6 +1392,7 @@ class SDL_View(QtGui.QGraphicsView, object):
self.update_asn1_dock.emit(ast)
# Set AST to be used as data dictionnary and updated on the fly
sdlSymbols.AST = ast
sdlSymbols.CONTEXT = process
def open_diagram(self):
''' Load one or several .pr file and display the state machine '''
......
......@@ -38,6 +38,7 @@ import ogAST
LOG = logging.getLogger('sdlSymbols')
AST = ogAST.AST()
CONTEXT = ogAST.Process()
# SDL-specific: reserved keywords, to be highlighted in textboxes
# Two kind of formatting are possible: black bold, and red bold
......@@ -52,7 +53,7 @@ SDL_BLACKBOLD = ['\\b{word}\\b'.format(word=word) for word in (
SDL_REDBOLD = ['\\b{word}\\b'.format(word=word) for word in (
'INPUT', 'OUTPUT', 'STATE', 'DECISION', 'NEXTSTATE',
'TASK', 'PROCESS', 'LABEL', 'JOIN', 'CONNECTION')]
'TASK', 'PROCESS', 'LABEL', 'JOIN', 'CONNECTION', 'CONNECT')]
# pylint: disable=R0904
......@@ -510,12 +511,46 @@ class Task(VerticalSymbol):
@property
def completion_list(self):
''' Dynamically set completion list depending on current context '''
# Need access to the AST
try:
print self.text.context.encode('utf-8')
except AttributeError:
pass # text not set yet
return ['hello', 'world']
res = []
if not self.text:
return res
#print self.text.context.encode('utf-8')
parts = self.text.context.split('!')
if len(parts) == 0:
return res
elif len(parts) == 1:
# Return the list of variables
res = set(CONTEXT.variables.keys() + AST.asn1_constants.keys())
else:
var = parts[0].lower()
try:
var_t = ogParser.find_variable_type(var, CONTEXT)
basic = ogParser.find_basic_type(var_t, AST.dataview)
res = (field.replace('-', '_')
for field in basic.Children.keys())
except (AttributeError, TypeError):
res = []
else:
for each in parts[1:-1]:
try:
for child, childtype in basic.Children.viewitems():
if child.lower() == each.lower().replace('_', '-'):
basic = ogParser.find_basic_type(childtype.type,
AST.dataview)
break
else:
res = []
break
except (AttributeError, TypeError):
res = []
break
else:
try:
res = (field.replace('-', '_')
for field in basic.Children.keys())
except AttributeError:
res = []
return res
# pylint: disable=R0904
......
......@@ -42,8 +42,17 @@ SeqInt ::= SEQUENCE (SIZE(1..2)) OF T-UInt8
MyOctStr ::= OCTET STRING (SIZE (3))
String ::= OCTET STRING (SIZE(0..100))
Autocompletion ::= SEQUENCE {
first-field BOOLEAN,
secondField SEQUENCE {
third BOOLEAN,
fourth BOOLEAN
}
}
-- You can also declare variables (they will be visible in C, Ada and SDL)
myVar MySeqOf ::= { hello, world }
mySeq Autocompletion ::= { first-field TRUE, secondField { third TRUE, fourth FALSE } }
END
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