# HG changeset patch # User Aziz K?ksal # Date 1200525676 -3600 # Node ID 1ac758cd952a80ee36fee6f7e98265df1a9e8365 # Parent 8d96a7b50982c7257063768cafb99d007ba01028 Fixed a few things in DefaultVisitor.d and Pass1.d Returning parameter node in visit() methods in module Visitor. Added member type to TypeNode class. diff -r 8d96a7b50982 -r 1ac758cd952a trunk/src/dil/ast/DefaultVisitor.d --- a/trunk/src/dil/ast/DefaultVisitor.d Wed Jan 16 21:42:21 2008 +0100 +++ b/trunk/src/dil/ast/DefaultVisitor.d Thu Jan 17 00:21:16 2008 +0100 @@ -21,7 +21,7 @@ returnType!(T.stringof) visitDefault(T)(T t) { assert(t !is null, "node passed to visitDefault() is null"); - // Stdout(t).newline; + //Stdout(t).newline; alias t d, s, e, n; // Variable aliases of t. @@ -31,21 +31,21 @@ static if (is(D == Declarations)) foreach (node; d.children) visitN(node); - //static if (is(D == EmptyDeclaration)) - //static if (is(D == IllegalDeclaration)) - //static if (is(D == ModuleDeclaration)) + //EmptyDeclaration, + //IllegalDeclaration, + //ModuleDeclaration have no subnodes. static if (is(D == AliasDeclaration) || is(D == AliasDeclaration) || is(D == TypedefDeclaration)) visitD(d.decl); static if (is(D == EnumDeclaration)) { + d.baseType && visitT(d.baseType); foreach (member; d.members) visitD(member); - visitT(d.baseType); } static if (is(D == EnumMember)) - visitE(d.value); + d.value && visitE(d.value); static if (is(D == ClassDeclaration) || is( D == InterfaceDeclaration)) { d.tparams && visitN(d.tparams); @@ -123,12 +123,12 @@ { static if (is(E == CastExpression)) visitT(e.type); - visitE(e.e); // member of UnaryExpression + visitE(e.e); // Visit member in base class UnaryExpression. static if (is(E == IndexExpression)) foreach (arg; e.args) visitE(arg); static if (is(E == SliceExpression)) - visitE(e.left), visitE(e.right); + e.left && (visitE(e.left), visitE(e.right)); static if (is(E == AsmPostBracketExpression)) visitE(e.e2); } @@ -182,13 +182,13 @@ visitE(e.next); static if (is(E == TraitsExpression)) visitN(e.targs); + // VoidInitializer has no subnodes. static if (is(E == ArrayInitializer)) foreach (i, key; e.keys) key && visitE(key), visitE(e.values[i]); static if (is(E == StructInitializer)) foreach (value; e.values) visitE(value); - } } else @@ -197,8 +197,8 @@ alias T S; static if (is(S == Statements)) foreach (node; s.children) - visitS(cast(Statement)cast(void*)node/+.to!(Statement)+/); - //static if (is(S == IllegalStatement)) + visitS(cast(Statement)cast(void*)node); + //IllegalStatement has no subnodes. static if (is(S == FunctionBody)) s.funcBody && visitS(s.funcBody), s.inBody && visitS(s.inBody), @@ -237,10 +237,10 @@ } static if (is(S == DefaultStatement)) visitS(s.defaultBody); - //static if (is(S == ContinueStatement)) - //static if (is(S == BreakStatement)) + //ContinueStatement, + //BreakStatement have no subnodes. static if (is(S == ReturnStatement)) - visitE(s.e); + s.e && visitE(s.e); static if (is(S == GotoStatement)) s.caseExpr && visitE(s.caseExpr); static if (is(S == WithStatement)) @@ -269,7 +269,7 @@ static if (is(S == AsmInstruction)) foreach (op; s.operands) visitE(op); - //static if (is(S == AsmAlignStatement)) + //AsmAlignStatement has no subnodes. static if (is(S == PragmaStatement)) { foreach (arg; s.args) @@ -288,9 +288,9 @@ else static if (is(T : TypeNode)) { - //static if (is(T == UndefinedType)) - //static if (is(T == IntegralType)) - //static if (is(T == IdentifierType)) + //UndefinedType, + //IntegralType, + //IdentifierType have no subnodes. static if (is(T == QualifiedType)) visitT(t.left), visitT(t.right); static if (is(T == TypeofType)) @@ -343,7 +343,7 @@ visitT(n.valueType), n.specValue && visitN(n.specValue), n.defValue && visitN(n.defValue); - //static if (is(N == TemplateTupleParameter)) + //TemplateTupleParameter has no subnodes. } else assert(0, "Missing default visit method for: "~t.classinfo.name); diff -r 8d96a7b50982 -r 1ac758cd952a trunk/src/dil/ast/Types.d --- a/trunk/src/dil/ast/Types.d Wed Jan 16 21:42:21 2008 +0100 +++ b/trunk/src/dil/ast/Types.d Thu Jan 17 00:21:16 2008 +0100 @@ -58,6 +58,7 @@ { TID tid; TypeNode next; + Type type; /// The semantic type of this type node. this(TID tid) { @@ -172,12 +173,15 @@ Expression e, e2; TypeNode assocType; + /// Dynamic array: T[] this(TypeNode t) { super(TID.Array, t); mixin(set_kind); } + /// Static array: T[E] or + /// Slice array (for tuples): T[E..E] this(TypeNode t, Expression e, Expression e2) { addChild(e); @@ -187,6 +191,7 @@ this(t); } + /// Associative array: T[T] this(TypeNode t, TypeNode assocType) { addChild(assocType); diff -r 8d96a7b50982 -r 1ac758cd952a trunk/src/dil/ast/Visitor.d --- a/trunk/src/dil/ast/Visitor.d Wed Jan 16 21:42:21 2008 +0100 +++ b/trunk/src/dil/ast/Visitor.d Thu Jan 17 00:21:16 2008 +0100 @@ -21,7 +21,7 @@ { char[] text; foreach (className; classNames) - text ~= "returnType!(\""~className~"\") visit("~className~"){return null;}\n"; + text ~= "returnType!(\""~className~"\") visit("~className~" node){return node;}\n"; return text; } // pragma(msg, generateAbstractVisitMethods()); diff -r 8d96a7b50982 -r 1ac758cd952a trunk/src/dil/semantic/Pass1.d --- a/trunk/src/dil/semantic/Pass1.d Wed Jan 16 21:42:21 2008 +0100 +++ b/trunk/src/dil/semantic/Pass1.d Thu Jan 17 00:21:16 2008 +0100 @@ -67,7 +67,7 @@ foreach (node; d.children) { assert(node.category == NodeCategory.Declaration); - visitD(node.to!(Declaration)); + visitD(cast(Declaration)cast(void*)node); } return d; } @@ -188,7 +188,8 @@ return d; d.symbol = new Struct(d.name, d); // Insert into current scope. - scop.insert(d.symbol, d.name); + if (d.name) + scop.insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls); @@ -202,7 +203,8 @@ return d; d.symbol = new Union(d.name, d); // Insert into current scope. - scop.insert(d.symbol, d.name); + if (d.name) + scop.insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls); @@ -223,20 +225,20 @@ Declaration visit(VariableDeclaration vd) { - Type type; + Type type = Types.Undefined; if (vd.typeNode) // Get type from typeNode. - type = Types.Undefined; // visitN(d.typeNode); + type = visitT(vd.typeNode).type; else { // Infer type from first initializer. - auto firstValue = vd.values[0]; - firstValue = visitE(firstValue); - type = firstValue.type; + auto firstInit = vd.values[0]; + firstInit = visitE(firstInit); + type = firstInit.type; } - assert(type !is null); + //assert(type !is null); - // Check for interface. + // Check if we are in an interface. if (scop.isInterface) return error(vd.begin, MSG.InterfaceCantHaveVariables), vd; @@ -418,6 +420,11 @@ return e; } + Expression visit(StringExpression e) + { + return e; + } + Expression visit(MixinExpression me) { /+