Skip to content
Snippets Groups Projects
Commit 1a3b0a92 authored by Jesper's avatar Jesper
Browse files

[cleanup] Rename pushTopLevelOrAspect

parent 3fe23df9
No related branches found
No related tags found
No related merge requests found
...@@ -570,7 +570,7 @@ public class JastAdd { ...@@ -570,7 +570,7 @@ public class JastAdd {
jp.root = grammar; jp.root = grammar;
jp.setFileName(sourceName); jp.setFileName(sourceName);
jp.className = sourceName; jp.className = sourceName;
jp.pushTopLevelOrAspect("aspect"); jp.pushContext("aspect");
try { try {
jp.AspectBodyDeclarationsEOF(); jp.AspectBodyDeclarationsEOF();
problems.addAll(JastAdd.weaveInterTypeObjects(grammar)); problems.addAll(JastAdd.weaveInterTypeObjects(grammar));
...@@ -579,7 +579,7 @@ public class JastAdd { ...@@ -579,7 +579,7 @@ public class JastAdd {
.message("Internal Error in %s: %s", sourceName, e.getMessage()) .message("Internal Error in %s: %s", sourceName, e.getMessage())
.buildError()); .buildError());
} }
jp.popTopLevelOrAspect(); jp.popContext();
return problems; return problems;
} }
......
/* Copyright (c) 2006, Sun Microsystems, Inc. /* Copyright (c) 2006, Sun Microsystems, Inc.
* 2006-2018, The JastAdd Team * 2006-2021, The JastAdd Team
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -59,6 +59,8 @@ public class JragParser { ...@@ -59,6 +59,8 @@ public class JragParser {
public String enclosingAspect = ""; // The name of the aspect currently being parsed. public String enclosingAspect = ""; // The name of the aspect currently being parsed.
public String fileName; // Name of parsed file. public String fileName; // Name of parsed file.
// TODO(joqvist): the mechanisms for adding class body decl to the enclosing class is very ugly
// and needs to be cleaned up. Either use the context everywhere or remove it?
private java.util.List<String> contextStack = new java.util.ArrayList<String>(); private java.util.List<String> contextStack = new java.util.ArrayList<String>();
public boolean inTopLevelOrAspect() { public boolean inTopLevelOrAspect() {
...@@ -74,11 +76,11 @@ public class JragParser { ...@@ -74,11 +76,11 @@ public class JragParser {
contextStack.get(0).equals("interface")); contextStack.get(0).equals("interface"));
} }
public void pushTopLevelOrAspect(String context) { public void pushContext(String context) {
contextStack.add(context); contextStack.add(context);
} }
public void popTopLevelOrAspect() { public void popContext() {
contextStack.remove(contextStack.size()-1); contextStack.remove(contextStack.size()-1);
} }
...@@ -593,13 +595,13 @@ void TypeDeclaration() : ...@@ -593,13 +595,13 @@ void TypeDeclaration() :
void AspectDeclaration(String modifiers) : void AspectDeclaration(String modifiers) :
{ Token t; } { Token t; }
{ {
"aspect" { pushTopLevelOrAspect("aspect"); } "aspect" { pushContext("aspect"); }
t = <IDENTIFIER> { t = <IDENTIFIER> {
enclosingAspect = t.image; enclosingAspect = t.image;
root.registerAspect(enclosingAspect, Unparser.unparseComment(jjtThis)); root.registerAspect(enclosingAspect, Unparser.unparseComment(jjtThis));
} }
AspectBody() AspectBody()
{ popTopLevelOrAspect(); enclosingAspect = ""; } { popContext(); enclosingAspect = ""; }
} }
void AspectBody() : void AspectBody() :
...@@ -697,7 +699,7 @@ void AspectClassDeclaration() : ...@@ -697,7 +699,7 @@ void AspectClassDeclaration() :
modifiers = Modifiers() modifiers = Modifiers()
first = "class" first = "class"
t = <IDENTIFIER> { t = <IDENTIFIER> {
pushTopLevelOrAspect("class"); pushContext("class");
outerClassName = className; outerClassName = className;
className = t.image; className = t.image;
typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis), typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis),
...@@ -714,7 +716,7 @@ void AspectClassDeclaration() : ...@@ -714,7 +716,7 @@ void AspectClassDeclaration() :
} }
] ]
[ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ] [ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ]
AspectClassBody() { className = outerClassName; popTopLevelOrAspect(); } AspectClassBody() { className = outerClassName; popContext(); }
} }
void AspectClassBody() : void AspectClassBody() :
...@@ -739,7 +741,7 @@ void AspectInterfaceDeclaration() : ...@@ -739,7 +741,7 @@ void AspectInterfaceDeclaration() :
modifiers = Modifiers() modifiers = Modifiers()
first = "interface" first = "interface"
t = <IDENTIFIER> { t = <IDENTIFIER> {
pushTopLevelOrAspect("interface"); pushContext("interface");
outerClassName = className; outerClassName = className;
className = t.image; className = t.image;
typeDecl = root.findInterfaceDecl(className, Unparser.unparseComment(jjtThis), typeDecl = root.findInterfaceDecl(className, Unparser.unparseComment(jjtThis),
...@@ -748,7 +750,7 @@ void AspectInterfaceDeclaration() : ...@@ -748,7 +750,7 @@ void AspectInterfaceDeclaration() :
} }
[ typeParameters = TypeParameters() { typeDecl.typeParameters = typeParameters; } ] [ typeParameters = TypeParameters() { typeDecl.typeParameters = typeParameters; } ]
[ "extends" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ] [ "extends" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ]
"{" ( AspectInterfaceMemberDeclaration() )* "}" { className = outerClassName; popTopLevelOrAspect(); } "{" ( AspectInterfaceMemberDeclaration() )* "}" { className = outerClassName; popContext(); }
} }
void AspectInterfaceMemberDeclaration() : void AspectInterfaceMemberDeclaration() :
...@@ -894,14 +896,14 @@ void AspectNestedInterfaceDeclaration() : ...@@ -894,14 +896,14 @@ void AspectNestedInterfaceDeclaration() :
} }
{ {
modifiers = Modifiers() modifiers = Modifiers()
"interface" { pushTopLevelOrAspect("interface"); } <IDENTIFIER> "interface" { pushContext("interface"); } <IDENTIFIER>
[ TypeParameters() ] [ TypeParameters() ]
[ "extends" TypeNameList() ] [ "extends" TypeNameList() ]
"{" ( InterfaceMemberDeclaration() )* "}" "{" ( InterfaceMemberDeclaration() )* "}"
{ {
className = outerClassName; className = outerClassName;
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
popTopLevelOrAspect(); popContext();
} }
} }
...@@ -914,7 +916,7 @@ void AspectNestedClassDeclaration() : ...@@ -914,7 +916,7 @@ void AspectNestedClassDeclaration() :
} }
{ {
modifiers = Modifiers() modifiers = Modifiers()
"class" { pushTopLevelOrAspect("class"); } <IDENTIFIER> "class" { pushContext("class"); } <IDENTIFIER>
[ TypeParameters() ] [ TypeParameters() ]
[ "extends" ClassOrInterfaceType() ] [ "extends" ClassOrInterfaceType() ]
[ "implements" TypeNameList() ] [ "implements" TypeNameList() ]
...@@ -922,7 +924,7 @@ void AspectNestedClassDeclaration() : ...@@ -922,7 +924,7 @@ void AspectNestedClassDeclaration() :
{ {
className = outerClassName; className = outerClassName;
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
popTopLevelOrAspect(); popContext();
} }
} }
...@@ -1468,7 +1470,7 @@ void ClassDeclaration(String modifiers) : ...@@ -1468,7 +1470,7 @@ void ClassDeclaration(String modifiers) :
{ {
first = "class" first = "class"
t = <IDENTIFIER> { t = <IDENTIFIER> {
pushTopLevelOrAspect("class"); pushContext("class");
outerClassName = className; outerClassName = className;
className = t.image; className = t.image;
typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis), typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis),
...@@ -1483,7 +1485,7 @@ void ClassDeclaration(String modifiers) : ...@@ -1483,7 +1485,7 @@ void ClassDeclaration(String modifiers) :
} }
] ]
[ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName);} ] [ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName);} ]
ClassBody() { className = outerClassName; popTopLevelOrAspect(); } ClassBody() { className = outerClassName; popContext(); }
} }
SimpleNode TypeNameList(): SimpleNode TypeNameList():
...@@ -1505,10 +1507,10 @@ void UnmodifiedClassDeclaration(String modifiers) : ...@@ -1505,10 +1507,10 @@ void UnmodifiedClassDeclaration(String modifiers) :
String outerClassName; String outerClassName;
} }
{ {
"class" t = <IDENTIFIER> { pushTopLevelOrAspect("class"); outerClassName = className; className = t.image; } "class" t = <IDENTIFIER> { pushContext("class"); outerClassName = className; className = t.image; }
[ TypeParameters() ] [ TypeParameters() ]
[ "extends" ClassOrInterfaceType() ] [ "implements" nameList = TypeNameList() ] [ "extends" ClassOrInterfaceType() ] [ "implements" nameList = TypeNameList() ]
ClassBody() { className = outerClassName; popTopLevelOrAspect(); } ClassBody() { className = outerClassName; popContext(); }
{ if (shouldAddClassBodyDecl()) { { if (shouldAddClassBodyDecl()) {
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
} }
...@@ -1529,7 +1531,7 @@ void AspectEnumDeclaration(): ...@@ -1529,7 +1531,7 @@ void AspectEnumDeclaration():
modifiers = Modifiers() modifiers = Modifiers()
first = "enum" first = "enum"
t = <IDENTIFIER> { t = <IDENTIFIER> {
pushTopLevelOrAspect("enum"); pushContext("enum");
outerClassName = className; outerClassName = className;
className = t.image; className = t.image;
typeDecl = (org.jastadd.ast.AST.EnumDecl) root.findEnumDecl(className, Unparser.unparseComment(jjtThis), typeDecl = (org.jastadd.ast.AST.EnumDecl) root.findEnumDecl(className, Unparser.unparseComment(jjtThis),
...@@ -1538,16 +1540,16 @@ void AspectEnumDeclaration(): ...@@ -1538,16 +1540,16 @@ void AspectEnumDeclaration():
typeDecl.simpleNode = jjtThis; typeDecl.simpleNode = jjtThis;
} }
[ "implements" TypeNameList() ] [ "implements" TypeNameList() ]
EnumBody() { className = outerClassName; popTopLevelOrAspect(); } EnumBody() { className = outerClassName; popContext(); }
} }
void UnmodifiedEnumDeclaration(String modifiers): void UnmodifiedEnumDeclaration(String modifiers):
{} {}
{ {
"enum" { pushTopLevelOrAspect("enum"); } JavaIdentifier() "enum" { pushContext("enum"); } JavaIdentifier()
[ "implements" TypeNameList() ] [ "implements" TypeNameList() ]
EnumBody() EnumBody()
{ popTopLevelOrAspect(); { popContext();
if (shouldAddClassBodyDecl()) { if (shouldAddClassBodyDecl()) {
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
} }
...@@ -1658,7 +1660,7 @@ void UnmodifiedInterfaceDeclaration(String modifiers) : ...@@ -1658,7 +1660,7 @@ void UnmodifiedInterfaceDeclaration(String modifiers) :
first = "interface" first = "interface"
t = <IDENTIFIER> { t = <IDENTIFIER> {
isTopLevel = inTopLevelOrAspect(); isTopLevel = inTopLevelOrAspect();
pushTopLevelOrAspect("interface"); pushContext("interface");
outerClassName = className; outerClassName = className;
className = t.image; className = t.image;
if (isTopLevel) { if (isTopLevel) {
...@@ -1669,7 +1671,7 @@ void UnmodifiedInterfaceDeclaration(String modifiers) : ...@@ -1669,7 +1671,7 @@ void UnmodifiedInterfaceDeclaration(String modifiers) :
} }
[ typeParameters = TypeParameters() { if (isTopLevel) typeDecl.typeParameters = typeParameters; } ] [ typeParameters = TypeParameters() { if (isTopLevel) typeDecl.typeParameters = typeParameters; } ]
[ "extends" nameList = TypeNameList() { if (isTopLevel) root.addInterface(nameList, className, fileName); } ] [ "extends" nameList = TypeNameList() { if (isTopLevel) root.addInterface(nameList, className, fileName); } ]
"{" ( InterfaceMemberDeclaration() )* "}" { className = outerClassName; popTopLevelOrAspect(); } "{" ( InterfaceMemberDeclaration() )* "}" { className = outerClassName; popContext(); }
{ if (shouldAddClassBodyDecl()) { { if (shouldAddClassBodyDecl()) {
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
} }
...@@ -2224,7 +2226,7 @@ void ArgumentList() : ...@@ -2224,7 +2226,7 @@ void ArgumentList() :
void AllocationExpression() : void AllocationExpression() :
{ String outerClassName = className; { String outerClassName = className;
className = "D$u$m$m$y"; className = "D$u$m$m$y";
pushTopLevelOrAspect("expr"); pushContext("expr");
} }
{ {
( (
...@@ -2242,7 +2244,7 @@ void AllocationExpression() : ...@@ -2242,7 +2244,7 @@ void AllocationExpression() :
) )
{ {
className = outerClassName; className = outerClassName;
popTopLevelOrAspect(); popContext();
} }
} }
...@@ -2611,7 +2613,7 @@ void MemberValueArrayInitializer(): ...@@ -2611,7 +2613,7 @@ void MemberValueArrayInitializer():
void AnnotationTypeDeclaration(String modifiers): void AnnotationTypeDeclaration(String modifiers):
{} {}
{ {
"@" "interface" { pushTopLevelOrAspect("annotation"); } JavaIdentifier() AnnotationTypeBody() { popTopLevelOrAspect(); } "@" "interface" { pushContext("annotation"); } JavaIdentifier() AnnotationTypeBody() { popContext(); }
{ if (shouldAddClassBodyDecl()) { { if (shouldAddClassBodyDecl()) {
root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment