Example #1
0
 def visit(self, node: ast.Action, scope: Scope):
     scope.getType(node.action_type)
     new_scope = Scope(scope.classname, scope)
     new_scope.defineSymbol(node.name, scope.getType(node.action_type))
     return_type = self.visit(node.body, new_scope)
     node.static_type = return_type
     return return_type
Example #2
0
 def visit(self, node:ast.ClassMethod, scope:Scope, errors):
     for i in node.formal_params:
         try:
             scope.defineSymbol(i.name, scope.getType(i.param_type))
         except Exception as e:
             print(e)
     tb = self.visit(node.body, scope, error)
     if not tb < scope.getType(node.return_type):
         raise CheckSemanticError(f'{tb} doesn\'t conform {node.return_type}')
     return scope.getType(node.return_type)
Example #3
0
 def visit(self, node: ast.ClassMethod, scope: Scope):
     node.static_type = scope.getType(node.return_type)
     for i in node.formal_params:
         scope.defineSymbol(i.name, scope.getType(i.param_type))
     tb = self.visit(node.body, scope)
     if tb.name == 'SELF_TYPE' and node.return_type == 'SELF_TYPE':
         return scope.classname
     elif tb.name == 'SELF_TYPE':
         if scope.getType(scope.classname) < node.static_type:
             return node.static_type
         else:
             raise CheckSemanticError(
                 f'{scope.getType(scope.classname)} doesn\'t conform {node.static_type}'
             )
     elif node.return_type == 'SELF_TYPE':
         raise CheckSemanticError(
             f'Method {node.name} returns SELF_TYPE and body doesn\'t')
     if not tb < scope.getType(node.return_type):
         raise CheckSemanticError(
             f'{tb} doesn\'t conform {node.return_type}')
     return scope.getType(node.return_type)
Example #4
0
 def visit(self, node: ast.Formal, scope: Scope):
     scope.defineSymbol(node.name, scope.getType(node.param_type), True)
     t = self.visit(node.init_expr, scope)
     if not t:
         node.static_type = scope.getType(
             node.param_type
         ) if node.param_type != 'SELF_TYPE' else scope.getType(
             scope.classname)
         return
     if node.param_type == 'SELF_TYPE' and t.name == 'SELF_TYPE':
         return
     elif t.name == 'SELF_TYPE':
         if t < scope.getType(scope.classname):
             return
         else:
             raise CheckSemanticError(
                 f'{node.name} doesn\'t conform {scope.classname}')
     elif node.param_type == 'SELF_TYPE':
         raise CheckSemanticError(
             f'Only can assign SELF_TYPE in a SELF_TYPE variable.')
     if not t < scope.getType(node.param_type):
         raise CheckSemanticError(
             f'{str(t)} doesn\'t conform {str(node.param_type)}')
Example #5
0
 def visit(self, node:ast.Action, scope:Scope, errors):
     newScope = Scope(scope.classname, scope)
     newScope.defineSymbol(node.name, scope.getType(node.action_type))
     return self.visit(node.body, newScope, errors)
Example #6
0
 def visit(self, node:ast.Formal, scope:Scope, errors):
     scope.defineSymbol(node.name, scope.getType(node.param_type), True)
     t = self.visit(node.init_expr, scope)
 	if not t < node.param_type:
         raise CheckSemanticError(f'{str(t)} doesn\'t conform {str(node.param_type)}')