def add_component_ctor(self, dot_path, component): """ Add a component if the component does not already exists. If it does exists, then this raises an Error. :type dot_path: DotPath :param dot_path: Name of the variable or property path :type component: Component :param component: AST part that will contains all properties """ if not isinstance(dot_path, DotPath): raise exception.BananaAssignmentError(dot_path.span, component.span) if not len(dot_path.properties) == 0: raise exception.BananaAssignmentError(dot_path.span, component.span) if dot_path.varname in self.components: other_dot_path = filter(lambda x: x == dot_path, self.components.keys())[0] no_effect_str = dot_path.span.str_from_to(component.span) collision_str = other_dot_path.span.str_from_to( self.components[other_dot_path].span) self._emitter.emit_warning( dot_path.span, "Statement has no effect: '{}'".format(no_effect_str)) self._emitter.emit_warning( other_dot_path.span, "It collides with: '{}'".format(collision_str)) else: self.components[dot_path.varname] = component self.statements.append((dot_path, component))
def add_assignment(self, dot_path, ast_value): """ Add an assignment to a property or a variable. We don't check at this point whether or not the variable has collision with a component. This will be done during the name resolution pass. :type dot_path: DotPath :param dot_path: Name of the variable or property :type ast_value: Ident | JsonObj | StringLit | Number | DotPath :param ast_value: Ast node this variable is assigned to. """ if not isinstance(dot_path, DotPath): raise exception.BananaAssignmentError(dot_path.span, ast_value.span) self.statements.append((dot_path, ast_value))