Exemple #1
0
 def __init__(self, kind, node = None, scope = None, parent_scope = None, bases = None, value = None, klass_name =
         None):
     self.kind = kind
     self.node = node
     self.value = value
     self.is_method = False
     self.self_obj = None
     
     if scope != None:
         self.scope = scope
     else:
         if parent_scope != None:
             self.scope = Scope(parent = parent_scope)
         else:
             self.scope = Scope(is_root = True)
     if self.kind == 'obj':
         if klass_name:
             class_type = find_by_name(klass_name)
             self.scope.update({'__class__':class_type})
     if self.kind == 'class':
         if not bases:
             inf_object = scope.resolve('object', 'cascade')
             if inf_object:
                 bases = (inf_object,)
             else:
                 logger.info('nepodarilo sa resolvnut inf_object')
                 logger.debug('nepodarilo sa ... data: ' + str(scope) +' '+ str(scope.parent) + ' ' + str(scope.parent.parent))
                 bases = ()
         self.bases = bases
         self.scope['__bases__'] = bases
         self.scope['__name__'] = klass_name
Exemple #2
0
 def __init__(self,extern_scope=None):
     self.specials = {}
     self.modules = []
     self.problems = []
     self.visited_ast_nodes=[]
     self.breakpoint = None
     
     if extern_scope is None:
         #f = open("inf/inference/externs.py", "r")
         curr_location = os.path.dirname(os.path.realpath(__file__))
         f = open(curr_location+'/externs.py', 'r')
         source = f.read()
         f.close()
         node = ast.parse(source, filename = 'externs.py', mode = 'exec')
         logger.info('parsing externs')
         self.extern_scope = Scope(is_root = True)
         self.root_scope = Scope(parent = self.extern_scope)
         self.eval_code(node, self.extern_scope)
         logger.info('!!!externs parsed')
         #print('externs parsed')
     else:
         self.extern_scope = extern_scope
         self.root_scope = Scope(parent = self.extern_scope)
     
     self.modules = []
     self.problems = []
Exemple #3
0
def load_externs():
    from inf.inference.parse_ast import Parser
    parser = Parser()
    f = open("inf/inference/externs.py", "r")
    source = f.read()
    node = ast.parse(source, filename = 'externs.py', mode = 'exec')
    scope = Scope(is_root = True)
    logger.info('parsing externs')
    extern_scope = inf.inference.typez.extern_scope = parser.eval_code(node, scope)
    inf.inference.typez.inf_setattr = extern_scope['inf_setattr']
    inf.inference.typez.inf_getattr = extern_scope['inf_getattr']
    #extern_scope['int'] = extern_scope['inf_num']
    #extern_scope['str'] = extern_scope['inf_str']
    #extern_scope['object'] = extern_scope['inf_object']
    logger.info('externs parsed')