def NAMESPACE_ENTER(ast): sym = ast[1][1] n = id_engine.resolve(sym, True) print "enter namespace ?", n if n is Entity.Null: n = Namespace(sym, id_engine.current()) print "new namespace !", n id_engine.enter(n) return id_engine.current()
def _MARK_STRUC(ast): if ast[2][0] == 'symbol': sym = ast[2][1] else: sym = make_anon() ret = id_engine.resolve(sym) if ret is Entity.Null: ret = StructuredType(sym, id_engine.current()) print "_MARK_STRUC current =", id_engine.current() #id_engine.enter(ret) return ret
def validate_ast(self, ast): if ast[0] in main_grammar.validators: print "VALIDATING", ast, "=>", ret = main_grammar.validators[ast[0]](ast) print ret print 'ROOT', id_engine.root() print 'CURPATH', id_engine.current().full_path print 'CURRENT', id_engine.current() return ret else: print "AST", ast return ast
def _ENTER_STRUC(ast): if ast[2][0] == 'symbol': sym = ast[2][1] ret = id_engine.resolve(sym) else: sym = make_anon() ret = Entity.Null if ret is Entity.Null: ret = StructuredType(sym, id_engine.current()) print "_ENTER_STRUC current =", id_engine.current() id_engine.enter(ret) print "_ENTER_STRUC in_struc =", id_engine.current() return ret
def single_var(ast): global __var_type if type(ast[1]) is tuple: vari = 2 mod = ast[1] if mod[0] == 'AMPERSAND': typ = ReferenceTo(__var_type) elif mod[0] == 'stars': # stars typ = __var_type for k in mod[1:]: typ = PointerTo(typ) else: vari = 1 typ = __var_type else: vari = 1 typ = __var_type print ast, vari var = ast[vari][1] for k in ast[-1:vari:-1]: if k[0] == 'subscript': typ = Array(typ, k[2]) ret = Variable(var, id_engine.current(), typ) return ret
def func_signature(ast): print ast params = [] cv = None for x in ast[1:]: if x[0] == 'func_type': ftype = x[1] elif x[0] == 'func_id': print "FUNC ID", x[1:] if type(x[1]) is Function: fid = x[1].name else: fid = x[1][1] elif x[0] == 'func_param': params.append(x[1]) elif x[0] == 'opt_cv_qualifier': cv = (a[0] for a in x[1:]) print "ftype", ftype print "fid", fid print "fparam", params f = id_engine.resolve(fid, True) if f is Entity.Null: f = Function(fid, id_engine.current()) sig = f.create_signature(ftype, params, cv) id_engine.enter(f.scopes[sig]) return ('func_signature', fid, sig)
def using_decl(ast): if type(ast[2]) is tuple and ast[2][0] == 'NAMESPACE': print "TODO ! import namespace" else: what = ast[2] id_engine.add(what) print "Imported", what.full_path, "in", id_engine.current().full_path return tuple()
def template_type_decl_prefix(ast): free_params = [] print ast #for x in ast[2:]: # if x[0] == 'symbol': # sym = x[1] decl = ast[-1] sym = decl[-1][1] kw = decl[-2][1] ret = TemplateType(sym, id_engine.current(), kw, ast[1], []) id_engine.enter(ret) return ret
def LEAVE_SCOPE(ast): id_engine.leave() print "LEAVE current =", id_engine.current() return tuple()
def enter_template_free_params(ast): ret = Scope(None, id_engine.current()) id_engine.enter(ret) return ret
def typedef(ast): sym = ast[-2][1] typ = ast[-3] ret = TypeAlias(sym, id_engine.current(), typ) return ret
def _ENTER_LOCAL_SCOPE(ast): ret = Scope(None, id_engine.current()) id_engine.enter(ret) return tuple()