Пример #1
0
 def visitFun_def(self, ctx: LuLu2GrammarParser.Fun_defContext):
     tmp_scope = self.__current_scope__
     self.__current_scope__ = global_scope.get_current_scope(
         ctx.start.line, ctx.start.column)
     self.__is_need_new_scope__ = False
     children = self.visitChildren(ctx)
     self.__current_scope__ = tmp_scope
     return children
Пример #2
0
    def visitBlock(self, ctx: LuLu2GrammarParser.BlockContext):
        tmp_scope = self.__current_scope__
        if self.__is_need_new_scope__ is True:
            self.__current_scope__ = global_scope.get_current_scope(
                ctx.start.line, ctx.start.column)

        self.__is_need_new_scope__ = True
        children = self.visitChildren(ctx)
        self.__current_scope__ = tmp_scope
        return children
Пример #3
0
    def visitFunc_call(self, ctx: LuLu2GrammarParser.Func_callContext):

        children = self.visitChildren(ctx)

        param = ctx.handle_call().params()

        input_type = []
        while param is not None:
            t = self._visited_typed_.pop()
            input_type.append(t)
            param = param.params()
        input_type.reverse()

        if len(input_type) == 1:
            input_type = input_type[0]

        scope = None
        if ctx.var() is not None:
            tmp = global_scope.get_define_type(
                self._visited_typed_.pop(),
                ctx.start.line,
                ctx.start.column,
            )
            scope = global_scope.get_current_scope(tmp.line, tmp.column)
        else:
            scope = self.__current_scope__

        key = ctx.handle_call().ID().getText()

        fun = scope.get_function(key, input_type, ctx.start.line,
                                 ctx.start.column)
        if fun is not None:
            self._visited_typed_.append(fun.output)
        else:
            self._visited_typed_.append("NoneType")
        return children
Пример #4
0
 def visitVar(self, ctx: LuLu2GrammarParser.VarContext):
     scope = self.__current_scope__
     if ctx.KEYWORD_THIS() is not None:
         v = scope.get_variable("this", ctx.start.line, ctx.start.column)
         if v is not None:
             tmp = scope.get_define_type(v.Type, ctx.start.line,
                                         ctx.start.column)
             if tmp is not None:
                 scope = global_scope.get_current_scope(
                     tmp.line, tmp.column)
             else:
                 scope = None
         else:
             scope = None
     elif ctx.KEYWORD_SUPER() is not None:
         v = scope.get_variable("super", ctx.start.line, ctx.start.column)
         if v is not None:
             tmp = scope.get_define_type(v.Type, ctx.start.line,
                                         ctx.start.column)
             if tmp is not None:
                 scope = global_scope.get_current_scope(
                     tmp.line, tmp.column)
             else:
                 scope = None
         else:
             scope = None
     if scope is None:
         t1 = "NoneType"
     else:
         if ctx.KEYWORD_THIS() is not None or ctx.KEYWORD_SUPER(
         ) is not None:
             v = scope.get_local_variable(
                 ctx.ref(0).ID().getText(), ctx.start.line,
                 ctx.start.column)
         else:
             v = scope.get_variable(
                 ctx.ref(0).ID().getText(), ctx.start.line,
                 ctx.start.column)
         if v is None:
             t1 = "NoneType"
         else:
             tmp = scope.get_define_type(v.Type, ctx.start.line,
                                         ctx.start.column)
             if tmp is not None:
                 scope = global_scope.get_current_scope(
                     tmp.line, tmp.column)
                 t1 = tmp.key
                 if scope is not None:
                     for item in ctx.ref()[1:]:
                         v = scope.get_local_variable(
                             item.ID().getText(), item.start.line,
                             item.start.column)
                         if v is None:
                             break
                         tmp_type = scope.get_type(v.Type, item.line,
                                                   item.column)
                         scope = global_scope.get_current_scope(
                             tmp_type.line, tmp_type.column)
                         if scope is None:
                             break
                     if v is None or scope is None:
                         t1 = "NoneType"
                     else:
                         t1 = v.Type
             else:
                 t1 = "NoneType"
     self._visited_typed_.append(t1)
     return self.visitChildren(ctx)