Skip to content

Commit

Permalink
Revert "fix #158 - handle identifier list containing an indexing expr…
Browse files Browse the repository at this point in the history
…ession (#159)"

This reverts commit abab226.
  • Loading branch information
Basile Burg committed Aug 2, 2017
1 parent abab226 commit 8c836fb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 182 deletions.
41 changes: 13 additions & 28 deletions src/dparse/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public:
/** */ void visit(const FunctionLiteralExpression functionLiteralExpression) { functionLiteralExpression.accept(this); }
/** */ void visit(const GotoStatement gotoStatement) { gotoStatement.accept(this); }
/** */ void visit(const IdentifierChain identifierChain) { identifierChain.accept(this); }
/** */ void visit(const DeclaratorIdentifierList identifierList) { identifierList.accept(this); }
/** */ void visit(const IdentifierList identifierList) { identifierList.accept(this); }
/** */ void visit(const IdentifierOrTemplateChain identifierOrTemplateChain) { identifierOrTemplateChain.accept(this); }
/** */ void visit(const IdentifierOrTemplateInstance identifierOrTemplateInstance) { identifierOrTemplateInstance.accept(this); }
/** */ void visit(const IdentityExpression identityExpression) { identityExpression.accept(this); }
Expand Down Expand Up @@ -322,7 +322,6 @@ public:
/** */ void visit(const TraitsExpression traitsExpression) { traitsExpression.accept(this); }
/** */ void visit(const TryStatement tryStatement) { tryStatement.accept(this); }
/** */ void visit(const Type type) { type.accept(this); }
/** */ void visit(const TypeIdentifierChain typeIdentChain) { typeIdentChain.accept(this); }
/** */ void visit(const Type2 type2) { type2.accept(this); }
/** */ void visit(const TypeSpecialization typeSpecialization) { typeSpecialization.accept(this); }
/** */ void visit(const TypeSuffix typeSuffix) { typeSuffix.accept(this); }
Expand Down Expand Up @@ -443,13 +442,13 @@ final class AliasDeclaration : ASTNode
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(storageClasses, type, declaratorIdentifierList,
initializers, parameters, memberFunctionAttributes));
mixin (visitIfNotNull!(storageClasses, type, identifierList, initializers,
parameters, memberFunctionAttributes));
}
mixin OpEquals;
/** */ StorageClass[] storageClasses;
/** */ Type type;
/** */ DeclaratorIdentifierList declaratorIdentifierList;
/** */ IdentifierList identifierList;
/** */ AliasInitializer[] initializers;
/** */ string comment;
/** */ Parameters parameters;
Expand Down Expand Up @@ -1402,18 +1401,6 @@ public:
mixin OpEquals;
}

///
final class DeclaratorIdentifierList : ASTNode
{
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifiers));
}
/** */ Token[] identifiers;
mixin OpEquals;
}

///
final class DefaultStatement : ASTNode
{
Expand Down Expand Up @@ -1806,18 +1793,14 @@ public:
}

///
final class TypeIdentifierChain : ASTNode
final class IdentifierList : ASTNode
{
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifierOrTemplateInstance, typeIdentifierChain,
indexer));
mixin (visitIfNotNull!(identifiers));
}
/** */ bool dot;
/** */ IdentifierOrTemplateInstance identifierOrTemplateInstance;
/** */ TypeIdentifierChain typeIdentifierChain ;
/** */ ExpressionNode indexer;
/** */ Token[] identifiers;
mixin OpEquals;
}

Expand Down Expand Up @@ -2118,11 +2101,11 @@ final class LinkageAttribute : ASTNode
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifier, typeIdentifierChain));
mixin (visitIfNotNull!(identifier, identifierChain));
}
/** */ Token identifier;
/** */ bool hasPlusPlus;
/** */ TypeIdentifierChain typeIdentifierChain;
/** */ IdentifierChain identifierChain;
/** */ IdType classOrStruct;
mixin OpEquals;
}
Expand Down Expand Up @@ -3152,13 +3135,15 @@ final class Type2 : ASTNode
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(typeofExpression, typeIdentifierChain, type, vector));
mixin (visitIfNotNull!(symbol, typeofExpression,
identifierOrTemplateChain, type, vector));
}

/** */ IdType builtinType;
/** */ alias superOrThis = builtinType;
/** */ Symbol symbol;
/** */ TypeofExpression typeofExpression;
/** */ TypeIdentifierChain typeIdentifierChain;
/** */ IdentifierOrTemplateChain identifierOrTemplateChain;
/** */ IdType typeConstructor;
/** */ Type type;
/** */ Vector vector;
Expand Down
97 changes: 15 additions & 82 deletions src/dparse/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import std.typetuple:TypeTuple;

