def _automaton(ast, scene): ''' Render graphical elements of a process or procedure ''' top_level_symbols = [] # Render text areas (DCL declarations, etc.) for text in ast.textAreas: top_level_symbols.append(render(text, scene)) # Render procedures symbols top_level_symbols.extend([ render(proc, scene) for proc in ast.inner_procedures if not proc.external ]) # Render the start symbol if ast.start: top_level_symbols.append(render(ast.start, scene, ast.states)) # Render named start symbols in nested states for each in ast.named_start: top_level_symbols.append(render(each, scene, ast.states)) # Render floating labels for label in ast.floating_labels: top_level_symbols.append(render(label, scene, ast.states)) # Render floating states nested_states = [] for state in ast.states: # Create only floating states try: new_state = render(state, scene=scene, states=ast.states, terminators=ast.parent.terminators) if new_state.nested_scene: if unicode(new_state).lower() in nested_states: new_state.nested_scene = None else: nested_states.append(unicode(new_state).lower()) except TypeError: # Discard terminators (see _state function for explanation) pass else: top_level_symbols.append(new_state) # If the source .pr contained FPAR outside a textbox, create one if ast.parent.fpar and not any(x.fpar for x in ast.textAreas): text_area = ogAST.TextArea() fpars = ('{} {}'.format(fp['name'], type_name(fp['type']).replace('-', '_')) for fp in ast.parent.fpar) text_area.inputString = ("-- Formal parameters\n" "fpar {};".format( ',\n '.join(fpars))) text_area.pos_x = scene.itemsBoundingRect().x() - 200 text_area.pos_y = scene.itemsBoundingRect().y() top_level_symbols.append(render(text_area, scene)) return top_level_symbols
def _automaton(ast, scene): ''' Render graphical elements of a process or procedure ''' top_level_symbols = [] # Render text areas (DCL declarations, etc.) for text in ast.textAreas: top_level_symbols.append(render(text, scene)) # Render procedures symbols top_level_symbols.extend( [render(proc, scene) for proc in ast.inner_procedures if not proc.external]) # Render the start symbol if ast.start: top_level_symbols.append(render(ast.start, scene, ast.states)) # Render named start symbols in nested states for each in ast.named_start: top_level_symbols.append(render(each, scene, ast.states)) # Render floating labels for label in ast.floating_labels: top_level_symbols.append(render(label, scene, ast.states)) # Render floating states nested_states = [] for state in ast.states: # Create only floating states try: new_state = render(state, scene=scene, states=ast.states, terminators=ast.parent.terminators) if new_state.nested_scene: if unicode(new_state).lower() in nested_states: new_state.nested_scene = None else: nested_states.append(unicode(new_state).lower()) except TypeError: # Discard terminators (see _state function for explanation) pass else: top_level_symbols.append(new_state) # If the source .pr contained FPAR outside a textbox, create one if ast.parent.fpar and not any(x.fpar for x in ast.textAreas): text_area = ogAST.TextArea() fpars = ('{} {}'.format(fp['name'], type_name(fp['type']).replace('-', '_')) for fp in ast.parent.fpar) text_area.inputString = ("-- Formal parameters\n" "fpar {};".format(',\n '.join(fpars))) text_area.pos_x = scene.itemsBoundingRect().x() - 200 text_area.pos_y = scene.itemsBoundingRect().y() top_level_symbols.append(render(text_area, scene)) return top_level_symbols
def variables_autocompletion(symbol, type_filter=None): ''' Intelligent autocompletion for variables - including struct fields Optional: only variables of a type listed in type_filter are kept ''' res = set() if not symbol.text: return res parts = symbol.text.context.split('!') if len(parts) == 0: return res elif len(parts) == 1: try: fpar = {fp['name']: (fp['type'], None) for fp in CONTEXT.fpar} except AttributeError: # not in the context of a procedure fpar = {} # Return the list of variables, possibly filterd by type if not type_filter: res = set(CONTEXT.variables.keys() + CONTEXT.global_variables.keys() + AST.asn1_constants.keys() + fpar.keys()) else: constants = {name: (cty.type, None) for name, cty in AST.asn1_constants.viewitems()} try: type_filter_names = [ogParser.type_name(ty) for ty in type_filter] except AttributeError as err: # This would need to be investigated: it can happen when # using a parameter in an input just after the parameter was # added to the signal in the block view, and before any # variable has been declared.... LOG.debug(str(err)) return res for name, (asn1type, _) in chain(CONTEXT.variables.viewitems(), CONTEXT.global_variables.viewitems(), constants.viewitems(), fpar.viewitems()): if ogParser.type_name(asn1type) in type_filter_names: res.add(name) 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