Mercurial > projects > dil
changeset 264:50cc74026ea8
- Changed some string types to Token*.
author | aziz |
---|---|
date | Fri, 03 Aug 2007 17:51:02 +0000 |
parents | ebcf7941f1db |
children | 3a2a0a63c638 |
files | trunk/src/Declarations.d trunk/src/Parser.d trunk/src/Statements.d trunk/src/Types.d |
diffstat | 4 files changed, 119 insertions(+), 141 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Declarations.d Fri Aug 03 17:08:02 2007 +0000 +++ b/trunk/src/Declarations.d Fri Aug 03 17:51:02 2007 +0000 @@ -87,11 +87,11 @@ class EnumDeclaration : Declaration { - string name; + Token* name; Type baseType; - string[] members; + Token*[] members; Expression[] values; - this(string name, Type baseType, string[] members, Expression[] values, bool hasBody) + this(Token* name, Type baseType, Token*[] members, Expression[] values, bool hasBody) { super(hasBody); this.name = name; @@ -103,11 +103,11 @@ class ClassDeclaration : Declaration { - string name; + Token* name; TemplateParameters tparams; BaseClass[] bases; Declaration[] decls; - this(string name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody) + this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody) { super(hasBody); this.name = name; @@ -119,11 +119,11 @@ class InterfaceDeclaration : Declaration { - string name; + Token* name; TemplateParameters tparams; BaseClass[] bases; Declaration[] decls; - this(string name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody) + this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody) { super(hasBody); this.name = name; @@ -135,10 +135,10 @@ class StructDeclaration : Declaration { - string name; + Token* name; TemplateParameters tparams; Declaration[] decls; - this(string name, TemplateParameters tparams, Declaration[] decls, bool hasBody) + this(Token* name, TemplateParameters tparams, Declaration[] decls, bool hasBody) { super(hasBody); this.name = name; @@ -149,10 +149,10 @@ class UnionDeclaration : Declaration { - string name; + Token* name; TemplateParameters tparams; Declaration[] decls; - this(string name, TemplateParameters tparams, Declaration[] decls, bool hasBody) + this(Token* name, TemplateParameters tparams, Declaration[] decls, bool hasBody) { super(hasBody); this.name = name; @@ -252,19 +252,15 @@ class DebugDeclaration : Declaration { - int levelSpec; - string identSpec; - int levelCond; - string identCond; + Token* spec; + Token* cond; Declaration[] decls, elseDecls; - this(int levelSpec, string identSpec, int levelCond, string identCond, Declaration[] decls, Declaration[] elseDecls) + this(Token* spec, Token* cond, Declaration[] decls, Declaration[] elseDecls) { super(decls.length != 0); - this.levelSpec = levelSpec; - this.identSpec = identSpec; - this.levelCond = levelCond; - this.identCond = identCond; + this.spec = spec; + this.cond = cond; this.decls = decls; this.elseDecls = elseDecls; } @@ -272,19 +268,15 @@ class VersionDeclaration : Declaration { - int levelSpec; - string identSpec; - int levelCond; - string identCond; + Token* spec; + Token* cond; Declaration[] decls, elseDecls; - this(int levelSpec, string identSpec, int levelCond, string identCond, Declaration[] decls, Declaration[] elseDecls) + this(Token* spec, Token* cond, Declaration[] decls, Declaration[] elseDecls) { super(decls.length != 0); - this.levelSpec = levelSpec; - this.identSpec = identSpec; - this.levelCond = levelCond; - this.identCond = identCond; + this.spec = spec; + this.cond = cond; this.decls = decls; this.elseDecls = elseDecls; }
--- a/trunk/src/Parser.d Fri Aug 03 17:08:02 2007 +0000 +++ b/trunk/src/Parser.d Fri Aug 03 17:51:02 2007 +0000 @@ -500,7 +500,7 @@ if (token.type == T.LParen) { nT(); - func.outIdent = requireIdentifier(); + func.outIdent = requireId(); require(T.RParen); } require(T.LBrace); @@ -792,9 +792,9 @@ { assert(token.type == T.Enum); - string enumName; + Token* enumName; Type baseType; - string[] members; + Token*[] members; Expression[] values; bool hasBody; @@ -802,7 +802,7 @@ if (token.type == T.Identifier) { - enumName = token.identifier; + enumName = token; nT(); } @@ -814,7 +814,7 @@ if (token.type == T.Semicolon) { - if (enumName.length == 0) + if (enumName is null) expected(T.Identifier); nT(); } @@ -824,7 +824,7 @@ nT(); do { - members ~= requireIdentifier(); + members ~= requireId(); if (token.type == T.Assign) { @@ -854,14 +854,14 @@ { assert(token.type == T.Class); - string className; + Token* className; TemplateParameters tparams; BaseClass[] bases; Declaration[] decls; bool hasBody; nT(); // Skip class keyword. - className = requireIdentifier(); + className = requireId(); if (token.type == T.LParen) { @@ -929,14 +929,14 @@ { assert(token.type == T.Interface); - string name; + Token* name; TemplateParameters tparams; BaseClass[] bases; Declaration[] decls; bool hasBody; nT(); // Skip interface keyword. - name = requireIdentifier(); + name = requireId(); if (token.type == T.LParen) { @@ -971,7 +971,7 @@ TOK tok = token.type; - string name; + Token* name; TemplateParameters tparams; Declaration[] decls; bool hasBody; @@ -980,7 +980,7 @@ // name is optional. if (token.type == T.Identifier) { - name = token.identifier; + name = token; nT(); if (token.type == T.LParen) { @@ -1079,30 +1079,28 @@ nT(); // Skip debug keyword. - int levelSpec = -1; // debug = Integer ; - string identSpec; // debug = Identifier ; - int levelCond = -1; // debug ( Integer ) - string identCond; // debug ( Identifier ) + Token* spec; // debug = Integer ; + // debug = Identifier ; + Token* cond; // debug ( Integer ) + // debug ( Identifier ) Declaration[] decls, elseDecls; - void parseIdentOrInt(ref string ident, ref int level) + void parseIdentOrInt(ref Token* tok) { nT(); - if (token.type == T.Int32) - level = token.int_; - else if (token.type == T.Identifier) - ident = token.identifier; + if (token.type == T.Int32 || + token.type == T.Identifier) + { + tok = token; + nT(); + } else - { expected(T.Identifier); // TODO: better error msg - return; - } - nT(); } if (token.type == T.Assign) { - parseIdentOrInt(identSpec, levelSpec); + parseIdentOrInt(spec); require(T.Semicolon); } else @@ -1113,7 +1111,7 @@ // ( Condition ) if (token.type == T.LParen) { - parseIdentOrInt(identCond, levelCond); + parseIdentOrInt(cond); require(T.RParen); } @@ -1122,19 +1120,16 @@ decls = parseDeclarationsBlock(); // else DeclarationsBlock - // debug without condition and else body makes no sense - if (token.type == T.Else && (levelCond != -1 || identCond.length != 0)) + if (token.type == T.Else) { nT(); //if (token.type == T.Colon) // TODO: avoid "else:"? elseDecls = parseDeclarationsBlock(); } -// else - // TODO: issue error msg } - return new DebugDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); + return new DebugDeclaration(spec, cond, decls, elseDecls); } Declaration parseVersionDeclaration() @@ -1143,30 +1138,29 @@ nT(); // Skip version keyword. - int levelSpec = -1; // version = Integer ; - string identSpec; // version = Identifier ; - int levelCond = -1; // version ( Integer ) - string identCond; // version ( Identifier ) + Token* spec; // version = Integer ; + // version = Identifier ; + Token* cond; // version ( Integer ) + // version ( Identifier ) Declaration[] decls, elseDecls; - void parseIdentOrInt(ref string ident, ref int level) + void parseIdentOrInt(ref Token* tok) { - if (token.type == T.Int32) - level = token.int_; - else if (token.type == T.Identifier) - ident = token.identifier; + nT(); + if (token.type == T.Int32 || + token.type == T.Identifier) + { + tok = token; + nT(); + } else - { expected(T.Identifier); // TODO: better error msg - return; - } - nT(); } if (token.type == T.Assign) { nT(); - parseIdentOrInt(identSpec, levelSpec); + parseIdentOrInt(spec); require(T.Semicolon); } else @@ -1177,7 +1171,7 @@ // ( Condition ) require(T.LParen); - parseIdentOrInt(identCond, levelCond); + parseIdentOrInt(cond); require(T.RParen); // version ( Condition ) DeclarationsBlock @@ -1193,7 +1187,7 @@ } } - return new VersionDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); + return new VersionDeclaration(spec, cond, decls, elseDecls); } Declaration parseStaticIfDeclaration() @@ -1367,8 +1361,8 @@ Type[] identList; if (token.type == T.Dot) { + identList ~= new IdentifierType(token); nT(); - identList ~= new IdentifierType("."); } else if (token.type == T.Typeof) { @@ -1382,7 +1376,7 @@ while (1) { - string ident = requireIdentifier(); + auto ident = requireId(); // NB.: Currently Types can't be followed by "!=" so we don't need to peek for "(" when parsing TemplateInstances. if (token.type == T.Not/+ && peekNext() == T.LParen+/) // Identifier !( TemplateArguments ) { @@ -1522,7 +1516,7 @@ case T.Identifier: if (peekNext() == T.Colon) { - string ident = token.identifier; + auto ident = token; nT(); // Skip Identifier nT(); // Skip : s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); @@ -2018,10 +2012,10 @@ { assert(token.type == T.Continue); nT(); - string ident; + Token* ident; if (token.type == T.Identifier) { - ident = token.identifier; + ident = token; nT(); } require(T.Semicolon); @@ -2032,10 +2026,10 @@ { assert(token.type == T.Break); nT(); - string ident; + Token* ident; if (token.type == T.Identifier) { - ident = token.identifier; + ident = token; nT(); } require(T.Semicolon); @@ -2057,7 +2051,7 @@ { assert(token.type == T.Goto); nT(); - string ident; + Token* ident; Expression caseExpr; switch (token.type) { @@ -2071,7 +2065,7 @@ nT(); break; default: - ident = requireIdentifier(); + ident = requireId(); } require(T.Semicolon); return new GotoStatement(ident, caseExpr); @@ -2158,9 +2152,9 @@ assert(token.type == T.LParen); nT(); - string condition = requireIdentifier(); - if (condition.length) - switch (condition) + Token* condition = requireId(); + if (condition) + switch (condition.identifier) { case "exit": case "success": @@ -2266,22 +2260,21 @@ assert(token.type == T.Debug); nT(); // Skip debug keyword. -// int levelSpec = -1; // debug = Integer ; -// string identSpec; // debug = Identifier ; - int levelCond = -1; // debug ( Integer ) - string identCond; // debug ( Identifier ) + Token* cond; // debug ( Integer ) + // debug ( Identifier ) Statement debugBody, elseBody; - void parseIdentOrInt(ref string ident, ref int level) + void parseIdentOrInt(ref Token* tok) { nT(); - if (token.type == T.Int32) - level = token.int_; - else if (token.type == T.Identifier) - ident = token.identifier; + if (token.type == T.Int32 || + token.type == T.Identifier) + { + tok = token; + nT(); + } else expected(T.Identifier); // TODO: better error msg - nT(); } // if (token.type == T.Assign) @@ -2298,7 +2291,7 @@ // ( Condition ) if (token.type == T.LParen) { - parseIdentOrInt(identCond, levelCond); + parseIdentOrInt(cond); require(T.RParen); } @@ -2317,7 +2310,7 @@ } } - return new DebugStatement(/+levelSpec, identSpec,+/ levelCond, identCond, debugBody, elseBody); + return new DebugStatement(cond, debugBody, elseBody); } Statement parseVersionStatement() @@ -2326,24 +2319,21 @@ nT(); // Skip version keyword. -// int levelSpec = -1; // version = Integer ; -// string identSpec; // version = Identifier ; - int levelCond = -1; // version ( Integer ) - string identCond; // version ( Identifier ) + Token* cond; // version ( Integer ) + // version ( Identifier ) Statement versionBody, elseBody; - void parseIdentOrInt(ref string ident, ref int level) + void parseIdentOrInt(ref Token* tok) { - if (token.type == T.Int32) - level = token.int_; - else if (token.type == T.Identifier) - ident = token.identifier; + nT(); + if (token.type == T.Int32 || + token.type == T.Identifier) + { + tok = token; + nT(); + } else - { expected(T.Identifier); // TODO: better error msg - return; - } - nT(); } // if (token.type == T.Assign) @@ -2359,7 +2349,7 @@ // ( Condition ) require(T.LParen); - parseIdentOrInt(identCond, levelCond); + parseIdentOrInt(cond); require(T.RParen); // version ( Condition ) Statement @@ -2373,7 +2363,7 @@ } } - return new VersionStatement(/+levelSpec, identSpec,+/ levelCond, identCond, versionBody, elseBody); + return new VersionStatement(cond, versionBody, elseBody); } /+++++++++++++++++++++++++++++
--- a/trunk/src/Statements.d Fri Aug 03 17:08:02 2007 +0000 +++ b/trunk/src/Statements.d Fri Aug 03 17:51:02 2007 +0000 @@ -45,7 +45,7 @@ class FunctionBody { Statement funcBody, inBody, outBody; - string outIdent; + Token* outIdent; } class ScopeStatement : Statement @@ -59,9 +59,9 @@ class LabeledStatement : Statement { - string label; + Token* label; Statement s; - this(string label, Statement s) + this(Token* label, Statement s) { this.label = label; this.s = s; @@ -196,8 +196,8 @@ class ContinueStatement : Statement { - string ident; - this(string ident) + Token* ident; + this(Token* ident) { this.ident = ident; } @@ -205,8 +205,8 @@ class BreakStatement : Statement { - string ident; - this(string ident) + Token* ident; + this(Token* ident) { this.ident = ident; } @@ -223,9 +223,9 @@ class GotoStatement : Statement { - string ident; + Token* ident; Expression caseExpr; - this(string ident, Expression caseExpr) + this(Token* ident, Expression caseExpr) { this.ident = ident; this.caseExpr = caseExpr; @@ -289,9 +289,9 @@ class ScopeGuardStatement : Statement { - string condition; + Token* condition; Statement scopeBody; - this(string condition, Statement scopeBody) + this(Token* condition, Statement scopeBody) { this.condition = condition; this.scopeBody = scopeBody; @@ -369,13 +369,11 @@ class DebugStatement : Statement { - int levelCond; - string identCond; + Token* cond; Statement debugBody, elseBody; - this(int levelCond, string identCond, Statement debugBody, Statement elseBody) + this(Token* cond, Statement debugBody, Statement elseBody) { - this.levelCond = levelCond; - this.identCond = identCond; + this.cond = cond; this.debugBody = debugBody; this.elseBody = elseBody; } @@ -383,13 +381,11 @@ class VersionStatement : Statement { - int levelCond; - string identCond; + Token* cond; Statement versionBody, elseBody; - this(int levelCond, string identCond, Statement versionBody, Statement elseBody) + this(Token* cond, Statement versionBody, Statement elseBody) { - this.levelCond = levelCond; - this.identCond = identCond; + this.cond = cond; this.versionBody = versionBody; this.elseBody = elseBody; }
--- a/trunk/src/Types.d Fri Aug 03 17:08:02 2007 +0000 +++ b/trunk/src/Types.d Fri Aug 03 17:51:02 2007 +0000 @@ -297,8 +297,8 @@ class IdentifierType : Type { - string ident; - this(string ident) + Token* ident; + this(Token* ident) { super(TID.Identifier, null); this.ident = ident; @@ -328,9 +328,9 @@ class TemplateInstanceType : Type { - string ident; + Token* ident; TemplateArguments targs; - this(string ident, TemplateArguments targs) + this(Token* ident, TemplateArguments targs) { super(TID.TemplateInstance, null); this.ident = ident;