import dparse.ast;
import dparse.lexer;
version (unittest)
{
import dparse.parser;
import dparse.rollback_allocator;
import std.array : Appender;
import std.algorithm : canFind;
}

//debug = verbose;

Expand Down Expand Up @@ -128,10 +121,7 @@ class Formatter(Sink)
format(type);
space();
}
if (declaratorIdentifierList)
{
format(declaratorIdentifierList);
}
format(identifierList);
}
put(";");
}
Expand Down Expand Up @@ -1561,43 +1551,16 @@ class Formatter(Sink)
}
}

void format(const DeclaratorIdentifierList declaratorIdentifierList)
void format(const IdentifierList identifierList)
{
debug(verbose) writeln("DeclaratorIdentifierList");

foreach(count, ident; declaratorIdentifierList.identifiers)
debug(verbose) writeln("IdentifierList");
foreach(count, ident; identifierList.identifiers)
{
if (count)
put(", ");
if (count) put(", ");
put(ident.text);
}
}

void format(const TypeIdentifierChain typeIdentifierChain)
{
debug(verbose) writeln("TypeIdentifierChain");

if (typeIdentifierChain.dot)
{
put(".");
}
if (typeIdentifierChain.identifierOrTemplateInstance)
{
format(typeIdentifierChain.identifierOrTemplateInstance);
}
if (typeIdentifierChain.indexer)
{
put("[");
format(typeIdentifierChain.indexer);
put("]");
}
if (typeIdentifierChain.typeIdentifierChain)
{
put(".");
format(typeIdentifierChain.typeIdentifierChain);
}
}

void format(const IdentifierOrTemplateChain identifierOrTemplateChain)
{
debug(verbose) writeln("IdentifierOrTemplateChain");
Expand Down Expand Up @@ -2007,10 +1970,10 @@ class Formatter(Sink)
if (linkageAttribute.hasPlusPlus)
{
put("++");
if (linkageAttribute.typeIdentifierChain)
if (linkageAttribute.identifierChain && linkageAttribute.identifierChain.identifiers.length > 0)
{
put(", ");
format(linkageAttribute.typeIdentifierChain);
format(linkageAttribute.identifierChain);
}
else if (linkageAttribute.classOrStruct == tok!"class")
put(", class");
Expand Down Expand Up @@ -3224,23 +3187,24 @@ class Formatter(Sink)

/**
IdType builtinType;
Symbol symbol;
TypeofExpression typeofExpression;
IdentifierList identifierList;
IdentifierOrTemplateChain identifierOrTemplateChain;
IdType typeConstructor;
Type type;
**/

if (type2.typeIdentifierChain !is null)
if (type2.symbol !is null)
{
format(type2.typeIdentifierChain);
format(type2.symbol);
}
else if (type2.typeofExpression !is null)
{
format(type2.typeofExpression);
if (type2.typeIdentifierChain)
if (type2.identifierOrTemplateChain)
{
put(".");
format(type2.typeIdentifierChain);
format(type2.identifierOrTemplateChain);
}
return;
}
Expand All @@ -3254,10 +3218,10 @@ class Formatter(Sink)
else
{
put(tokenRep(type2.builtinType));
if (type2.typeIdentifierChain)
if (type2.identifierOrTemplateChain !is null)
{
put(".");
format(type2.typeIdentifierChain);
format(type2.identifierOrTemplateChain);
}
}
}
Expand Down Expand Up @@ -3903,34 +3867,3 @@ protected:
"postblit"
];
}

version (unittest)
void testFormatNode(Node)(string sourceCode)
{
Appender!string fmt;
ubyte[] code = cast(ubyte[]) sourceCode;

class CatchInterestingStuff : ASTVisitor
{
alias visit = ASTVisitor.visit;
override void visit(const(Node) stuff)
{
stuff.accept(this);
format(&fmt, stuff);
assert(fmt.data.canFind(code), fmt.data);
}
}

LexerConfig config;
StringCache cache = StringCache(32);
RollbackAllocator rba;
auto toks = getTokensForParser(code, config, &cache);
Module mod = parseModule(toks, "stdin", &rba);
(new CatchInterestingStuff).visit(mod);
}

unittest
{
testFormatNode!(VariableDeclaration)("T[0].Y y;");
testFormatNode!(VariableDeclaration)(`.T!"oof" toof;`);
}
Loading

0 comments on commit 8c836fb

Please sign in to comment.