Mercurial > projects > dang
diff sema/AstAction.d @ 144:6e6355fb5f0f
- Parsing nested attributes.
- Creating classes and interfaces in AST.
- Updated AstPrinter to print attributes, classes and interfaces.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 17:41:40 +0200 |
parents | d76cc5cad4fc |
children | 393a1f47a6d2 6c5a3c0bb4fb |
line wrap: on
line diff
--- a/sema/AstAction.d Mon Jul 21 01:05:20 2008 +0200 +++ b/sema/AstAction.d Mon Jul 21 17:41:40 2008 +0200 @@ -41,24 +41,25 @@ { return new Identifier(t.location, sm.getText(t.asRange)); } - - override ModuleT actOnModule(ref Token _module, char[] name) +override +{ + ModuleT actOnModule(ref Token _module, char[] name) { return new Module(name); } - override ModuleT actOnImplicitModule(SLoc startLoc, char[] name) + ModuleT actOnImplicitModule(SLoc startLoc, char[] name) { return new Module(name); } - override void actOnModuleDecl(ModuleT m, DeclT d) + void actOnModuleDecl(ModuleT m, DeclT d) { (cast(Module)m).addDecl(cast(Decl)d); } // -- Declarations -- - override DeclT actOnImport(ref Token _, ref ModuleName target, Id* name) + DeclT actOnImport(ref Token _, ref ModuleName target, Id* name) { auto res = new ImportDecl; Identifier[] packages = new Identifier[target.packages.length]; @@ -72,7 +73,7 @@ return res; } - override void addSelectiveImport(DeclT _import, ref Id target, Id* name) + void addSelectiveImport(DeclT _import, ref Id target, Id* name) { auto d = cast(ImportDecl)_import; Identifier t = identifierFromTok(target.tok); @@ -82,12 +83,16 @@ d.explicitSymbols ~= [t, n]; } - override DeclT actOnDeclarator(ref Id type, ref Id id, ExprT init, Attribute att) + DeclT actOnDeclarator(ref Id type, ref Id id, ExprT init, Attribute att) { Decl d; Exp exp = cast(Exp)init; - if(type.tok.type == Tok.Struct) + if (type.tok.type == Tok.Struct) d = new StructDecl(identifierFromTok(id.tok)); + else if (type.tok.type == Tok.Class) + d = new ClassDecl(identifierFromTok(id.tok)); + else if (type.tok.type == Tok.Interface) + d = new InterfaceDecl(identifierFromTok(id.tok)); else d = new VarDecl(handleType(type), identifierFromTok(id.tok), exp); @@ -95,27 +100,51 @@ return d; } - override void actOnStructMember(DeclT st_decl, DeclT m_decl) //ref Id type, ref Id name, ExprT init) + void actOnStructMember(DeclT st_decl, DeclT m_decl) //ref Id type, ref Id name, ExprT init) { StructDecl st = cast(StructDecl)st_decl; st.addMember(cast(Decl)m_decl); } - override ExprT actOnMemberReference(ExprT lhs, SLoc op, Id member) + void actOnClassMember(DeclT cl_decl, DeclT m_decl) + { + ClassDecl cl = cast(ClassDecl)cl_decl; + cl.addMember(cast(Decl)m_decl); + } + + void actOnClassBaseClass(DeclT cl_decl, ref Id name) + { + ClassDecl cl = cast(ClassDecl)cl_decl; + cl.addBaseClass(identifierFromTok(name.tok)); + } + + void actOnInterfaceMember(DeclT if_decl, DeclT m_decl) + { + InterfaceDecl inf = cast(InterfaceDecl)if_decl; + inf.addMember(cast(Decl)m_decl); + } + + void actOnInterfaceBaseClass(DeclT if_decl, ref Id name) + { + InterfaceDecl inf = cast(InterfaceDecl)if_decl; + inf.addBaseClass(identifierFromTok(name.tok)); + } + + ExprT actOnMemberReference(ExprT lhs, SLoc op, Id member) { Exp exp = cast(Exp)lhs; Identifier id = identifierFromTok(member.tok); return new MemberReference(op, exp, id); } - override DeclT actOnStartOfFunctionDef(ref Id type, ref Id name, Attribute att) + DeclT actOnStartOfFunctionDef(ref Id type, ref Id name, Attribute att) { auto res = new FuncDecl(identifierFromTok(type.tok), identifierFromTok(name.tok)); res.att = att; return res; } - override void addFuncArg(DeclT func, Id type, Id name) + void addFuncArg(DeclT func, Id type, Id name) { FuncDecl fd = cast(FuncDecl)func; if(name) @@ -124,7 +153,7 @@ fd.addParam(identifierFromTok(type.tok)); } - override DeclT actOnEndOfFunction(DeclT func, StmtT stmts) + DeclT actOnEndOfFunction(DeclT func, StmtT stmts) { FuncDecl fd = cast(FuncDecl)func; fd.setBody(cast(CompoundStatement)stmts); @@ -132,18 +161,18 @@ } // -- Statements -- - override StmtT actOnCompoundStmt(ref Token l, ref Token r, StmtT[] stmts) + StmtT actOnCompoundStmt(ref Token l, ref Token r, StmtT[] stmts) { Stmt[] statements = cast(Stmt[])stmts; return new CompoundStatement(statements.dup); } - override StmtT actOnExprStmt(ExprT exp) + StmtT actOnExprStmt(ExprT exp) { return new ExpStmt(cast(Exp)exp); } - override StmtT actOnReturnStmt(ref Token loc, ExprT exp) + StmtT actOnReturnStmt(ref Token loc, ExprT exp) { Exp e = cast(Exp)exp; auto res = new ReturnStmt; @@ -151,7 +180,7 @@ return res; } - override StmtT actOnIfStmt(ref Token ifTok, ExprT cond, StmtT thenBody, + StmtT actOnIfStmt(ref Token ifTok, ExprT cond, StmtT thenBody, ref Token elseTok, StmtT elseBody) { Exp c = cast(Exp)cond; @@ -160,53 +189,53 @@ return new IfStmt(c, t, e); } - override StmtT actOnWhileStmt(ref Token tok, ExprT cond, StmtT whileBody) + StmtT actOnWhileStmt(ref Token tok, ExprT cond, StmtT whileBody) { Exp c = cast(Exp)cond; Stmt b = cast(Stmt)whileBody; return new WhileStmt(c, b); } - override StmtT actOnDeclStmt(DeclT decl) + StmtT actOnDeclStmt(DeclT decl) { Decl d = cast(Decl)decl; return new DeclStmt(d); } - override StmtT actOnStartOfSwitchStmt(ExprT exp) + StmtT actOnStartOfSwitchStmt(ExprT exp) { return new SwitchStmt(cast(Exp)exp); } - override void actOnCaseStmt(StmtT stmt, ExprT[] exps, StmtT[] stmts) + void actOnCaseStmt(StmtT stmt, ExprT[] exps, StmtT[] stmts) { auto sw = cast(SwitchStmt)stmt; sw.addCase(cast(Exp[])exps, cast(Stmt[])stmts); } - override void actOnDefaultStmt(StmtT stmt, StmtT[] stmts) + void actOnDefaultStmt(StmtT stmt, StmtT[] stmts) { auto sw = cast(SwitchStmt)stmt; sw.setDefault(cast(Stmt[])stmts); } // -- Expressions -- - override ExprT actOnNumericConstant(Token c) + ExprT actOnNumericConstant(Token c) { return new IntegerLit(c.location, sm.getText(c.asRange)); } - override ExprT actOnStringExp(Token s) + ExprT actOnStringExp(Token s) { return new StringExp(s.location, sm.getText(s.asRange)); } - override ExprT actOnIdentifierExp(Id id) + ExprT actOnIdentifierExp(Id id) { return identifierFromTok(id.tok); } - override ExprT actOnBinaryOp(SLoc op_loc, Operator op, ExprT l, ExprT r) + ExprT actOnBinaryOp(SLoc op_loc, Operator op, ExprT l, ExprT r) { Exp left = cast(Exp)l; Exp right = cast(Exp)r; @@ -225,7 +254,7 @@ } } - override ExprT actOnUnaryOp(Token op, ExprT operand) + ExprT actOnUnaryOp(Token op, ExprT operand) { Exp target = cast(Exp)operand; if (op.type == Tok.Minus) @@ -235,21 +264,21 @@ assert(0, "Only valid unary expressions are -x and *x"); } - override ExprT actOnCallExpr(ExprT fn, ref Token, ExprT[] args, ref Token) + ExprT actOnCallExpr(ExprT fn, ref Token, ExprT[] args, ref Token) { Exp f = cast(Exp)fn; Exp[] arguments = cast(Exp[])args.dup; return new CallExp(f, arguments); } - override ExprT actOnCastExpr(ref Token _cast, Id id, ExprT exp) + ExprT actOnCastExpr(ref Token _cast, Id id, ExprT exp) { Exp target = cast(Exp)exp; Identifier target_type = identifierFromTok(id.tok); return new CastExp(_cast.location, target_type, target); } - override ExprT + ExprT actOnIndexEpr(ExprT arr, ref Token lb, ExprT index, ref Token rb) { Exp target = cast(Exp)arr; @@ -257,4 +286,5 @@ return new IndexExp(target, lb.location, idx, rb.location); } } +}