diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 59fbed2814b..d48dbb86b78 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -32,7 +32,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -222,12 +224,12 @@ public class AST2BaseTest extends TestCase { return s.getExpression(); } - static protected class CNameCollector extends CVisitor.CBaseVisitorAction { + static protected class CNameCollector extends CASTVisitor { { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); - public int processName( IASTName name ){ + public int visit( IASTName name ){ nameList.add( name ); return PROCESS_CONTINUE; } @@ -251,12 +253,12 @@ public class AST2BaseTest extends TestCase { assertEquals( count, num ); } - static protected class CPPNameCollector extends CPPVisitor.CPPBaseVisitorAction { + static protected class CPPNameCollector extends CPPASTVisitor { { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); - public int processName( IASTName name ){ + public int visit( IASTName name ){ nameList.add( name ); return PROCESS_CONTINUE; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 02fbe137034..60d82a3a40b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -379,7 +379,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 13); ICPPNamespace A = (ICPPNamespace) collector.getName(0).resolveBinding(); @@ -409,7 +409,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 6); IVariable vA = (IVariable) collector.getName(0).resolveBinding(); @@ -423,7 +423,7 @@ public class AST2CPPTests extends AST2BaseTest { tu = parse(buffer.toString(), ParserLanguage.CPP); collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); cA = (ICompositeType) collector.getName(1).resolveBinding(); IBinding A = collector.getName(3).resolveBinding(); @@ -442,7 +442,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 9); ICompositeType A = (ICompositeType) collector.getName(0) @@ -472,7 +472,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IFunction f1 = (IFunction) collector.getName(0).resolveBinding(); IFunction f2 = (IFunction) collector.getName(2).resolveBinding(); @@ -492,7 +492,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType anonStruct = (ICPPClassType) collector.getName(0) .resolveBinding(); ICPPField x = (ICPPField) collector.getName(1).resolveBinding(); @@ -517,7 +517,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType A1 = (ICPPClassType) collector.getName(0) .resolveBinding(); @@ -542,7 +542,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType A1 = (ICPPClassType) collector.getName(0) .resolveBinding(); @@ -568,7 +568,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType A1 = (ICPPClassType) collector.getName(0) .resolveBinding(); @@ -589,7 +589,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType x = (ICPPClassType) collector.getName(0).resolveBinding(); @@ -605,7 +605,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IFunction f = (IFunction) collector.getName(0).resolveBinding(); IParameter a = (IParameter) collector.getName(1).resolveBinding(); @@ -628,7 +628,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IFunction f = (IFunction) collector.getName(0).resolveBinding(); IFunction g = (IFunction) collector.getName(1).resolveBinding(); @@ -647,7 +647,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IVariable i = (IVariable) collector.getName(1).resolveBinding(); @@ -663,7 +663,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType A = (ICPPClassType) collector.getName(0).resolveBinding(); IField x = (IField) collector.getName(1).resolveBinding(); @@ -685,7 +685,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IEnumeration hue = (IEnumeration) collector.getName(0).resolveBinding(); IEnumerator red = (IEnumerator) collector.getName(1).resolveBinding(); @@ -709,7 +709,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testPointerToFunction() throws Exception { IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.CPP); //$NON-NLS-1$ CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IVariable pf = (IVariable) collector.getName(0).resolveBinding(); IPointerType pt = (IPointerType) pf.getType(); assertTrue(pt.getType() instanceof IFunctionType); @@ -717,7 +717,7 @@ public class AST2CPPTests extends AST2BaseTest { tu = parse( "struct A; int (*pfi)( int, struct A * );", ParserLanguage.CPP); //$NON-NLS-1$ collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); ICPPClassType A = (ICPPClassType) collector.getName(0).resolveBinding(); pf = (IVariable) collector.getName(1).resolveBinding(); pt = (IPointerType) pf.getType(); @@ -840,7 +840,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IFunction f = (IFunction) collector.getName(0).resolveBinding(); ICPPNamespace A = (ICPPNamespace) collector.getName(1).resolveBinding(); @@ -866,7 +866,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IFunction f = (IFunction) collector.getName(1).resolveBinding(); IFunction g = (IFunction) collector.getName(8).resolveBinding(); @@ -889,7 +889,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); IProblemBinding x = (IProblemBinding) collector.getName(12) .resolveBinding(); @@ -909,7 +909,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 15); @@ -940,7 +940,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 15); @@ -974,7 +974,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 6); @@ -1049,7 +1049,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 8); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -1076,7 +1076,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); IVariable p = (IVariable) col.getName(1).resolveBinding(); @@ -1097,7 +1097,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -1114,7 +1114,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 7); @@ -1128,7 +1128,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testBug84266_2() throws Exception { IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -1137,7 +1137,7 @@ public class AST2CPPTests extends AST2BaseTest { tu = parse("struct s f(void){}", ParserLanguage.CPP); //$NON-NLS-1$ col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -1155,7 +1155,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 13); @@ -1183,7 +1183,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 9); @@ -1231,7 +1231,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPNamespace Y = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace A = (ICPPNamespace) col.getName(3).resolveBinding(); @@ -1262,7 +1262,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 9); @@ -1283,7 +1283,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 11); @@ -1309,7 +1309,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 17); @@ -1368,7 +1368,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testBug84710() throws Exception { IASTTranslationUnit tu = parse("class T { T(); };", ParserLanguage.CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPConstructor T = (ICPPConstructor) col.getName(1).resolveBinding(); assertTrue(CharArrayUtils.equals(T.getNameCharArray(), "T".toCharArray())); //$NON-NLS-1$ @@ -1388,7 +1388,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPNamespace NS = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType T = (ICPPClassType) col.getName(1).resolveBinding(); @@ -1418,7 +1418,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction fref = (IFunction) col.getName(14).resolveBinding(); IFunction f1 = (IFunction) col.getName(1).resolveBinding(); @@ -1449,7 +1449,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(17, col.size()); @@ -1478,7 +1478,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(8, col.size()); @@ -1500,7 +1500,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(9, col.size()); } @@ -1509,7 +1509,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse("struct S; int S::* pm;", //$NON-NLS-1$ ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(4, col.size()); @@ -1534,7 +1534,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IBinding ref = col.getName(11).resolveBinding(); IVariable pm = (IVariable) col.getName(5).resolveBinding(); @@ -1555,7 +1555,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType S = (ICPPClassType) col.getName(0).resolveBinding(); IVariable pm = (IVariable) col.getName(8).resolveBinding(); @@ -1588,7 +1588,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); } public void testFindTypeBinding_1() throws Exception { @@ -1651,7 +1651,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f = (IFunction) col.getName(15).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1679,7 +1679,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f = (IFunction) col.getName(16).resolveBinding(); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -1707,7 +1707,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f = (IFunction) col.getName(27).resolveBinding(); ICPPNamespace M = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -1735,7 +1735,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IFunction set = (IFunction) col.getName(1).resolveBinding(); @@ -1757,7 +1757,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1779,7 +1779,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType N = (ICPPClassType) col.getName(5).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1802,7 +1802,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction helper = (IFunction) col.getName(2).resolveBinding(); assertSame( helper.getScope(), tu.getScope() ); @@ -1827,7 +1827,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); IFunction f2 = (IFunction) col.getName(2).resolveBinding(); @@ -1851,7 +1851,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); IFunction f2 = (IFunction) col.getName(2).resolveBinding(); @@ -1874,7 +1874,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); IFunction f2 = (IFunction) col.getName(2).resolveBinding(); @@ -1894,7 +1894,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); IFunction f2 = (IFunction) col.getName(2).resolveBinding(); @@ -1913,7 +1913,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IVariable g = (IVariable) col.getName(3).resolveBinding(); assertInstances( col, g, 3 ); @@ -1936,7 +1936,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IASTName name = col.getName(11); IBinding [] bs = CPPSemantics.prefixLookup( name ); @@ -1950,7 +1950,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction f = (IFunction) col.getName(1).resolveBinding(); assertTrue( f.isStatic() ); @@ -1988,7 +1988,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType D1 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType D2 = (ICPPClassType) col.getName(4).resolveBinding(); @@ -2020,7 +2020,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); ICPPClassType C = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f = (ICPPMethod) col.getName(1).resolveBinding(); @@ -2049,7 +2049,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IFunction r1 = (IFunction) col.getName(6).resolveBinding(); IFunction r2 = (IFunction) col.getName(8).resolveBinding(); @@ -2070,7 +2070,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPClassType S = (ICPPClassType) col.getName(0).resolveBinding(); IFunction g = (IFunction) col.getName(3).resolveBinding(); @@ -2119,7 +2119,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPConstructor T1_ctor = (ICPPConstructor) col.getName(6).resolveBinding(); ICPPClassType T1 = (ICPPClassType) col.getName(0).resolveBinding(); @@ -2137,7 +2137,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPClassType S = (ICPPClassType) col.getName(0).resolveBinding(); @@ -2164,7 +2164,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); } public void testBug86319() throws Exception { @@ -2179,7 +2179,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IVariable i1 = (IVariable) col.getName(1).resolveBinding(); IVariable i2 = (IVariable) col.getName(3).resolveBinding(); @@ -2204,7 +2204,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPField i = (ICPPField) col.getName(1).resolveBinding(); ICPPField j = (ICPPField) col.getName(2).resolveBinding(); @@ -2244,7 +2244,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IEnumerator enum_x = (IEnumerator) col.getName(3).resolveBinding(); IBinding x_ref = col.getName(4).resolveBinding(); @@ -2275,7 +2275,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); assertEquals( col.size(), 10 ); IVariable d1 = (IVariable) col.getName(6).resolveBinding(); @@ -2298,7 +2298,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction point = (IFunction) col.getName(0).resolveBinding(); @@ -2318,7 +2318,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IVariable i = (IVariable) col.getName(4).resolveBinding(); IVariable i2 = (IVariable) col.getName(7).resolveBinding(); @@ -2340,7 +2340,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction f1 = (IFunction) col.getName(2).resolveBinding(); IFunction f2 = (IFunction) col.getName(5).resolveBinding(); @@ -2366,7 +2366,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction f_ref = (IFunction) col.getName(12).resolveBinding(); IFunction g_ref = (IFunction) col.getName(15).resolveBinding(); @@ -2390,7 +2390,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPNamespace ns = (ICPPNamespace) col.getName(0).resolveBinding(); IASTName [] refs = tu.getReferences( ns ); @@ -2416,7 +2416,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IBinding b = col.getName(7).resolveBinding(); IASTName [] decls = tu.getDeclarations( b ); @@ -2444,7 +2444,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction f_decl = (IFunction) col.getName(10).resolveBinding(); IFunction f_ref = (IFunction) col.getName(19).resolveBinding(); @@ -2466,7 +2466,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IBinding ref1 = col.getName(8).resolveBinding(); IBinding ref2 = col.getName(9).resolveBinding(); @@ -2501,7 +2501,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IBinding ref1 = col.getName(11).resolveBinding(); IBinding ref2 = col.getName(12).resolveBinding(); @@ -2527,7 +2527,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction f = (IFunction) col.getName(3).resolveBinding(); @@ -2548,7 +2548,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPClassType B = (ICPPClassType) col.getName(6).resolveBinding(); ICPPField i = (ICPPField) col.getName(12).resolveBinding(); @@ -2570,7 +2570,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction printf = (IFunction) col.getName(6).resolveBinding(); assertInstances( col, printf, 3 ); @@ -2585,7 +2585,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IVariable m = (IVariable) col.getName(11).resolveBinding(); IParameter a = (IParameter) col.getName(1).resolveBinding(); @@ -2607,7 +2607,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IFunction g1 = (IFunction) col.getName(0).resolveBinding(); ICPPMethod g2 = (ICPPMethod) col.getName(9).resolveBinding(); @@ -2637,7 +2637,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); ICPPField x = (ICPPField) col.getName(23).resolveBinding(); ICPPMethod f = (ICPPMethod) col.getName(24).resolveBinding(); @@ -2661,7 +2661,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); IVariable c = (IVariable) col.getName(1).resolveBinding(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 8502e818671..62fbd21f0ab 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -1136,7 +1136,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 3); IFunction function = (IFunction) collector.getName(0).resolveBinding(); @@ -2502,7 +2502,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IVariable a = (IVariable) col.getName(1).resolveBinding(); assertNotNull(a); @@ -2523,7 +2523,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IVariable a = (IVariable) col.getName(1).resolveBinding(); IFunction g = (IFunction) col.getName(2).resolveBinding(); @@ -2546,7 +2546,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 9); IField x = (IField) col.getName(1).resolveBinding(); @@ -2568,7 +2568,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 6); IEnumerator one = (IEnumerator) col.getName(1).resolveBinding(); @@ -2615,7 +2615,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); ILabel end = (ILabel) col.getName(1).resolveBinding(); @@ -2632,7 +2632,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 5); IEnumeration col = (IEnumeration) collector.getName(0).resolveBinding(); @@ -2646,7 +2646,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse( "struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$ CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector); + tu.accept( collector); assertEquals(collector.size(), 4); IField a = (IField) collector.getName(1).resolveBinding(); @@ -2672,7 +2672,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); IEnumeration e = (IEnumeration) col.getName(0).resolveBinding(); @@ -2692,7 +2692,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); IVariable p = (IVariable) col.getName(1).resolveBinding(); @@ -2713,7 +2713,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -2744,7 +2744,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 7); @@ -2764,7 +2764,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84266_2() throws Exception { IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -2773,7 +2773,7 @@ public class AST2Tests extends AST2BaseTest { tu = parse("struct s f(void){}", ParserLanguage.C); //$NON-NLS-1$ col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 3); @@ -2793,7 +2793,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 6); @@ -2820,7 +2820,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 11); @@ -2849,7 +2849,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 13); @@ -2899,7 +2899,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); assertEquals(col.size(), 26); @@ -2945,7 +2945,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug86766() throws Exception { IASTTranslationUnit tu = parse("char foo; void foo(){}", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col); + tu.accept( col); IVariable foo = (IVariable) col.getName(0).resolveBinding(); IProblemBinding prob = (IProblemBinding) col.getName(1).resolveBinding(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 9a2f3b2c442..0b9dca749c4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -46,6 +46,8 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; @@ -85,12 +87,12 @@ public class CompleteParser2Tests extends TestCase { private static final NullLogService NULL_LOG = new NullLogService(); - static private class CPPNameCollector extends CPPVisitor.CPPBaseVisitorAction { + static private class CPPNameCollector extends CPPASTVisitor { { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); - public int processName( IASTName name ){ + public int visit( IASTName name ){ nameList.add( name ); return PROCESS_CONTINUE; } @@ -101,12 +103,12 @@ public class CompleteParser2Tests extends TestCase { } public int size() { return nameList.size(); } } - static protected class CNameCollector extends CVisitor.CBaseVisitorAction { + static protected class CNameCollector extends CASTVisitor { { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); - public int processName( IASTName name ){ + public int visit( IASTName name ){ nameList.add( name ); return PROCESS_CONTINUE; } @@ -215,7 +217,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 1 ); assertTrue( col.getName(0).resolveBinding() instanceof ICPPNamespace ); @@ -225,7 +227,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { } namespace A { }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -236,7 +238,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { namespace B { } }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -249,7 +251,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 1 ); assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType ); @@ -259,7 +261,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; class B : public A { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -278,7 +280,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace N { class A { }; } class B : protected virtual N::A { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -301,7 +303,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "int x;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 1 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -315,7 +317,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; A x;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -329,7 +331,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace N { class A { }; } N::A x;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -346,7 +348,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; A x, y, z;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -364,7 +366,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { double x; };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -380,7 +382,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n using namespace A::B;\n using A::B::x;using A::B::C;using A::B::C::y;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 21 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -400,7 +402,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -422,7 +424,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "void foo( void );"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); IFunction foo = (IFunction) col.getName(0).resolveBinding(); @@ -437,7 +439,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 8 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -464,7 +466,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { void foo(); };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -477,7 +479,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class U { }; class A { U foo( U areDumb ); };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); ICPPClassType U = (ICPPClassType) col.getName(0).resolveBinding(); @@ -496,7 +498,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 12 ); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -514,7 +516,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "extern \"C\" { int foo(); }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 1 ); IFunction foo = (IFunction) col.getName(0).resolveBinding(); @@ -526,7 +528,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 8 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -551,7 +553,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace N{ class A {}; } using namespace N; class B: public A{};"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -569,7 +571,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "typedef int myInt;\n myInt var;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ITypedef myInt = (ITypedef) col.getName(0).resolveBinding(); @@ -584,7 +586,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A{ }; typedef A ** A_DOUBLEPTR;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -626,7 +628,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { } \n class A::B { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); @@ -649,7 +651,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A; class A * a;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -663,7 +665,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A; A * anA;class A { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -683,7 +685,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "void foo();\n void foo( int );\n"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IFunction foo1 = (IFunction) col.getName(0).resolveBinding(); @@ -696,7 +698,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "int x; int y = x;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -709,7 +711,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "int x = 5; void foo( int sub = x ) { }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -720,7 +722,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "namespace A { int x = 666; } int y = A::x;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -733,7 +735,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "int x = 5;\n class A \n{ public : \n int a; \n A() : a( x ) { } };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -748,7 +750,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const int x = 5; int y [ x ]; "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -763,7 +765,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; A * anA;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -777,7 +779,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; void foo( void ) throw ( A );"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -788,7 +790,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "typedef int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 11 ); ITypedef A = (ITypedef) col.getName(0).resolveBinding(); @@ -817,7 +819,7 @@ public class CompleteParser2Tests extends TestCase { // assertNotNull( dtor.getInitializer() ); // // CPPNameCollector col = new CPPNameCollector(); -// tu.getVisitor().visitTranslationUnit( col ); +// tu.accept( col ); // // assertEquals( col.size(), 3 ); // IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -830,7 +832,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const int max = 5;\n int * x = new int[max];"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IVariable max = (IVariable) col.getName(0).resolveBinding(); @@ -842,7 +844,7 @@ public class CompleteParser2Tests extends TestCase { // Used to cause AST Semantic exception IASTTranslationUnit tu = parse( "class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -864,7 +866,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A{ public: A(); }; \n A::A() {}; \n" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -878,7 +880,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A{ public: ~A(); }; \n A::~A() {}; \n" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -892,7 +894,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; namespace N { class B : public A { struct A {}; }; }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -912,7 +914,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -929,7 +931,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) { x += i; } }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); IVariable FIVE = (IVariable) col.getName(0).resolveBinding(); @@ -945,7 +947,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "union{ int v; char a; } id;" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); @@ -978,7 +980,7 @@ public class CompleteParser2Tests extends TestCase { assertTrue( ifstmt.getElseClause() instanceof IASTCompoundStatement ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); @@ -990,7 +992,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); IVariable T = (IVariable) col.getName(0).resolveBinding(); @@ -1014,7 +1016,7 @@ public class CompleteParser2Tests extends TestCase { " blah : ; " + //$NON-NLS-1$ "} "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -1030,7 +1032,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 6 ); IVariable x = (IVariable) col.getName(0).resolveBinding(); @@ -1043,7 +1045,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { }; void foo() throw ( A ) { throw A; throw; } "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); @@ -1055,7 +1057,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "void foo() { int x = 3; if( x == 1 ) { int x = 4; } else int x = 2; }"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); IVariable x1 = (IVariable) col.getName(1).resolveBinding(); @@ -1071,7 +1073,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "enum E { e1, e2, e3 }; E anE = e1;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); IEnumeration E = (IEnumeration) col.getName(0).resolveBinding(); @@ -1091,7 +1093,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "void foo(); void foo() { } class SearchMe { };"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IFunction foo = (IFunction) col.getName(0).resolveBinding(); @@ -1103,7 +1105,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 10 ); ICompositeType B = (ICompositeType) col.getName(0).resolveBinding(); @@ -1116,7 +1118,7 @@ public class CompleteParser2Tests extends TestCase { public void testBug43503A() throws Exception { IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 8 ); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1143,7 +1145,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( code.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 12 ); ICompositeType OperatorOverload = (ICompositeType) col.getName(0).resolveBinding(); @@ -1161,7 +1163,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class A { static int x; }; int A::x = 5;" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); @@ -1175,7 +1177,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof ( x[w] );" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); IVariable w = (IVariable) col.getName(0).resolveBinding(); @@ -1214,7 +1216,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buff.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 17 ); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); @@ -1236,7 +1238,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } " ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); @@ -1252,7 +1254,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "struct Sample{int size() const; }; struct Sample; " ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); @@ -1266,7 +1268,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); ICPPClassType B = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1281,7 +1283,7 @@ public class CompleteParser2Tests extends TestCase { public void testBug44342() throws Exception { IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 10 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1344,7 +1346,7 @@ public class CompleteParser2Tests extends TestCase { "void main(){ int i = initialize(); }" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); IFunction init1 = (IFunction) col.getName(0).resolveBinding(); @@ -1364,7 +1366,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); ICPPClassType myClass = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1388,7 +1390,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 12 ); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1420,7 +1422,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1444,7 +1446,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 13 ); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); @@ -1468,7 +1470,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 5 ); IFunction x = (IFunction) col.getName(0).resolveBinding(); @@ -1488,7 +1490,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( buffer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); IFunction foo = (IFunction) col.getName(0).resolveBinding(); @@ -1500,7 +1502,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); IProblemBinding p = (IProblemBinding) col.getName(0).resolveBinding(); @@ -1523,7 +1525,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse ("class A{ int getX() {return x[1];} int x[10];};"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); @@ -1548,7 +1550,7 @@ public class CompleteParser2Tests extends TestCase { writer.write( "void f( char * ){} \n" ); //$NON-NLS-1$ IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); @@ -1567,7 +1569,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); IFunction f1 = (IFunction) col.getName(0).resolveBinding(); @@ -1586,7 +1588,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 3 ); @@ -1611,7 +1613,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 11 ); IVariable i = (IVariable)col.getName(1).resolveBinding(); @@ -1629,7 +1631,7 @@ public class CompleteParser2Tests extends TestCase { parse( writer.toString() ); IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 4 ); ICPPField pfi = (ICPPField)col.getName(2).resolveBinding(); @@ -1648,7 +1650,7 @@ public class CompleteParser2Tests extends TestCase { { IASTTranslationUnit tu = parse( "typedef struct blah sb;"); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 2 ); @@ -1680,7 +1682,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 10 ); @@ -1704,7 +1706,7 @@ public class CompleteParser2Tests extends TestCase { writer.write( "void X::f( T ) { } " ); //$NON-NLS-1$ IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 10 ); ICPPClassType X = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1724,7 +1726,7 @@ public class CompleteParser2Tests extends TestCase { writer.write( "class AltG3 : AltG2 { int x;};"); //$NON-NLS-1$ IASTTranslationUnit tu = parse( writer.toString() ); CPPNameCollector col = new CPPNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 7 ); ICPPClassType G2 = (ICPPClassType) col.getName(0).resolveBinding(); @@ -1746,7 +1748,7 @@ public class CompleteParser2Tests extends TestCase { IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.C ); CNameCollector col = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( col ); + tu.accept( col ); assertEquals( col.size(), 9 ); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java index e50498ac737..33574eb7665 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java @@ -51,7 +51,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 33 ); ICompositeType x = (ICompositeType) collector.getName( 0 ).resolveBinding(); @@ -92,7 +92,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 5 ); IFunction f = (IFunction) collector.getName( 0 ).resolveBinding(); @@ -119,7 +119,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 12 ); @@ -157,7 +157,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 16 ); IVariable loop1 = (IVariable) collector.getName( 0 ).resolveBinding(); @@ -191,7 +191,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 11 ); IVariable nResult = (IVariable) collector.getName( 1 ).resolveBinding(); @@ -219,7 +219,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 11 ); IVariable f = (IVariable) collector.getName( 0 ).resolveBinding(); @@ -249,7 +249,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 19 ); IFunction buggy = (IFunction) collector.getName(0).resolveBinding(); @@ -284,7 +284,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 7 ); IVariable winds = (IVariable) collector.getName( 1 ).resolveBinding(); @@ -310,7 +310,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 15 ); ITypedef uint64 = (ITypedef) collector.getName( 0 ).resolveBinding(); @@ -348,7 +348,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 34 ); IVariable aa = (IVariable) collector.getName( 0 ).resolveBinding(); @@ -390,7 +390,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 11 ); IVariable i = (IVariable) collector.getName( 0 ).resolveBinding(); @@ -419,7 +419,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 14 ); IFunction f = (IFunction) collector.getName( 0 ).resolveBinding(); @@ -459,7 +459,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 36 ); IField y = (IField) collector.getName( 1 ).resolveBinding(); @@ -504,7 +504,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 43 ); IFunction f = (IFunction) collector.getName( 0 ).resolveBinding(); @@ -550,7 +550,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 10 ); IField node = (IField) collector.getName( 3 ).resolveBinding(); @@ -579,7 +579,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 25 ); ICompositeType foo = (ICompositeType) collector.getName( 0 ).resolveBinding(); @@ -621,7 +621,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 6 ); IFunction sub = (IFunction) collector.getName( 0 ).resolveBinding(); @@ -663,7 +663,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 95 ); IFunction f = (IFunction) collector.getName( 0 ).resolveBinding(); @@ -703,7 +703,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 22 ); ICompositeType s1 = (ICompositeType) collector.getName( 0 ).resolveBinding(); @@ -741,7 +741,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 27 ); ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding(); @@ -779,7 +779,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 14 ); ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding(); @@ -810,7 +810,7 @@ public class GCCTests extends AST2BaseTest { IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); CNameCollector collector = new CNameCollector(); - tu.getVisitor().visitTranslationUnit( collector ); + tu.accept( collector ); assertEquals( collector.size(), 11 ); IEnumeration foo = (IEnumeration) collector.getName( 0 ).resolveBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java new file mode 100644 index 00000000000..97ecf1e2148 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Mar 8, 2005 + */ +package org.eclipse.cdt.core.dom.ast; + +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; + + +public abstract class ASTVisitor { + public boolean shouldVisitNames = false; + public boolean shouldVisitDeclarations = false; + public boolean shouldVisitInitializers = false; + public boolean shouldVisitParameterDeclarations = false; + public boolean shouldVisitDeclarators = false; + public boolean shouldVisitDeclSpecifiers = false; + public boolean shouldVisitExpressions = false; + public boolean shouldVisitStatements = false; + public boolean shouldVisitTypeIds = false; + public boolean shouldVisitEnumerators = false; + public boolean shouldVisitTranslationUnit = false; + + /** + * @return continue to continue visiting, abort to stop, skip to not descend into this node. + */ + public final static int PROCESS_SKIP = 1; + public final static int PROCESS_ABORT = 2; + public final static int PROCESS_CONTINUE = 3; + + + public int visit( IASTTranslationUnit tu ) { return PROCESS_CONTINUE; } + public int visit( IASTName name ) { return PROCESS_CONTINUE; } + public int visit( IASTDeclaration declaration ) { return PROCESS_CONTINUE; } + public int visit( IASTInitializer initializer ) { return PROCESS_CONTINUE; } + public int visit( IASTParameterDeclaration parameterDeclaration ) { return PROCESS_CONTINUE; } + public int visit( IASTDeclarator declarator ) { return PROCESS_CONTINUE; } + public int visit( IASTDeclSpecifier declSpec ) {return PROCESS_CONTINUE; } + public int visit( IASTExpression expression ) { return PROCESS_CONTINUE; } + public int visit( IASTStatement statement ) { return PROCESS_CONTINUE; } + public int visit( IASTTypeId typeId ) { return PROCESS_CONTINUE; } + public int visit( IASTEnumerator enumerator ) { return PROCESS_CONTINUE; } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java index bc3e68d66db..9e6c404da73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java @@ -40,5 +40,6 @@ public interface IASTNode { public void setPropertyInParent( ASTNodeProperty property ); + public boolean accept( ASTVisitor visitor ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index b3a8701db87..df08ce22b59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -73,7 +73,5 @@ public interface IASTTranslationUnit extends IASTNode { public String getUnpreprocessedSignature( IASTNodeLocation [] locations ); - public IASTVisitor getVisitor(); - public String getFilePath(); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTVisitor.java deleted file mode 100644 index 56d7dacee97..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTVisitor.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Feb 22, 2005 - */ -package org.eclipse.cdt.core.dom.ast; - -import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; - -/** - * @author aniefer - */ -public interface IASTVisitor { - public static abstract class BaseVisitorAction { - public boolean processNames = false; - public boolean processDeclarations = false; - public boolean processInitializers = false; - public boolean processParameterDeclarations = false; - public boolean processDeclarators = false; - public boolean processDeclSpecifiers = false; - public boolean processExpressions = false; - public boolean processStatements = false; - public boolean processTypeIds = false; - public boolean processEnumerators = false; - - /** - * @return continue to continue visiting, abort to stop, skip to not descend into this node. - */ - public final static int PROCESS_SKIP = 1; - public final static int PROCESS_ABORT = 2; - public final static int PROCESS_CONTINUE = 3; - - - public int processName( IASTName name ) { return PROCESS_CONTINUE; } - public int processDeclaration( IASTDeclaration declaration ){ return PROCESS_CONTINUE; } - public int processInitializer( IASTInitializer initializer ){ return PROCESS_CONTINUE; } - public int processParameterDeclaration( IASTParameterDeclaration parameterDeclaration ) { return PROCESS_CONTINUE; } - public int processDeclarator( IASTDeclarator declarator ) { return PROCESS_CONTINUE; } - public int processDeclSpecifier( IASTDeclSpecifier declSpec ){return PROCESS_CONTINUE; } - public int processExpression( IASTExpression expression ) { return PROCESS_CONTINUE; } - public int processStatement( IASTStatement statement ) { return PROCESS_CONTINUE; } - public int processTypeId( IASTTypeId typeId ) { return PROCESS_CONTINUE; } - public int processEnumerator( IASTEnumerator enumerator ) { return PROCESS_CONTINUE; } - } - - public void visitTranslationUnit( BaseVisitorAction action ); - public boolean visitDeclaration( IASTDeclaration declaration, BaseVisitorAction action ); - public boolean visitName( IASTName name, BaseVisitorAction action ); - public boolean visitDeclSpecifier( IASTDeclSpecifier declSpecifier, BaseVisitorAction action ); - public boolean visitDeclarator( IASTDeclarator declarator, BaseVisitorAction action ); - public boolean visitStatement( IASTStatement statement, BaseVisitorAction action ); - public boolean visitExpression( IASTExpression expression, BaseVisitorAction action ); - public boolean visitTypeId( IASTTypeId typeId, BaseVisitorAction action ); - public boolean visitInitializer( IASTInitializer initializer, BaseVisitorAction action ); - public boolean visitEnumerator( IASTEnumerator enumerator, BaseVisitorAction action ); - public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, BaseVisitorAction action ); -} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/CASTVisitor.java similarity index 55% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTVisitor.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/CASTVisitor.java index 7266b2073cd..72832c7442b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/CASTVisitor.java @@ -10,22 +10,15 @@ *******************************************************************************/ /* - * Created on Feb 22, 2005 + * Created on Mar 8, 2005 */ package org.eclipse.cdt.core.dom.ast.c; -import org.eclipse.cdt.core.dom.ast.IASTVisitor; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; -/** - * @author aniefer - */ -public interface ICASTVisitor extends IASTVisitor { - - public static abstract class CBaseVisitorAction extends BaseVisitorAction { - public boolean processDesignators = false; - - public int processDesignator( ICASTDesignator designator ) { return PROCESS_CONTINUE; } - } - public boolean visitDesignator( ICASTDesignator designator, BaseVisitorAction action ); +public abstract class CASTVisitor extends ASTVisitor { + public boolean shouldVisitDesignators = false; + + public int visit( ICASTDesignator designator ) { return PROCESS_CONTINUE; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/CPPASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/CPPASTVisitor.java new file mode 100644 index 00000000000..fcd2418ebcb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/CPPASTVisitor.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Mar 8, 2005 + */ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; + + +public abstract class CPPASTVisitor extends ASTVisitor{ + public boolean shouldVisitBaseSpecifiers = false; + public boolean shouldVisitNamespaces = false; + public boolean shouldVisitTemplateParameters = false; + + public int visit( ICPPASTBaseSpecifier specifier ) { return PROCESS_CONTINUE; } + public int visit( ICPPASTNamespaceDefinition namespace ){ return PROCESS_CONTINUE; } + public int visit( ICPPASTTemplateParameter parameter ) { return PROCESS_CONTINUE; } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTVisitor.java deleted file mode 100644 index 7b28fa52eac..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTVisitor.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Feb 22, 2005 - */ -package org.eclipse.cdt.core.dom.ast.cpp; - -import org.eclipse.cdt.core.dom.ast.IASTVisitor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; - -/** - * @author aniefer - */ -public interface ICPPASTVisitor extends IASTVisitor { - - public static abstract class CPPBaseVisitorAction extends BaseVisitorAction{ - public boolean processBaseSpecifiers = false; - public boolean processNamespaces = false; - public boolean processTemplateParameters = false; - - public int processBaseSpecifier(ICPPASTBaseSpecifier specifier) { return PROCESS_CONTINUE; } - public int processNamespace( ICPPASTNamespaceDefinition namespace) { return PROCESS_CONTINUE; } - public int processTemplateParameter( ICPPASTTemplateParameter parameter) { return PROCESS_CONTINUE; } - } - - - public boolean visitNamespaceDefinition( ICPPASTNamespaceDefinition namespace, BaseVisitorAction action ); - public abstract boolean visitBaseSpecifier( ICPPASTBaseSpecifier specifier, BaseVisitorAction action ); - public abstract boolean visitTemplateParameter( ICPPASTTemplateParameter parameter, BaseVisitorAction action ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java index 4403a0ac007..4a0dd5ccc8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; /** @@ -32,4 +33,14 @@ public class CASTASMDeclaration extends CASTNode implements IASTASMDeclaration { this.assembly = assembly.toCharArray(); } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java index 6cc9d41f174..6b5cdd8cc61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java @@ -9,8 +9,10 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; /** * @author jcamelon @@ -61,4 +63,13 @@ public class CASTArrayDeclarator extends CASTDeclarator implements arrayMods[ currentIndex++ ] = arrayModifier; } + protected boolean postAccept( ASTVisitor action ){ + IASTArrayModifier [] mods = getArrayModifiers(); + for ( int i = 0; i < mods.length; i++ ) { + if( !mods[i].accept( action ) ) return false; + } + IASTInitializer initializer = getInitializer(); + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java index 24f402fa2c8..a09f98d7042 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java @@ -9,7 +9,9 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; /** @@ -34,4 +36,15 @@ public class CASTArrayDesignator extends CASTNode implements exp = value; } + public boolean accept( ASTVisitor action ){ + if( action instanceof CASTVisitor && ((CASTVisitor)action).shouldVisitDesignators ){ + switch( ((CASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( exp != null ) if( !exp.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java index f827bc74cc2..e7b93eac9ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -33,4 +34,8 @@ public class CASTArrayModifier extends CASTNode implements IASTArrayModifier { this.exp = expression; } + public boolean accept( ASTVisitor action ){ + if( exp != null ) if( !exp.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java index dc1b0b6d3ce..0c14c69c83f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java @@ -9,7 +9,9 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; /** @@ -48,4 +50,16 @@ public class CASTArrayRangeDesignator extends CASTNode implements ceiling = expression; } + public boolean accept( ASTVisitor action ){ + if( action instanceof CASTVisitor && ((CASTVisitor)action).shouldVisitDesignators ){ + switch( ((CASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( floor != null ) if( !floor.accept( action ) ) return false; + if( ceiling != null ) if( !ceiling.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java index aac11b0cc83..9b0ef73d421 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -49,4 +50,17 @@ public class CASTArraySubscriptExpression extends CASTNode implements this.subscript = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( array != null ) if( !array.accept( action ) ) return false; + if( subscript != null ) if( !subscript.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java index e80104ddc11..e11533f16b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -64,4 +65,17 @@ public class CASTBinaryExpression extends CASTNode implements operand2 = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( operand1 != null ) if( !operand1.accept( action ) ) return false; + if( operand2 != null ) if( !operand2.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java index c1b7c2886a6..dcf958da0b1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; /** @@ -16,4 +17,14 @@ import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; */ public class CASTBreakStatement extends CASTNode implements IASTBreakStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java index 916b30bb5c7..2ebf1836467 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -33,4 +34,16 @@ public class CASTCaseStatement extends CASTNode implements IASTCaseStatement { this.expression = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( expression != null ) if( !expression.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java index a10e2bfb695..948d7be2995 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java @@ -9,8 +9,10 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; -import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; /** * @author jcamelon @@ -34,4 +36,18 @@ public class CASTCastExpression extends CASTUnaryExpression implements return typeId; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( typeId != null ) if( !typeId.accept( action ) ) return false; + IASTExpression operand = getOperand(); + if( operand != null ) if( !operand.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index 6726ec65ee8..c3911fecde9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; @@ -118,4 +119,20 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements return getName().toString() == null ? "" : getName().toString(); //$NON-NLS-1$ } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + + IASTDeclaration [] decls = getMembers(); + for( int i = 0; i < decls.length; i++ ) + if( !decls[i].accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java index 2d00b433667..bbcb26131c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; @@ -77,4 +78,19 @@ public class CASTCompoundStatement extends CASTNode implements return scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTStatement [] s = getStatements(); + for ( int i = 0; i < s.length; i++ ) { + if( !s[i].accept( action ) ) return false; + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java index 196d9c48aae..7efa16e1f50 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; @@ -34,4 +35,16 @@ public class CASTCompoundStatementExpression extends CASTNode implements this.statement = statement; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( statement != null ) if( !statement.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java index 6bb5cb7f7ca..efc8129da05 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -64,4 +65,18 @@ public class CASTConditionalExpression extends CASTNode implements this.negative = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( condition != null ) if( !condition.accept( action ) ) return false; + if( postive != null ) if( !postive.accept( action ) ) return false; + if( negative != null ) if( !negative.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java index 2f67fb366f2..9516a2e09df 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; /** @@ -17,4 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; public class CASTContinueStatement extends CASTNode implements IASTContinueStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java index 7d821a8fc3b..a61cbd6c5df 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; @@ -34,4 +35,15 @@ public class CASTDeclarationStatement extends CASTNode implements this.declaration = declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( declaration != null ) if( !declaration.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index 61078e4031e..9caff255089 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -9,10 +9,12 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; /** * @author jcamelon @@ -110,4 +112,32 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarators ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && + nestedDeclarator == null ) + { + if( name != null ) if( !name.accept( action ) ) return false; + } + if( nestedDeclarator != null ) if( !nestedDeclarator.accept( action ) ) return false; + + IASTPointerOperator [] ptrOps = getPointerOperators(); + for ( int i = 0; i < ptrOps.length; i++ ) { + if( !ptrOps[i].accept( action ) ) return false; + } + + return postAccept( action ); + } + + protected boolean postAccept( ASTVisitor action ){ + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java index d8f11340cfc..092e4906601 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; /** @@ -17,4 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; public class CASTDefaultStatement extends CASTNode implements IASTDefaultStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java index 0db9f06c410..ed5c9f3f1d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; @@ -81,4 +82,20 @@ public class CASTDesignatedInitializer extends CASTNode implements this.rhs = rhs; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + ICASTDesignator [] ds = getDesignators(); + for ( int i = 0; i < ds.length; i++ ) { + if( !ds[i].accept( action ) ) return false; + } + if( rhs != null ) if( !rhs.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java index a86f4962ffb..03607aaeb22 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; @@ -49,4 +50,16 @@ public class CASTDoStatement extends CASTNode implements IASTDoStatement { this.condition = condition; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( body != null ) if( !body.accept( action ) ) return false; + if( condition != null ) if( !condition.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java index 818d0ba665f..7ae6a3c152a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; @@ -49,4 +50,15 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java index c61b66788d7..53b967041eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; @@ -87,4 +88,20 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements return getName().toString() == null ? "" : getName().toString(); //$NON-NLS-1$ } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + IASTEnumerator[] etors = getEnumerators(); + for ( int i = 0; i < etors.length; i++ ) { + if( !etors[i].accept( action ) ) return false; + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java index 1062c37bb3b..701c76b3bdf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; @@ -49,4 +50,17 @@ public class CASTEnumerator extends CASTNode implements IASTEnumerator { return value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitEnumerators ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + if( value != null ) if( !value.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java index dec4e8fe78e..5fe0397e960 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; @@ -66,4 +67,19 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList { private IASTExpression [] expressions = null; private static final int DEFAULT_EXPRESSIONLIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + IASTExpression [] exps = getExpressions(); + for( int i = 0; i < exps.length; i++ ) + if( !exps[i].accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java index 815ac97683f..c22cb50fb8c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; @@ -34,4 +35,16 @@ public class CASTExpressionStatement extends CASTNode implements this.expression = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( expression != null ) if( !expression.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java index 5fc73f8a395..07f4712d6a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java @@ -9,8 +9,10 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; /** * @author jcamelon @@ -34,5 +36,11 @@ public class CASTFieldDeclarator extends CASTDeclarator implements bitFieldSize = size; } - + protected boolean postAccept( ASTVisitor action ){ + if( bitFieldSize != null ) if( !bitFieldSize.accept( action ) ) return false; + + IASTInitializer initializer = getInitializer(); + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java index c4710b69431..8159ad65b84 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java @@ -9,7 +9,9 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; /** @@ -34,4 +36,15 @@ public class CASTFieldDesignator extends CASTNode implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action instanceof CASTVisitor && ((CASTVisitor)action).shouldVisitDesignators ){ + switch( ((CASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java index 276fed39012..2fa97e16917 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -64,4 +65,17 @@ public class CASTFieldReference extends CASTNode implements IASTFieldReference { ptr = value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( owner != null ) if( !owner.accept( action ) ) return false; + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java index 793d9a6c12a..fd4d617e0f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTForStatement; @@ -107,4 +108,20 @@ public class CASTForStatement extends CASTNode implements IASTForStatement { return scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( initDeclaration != null ) if( !initDeclaration.accept( action ) ) return false; + if( initialExpression != null ) if( !initialExpression.accept( action ) ) return false; + if( condition != null ) if( !condition.accept( action ) ) return false; + if( iterationExpression != null ) if( !iterationExpression.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java index 3a7da4b4e82..953dfde2ac2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; @@ -49,4 +50,18 @@ public class CASTFunctionCallExpression extends CASTNode implements return parameter; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( functionName != null ) if( !functionName.accept( action ) ) return false; + if( parameter != null ) if( !parameter.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java index 4207d3ef518..8671e92f1b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java @@ -9,8 +9,9 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; -import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; /** * @author jcamelon @@ -84,4 +85,11 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements varArgs = value; } + protected boolean postAccept( ASTVisitor action ){ + IASTParameterDeclaration [] params = getParameters(); + for ( int i = 0; i < params.length; i++ ) { + if( !params[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java index 093dac18411..55dca2f00a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; @@ -78,4 +79,19 @@ public class CASTFunctionDefinition extends CASTNode implements return scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; + if( declarator != null ) if( !declarator.accept( action ) ) return false; + if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java index a6a6f53262c..bf2f270e260 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -33,4 +34,15 @@ public class CASTGotoStatement extends CASTNode implements IASTGotoStatement { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java index bdb7f505b84..5b57aa52dd2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -33,4 +34,16 @@ public class CASTIdExpression extends CASTNode implements IASTIdExpression { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java index d48e9873fe6..9245940f8fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; @@ -64,4 +65,17 @@ public class CASTIfStatement extends CASTNode implements IASTIfStatement { this.elseClause = elseClause; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( condition != null ) if( !condition.accept( action ) ) return false; + if( thenClause != null ) if( !thenClause.accept( action ) ) return false; + if( elseClause != null ) if( !elseClause.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java index 7ebd179ac4b..5f32e5834b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; @@ -33,5 +34,17 @@ public class CASTInitializerExpression extends CASTNode implements public void setExpression(IASTExpression expression) { this.expression = expression; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( expression != null ) if( !expression.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java index e9ace4fed77..f32b312c25f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; @@ -69,4 +70,19 @@ public class CASTInitializerList extends CASTNode implements private IASTInitializer [] initializers = null; private static final int DEFAULT_INITIALIZERS_LIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTInitializer [] list = getInitializers(); + for ( int i = 0; i < list.length; i++ ) { + if( !list[i].accept( action ) ) return false; + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java index af959349ed7..39cf9b758eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; @@ -52,4 +53,17 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn return parameterDeclarations; } + protected boolean postAccept( ASTVisitor action ){ + IASTName [] ns = getParameterNames(); + for ( int i = 0; i < ns.length; i++ ) { + if( !ns[i].accept( action ) ) return false; + } + + IASTDeclaration [] params = getParameterDeclarations(); + for ( int i = 0; i < params.length; i++ ) { + if( !params[i].accept( action ) ) return false; + } + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java index 6093d8378c5..3fa5add9d30 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -33,4 +34,15 @@ public class CASTLabelStatement extends CASTNode implements IASTLabelStatement { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java index a148827f562..7ad4763f257 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; /** @@ -48,4 +49,14 @@ public class CASTLiteralExpression extends CASTNode implements return value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java index 7b9c1612bc9..e1513a5529d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -69,4 +70,16 @@ public class CASTName extends CASTNode implements IASTName { public char[] toCharArray() { return name; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitNames ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java index 421904c1198..9c0b907a5b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -62,4 +63,7 @@ public class CASTNode extends ASTNode implements IASTNode { return (IASTTranslationUnit) node; } + public boolean accept( ASTVisitor action ){ + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java index a18ba786394..a4bd4dbd851 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; /** @@ -16,4 +17,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNullStatement; */ public class CASTNullStatement extends CASTNode implements IASTNullStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java index b27d10f2d11..2d8a4fade58 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; @@ -50,4 +51,17 @@ public class CASTParameterDeclaration extends CASTNode implements this.declarator = declarator; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitParameterDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpec != null ) if( !declSpec.accept( action ) ) return false; + if( declarator != null ) if( !declarator.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java index 1fdac5290dc..10abef79b6b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; /** @@ -18,4 +19,15 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; public class CASTProblemDeclaration extends CASTProblemOwner implements IASTProblemDeclaration { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java index 3bbe6a5c26b..00f5e67f848 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; /** @@ -18,4 +19,14 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; public class CASTProblemExpression extends CASTProblemOwner implements IASTProblemExpression { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java index 74c99081a1d..98e22a5c4e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; /** @@ -17,5 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; */ public class CASTProblemStatement extends CASTProblemOwner implements IASTProblemStatement { - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java index c20a7dae2a7..b49eccc45fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; @@ -34,4 +35,15 @@ public class CASTReturnStatement extends CASTNode implements retValue = returnValue; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( retValue != null ) if( !retValue.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java index fce24c74cd7..8d4fe171148 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; /** @@ -108,4 +109,15 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC longlong = value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index 42b00233b74..30fc6e86c3e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -79,4 +80,21 @@ public class CASTSimpleDeclaration extends CASTNode implements public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { this.declSpecifier = declSpecifier; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; + IASTDeclarator [] dtors = getDeclarators(); + for( int i = 0; i < dtors.length; i++ ) + if( !dtors[i].accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java index 22f24975577..c65e2945f00 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; @@ -50,4 +51,16 @@ public class CASTSwitchStatement extends CASTNode implements this.body = body; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( controller != null ) if( !controller.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 49c69e19adf..9f38b68c747 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -30,9 +31,9 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IASTVisitor; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -55,8 +56,6 @@ public class CASTTranslationUnit extends CASTNode implements // Binding private CScope compilationUnit = null; - private CVisitor visitor = null; - private ILocationResolver resolver; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; @@ -158,19 +157,19 @@ public class CASTTranslationUnit extends CASTNode implements return resolver.getLocations(offset, length); } - private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction { + private class CFindNodeForOffsetAction extends CASTVisitor { { - processNames = true; - processDeclarations = true; - processInitializers = true; - processParameterDeclarations = true; - processDeclarators = true; - processDeclSpecifiers = true; - processDesignators = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; - processEnumerators = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; + shouldVisitInitializers = true; + shouldVisitParameterDeclarations = true; + shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitDesignators = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; + shouldVisitEnumerators = true; } IASTNode foundNode = null; @@ -213,7 +212,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { // use declarations to determine if the search has gone past the // offset (i.e. don't know the order the visitor visits the nodes) if (declaration instanceof ASTNode @@ -228,7 +227,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ - public int processDeclarator(IASTDeclarator declarator) { + public int visit(IASTDeclarator declarator) { int ret = processNode(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); @@ -250,7 +249,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) */ - public int processDesignator(ICASTDesignator designator) { + public int visit(ICASTDesignator designator) { return processNode(designator); } @@ -259,7 +258,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ - public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + public int visit(IASTDeclSpecifier declSpec) { return processNode(declSpec); } @@ -268,7 +267,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ - public int processEnumerator(IASTEnumerator enumerator) { + public int visit(IASTEnumerator enumerator) { return processNode((IASTNode) enumerator); } @@ -277,7 +276,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { return processNode(expression); } @@ -286,7 +285,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ - public int processInitializer(IASTInitializer initializer) { + public int visit(IASTInitializer initializer) { return processNode(initializer); } @@ -295,7 +294,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) */ - public int processName(IASTName name) { + public int visit(IASTName name) { if (name.toString() != null) return processNode(name); return PROCESS_CONTINUE; @@ -306,7 +305,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ - public int processParameterDeclaration( + public int visit( IASTParameterDeclaration parameterDeclaration) { return processNode(parameterDeclaration); } @@ -316,7 +315,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { return processNode(statement); } @@ -325,7 +324,7 @@ public class CASTTranslationUnit extends CASTNode implements * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { return processNode(typeId); } @@ -358,7 +357,7 @@ public class CASTTranslationUnit extends CASTNode implements globalOffset = result == null ? globalOffset : result.getGlobalOffset(); if (globalOffset >= 0) { CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(globalOffset, realLength); - getVisitor().visitTranslationUnit(nodeFinder); + accept(nodeFinder); node = nodeFinder.getNode(); } } @@ -471,17 +470,6 @@ public class CASTTranslationUnit extends CASTNode implements return new String(resolver.getUnpreprocessedSignature(locations)); } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor() - */ - public IASTVisitor getVisitor() { - if (visitor == null) - visitor = new CVisitor(this); - return visitor; - } - /* * (non-Javadoc) * @@ -492,4 +480,19 @@ public class CASTTranslationUnit extends CASTNode implements return EMPTY_STRING; return new String(resolver.getTranslationUnitPath()); } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitTranslationUnit){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTDeclaration [] ds = getDeclarations(); + for( int i = 0; i < ds.length; i++ ){ + if( !ds[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java index 68db2adc9c2..a0b28510f88 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; @@ -50,4 +51,17 @@ public class CASTTypeId extends CASTNode implements IASTTypeId { } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitTypeIds ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; + if( declarator != null ) if( !declarator.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java index d6549598e34..7c90626d9c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; @@ -49,4 +50,16 @@ public class CASTTypeIdExpression extends CASTNode implements return typeId; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( typeId != null ) if( !typeId.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java index 0d051d1224e..458d3cd4d82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; @@ -50,4 +51,17 @@ public class CASTTypeIdInitializerExpression extends CASTNode implements i = initializer; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( t != null ) if( !t.accept( action ) ) return false; + if( i != null ) if( !i.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java index 2301164dff2..c494fd6a597 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; @@ -33,4 +34,16 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java index 8ee6c74e63c..96b563e2a87 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; @@ -49,4 +50,16 @@ public class CASTUnaryExpression extends CASTNode implements operand = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( operand != null ) if( !operand.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java index ba65348b7d3..845c0e1cd3e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java @@ -9,6 +9,7 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; @@ -48,5 +49,18 @@ public class CASTWhileStatement extends CASTNode implements IASTWhileStatement { public void setBody(IASTStatement body) { this.body = body; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( condition != null ) if( !condition.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java index f14f17cd4c3..615d57e54a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java @@ -17,8 +17,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IASTVisitor; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; @@ -74,12 +72,8 @@ public class CCompositeTypeScope implements ICCompositeTypeScope { * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) */ public IBinding[] find( String name ) { - IASTNode node = getPhysicalNode(); - IASTTranslationUnit tu = node.getTranslationUnit(); - IASTVisitor visitor = tu.getVisitor(); - CollectNamesAction action = new CollectNamesAction( name.toCharArray() ); - visitor.visitDeclSpecifier( compositeTypeSpec, action ); + compositeTypeSpec.accept( action ); IASTName [] names = action.getNames(); IBinding [] result = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java index 7a1621d7c6d..ca89b4d4606 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java @@ -19,9 +19,9 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.c.ICScope; -import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor.CBaseVisitorAction; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; @@ -86,7 +86,7 @@ public class CFunctionScope implements ICFunctionScope { public ILabel[] getLabels(){ FindLabelsAction action = new FindLabelsAction(); - function.getTranslationUnit().getVisitor().visitDeclaration( function, action ); + function.accept( action ); ILabel [] result = null; if( action.labels != null ){ @@ -100,14 +100,14 @@ public class CFunctionScope implements ICFunctionScope { return (ILabel[]) ArrayUtil.trim( ILabel.class, result ); } - static private class FindLabelsAction extends CBaseVisitorAction { + static private class FindLabelsAction extends CASTVisitor { public IASTLabelStatement [] labels = null; public FindLabelsAction(){ - processStatements = true; + shouldVisitStatements = true; } - public int processStatement( IASTStatement statement ) { + public int visit( IASTStatement statement ) { if( statement instanceof IASTLabelStatement ){ labels = (IASTLabelStatement[]) ArrayUtil.append( IASTLabelStatement.class, labels, statement ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java index 9a5cfccdda8..4a3b6fa26f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java @@ -23,13 +23,11 @@ import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IASTVisitor; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; @@ -54,14 +52,14 @@ public class CScope implements ICScope { return CVisitor.getContainingScope( physicalNode ); } - protected static class CollectNamesAction extends ICASTVisitor.CBaseVisitorAction { + protected static class CollectNamesAction extends CASTVisitor { private char [] name; private IASTName [] result = null; CollectNamesAction( char [] n ){ name = n; - processNames = true; + shouldVisitNames = true; } - public int processName( IASTName n ){ + public int visit( IASTName n ){ ASTNodeProperty prop = n.getPropertyInParent(); if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME || prop == IASTCompositeTypeSpecifier.TYPE_NAME || @@ -73,7 +71,7 @@ public class CScope implements ICScope { return PROCESS_CONTINUE; } - public int processStatement( IASTStatement statement ){ + public int visit( IASTStatement statement ){ if( statement instanceof IASTDeclarationStatement ) return PROCESS_CONTINUE; return PROCESS_SKIP; @@ -87,14 +85,8 @@ public class CScope implements ICScope { */ public IBinding[] find( String name ) { IASTNode node = getPhysicalNode(); - IASTTranslationUnit tu = node.getTranslationUnit(); - IASTVisitor visitor = tu.getVisitor(); - CollectNamesAction action = new CollectNamesAction( name.toCharArray() ); - if( node instanceof IASTTranslationUnit ) - visitor.visitTranslationUnit( action ); - else if( node instanceof IASTStatement ) - visitor.visitStatement( (IASTStatement) node, action ); + node.accept( action ); IASTName [] names = action.getNames(); IBinding [] result = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 37696689bb6..edf3e437fc5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -16,23 +16,16 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; -import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpressionList; -import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; -import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; @@ -40,10 +33,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTIfStatement; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; -import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; -import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; @@ -52,16 +41,12 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemHolder; -import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -77,26 +62,20 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; -import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; -import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; -import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.c.ICScope; -import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; -import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; @@ -106,12 +85,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; * Created on Nov 5, 2004 * @author aniefer */ -public class CVisitor implements ICASTVisitor { - public static class ClearBindingAction extends CBaseVisitorAction { +public class CVisitor { + public static class ClearBindingAction extends CASTVisitor { { - processNames = true; + shouldVisitNames = true; } - public int processName(IASTName name) { + public int visit(IASTName name) { if ( ((CASTName)name).hasBinding() ) { ICScope scope; try { @@ -127,12 +106,12 @@ public class CVisitor implements ICASTVisitor { } } - public static class CollectProblemsAction extends CBaseVisitorAction { + public static class CollectProblemsAction extends CASTVisitor { { - processDeclarations = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; + shouldVisitDeclarations = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; } private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; @@ -175,7 +154,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { if ( declaration instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)declaration).getProblem()); @@ -185,7 +164,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { if ( expression instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)expression).getProblem()); @@ -195,7 +174,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { if ( statement instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)statement).getProblem()); @@ -205,7 +184,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { if ( typeId instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)typeId).getProblem()); @@ -213,12 +192,12 @@ public class CVisitor implements ICASTVisitor { } } - public static class CollectDeclarationsAction extends CBaseVisitorAction { + public static class CollectDeclarationsAction extends CASTVisitor { { - processDeclarators = true; - processDeclSpecifiers = true; - processEnumerators = true; - processStatements = true; + shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitEnumerators = true; + shouldVisitStatements = true; } private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; @@ -264,7 +243,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ - public int processDeclarator(IASTDeclarator declarator) { + public int visit(IASTDeclarator declarator) { //GCC allows declarations in expressions, so we have to continue from the //declarator in case there is something in the initializer expression if ( declarator == null || declarator.getName() == null || declarator.getName().toCharArray().length == 0 ) return PROCESS_CONTINUE; @@ -303,7 +282,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ - public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + public int visit(IASTDeclSpecifier declSpec) { if ( compositeTypeDeclared && declSpec instanceof ICASTTypedefNameSpecifier ) return PROCESS_CONTINUE; @@ -340,7 +319,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ - public int processEnumerator(IASTEnumerator enumerator) { + public int visit(IASTEnumerator enumerator) { if( binding instanceof IEnumerator && enumerator.getName().resolveBinding() == binding ){ addName( enumerator.getName() ); } @@ -351,7 +330,7 @@ public class CVisitor implements ICASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { if ( statement instanceof IASTLabelStatement && binding instanceof ILabel ){ if ( ((IASTLabelStatement)statement).getName().resolveBinding() == binding ) addName(((IASTLabelStatement)statement).getName()); @@ -362,7 +341,7 @@ public class CVisitor implements ICASTVisitor { } } - public static class CollectReferencesAction extends CBaseVisitorAction { + public static class CollectReferencesAction extends CASTVisitor { private static final int DEFAULT_LIST_SIZE = 8; private IASTName [] refs; private IBinding binding; @@ -378,7 +357,7 @@ public class CVisitor implements ICASTVisitor { this.binding = binding; this.refs = new IASTName[ DEFAULT_LIST_SIZE ]; - processNames = true; + shouldVisitNames = true; if( binding instanceof ILabel ) kind = KIND_LABEL; else if( binding instanceof ICompositeType || @@ -390,7 +369,7 @@ public class CVisitor implements ICASTVisitor { kind = KIND_OBJ_FN; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ ASTNodeProperty prop = name.getPropertyInParent(); switch( kind ){ case KIND_LABEL: @@ -1337,355 +1316,354 @@ public class CVisitor implements ICASTVisitor { } public static void clearBindings( IASTTranslationUnit tu ){ - tu.getVisitor().visitTranslationUnit( new ClearBindingAction() ); + tu.accept( new ClearBindingAction() ); } - private IASTTranslationUnit tu = null; - public CVisitor( IASTTranslationUnit tu ) { - this.tu = tu; - } +// public CVisitor( IASTTranslationUnit tu ) { +// this.tu = tu; +// } - public void visitTranslationUnit( BaseVisitorAction action ){ - IASTDeclaration[] decls = tu.getDeclarations(); - for( int i = 0; i < decls.length; i++ ){ - if( !visitDeclaration( decls[i], action ) ) return; - } - } - - public boolean visitName( IASTName name, BaseVisitorAction action ){ - if( action.processNames ) { - switch( action.processName( name ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - return true; - } - - public boolean visitDeclaration( IASTDeclaration declaration, BaseVisitorAction action ){ - if( action.processDeclarations ) { - switch( action.processDeclaration( declaration ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( declaration instanceof IASTSimpleDeclaration ){ - IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; - if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false; - IASTDeclarator [] list = simpleDecl.getDeclarators(); - for( int i = 0; list != null && i < list.length; i++ ){ - if( !visitDeclarator( list[i], action ) ) return false; - } - } else if( declaration instanceof IASTFunctionDefinition ){ - IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration; - if( !visitDeclSpecifier( fnDef.getDeclSpecifier(), action ) ) return false; - if( !visitDeclarator( fnDef.getDeclarator(), action ) ) return false; - if( !visitStatement( fnDef.getBody(), action ) ) return false; - } - return true; - } - public boolean visitDeclarator( IASTDeclarator declarator, BaseVisitorAction action ){ - if( action.processDeclarators ){ - switch( action.processDeclarator( declarator ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - //having a nested declarator implies that the name on this declarator is empty - if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && - declarator.getNestedDeclarator() == null ) - { - if( !visitName( declarator.getName(), action ) ) return false; - } - - if( declarator.getNestedDeclarator() != null ) - if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false; - - if( declarator.getInitializer() != null ) - if( !visitInitializer( declarator.getInitializer(), action ) ) return false; - - if( declarator instanceof IASTStandardFunctionDeclarator ){ - IASTParameterDeclaration [] list = ((IASTStandardFunctionDeclarator)declarator).getParameters(); - for( int i = 0; i < list.length; i++ ){ - if( !visitParameterDeclaration( list[i], action ) ) return false; - } - } else if ( declarator instanceof ICASTKnRFunctionDeclarator ) { - ICASTKnRFunctionDeclarator knr = (ICASTKnRFunctionDeclarator) declarator; - IASTName [] names = knr.getParameterNames(); - for( int i = 0; i < names.length; i++ ){ - if( !visitName( names[i], action ) ) return false; - } - - IASTDeclaration[] parmDeclarations = knr.getParameterDeclarations(); - for( int i = 0; i < parmDeclarations.length; i++ ){ - if( !visitDeclaration( parmDeclarations[i], action ) ) return false; - } - } - else if( declarator instanceof IASTArrayDeclarator ) - { - IASTArrayDeclarator arrayDecl = (IASTArrayDeclarator) declarator; - IASTArrayModifier [] mods = arrayDecl.getArrayModifiers(); - for( int i = 0; i < mods.length; ++i ) - if( mods[i].getConstantExpression() != null && - !visitExpression( mods[i].getConstantExpression(), action ) ) return false; - } - else if( declarator instanceof IASTFieldDeclarator ) - if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false; - - return true; - } - - public boolean visitInitializer( IASTInitializer initializer, BaseVisitorAction action ){ - if( initializer == null ) - return true; - - if( action.processInitializers ){ - switch( action.processInitializer( initializer ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( initializer instanceof IASTInitializerExpression ){ - if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false; - } else if( initializer instanceof IASTInitializerList ){ - IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers(); - for( int i = 0; i < list.length; i++ ){ - if( !visitInitializer( list[i], action ) ) return false; - } - } else if( initializer instanceof ICASTDesignatedInitializer ){ - ICASTDesignatedInitializer dinit = (ICASTDesignatedInitializer) initializer; - ICASTDesignator [] ds = dinit.getDesignators(); - for( int i = 0; i < ds.length; i++ ){ - if( !visitDesignator( ds[i], action ) ) return false; - } - if( !visitInitializer( dinit.getOperandInitializer(), action ) ) return false; - } - return true; - } - public boolean visitDesignator( ICASTDesignator designator, BaseVisitorAction action ){ - if( action instanceof CBaseVisitorAction && ((CBaseVisitorAction)action).processDesignators ){ - switch( ((CBaseVisitorAction)action).processDesignator( designator ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - if( designator instanceof ICASTFieldDesignator ){ - if( !visitName( ((ICASTFieldDesignator)designator).getName(), action ) ) return false; - } else if( designator instanceof ICASTArrayDesignator ){ - if( !visitExpression( ((ICASTArrayDesignator)designator).getSubscriptExpression(), action ) ) return false; - } else if( designator instanceof IGCCASTArrayRangeDesignator ){ - if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeFloor(), action ) ) return false; - if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeCeiling(), action ) ) return false; - } - return true; - } - public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, BaseVisitorAction action ){ - if( action.processParameterDeclarations ){ - switch( action.processParameterDeclaration( parameterDeclaration ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false; - if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false; - return true; - } - - public boolean visitDeclSpecifier( IASTDeclSpecifier declSpec, BaseVisitorAction action ){ - if( action.processDeclSpecifiers ){ - switch( action.processDeclSpecifier( declSpec ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( declSpec instanceof ICASTCompositeTypeSpecifier ){ - ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; - if( !visitName( compTypeSpec.getName(), action ) ) return false; - - IASTDeclaration [] list = compTypeSpec.getMembers(); - for( int i = 0; i < list.length; i++ ){ - if( !visitDeclaration( list[i], action ) ) return false; - } - } else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ - if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false; - } else if( declSpec instanceof ICASTTypedefNameSpecifier ){ - if( !visitName( ((ICASTTypedefNameSpecifier) declSpec).getName(), action ) ) return false; - } else if( declSpec instanceof ICASTEnumerationSpecifier ){ - ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec; - if( !visitName( enumSpec.getName(), action ) ) return false; - IASTEnumerator [] list = enumSpec.getEnumerators(); - for( int i = 0; i < list.length; i++ ){ - if( !visitEnumerator( list[i], action ) ) return false; - } - } - return true; - } - public boolean visitEnumerator( IASTEnumerator enumerator, BaseVisitorAction action ){ - if( action.processEnumerators ){ - switch( action.processEnumerator( enumerator ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitName( enumerator.getName(), action ) ) return false; - if( enumerator.getValue() != null ) - if( !visitExpression( enumerator.getValue(), action ) ) return false; - return true; - } - - private boolean visitIfStatement( IASTIfStatement ifStatement, BaseVisitorAction action ){ - while( ifStatement != null ){ - if( action.processStatements ){ - switch( action.processStatement( ifStatement ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - if( !visitExpression( ifStatement.getCondition(), action ) ) return false; - if( !visitStatement( ifStatement.getThenClause(), action ) ) return false; - if( ifStatement.getElseClause() != null ){ - IASTStatement statement = ifStatement.getElseClause(); - if( statement instanceof IASTIfStatement ){ - ifStatement = (IASTIfStatement) statement; - continue; - } - if( !visitStatement( statement, action ) ) return false; - } - ifStatement = null; - } - return true; - } - public boolean visitStatement( IASTStatement statement, BaseVisitorAction action ){ - //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses - if( statement instanceof IASTIfStatement ) - return visitIfStatement( (IASTIfStatement) statement, action ); - - if( action.processStatements ){ - switch( action.processStatement( statement ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( statement instanceof IASTCompoundStatement ){ - IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements(); - for( int i = 0; i < list.length; i++ ){ - if( list[i] == null ) break; - if( !visitStatement( list[i], action ) ) return false; - } - } else if( statement instanceof IASTDeclarationStatement ){ - if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false; - } else if( statement instanceof IASTExpressionStatement ){ - if( ((IASTExpressionStatement)statement).getExpression() != null && !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false; - } else if( statement instanceof IASTCaseStatement ){ - if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false; - } else if( statement instanceof IASTDoStatement ){ - if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false; - if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false; - } else if( statement instanceof IASTGotoStatement ){ - if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false; - } else if( statement instanceof IASTLabelStatement ){ - if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false; - } else if( statement instanceof IASTReturnStatement ){ - if( ((IASTReturnStatement) statement ).getReturnValue() != null ) - if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false; - } else if( statement instanceof IASTSwitchStatement ){ - if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false; - if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false; - } else if( statement instanceof IASTWhileStatement ){ - if( !visitExpression( ((IASTWhileStatement) statement ).getCondition(), action ) ) return false; - if( !visitStatement( ((IASTWhileStatement) statement ).getBody(), action ) ) return false; - } else if( statement instanceof IASTForStatement ){ - IASTForStatement s = (IASTForStatement) statement; - if( s.getInitDeclaration() != null ) - if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false; - if( s.getInitExpression() != null ) - if( !visitExpression( s.getInitExpression(), action ) ) return false; - if( !visitExpression( s.getCondition(), action ) ) return false; - if( !visitExpression( s.getIterationExpression(), action ) ) return false; - if( !visitStatement( s.getBody(), action ) ) return false; - } - return true; - } - public boolean visitTypeId( IASTTypeId typeId, BaseVisitorAction action ){ - if( action.processTypeIds ){ - switch( action.processTypeId( typeId ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false; - if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false; - return true; - } - public boolean visitExpression( IASTExpression expression, BaseVisitorAction action ){ - if (expression == null) return true; - - if( action.processExpressions ){ - switch( action.processExpression( expression ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( expression instanceof IASTArraySubscriptExpression ){ - if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false; - if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false; - } else if( expression instanceof IASTBinaryExpression ){ - if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false; - if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false; - } else if( expression instanceof IASTConditionalExpression){ - if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false; - if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false; - if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false; - } else if( expression instanceof IASTExpressionList ){ - IASTExpression[] list = ((IASTExpressionList)expression).getExpressions(); - for( int i = 0; i < list.length; i++){ - if( list[i] == null ) break; - if( !visitExpression( list[i], action ) ) return false; - } - } else if( expression instanceof IASTFieldReference ){ - if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false; - if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false; - } else if( expression instanceof IASTFunctionCallExpression ){ - if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false; - if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null && !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false; - } else if( expression instanceof IASTIdExpression ){ - if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false; - } else if( expression instanceof IASTTypeIdExpression ){ - if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false; - } else if( expression instanceof IASTCastExpression ){ - if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false; - if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false; - } else if( expression instanceof IASTUnaryExpression ){ - if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false; - } else if( expression instanceof ICASTTypeIdInitializerExpression ){ - if( !visitTypeId( ((ICASTTypeIdInitializerExpression)expression).getTypeId(), action ) ) return false; - if( !visitInitializer( ((ICASTTypeIdInitializerExpression)expression).getInitializer(), action ) ) return false; - } else if( expression instanceof IGNUASTCompoundStatementExpression ){ - if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false; - } - return true; - } +// public void visitTranslationUnit( ASTVisitor action ){ +// IASTDeclaration[] decls = tu.getDeclarations(); +// for( int i = 0; i < decls.length; i++ ){ +// if( !visitDeclaration( decls[i], action ) ) return; +// } +// } +// +// public boolean visitName( IASTName name, ASTVisitor action ){ +// if( action.processNames ) { +// switch( action.processName( name ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// return true; +// } +// +// public boolean visitDeclaration( IASTDeclaration declaration, ASTVisitor action ){ +// if( action.processDeclarations ) { +// switch( action.processDeclaration( declaration ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( declaration instanceof IASTSimpleDeclaration ){ +// IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; +// if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false; +// IASTDeclarator [] list = simpleDecl.getDeclarators(); +// for( int i = 0; list != null && i < list.length; i++ ){ +// if( !visitDeclarator( list[i], action ) ) return false; +// } +// } else if( declaration instanceof IASTFunctionDefinition ){ +// IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration; +// if( !visitDeclSpecifier( fnDef.getDeclSpecifier(), action ) ) return false; +// if( !visitDeclarator( fnDef.getDeclarator(), action ) ) return false; +// if( !visitStatement( fnDef.getBody(), action ) ) return false; +// } +// return true; +// } +// public boolean visitDeclarator( IASTDeclarator declarator, ASTVisitor action ){ +// if( action.processDeclarators ){ +// switch( action.processDeclarator( declarator ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// //having a nested declarator implies that the name on this declarator is empty +// if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && +// declarator.getNestedDeclarator() == null ) +// { +// if( !visitName( declarator.getName(), action ) ) return false; +// } +// +// if( declarator.getNestedDeclarator() != null ) +// if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false; +// +// if( declarator.getInitializer() != null ) +// if( !visitInitializer( declarator.getInitializer(), action ) ) return false; +// +// if( declarator instanceof IASTStandardFunctionDeclarator ){ +// IASTParameterDeclaration [] list = ((IASTStandardFunctionDeclarator)declarator).getParameters(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitParameterDeclaration( list[i], action ) ) return false; +// } +// } else if ( declarator instanceof ICASTKnRFunctionDeclarator ) { +// ICASTKnRFunctionDeclarator knr = (ICASTKnRFunctionDeclarator) declarator; +// IASTName [] names = knr.getParameterNames(); +// for( int i = 0; i < names.length; i++ ){ +// if( !visitName( names[i], action ) ) return false; +// } +// +// IASTDeclaration[] parmDeclarations = knr.getParameterDeclarations(); +// for( int i = 0; i < parmDeclarations.length; i++ ){ +// if( !visitDeclaration( parmDeclarations[i], action ) ) return false; +// } +// } +// else if( declarator instanceof IASTArrayDeclarator ) +// { +// IASTArrayDeclarator arrayDecl = (IASTArrayDeclarator) declarator; +// IASTArrayModifier [] mods = arrayDecl.getArrayModifiers(); +// for( int i = 0; i < mods.length; ++i ) +// if( mods[i].getConstantExpression() != null && +// !visitExpression( mods[i].getConstantExpression(), action ) ) return false; +// } +// else if( declarator instanceof IASTFieldDeclarator ) +// if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false; +// +// return true; +// } +// +// public boolean visitInitializer( IASTInitializer initializer, ASTVisitor action ){ +// if( initializer == null ) +// return true; +// +// if( action.processInitializers ){ +// switch( action.processInitializer( initializer ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( initializer instanceof IASTInitializerExpression ){ +// if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false; +// } else if( initializer instanceof IASTInitializerList ){ +// IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitInitializer( list[i], action ) ) return false; +// } +// } else if( initializer instanceof ICASTDesignatedInitializer ){ +// ICASTDesignatedInitializer dinit = (ICASTDesignatedInitializer) initializer; +// ICASTDesignator [] ds = dinit.getDesignators(); +// for( int i = 0; i < ds.length; i++ ){ +// if( !visitDesignator( ds[i], action ) ) return false; +// } +// if( !visitInitializer( dinit.getOperandInitializer(), action ) ) return false; +// } +// return true; +// } +// public boolean visitDesignator( ICASTDesignator designator, ASTVisitor action ){ +// if( action instanceof CASTVisitor && ((CASTVisitor)action).processDesignators ){ +// switch( ((CASTVisitor)action).processDesignator( designator ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// if( designator instanceof ICASTFieldDesignator ){ +// if( !visitName( ((ICASTFieldDesignator)designator).getName(), action ) ) return false; +// } else if( designator instanceof ICASTArrayDesignator ){ +// if( !visitExpression( ((ICASTArrayDesignator)designator).getSubscriptExpression(), action ) ) return false; +// } else if( designator instanceof IGCCASTArrayRangeDesignator ){ +// if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeFloor(), action ) ) return false; +// if( !visitExpression( ((IGCCASTArrayRangeDesignator)designator).getRangeCeiling(), action ) ) return false; +// } +// return true; +// } +// public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, ASTVisitor action ){ +// if( action.processParameterDeclarations ){ +// switch( action.processParameterDeclaration( parameterDeclaration ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false; +// if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false; +// return true; +// } +// +// public boolean visitDeclSpecifier( IASTDeclSpecifier declSpec, ASTVisitor action ){ +// if( action.processDeclSpecifiers ){ +// switch( action.processDeclSpecifier( declSpec ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( declSpec instanceof ICASTCompositeTypeSpecifier ){ +// ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; +// if( !visitName( compTypeSpec.getName(), action ) ) return false; +// +// IASTDeclaration [] list = compTypeSpec.getMembers(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitDeclaration( list[i], action ) ) return false; +// } +// } else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ +// if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false; +// } else if( declSpec instanceof ICASTTypedefNameSpecifier ){ +// if( !visitName( ((ICASTTypedefNameSpecifier) declSpec).getName(), action ) ) return false; +// } else if( declSpec instanceof ICASTEnumerationSpecifier ){ +// ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec; +// if( !visitName( enumSpec.getName(), action ) ) return false; +// IASTEnumerator [] list = enumSpec.getEnumerators(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitEnumerator( list[i], action ) ) return false; +// } +// } +// return true; +// } +// public boolean visitEnumerator( IASTEnumerator enumerator, ASTVisitor action ){ +// if( action.processEnumerators ){ +// switch( action.processEnumerator( enumerator ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitName( enumerator.getName(), action ) ) return false; +// if( enumerator.getValue() != null ) +// if( !visitExpression( enumerator.getValue(), action ) ) return false; +// return true; +// } +// +// private boolean visitIfStatement( IASTIfStatement ifStatement, ASTVisitor action ){ +// while( ifStatement != null ){ +// if( action.processStatements ){ +// switch( action.processStatement( ifStatement ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// if( !visitExpression( ifStatement.getCondition(), action ) ) return false; +// if( !visitStatement( ifStatement.getThenClause(), action ) ) return false; +// if( ifStatement.getElseClause() != null ){ +// IASTStatement statement = ifStatement.getElseClause(); +// if( statement instanceof IASTIfStatement ){ +// ifStatement = (IASTIfStatement) statement; +// continue; +// } +// if( !visitStatement( statement, action ) ) return false; +// } +// ifStatement = null; +// } +// return true; +// } +// public boolean visitStatement( IASTStatement statement, ASTVisitor action ){ +// //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses +// if( statement instanceof IASTIfStatement ) +// return visitIfStatement( (IASTIfStatement) statement, action ); +// +// if( action.processStatements ){ +// switch( action.processStatement( statement ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( statement instanceof IASTCompoundStatement ){ +// IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements(); +// for( int i = 0; i < list.length; i++ ){ +// if( list[i] == null ) break; +// if( !visitStatement( list[i], action ) ) return false; +// } +// } else if( statement instanceof IASTDeclarationStatement ){ +// if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false; +// } else if( statement instanceof IASTExpressionStatement ){ +// if( ((IASTExpressionStatement)statement).getExpression() != null && !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false; +// } else if( statement instanceof IASTCaseStatement ){ +// if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false; +// } else if( statement instanceof IASTDoStatement ){ +// if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false; +// if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false; +// } else if( statement instanceof IASTGotoStatement ){ +// if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false; +// } else if( statement instanceof IASTLabelStatement ){ +// if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false; +// } else if( statement instanceof IASTReturnStatement ){ +// if( ((IASTReturnStatement) statement ).getReturnValue() != null ) +// if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false; +// } else if( statement instanceof IASTSwitchStatement ){ +// if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false; +// if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false; +// } else if( statement instanceof IASTWhileStatement ){ +// if( !visitExpression( ((IASTWhileStatement) statement ).getCondition(), action ) ) return false; +// if( !visitStatement( ((IASTWhileStatement) statement ).getBody(), action ) ) return false; +// } else if( statement instanceof IASTForStatement ){ +// IASTForStatement s = (IASTForStatement) statement; +// if( s.getInitDeclaration() != null ) +// if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false; +// if( s.getInitExpression() != null ) +// if( !visitExpression( s.getInitExpression(), action ) ) return false; +// if( !visitExpression( s.getCondition(), action ) ) return false; +// if( !visitExpression( s.getIterationExpression(), action ) ) return false; +// if( !visitStatement( s.getBody(), action ) ) return false; +// } +// return true; +// } +// public boolean visitTypeId( IASTTypeId typeId, ASTVisitor action ){ +// if( action.processTypeIds ){ +// switch( action.processTypeId( typeId ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false; +// if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false; +// return true; +// } +// public boolean visitExpression( IASTExpression expression, ASTVisitor action ){ +// if (expression == null) return true; +// +// if( action.processExpressions ){ +// switch( action.processExpression( expression ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( expression instanceof IASTArraySubscriptExpression ){ +// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false; +// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false; +// } else if( expression instanceof IASTBinaryExpression ){ +// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false; +// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false; +// } else if( expression instanceof IASTConditionalExpression){ +// if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false; +// if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false; +// if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false; +// } else if( expression instanceof IASTExpressionList ){ +// IASTExpression[] list = ((IASTExpressionList)expression).getExpressions(); +// for( int i = 0; i < list.length; i++){ +// if( list[i] == null ) break; +// if( !visitExpression( list[i], action ) ) return false; +// } +// } else if( expression instanceof IASTFieldReference ){ +// if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false; +// if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false; +// } else if( expression instanceof IASTFunctionCallExpression ){ +// if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false; +// if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null && !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false; +// } else if( expression instanceof IASTIdExpression ){ +// if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false; +// } else if( expression instanceof IASTTypeIdExpression ){ +// if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false; +// } else if( expression instanceof IASTCastExpression ){ +// if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false; +// if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false; +// } else if( expression instanceof IASTUnaryExpression ){ +// if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false; +// } else if( expression instanceof ICASTTypeIdInitializerExpression ){ +// if( !visitTypeId( ((ICASTTypeIdInitializerExpression)expression).getTypeId(), action ) ) return false; +// if( !visitInitializer( ((ICASTTypeIdInitializerExpression)expression).getInitializer(), action ) ) return false; +// } else if( expression instanceof IGNUASTCompoundStatementExpression ){ +// if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false; +// } +// return true; +// } /** * Create an IType for an IASTName. @@ -1928,14 +1906,14 @@ public class CVisitor implements ICASTVisitor { public static IASTProblem[] getProblems(IASTTranslationUnit tu) { CollectProblemsAction action = new CollectProblemsAction(); - tu.getVisitor().visitTranslationUnit(action); + tu.accept(action); return action.getProblems(); } public static IASTName[] getDeclarations(IASTTranslationUnit tu, IBinding binding) { CollectDeclarationsAction action = new CollectDeclarationsAction(binding); - tu.getVisitor().visitTranslationUnit(action); + tu.accept(action); return action.getDeclarationNames(); } @@ -1947,7 +1925,7 @@ public class CVisitor implements ICASTVisitor { */ public static IASTName[] getReferences(IASTTranslationUnit tu, IBinding binding) { CollectReferencesAction action = new CollectReferencesAction( binding ); - tu.getVisitor().visitTranslationUnit(action); + tu.accept(action); return action.getReferences(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java index 210e4f159b7..a2d7bf08eac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; /** @@ -33,4 +34,15 @@ public class CPPASTASMDeclaration extends CPPASTNode implements this.assembly = assembly.toCharArray(); } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java index 4ab61a9dce9..aedb7746130 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java @@ -10,8 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; /** * @author jcamelon @@ -61,4 +63,14 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements } arrayMods[ currentIndex++ ] = arrayModifier; } + + protected boolean postAccept( ASTVisitor action ){ + IASTArrayModifier [] mods = getArrayModifiers(); + for ( int i = 0; i < mods.length; i++ ) { + if( !mods[i].accept( action ) ) return false; + } + IASTInitializer initializer = getInitializer(); + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java index 2d5747e9af9..8dc559cd2aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -34,4 +35,11 @@ public class CPPASTArrayModifier extends CPPASTNode implements public void setConstantExpression(IASTExpression expression) { exp = expression; } + + public boolean accept( ASTVisitor action ){ + if( exp != null ) + if( !exp.accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java index 47f4c8c68e0..7fc34003de5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -49,5 +50,20 @@ public class CPPASTArraySubscriptExpression extends CPPASTNode implements public void setSubscriptExpression(IASTExpression expression) { subscriptExp = expression; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( arrayExpression != null ) + if( !arrayExpression.accept( action ) ) return false; + if( subscriptExp != null ) + if( !subscriptExp.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java index 974cda2d079..140a1beb775 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java @@ -10,7 +10,9 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; /** @@ -64,5 +66,19 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements public void setName(IASTName name) { this.name = name; } + + public boolean accept( ASTVisitor action ){ + if( action instanceof CPPASTVisitor && + ((CPPASTVisitor)action).shouldVisitBaseSpecifiers ){ + switch( ((CPPASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java index 7b4142f3c33..63f34a1c23b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; @@ -65,4 +66,18 @@ public class CPPASTBinaryExpression extends CPPASTNode implements operand2 = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( operand1 != null ) if( !operand1.accept( action ) ) return false; + if( operand2 != null ) if( !operand2.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java index e1f97d4045c..f7d44c394f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; /** @@ -18,4 +19,15 @@ import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; public class CPPASTBreakStatement extends CPPASTNode implements IASTBreakStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java index a13341319a7..9ce0d79d7ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -34,4 +35,16 @@ public class CPPASTCaseStatement extends CPPASTNode implements this.expression = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( expression != null ) if( !expression.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java index 383c2ed0f87..6fda6e46a52 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java @@ -10,6 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; @@ -34,4 +36,18 @@ public class CPPASTCastExpression extends CPPASTUnaryExpression implements return typeId; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( typeId != null ) if( !typeId.accept( action ) ) return false; + IASTExpression op = getOperand(); + if( op != null ) if( !op.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java index a624fcc94b1..97ec73610bb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; @@ -66,4 +67,16 @@ public class CPPASTCatchHandler extends CPPASTNode implements return declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( declaration != null ) if( !declaration.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index 7864aa2a5f6..fda2fcf517f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; @@ -166,4 +167,23 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier this.scope = scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( n != null ) if( !n.accept( action ) ) return false; + ICPPASTBaseSpecifier[] bases = getBaseSpecifiers(); + for( int i = 0; i < bases.length; i++ ) + if( !bases[i].accept( action ) ) return false; + + IASTDeclaration [] decls = getMembers(); + for( int i = 0; i < decls.length; i++ ) + if( !decls[i].accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index ca54779c861..927827e3667 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; @@ -79,4 +80,18 @@ public class CPPASTCompoundStatement extends CPPASTNode implements return scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTStatement [] s = getStatements(); + for ( int i = 0; i < s.length; i++ ) { + if( !s[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java index 57ae1b5eda4..1456d1e57a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; @@ -34,4 +35,16 @@ public class CPPASTCompoundStatementExpression extends CPPASTNode implements this.statement = statement; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( statement != null ) if( !statement.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java index 71642d80976..9130b62bd6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -64,4 +65,18 @@ public class CPPASTConditionalExpression extends CPPASTNode implements this.negative = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( condition != null ) if( !condition.accept( action ) ) return false; + if( postive != null ) if( !postive.accept( action ) ) return false; + if( negative != null ) if( !negative.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index 95bd4f9e2fa..f5bfb398fd4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; @@ -51,4 +52,9 @@ public class CPPASTConstructorChainInitializer extends CPPASTNode implements value = expression; } + public boolean accept( ASTVisitor action ){ + if( name != null ) if( !name.accept( action ) ) return false; + if( value != null ) if( !value.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java index 589e9aa878e..d418a3f4819 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; @@ -35,4 +36,16 @@ public class CPPASTConstructorInitializer extends CPPASTNode implements this.exp = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( exp != null ) if( !exp.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java index 38328082b32..892c960fa7f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; /** @@ -18,4 +19,14 @@ import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; public class CPPASTContinueStatement extends CPPASTNode implements IASTContinueStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java index 48eda0ae668..d7f9c2ba7ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; @@ -35,4 +36,15 @@ public class CPPASTDeclarationStatement extends CPPASTNode implements this.declaration = declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( declaration != null ) if( !declaration.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index e72f3367b08..0e234f4ae9a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -10,10 +10,12 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; /** * @author jcamelon @@ -110,4 +112,33 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarators ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + IASTPointerOperator [] ptrOps = getPointerOperators(); + for ( int i = 0; i < ptrOps.length; i++ ) { + if( !ptrOps[i].accept( action ) ) return false; + } + + if( getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && + nestedDeclarator == null ) + { + if( name != null ) if( !name.accept( action ) ) return false; + } + + if( nestedDeclarator != null ) if( !nestedDeclarator.accept( action ) ) return false; + + return postAccept( action ); + } + + protected boolean postAccept( ASTVisitor action ){ + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java index 474ef619ba6..c1f5f8b217b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; /** @@ -17,5 +18,15 @@ import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; */ public class CPPASTDefaultStatement extends CPPASTNode implements IASTDefaultStatement { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java index 56d320f9f9a..f73205e6f04 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; @@ -65,4 +66,16 @@ public class CPPASTDeleteExpression extends CPPASTNode implements return isVectored; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( operand != null ) if( !operand.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java index 1e304b28528..977131443c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; @@ -49,4 +50,16 @@ public class CPPASTDoStatement extends CPPASTNode implements IASTDoStatement { this.condition = condition; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( body != null ) if( !body.accept( action ) ) return false; + if( condition != null ) if( !condition.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java index 2b74516b662..bd21298aea0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; @@ -50,4 +51,15 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index 2a17e609bfe..c787a0e2089 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; @@ -89,4 +90,19 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier return getName().toString() == null ? "" : getName().toString(); //$NON-NLS-1$ } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + IASTEnumerator[] enums = getEnumerators(); + for( int i = 0; i < enums.length; i++ ) + if( !enums[i].accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index 05a86d1ccf6..b3d1b906a88 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; @@ -49,4 +50,16 @@ public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator { return value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitEnumerators ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + if( value != null ) if( !value.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java index e6d0115e8be..df13ab2917b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; @@ -35,4 +36,17 @@ public class CPPASTExplicitTemplateInstantiation extends CPPASTNode implements this.declaration = declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declaration != null ) if( !declaration.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index a57949ccd86..16d9ab6ab7f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; @@ -67,5 +68,19 @@ public class CPPASTExpressionList extends CPPASTNode implements private IASTExpression [] expressions = null; private static final int DEFAULT_EXPRESSIONLIST_SIZE = 4; - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + IASTExpression [] exps = getExpressions(); + for( int i = 0; i < exps.length; i++ ) + if( !exps[i].accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java index 007eb7ea1e2..3387d429ca1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; @@ -34,4 +35,16 @@ public class CPPASTExpressionStatement extends CPPASTNode implements this.expression = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( expression != null ) if( !expression.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java index b050bc1319a..1e99c13346a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java @@ -10,8 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; /** * @author jcamelon @@ -35,5 +37,12 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements this.bitField = size; } + protected boolean postAccept( ASTVisitor action ){ + if( bitField != null ) if( !bitField.accept( action ) ) return false; + + IASTInitializer initializer = getInitializer(); + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index ad8e992e657..fb097c062b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; @@ -80,5 +81,20 @@ public class CPPASTFieldReference extends CPPASTNode implements public void setIsPointerDereference(boolean value) { isDeref = value; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( owner != null ) if( !owner.accept( action ) ) return false; + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java index 883fdd7cdde..df329de0b1b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTForStatement; @@ -108,4 +109,19 @@ public class CPPASTForStatement extends CPPASTNode implements IASTForStatement { return scope; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( initDeclaration != null ) if( !initDeclaration.accept( action ) ) return false; + if( initialExpression != null ) if( !initialExpression.accept( action ) ) return false; + if( condition != null ) if( !condition.accept( action ) ) return false; + if( iterationExpression != null ) if( !iterationExpression.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index ee26e0c113f..aec89f36b71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; @@ -49,4 +50,17 @@ public class CPPASTFunctionCallExpression extends CPPASTNode implements return parameter; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( functionName != null ) if( !functionName.accept( action ) ) return false; + if( parameter != null ) if( !parameter.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index 67b96f41810..50d26b89ed4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -11,7 +11,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTypeId; @@ -246,4 +248,24 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements return scope; } + protected boolean postAccept( ASTVisitor action ){ + IASTParameterDeclaration [] params = getParameters(); + for ( int i = 0; i < params.length; i++ ) { + if( !params[i].accept( action ) ) return false; + } + + ICPPASTConstructorChainInitializer [] chain = getConstructorChain(); + for ( int i = 0; i < chain.length; i++ ) { + if( !chain[i].accept( action ) ) return false; + } + + IASTInitializer initializer = getInitializer(); + if( initializer != null ) if( !initializer.accept( action ) ) return false; + + IASTTypeId[] ids = getExceptionSpecification(); + for ( int i = 0; i < ids.length; i++ ) { + if( !ids[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java index 177ca2b8d4d..cefb57be037 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; @@ -76,5 +77,19 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements return ((ICPPASTFunctionDeclarator)declarator).getFunctionScope(); } - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; + if( declarator != null ) if( !declarator.accept( action ) ) return false; + if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java index ed12cde9cee..9f33d114243 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; @@ -64,4 +65,14 @@ public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator private ICPPASTCatchHandler [] catchHandlers = null; private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE = 4; + protected boolean postAccept( ASTVisitor action ){ + if( !super.postAccept( action ) ) return false; + + ICPPASTCatchHandler [] handlers = getCatchHandlers(); + for ( int i = 0; i < handlers.length; i++ ) { + if( !handlers[i].accept( action ) ) return false; + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java index 30927f0a67f..f12bc7683f4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -34,4 +35,15 @@ public class CPPASTGotoStatement extends CPPASTNode implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java index 41158e64c27..b64dc2aa78c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -33,4 +34,16 @@ public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java index b4f4b6e3974..e58c49b82b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; @@ -64,4 +65,17 @@ public class CPPASTIfStatement extends CPPASTNode implements IASTIfStatement { this.elseClause = elseClause; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( condition != null ) if( !condition.accept( action ) ) return false; + if( thenClause != null ) if( !thenClause.accept( action ) ) return false; + if( elseClause != null ) if( !elseClause.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java index ce806426891..de58127ce80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; @@ -35,4 +36,16 @@ public class CPPASTInitializerExpression extends CPPASTNode implements this.exp = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( exp != null ) if( !exp.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java index 39820d32486..f881f8b3c3c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; @@ -69,4 +70,19 @@ public class CPPASTInitializerList extends CPPASTNode implements private IASTInitializer [] initializers = null; private static final int DEFAULT_INITIALIZERS_LIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitInitializers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTInitializer [] list = getInitializers(); + for ( int i = 0; i < list.length; i++ ) { + if( !list[i].accept( action ) ) return false; + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java index 2cda5866678..0f48c1481d1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -34,4 +35,15 @@ public class CPPASTLabelStatement extends CPPASTNode implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java index b2ca33506ec..3459c6aed09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; @@ -80,4 +81,19 @@ public class CPPASTLinkageSpecification extends CPPASTNode implements private IASTDeclaration [] declarations = null; private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + IASTDeclaration [] decls = getDeclarations(); + for( int i = 0; i < decls.length; i++ ) + if( !decls[i].accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java index b0719c5644a..12686e69bc8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; @@ -50,6 +51,14 @@ public class CPPASTLiteralExpression extends CPPASTNode implements return value; } - - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index 22cd0f91045..05ead751ebe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -74,4 +75,14 @@ public class CPPASTName extends CPPASTNode implements IASTName { this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitNames ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java index 0f2b0a6c36c..da74b7113bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; @@ -50,4 +51,15 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java index 3d020c55be7..0367ee32631 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; @@ -50,4 +51,18 @@ public class CPPASTNamespaceAlias extends CPPASTNode implements this.qualifiedName = qualifiedName; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( alias != null ) if( !alias.accept( action ) ) return false; + if( qualifiedName != null ) if( !qualifiedName.accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index ec2b6dd145c..ea5d487790b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -10,10 +10,12 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; @@ -96,4 +98,22 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements } } + public boolean accept( ASTVisitor action ){ + if( action instanceof CPPASTVisitor && + ((CPPASTVisitor)action).shouldVisitNamespaces ){ + switch( ((CPPASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + IASTDeclaration [] decls = getDeclarations(); + for ( int i = 0; i < decls.length; i++ ) + if( !decls[i].accept( action ) ) return false; + + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index b373d65f3fd..f301b76ee4f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; @@ -142,4 +143,23 @@ public class CPPASTNewExpression extends CPPASTNode implements private IASTExpression [] arrayExpressions = null; private static final int DEFAULT_ARRAY_EXPRESSIONS_LIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( placement != null ) if( !placement.accept( action ) ) return false; + if( typeId != null ) if( !typeId.accept( action ) ) return false; + + IASTExpression [] exps = getNewTypeIdArrayExpressions(); + for( int i = 0; i < exps.length; i++ ) + if( !exps[i].accept( action ) ) return false; + + if( initializer != null ) if( !initializer.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java index bc801a58c52..751128bb8ca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -63,5 +64,8 @@ public class CPPASTNode extends ASTNode implements IASTNode { public void setPropertyInParent(ASTNodeProperty property) { this.property = property; } - + + public boolean accept( ASTVisitor action ){ + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java index 308d7e9afc0..1cc1be055be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; /** @@ -17,5 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNullStatement; */ public class CPPASTNullStatement extends CPPASTNode implements IASTNullStatement { - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java index ab9aefcbdaf..c5ded5d21ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; @@ -51,4 +52,17 @@ public class CPPASTParameterDeclaration extends CPPASTNode implements this.declarator = declarator; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitParameterDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpec != null ) if( !declSpec.accept( action ) ) return false; + if( declarator != null ) if( !declarator.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java index 68d7956434b..5fc24586443 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; @@ -35,4 +36,8 @@ public class CPPASTPointerToMember extends CPPASTPointer implements return n; } + public boolean accept( ASTVisitor action ){ + if( n != null ) if( !n.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java index 7c6a59c32d4..837f6b3599f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; /** @@ -18,4 +19,15 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IASTProblemDeclaration { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java index f6e0221f734..bbd939e4370 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; /** @@ -18,4 +19,14 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTProblemExpression { + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java index 16ac631cda8..9424eef6810 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; /** @@ -17,5 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; */ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTProblemStatement { - + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index a07ace92ccb..2d48f90a619 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; @@ -167,5 +168,22 @@ public class CPPASTQualifiedName extends CPPASTNode implements this.signature = string; } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitNames ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTName [] ns = getNames(); + for ( int i = 0; i < ns.length; i++ ) { + if( i == names.length - 1 ){ + if( names[i].toCharArray().length > 0 && !names[i].accept( action ) ) return false; + } else if( !names[i].accept( action ) ) return false; + } + return true; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java index e20cdd0863b..2b44d1f57ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; @@ -34,4 +35,15 @@ public class CPPASTReturnStatement extends CPPASTNode implements retValue = returnValue; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( retValue != null ) if( !retValue.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java index 999142eaf79..a7b5c880afb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; /** @@ -94,4 +95,14 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier isShort = value; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index 6b824bb6488..f0008fcdaba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -81,4 +82,20 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements this.declSpecifier = declSpecifier; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; + IASTDeclarator [] dtors = getDeclarators(); + for( int i = 0; i < dtors.length; i++ ) + if( !dtors[i].accept( action ) ) return false; + return true; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java index 30e523aecf0..8607ac242b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; @@ -50,4 +51,16 @@ public class CPPASTSimpleTypeConstructorExpression extends CPPASTNode implements init = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( init != null ) if( !init.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java index ea1c16ee627..7f925e1877b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java @@ -10,8 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; /** @@ -65,4 +67,18 @@ public class CPPASTSimpleTypeTemplateParameter extends CPPASTNode implements public void setDefaultType(IASTTypeId typeId) { this.typeId = typeId; } + public boolean accept( ASTVisitor action ){ + if( action instanceof CPPASTVisitor && + ((CPPASTVisitor)action).shouldVisitTemplateParameters ){ + switch( ((CPPASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( typeId != null ) if( !typeId.accept( action ) ) return false; + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java index 0d5d852e397..caae8586a8e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; @@ -51,4 +52,16 @@ public class CPPASTSwitchStatement extends CPPASTNode implements this.body = body; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( controller != null ) if( !controller.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java index d52284d9253..209d130e98e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; @@ -96,4 +97,21 @@ public class CPPASTTemplateDeclaration extends CPPASTNode implements private ICPPASTTemplateParameter [] parameters = null; private static final int DEFAULT_PARMS_LIST_SIZE = 4; + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + ICPPASTTemplateParameter [] params = getTemplateParameters(); + for ( int i = 0; i < params.length; i++ ) { + if( !params[i].accept( action ) ) return false; + } + + if( declaration != null ) if( !declaration.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index 26a29eb1ec5..9aa3ee8b8a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -128,4 +129,20 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId { return EMPTY_STRING; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitNames ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( templateName != null ) if( !templateName.accept( action ) ) return false; + + IASTNode [] nodes = getTemplateArguments(); + for ( int i = 0; i < nodes.length; i++ ) { + if( !nodes[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java index 9ec1c1becee..a396abcc3e9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization; @@ -35,4 +36,16 @@ public class CPPASTTemplateSpecialization extends CPPASTNode implements this.declaration = declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declaration != null ) if( !declaration.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java index ee2a52df07b..9aba5cf5934 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java @@ -10,8 +10,10 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; @@ -90,4 +92,22 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements this.defaultValue = expression; } + public boolean accept( ASTVisitor action ){ + if( action instanceof CPPASTVisitor && + ((CPPASTVisitor)action).shouldVisitTemplateParameters ){ + switch( ((CPPASTVisitor)action).visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + ICPPASTTemplateParameter [] ps = getTemplateParameters(); + for ( int i = 0; i < ps.length; i++ ) { + if( !ps[i].accept( action ) ) return false; + } + if( defaultValue != null ) if( !defaultValue.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 0fe54ff193b..2326eced315 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -31,17 +32,16 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IASTVisitor; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; @@ -60,8 +60,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements private ICPPNamespace binding = null; private ICPPScope scope = null; - - private ICPPASTVisitor visitor = null; private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; @@ -165,20 +163,20 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return resolver.getLocations(offset, length); } - private class CPPFindNodeForOffsetAction extends CPPVisitor.CPPBaseVisitorAction { + private class CPPFindNodeForOffsetAction extends CPPASTVisitor { { - processNames = true; - processDeclarations = true; - processInitializers = true; - processParameterDeclarations = true; - processDeclarators = true; - processDeclSpecifiers = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; - processEnumerators = true; - processBaseSpecifiers = true; - processNamespaces = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; + shouldVisitInitializers = true; + shouldVisitParameterDeclarations = true; + shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; + shouldVisitEnumerators = true; + shouldVisitBaseSpecifiers = true; + shouldVisitNamespaces = true; } IASTNode foundNode = null; @@ -216,7 +214,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { // use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes) // TODO take out fix below for bug 86993 check for: !(declaration instanceof ICPPASTLinkageSpecification) if (declaration instanceof ASTNode && !(declaration instanceof ICPPASTLinkageSpecification) && ((ASTNode)declaration).getOffset() > offset) @@ -228,7 +226,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ - public int processDeclarator(IASTDeclarator declarator) { + public int visit(IASTDeclarator declarator) { int ret = processNode(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); @@ -268,35 +266,35 @@ public class CPPASTTranslationUnit extends CPPASTNode implements /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ - public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + public int visit(IASTDeclSpecifier declSpec) { return processNode(declSpec); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ - public int processEnumerator(IASTEnumerator enumerator) { + public int visit(IASTEnumerator enumerator) { return processNode((IASTNode)enumerator); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { return processNode(expression); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ - public int processInitializer(IASTInitializer initializer) { + public int visit(IASTInitializer initializer) { return processNode(initializer); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) */ - public int processName(IASTName name) { + public int visit(IASTName name) { if ( name.toString() != null ) return processNode(name); return PROCESS_CONTINUE; @@ -305,7 +303,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ - public int processParameterDeclaration( + public int visit( IASTParameterDeclaration parameterDeclaration) { return processNode(parameterDeclaration); } @@ -313,14 +311,14 @@ public class CPPASTTranslationUnit extends CPPASTNode implements /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { return processNode(statement); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { return processNode(typeId); } @@ -352,7 +350,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements globalOffset = result == null ? globalOffset : result.getGlobalOffset(); if (globalOffset >= 0) { CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(globalOffset, realLength); - getVisitor().visitTranslationUnit(nodeFinder); + accept(nodeFinder); node = nodeFinder.getNode(); } } @@ -453,15 +451,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements if( resolver == null ) return EMPTY_STRING; return new String( resolver.getUnpreprocessedSignature(locations) ); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor() - */ - public IASTVisitor getVisitor() { - if( visitor == null ) - visitor = new CPPVisitor( this ); - return visitor; - } /* * (non-Javadoc) @@ -473,4 +462,19 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return EMPTY_STRING; return new String(resolver.getTranslationUnitPath()); } + + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitTranslationUnit){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + IASTDeclaration [] ds = getDeclarations(); + for( int i = 0; i < ds.length; i++ ){ + if( !ds[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index b0227031613..97343125b23 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; @@ -79,8 +80,21 @@ public class CPPASTTryBlockStatement extends CPPASTNode implements return tryBody; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement#addCatchHandler(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler) - */ + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( tryBody != null ) if( !tryBody.accept( action ) ) return false; + + ICPPASTCatchHandler [] handlers = getCatchHandlers(); + for ( int i = 0; i < handlers.length; i++ ) { + if( !handlers[i].accept( action ) ) return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java index f2f4477b85c..a79eb816f52 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; @@ -50,4 +51,17 @@ public class CPPASTTypeId extends CPPASTNode implements IASTTypeId { this.absDecl = abstractDeclarator; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitTypeIds ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( declSpec != null ) if( !declSpec.accept( action ) ) return false; + if( absDecl != null ) if( !absDecl.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java index 21b630b2cc9..395570bd324 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; @@ -50,4 +51,16 @@ public class CPPASTTypeIdExpression extends CPPASTNode implements return typeId; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( typeId != null ) if( !typeId.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java index d8bedcf20db..0d322fdabc6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression; @@ -66,4 +67,17 @@ public class CPPASTTypenameExpression extends CPPASTNode implements return init; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + if( init != null ) if( !init.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index 294c63e096a..474da234bdc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; @@ -50,4 +51,16 @@ public class CPPASTUnaryExpression extends CPPASTNode implements operand = expression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitExpressions ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( operand != null ) if( !operand.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java index 2511cc5f834..1c5bc44226e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; @@ -50,4 +51,16 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements this.name = name; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java index 2c4f331748f..b2ad37e2af3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; @@ -35,4 +36,16 @@ public class CPPASTUsingDirective extends CPPASTNode implements this.name = qualifiedName; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclarations ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + + if( name != null ) if( !name.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java index f5d690196f6..27be3f1b476 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; @@ -66,4 +67,17 @@ public class CPPASTWhileStatement extends CPPASTNode implements condition2 = declaration; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitStatements ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( condition != null ) if( !condition.accept( action ) ) return false; + if( condition2 != null ) if( !condition2.accept( action ) ) return false; + if( body != null ) if( !body.accept( action ) ) return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 4e868cf0840..b291e9b7807 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -18,7 +18,6 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -27,18 +26,16 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -132,19 +129,19 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { return definition; } - private class FindDefinitionAction extends CPPVisitor.CPPBaseVisitorAction { + private class FindDefinitionAction extends CPPASTVisitor { private char [] nameArray = CPPClassType.this.getNameCharArray(); public IASTName result = null; { - processNames = true; - processDeclarations = true; - processDeclSpecifiers = true; - processDeclarators = true; - processNamespaces = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; + shouldVisitDeclSpecifiers = true; + shouldVisitDeclarators = true; + shouldVisitNamespaces = true; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ if( name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals( name.toCharArray(), nameArray ) ) { @@ -157,10 +154,10 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { return PROCESS_CONTINUE; } - public int processDeclaration( IASTDeclaration declaration ){ + public int visit( IASTDeclaration declaration ){ return (declaration instanceof IASTSimpleDeclaration ) ? PROCESS_CONTINUE : PROCESS_SKIP; } - public int processDeclSpecifier( IASTDeclSpecifier declSpec ){ + public int visit( IASTDeclSpecifier declSpec ){ return (declSpec instanceof ICPPASTCompositeTypeSpecifier ) ? PROCESS_CONTINUE : PROCESS_SKIP; } public int processDeclarators( IASTDeclarator declarator ) { return PROCESS_SKIP; } @@ -169,18 +166,12 @@ public class CPPClassType implements ICPPClassType, ICPPBinding { private void checkForDefinition(){ FindDefinitionAction action = new FindDefinitionAction(); IASTNode node = CPPVisitor.getContainingBlockItem( getPhysicalNode() ).getParent(); - ICPPASTVisitor visitor = (ICPPASTVisitor) node.getTranslationUnit().getVisitor(); - if( node instanceof ICPPASTNamespaceDefinition ){ - visitor.visitNamespaceDefinition( (ICPPASTNamespaceDefinition) node, action ); - definition = action.result; - } else if( node instanceof IASTCompoundStatement ){ - //a local class, nowhere else to look if we don't find it here... - visitor.visitStatement( (IASTStatement) node, action ); - definition = action.result; - return; - } + + node.accept( action ); + definition = action.result; + if( definition == null ){ - visitor.visitTranslationUnit( action ); + node.getTranslationUnit().accept( action ); definition = action.result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 47d0e82616f..e7df9ce2bc1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -17,16 +17,15 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.core.dom.ast.IASTVisitor.BaseVisitorAction; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -59,18 +58,18 @@ public class CPPNamespace implements ICPPNamespace, ICPPBinding { return ( tu != null ) ? tu : (IASTNode) namespaceDefinitions[0]; } - static private class NamespaceCollector extends CPPVisitor.CPPBaseVisitorAction { + static private class NamespaceCollector extends CPPASTVisitor { private char [] name; public List namespaces = Collections.EMPTY_LIST; public int processResult = PROCESS_SKIP; public NamespaceCollector( IASTName name ){ - processNamespaces = true; - processDeclarations = true; + shouldVisitNamespaces = true; + shouldVisitDeclarations = true; this.name = name.toCharArray(); } - public int processNamespace( ICPPASTNamespaceDefinition namespace) { + public int visit( ICPPASTNamespaceDefinition namespace) { if( CharArrayUtils.equals( namespace.getName().toCharArray(), name ) ){ if( namespaces == Collections.EMPTY_LIST ) namespaces = new ArrayList(); @@ -84,7 +83,7 @@ public class CPPNamespace implements ICPPNamespace, ICPPBinding { return processResult; } - public int processDeclaration( IASTDeclaration declaration ){ + public int visit( IASTDeclaration declaration ){ if( declaration instanceof ICPPASTLinkageSpecification ) return PROCESS_CONTINUE; return PROCESS_SKIP; @@ -96,16 +95,15 @@ public class CPPNamespace implements ICPPNamespace, ICPPBinding { ICPPASTNamespaceDefinition nsDef = (ICPPASTNamespaceDefinition) namespaceName.getParent(); IASTNode node = nsDef.getParent(); - ICPPASTVisitor visitor = (ICPPASTVisitor) node.getTranslationUnit().getVisitor(); while( node instanceof ICPPASTLinkageSpecification ) node = node.getParent(); - if( node instanceof IASTTranslationUnit ) - visitor.visitTranslationUnit( collector ); - else if( node instanceof ICPPASTNamespaceDefinition ){ - collector.processResult = BaseVisitorAction.PROCESS_CONTINUE; - visitor.visitNamespaceDefinition( (ICPPASTNamespaceDefinition) node, collector ); + + if( node instanceof ICPPASTNamespaceDefinition ){ + collector.processResult = ASTVisitor.PROCESS_CONTINUE; } + node.accept( collector ); + int size = collector.namespaces.size(); namespaceDefinitions = new IASTName [ size ]; for( int i = 0; i < size; i++ ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 5e5805f01b0..be3d8ea3335 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -18,24 +18,17 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; -import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; -import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpressionList; -import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; -import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; @@ -43,10 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTIfStatement; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; -import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -57,17 +47,13 @@ import org.eclipse.cdt.core.dom.ast.IASTPointer; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemHolder; -import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -85,38 +71,25 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; @@ -128,7 +101,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; -import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -138,7 +110,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @author aniefer */ -public class CPPVisitor implements ICPPASTVisitor { +public class CPPVisitor { /** * @param name @@ -712,12 +684,12 @@ public class CPPVisitor implements ICPPASTVisitor { return null; } - public static class CollectProblemsAction extends CPPBaseVisitorAction { + public static class CollectProblemsAction extends CPPASTVisitor { { - processDeclarations = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; + shouldVisitDeclarations = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; } private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; @@ -760,7 +732,7 @@ public class CPPVisitor implements ICPPASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { if ( declaration instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)declaration).getProblem()); @@ -769,7 +741,7 @@ public class CPPVisitor implements ICPPASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { if ( expression instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)expression).getProblem()); @@ -779,7 +751,7 @@ public class CPPVisitor implements ICPPASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { if ( statement instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)statement).getProblem()); @@ -789,7 +761,7 @@ public class CPPVisitor implements ICPPASTVisitor { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { if ( typeId instanceof IASTProblemHolder ) addProblem(((IASTProblemHolder)typeId).getProblem()); @@ -797,7 +769,7 @@ public class CPPVisitor implements ICPPASTVisitor { } } - public static class CollectDeclarationsAction extends CPPBaseVisitorAction { + public static class CollectDeclarationsAction extends CPPASTVisitor { private static final int DEFAULT_LIST_SIZE = 8; private IASTName [] decls; private IBinding binding; @@ -815,7 +787,7 @@ public class CPPVisitor implements ICPPASTVisitor { this.binding = binding; this.decls = new IASTName[ DEFAULT_LIST_SIZE ]; - processNames = true; + shouldVisitNames = true; if( binding instanceof ILabel ) kind = KIND_LABEL; else if( binding instanceof ICompositeType || @@ -833,7 +805,7 @@ public class CPPVisitor implements ICPPASTVisitor { kind = KIND_OBJ_FN; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ if( name instanceof ICPPASTQualifiedName ) return PROCESS_CONTINUE; ASTNodeProperty prop = name.getPropertyInParent(); @@ -920,7 +892,7 @@ public class CPPVisitor implements ICPPASTVisitor { } } - public static class CollectReferencesAction extends CPPBaseVisitorAction { + public static class CollectReferencesAction extends CPPASTVisitor { private static final int DEFAULT_LIST_SIZE = 8; private IASTName [] refs; private IBinding binding; @@ -938,7 +910,7 @@ public class CPPVisitor implements ICPPASTVisitor { this.binding = binding; this.refs = new IASTName[ DEFAULT_LIST_SIZE ]; - processNames = true; + shouldVisitNames = true; if( binding instanceof ILabel ) kind = KIND_LABEL; else if( binding instanceof ICompositeType || @@ -955,7 +927,7 @@ public class CPPVisitor implements ICPPASTVisitor { kind = KIND_OBJ_FN; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ if( name instanceof ICPPASTQualifiedName ) return PROCESS_CONTINUE; ASTNodeProperty prop = name.getPropertyInParent(); @@ -1069,503 +1041,503 @@ public class CPPVisitor implements ICPPASTVisitor { } } - private IASTTranslationUnit tu = null; - public CPPVisitor( ICPPASTTranslationUnit tu ){ - this.tu = tu; - } - - public void visitTranslationUnit( BaseVisitorAction action ){ - IASTDeclaration [] decls = tu.getDeclarations(); - for( int i = 0; i < decls.length; i++ ){ - if( !visitDeclaration( decls[i], action ) ) return; - } - } - - public boolean visitNamespaceDefinition( ICPPASTNamespaceDefinition namespace, BaseVisitorAction action ){ - if( action instanceof CPPBaseVisitorAction && ((CPPBaseVisitorAction)action).processNamespaces ){ - switch( ((CPPBaseVisitorAction)action).processNamespace( namespace ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitName( namespace.getName(), action ) ) return false; - IASTDeclaration [] decls = namespace.getDeclarations(); - for( int i = 0; i < decls.length; i++ ){ - if( !visitDeclaration( decls[i], action ) ) return false; - } - return true; - } - /** - * @param declaration - * @param action - * @return - */ - public boolean visitDeclaration(IASTDeclaration declaration, BaseVisitorAction action) { - if( declaration instanceof ICPPASTNamespaceDefinition ) - return visitNamespaceDefinition( (ICPPASTNamespaceDefinition) declaration, action ); - - if( action.processDeclarations ) { - switch( action.processDeclaration( declaration ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( declaration instanceof IASTSimpleDeclaration ){ - IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration; - if( !visitDeclSpecifier( simple.getDeclSpecifier(), action ) ) return false; - IASTDeclarator [] dtors = simple.getDeclarators(); - for( int i = 0; i < dtors.length; i++ ){ - if( !visitDeclarator( dtors[i], action) ) return false; - } - } else if( declaration instanceof IASTFunctionDefinition ){ - IASTFunctionDefinition function = (IASTFunctionDefinition) declaration; - if( !visitDeclSpecifier( function.getDeclSpecifier(), action ) ) return false; - if( !visitDeclarator( function.getDeclarator(), action ) ) return false; - if( !visitStatement( function.getBody(), action ) ) return false; - } else if( declaration instanceof ICPPASTUsingDeclaration ){ - if( !visitName( ((ICPPASTUsingDeclaration)declaration).getName(), action ) ) return false; - } else if( declaration instanceof ICPPASTUsingDirective ){ - if( !visitName( ((ICPPASTUsingDirective)declaration).getQualifiedName(), action ) ) return false; - } else if( declaration instanceof ICPPASTNamespaceAlias ){ - ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration; - if( !visitName( alias.getAlias(), action ) ) return false; - if( !visitName( alias.getQualifiedName(), action ) ) return false; - } else if( declaration instanceof ICPPASTLinkageSpecification ){ - IASTDeclaration [] decls = ((ICPPASTLinkageSpecification) declaration).getDeclarations(); - for( int i = 0; i < decls.length; i++ ){ - if( !visitDeclaration( decls[i], action ) ) return false; - } - } else if( declaration instanceof ICPPASTTemplateDeclaration ){ - ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) declaration; - ICPPASTTemplateParameter [] params = template.getTemplateParameters(); - for( int i = 0; i < params.length; i++ ){ - if( !visitTemplateParameter( params[i], action ) ) return false; - } - if( !visitDeclaration( template.getDeclaration(), action ) ) return false; - } else if( declaration instanceof ICPPASTTemplateSpecialization ){ - if( !visitDeclaration( ((ICPPASTTemplateSpecialization) declaration).getDeclaration(), action ) ) return false; - } - return true; - } - - /** - * @param name - * @param action - * @return - */ - public boolean visitName(IASTName name, BaseVisitorAction action) { - if( action.processNames ){ - switch( action.processName( name ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName)name).getNames(); - for( int i = 0; i < names.length; i++ ){ - if( i == names.length - 1 ){ - if( names[i].toCharArray().length > 0 && !visitName( names[i], action ) ) return false; - } else if( !visitName( names[i], action ) ) return false; - } - } - return true; - } - - /** - * @param declSpecifier - * @param action - * @return - */ - public boolean visitDeclSpecifier(IASTDeclSpecifier declSpecifier, BaseVisitorAction action) { - if( action.processDeclSpecifiers ){ - switch( action.processDeclSpecifier( declSpecifier ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( declSpecifier instanceof ICPPASTCompositeTypeSpecifier ){ - ICPPASTCompositeTypeSpecifier composite = (ICPPASTCompositeTypeSpecifier) declSpecifier; - if( !visitName( composite.getName(), action ) ) return false; - ICPPASTBaseSpecifier [] bases = composite.getBaseSpecifiers(); - for( int i = 0; i < bases.length; i++ ) { - if( !visitBaseSpecifier( bases[i], action ) ) return false; - } - IASTDeclaration [] decls = composite.getMembers(); - for( int i = 0; i < decls.length; i++ ){ - if( !visitDeclaration( decls[i], action ) ) return false; - } - } else if( declSpecifier instanceof ICPPASTElaboratedTypeSpecifier ){ - if( !visitName( ((ICPPASTElaboratedTypeSpecifier) declSpecifier).getName(), action ) ) return false; - } else if( declSpecifier instanceof IASTEnumerationSpecifier ){ - IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) declSpecifier; - if( !visitName( enumeration.getName(), action ) ) return false; - IASTEnumerator [] etors = enumeration.getEnumerators(); - for( int i = 0; i < etors.length; i++ ){ - if( !visitEnumerator( etors[i], action ) ) return false; - } - } else if( declSpecifier instanceof ICPPASTNamedTypeSpecifier ){ - if( !visitName( ((ICPPASTNamedTypeSpecifier)declSpecifier).getName(), action ) ) return false; - } else if( declSpecifier instanceof IGPPASTSimpleDeclSpecifier ) { - IASTExpression typeOf = ((IGPPASTSimpleDeclSpecifier)declSpecifier).getTypeofExpression(); - if( typeOf != null ) - if( !visitExpression( typeOf, action ) ) return false; - } - return true; - } - - /** - * @param declarator - * @param action - * @return - */ - public boolean visitDeclarator(IASTDeclarator declarator, BaseVisitorAction action) { - if( action.processDeclarators ){ - switch( action.processDeclarator( declarator ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - IASTPointerOperator [] ptrs = declarator.getPointerOperators(); - if( ptrs.length > 0 ){ - for( int i = 0; i < ptrs.length; i++ ){ - if( ptrs[i] instanceof ICPPASTPointerToMember ){ - if( !visitName( ((ICPPASTPointerToMember) ptrs[i]).getName(), action ) ) return false; - } - } - } - - if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && - declarator.getNestedDeclarator() == null ) - { - if( !visitName( declarator.getName(), action ) ) return false; - } - - if( declarator.getNestedDeclarator() != null ) - if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false; - - if( declarator instanceof ICPPASTFunctionDeclarator ){ - ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) declarator; - IASTParameterDeclaration [] list = fdtor.getParameters(); - for( int i = 0; i < list.length; i++ ){ - if( !visitParameterDeclaration( list[i], action ) ) return false; - } - ICPPASTConstructorChainInitializer [] ctorChain = fdtor.getConstructorChain(); - for( int i = 0; i < ctorChain.length; i++ ){ - if( !visitName( ctorChain[i].getMemberInitializerId(), action ) ) return false; - if( !visitExpression( ctorChain[i].getInitializerValue(), action ) ) return false; - } - IASTTypeId [] typeIds = fdtor.getExceptionSpecification(); - for( int i = 0; i < typeIds.length; i++ ){ - if( !visitTypeId( typeIds[i], action ) ) return false; - } - - if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){ - ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers(); - for( int i = 0; i < catchHandlers.length; i++ ){ - if( !visitStatement( catchHandlers[i], action ) ) return false; - } - } - - } - if( declarator instanceof IASTArrayDeclarator ){ - IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers(); - for( int i = 0; i < mods.length; i++ ){ - if( mods[i].getConstantExpression() != null && !visitExpression( mods[i].getConstantExpression(), action ) ) return false; - } - } - - if( declarator.getInitializer() != null ) - if( !visitInitializer( declarator.getInitializer(), action ) ) return false; - - if( declarator instanceof IASTFieldDeclarator ) - if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false; - - return true; - } - - private boolean visitIfStatement( IASTIfStatement ifStatement, BaseVisitorAction action ){ - while( ifStatement != null ){ - if( action.processStatements ){ - switch( action.processStatement( ifStatement ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - if( !visitExpression( ifStatement.getCondition(), action ) ) return false; - if( !visitStatement( ifStatement.getThenClause(), action ) ) return false; - if( ifStatement.getElseClause() != null ){ - IASTStatement statement = ifStatement.getElseClause(); - if( statement instanceof IASTIfStatement ){ - ifStatement = (IASTIfStatement) statement; - continue; - } - if( !visitStatement( statement, action ) ) return false; - } - ifStatement = null; - } - return true; - } - /** - * @param body - * @param action - * @return - */ - public boolean visitStatement(IASTStatement statement, BaseVisitorAction action) { - //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses - if( statement instanceof IASTIfStatement ) - return visitIfStatement( (IASTIfStatement) statement, action ); - - if( action.processStatements ){ - switch( action.processStatement( statement ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( statement instanceof IASTCompoundStatement ){ - IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements(); - for( int i = 0; i < list.length; i++ ){ - if( list[i] == null ) break; - if( !visitStatement( list[i], action ) ) return false; - } - } else if( statement instanceof IASTDeclarationStatement ){ - if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false; - } else if( statement instanceof IASTExpressionStatement ){ - if( !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false; - } else if( statement instanceof IASTCaseStatement ){ - if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false; - } else if( statement instanceof IASTDoStatement ){ - if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false; - if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false; - } else if( statement instanceof IASTGotoStatement ){ - if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false; - } else if( statement instanceof IASTLabelStatement ){ - if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false; - } else if( statement instanceof IASTReturnStatement ){ - if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false; - } else if( statement instanceof IASTSwitchStatement ){ - if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false; - if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false; - } else if( statement instanceof IASTWhileStatement ){ - IASTWhileStatement whileStatement = (IASTWhileStatement) statement; - if( whileStatement.getCondition() != null && !visitExpression( (whileStatement ).getCondition(), action ) ) return false; - if( !visitStatement( (whileStatement ).getBody(), action ) ) return false; - if( whileStatement instanceof ICPPASTWhileStatement ) - { - ICPPASTWhileStatement cppWhile = ((ICPPASTWhileStatement)whileStatement); - if ( cppWhile.getConditionDeclaration() != null && !visitDeclaration( cppWhile.getConditionDeclaration(), action ) ) return false; - } - } else if( statement instanceof IASTForStatement ){ - IASTForStatement s = (IASTForStatement) statement; - if( s.getInitDeclaration() != null ) - if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false; - if( s.getInitExpression() != null ) - if( !visitExpression( s.getInitExpression(), action ) ) return false; - if( !visitExpression( s.getCondition(), action ) ) return false; - if( !visitExpression( s.getIterationExpression(), action ) ) return false; - if( !visitStatement( s.getBody(), action ) ) return false; - } else if( statement instanceof ICPPASTCatchHandler ){ - if( !visitDeclaration( ((ICPPASTCatchHandler) statement).getDeclaration(), action ) ) return false; - if( !visitStatement( ((ICPPASTCatchHandler) statement).getCatchBody(), action ) ) return false; - } else if( statement instanceof ICPPASTTryBlockStatement ){ - if( !visitStatement( ((ICPPASTTryBlockStatement)statement).getTryBody(), action ) ) return false; - ICPPASTCatchHandler [] handlers = ((ICPPASTTryBlockStatement)statement).getCatchHandlers(); - for( int i = 0; i < handlers.length; i++ ){ - if( !visitStatement( handlers[i], action ) ) return false; - } - } - - return true; - } - - /** - * @param typeOf - * @param action - * @return - */ - public boolean visitExpression(IASTExpression expression, BaseVisitorAction action) { - if( action.processExpressions ){ - switch( action.processExpression( expression ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( expression instanceof IASTArraySubscriptExpression ){ - if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false; - if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false; - } else if( expression instanceof IASTBinaryExpression ){ - if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false; - if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false; - } else if( expression instanceof IASTConditionalExpression){ - if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false; - if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false; - if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false; - } else if( expression instanceof IASTExpressionList ){ - IASTExpression[] list = ((IASTExpressionList)expression).getExpressions(); - for( int i = 0; i < list.length; i++){ - if( list[i] == null ) break; - if( !visitExpression( list[i], action ) ) return false; - } - } else if( expression instanceof IASTFieldReference ){ - if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false; - if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false; - } else if( expression instanceof IASTFunctionCallExpression ){ - if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false; - if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null ) - if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false; - } else if( expression instanceof IASTIdExpression ){ - if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false; - } else if( expression instanceof IASTTypeIdExpression ){ - if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false; - } else if( expression instanceof IASTCastExpression ){ - if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false; - if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false; - } else if( expression instanceof IASTUnaryExpression ){ - if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false; - } else if( expression instanceof IGNUASTCompoundStatementExpression ){ - if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false; - } else if( expression instanceof ICPPASTDeleteExpression ){ - if( !visitExpression( ((ICPPASTDeleteExpression)expression).getOperand(), action ) ) return false; - } else if( expression instanceof ICPPASTNewExpression ) { - ICPPASTNewExpression newExp = (ICPPASTNewExpression) expression; - if( newExp.getNewPlacement() != null ) - if( !visitExpression( newExp.getNewPlacement(), action ) ) return false; - if( newExp.getTypeId() != null ) - if( !visitTypeId( newExp.getTypeId(), action ) ) return false; - IASTExpression [] exps = newExp.getNewTypeIdArrayExpressions(); - for( int i = 0; i < exps.length; i++ ){ - if( !visitExpression( exps[i], action ) ) return false; - } - if( newExp.getNewInitializer() != null ) - if( !visitExpression( newExp.getNewInitializer(), action ) ) return false; - } else if( expression instanceof ICPPASTSimpleTypeConstructorExpression ){ - if( !visitExpression( ((ICPPASTSimpleTypeConstructorExpression)expression).getInitialValue(), action ) ) return false; - } else if( expression instanceof ICPPASTTypenameExpression ){ - if( !visitName( ((ICPPASTTypenameExpression)expression).getName(), action ) ) return false; - if( !visitExpression( ((ICPPASTTypenameExpression)expression).getInitialValue(), action ) ) return false; - } - return true; - } - - /** - * @param typeId - * @param action - * @return - */ - public boolean visitTypeId(IASTTypeId typeId, BaseVisitorAction action) { - if( action.processTypeIds ){ - switch( action.processTypeId( typeId ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false; - if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false; - return true; - } - - /** - * @param initializer - * @param action - * @return - */ - public boolean visitInitializer(IASTInitializer initializer, BaseVisitorAction action) { - if( action.processInitializers ){ - switch( action.processInitializer( initializer ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( initializer instanceof IASTInitializerExpression ){ - if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false; - } else if( initializer instanceof IASTInitializerList ){ - IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers(); - for( int i = 0; i < list.length; i++ ){ - if( !visitInitializer( list[i], action ) ) return false; - } - } else if( initializer instanceof ICPPASTConstructorInitializer ){ - if( !visitExpression( ((ICPPASTConstructorInitializer) initializer).getExpression(), action ) ) return false; - } - return true; - } - - /** - * @param enumerator - * @param action - * @return - */ - public boolean visitEnumerator(IASTEnumerator enumerator, BaseVisitorAction action) { - if( action.processEnumerators ){ - switch( action.processEnumerator( enumerator ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitName( enumerator.getName(), action ) ) return false; - if( enumerator.getValue() != null ) - if( !visitExpression( enumerator.getValue(), action ) ) return false; - return true; - } - - /** - * @param specifier - * @param action - * @return - */ - public boolean visitBaseSpecifier(ICPPASTBaseSpecifier specifier, BaseVisitorAction action) { - if( action instanceof CPPBaseVisitorAction && ((CPPBaseVisitorAction)action).processBaseSpecifiers ){ - switch( ((CPPBaseVisitorAction)action).processBaseSpecifier( specifier ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitName( specifier.getName(), action ) ) return false; - return true; - } - - public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, BaseVisitorAction action ){ - if( action.processParameterDeclarations ){ - switch( action.processParameterDeclaration( parameterDeclaration ) ){ - case BaseVisitorAction.PROCESS_ABORT : return false; - case BaseVisitorAction.PROCESS_SKIP : return true; - default : break; - } - } - - if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false; - if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false; - return true; - } - - /** - * @param parameter - * @param action - * @return - */ - public boolean visitTemplateParameter(ICPPASTTemplateParameter parameter, BaseVisitorAction action) { - return true; - } +// private IASTTranslationUnit tu = null; +// public CPPVisitor( ICPPASTTranslationUnit tu ){ +// this.tu = tu; +// } +// +// public void visitTranslationUnit( ASTVisitor action ){ +// IASTDeclaration [] decls = tu.getDeclarations(); +// for( int i = 0; i < decls.length; i++ ){ +// if( !visitDeclaration( decls[i], action ) ) return; +// } +// } +// +// public boolean visitNamespaceDefinition( ICPPASTNamespaceDefinition namespace, ASTVisitor action ){ +// if( action instanceof CPPASTVisitor && ((CPPASTVisitor)action).processNamespaces ){ +// switch( ((CPPASTVisitor)action).processNamespace( namespace ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitName( namespace.getName(), action ) ) return false; +// IASTDeclaration [] decls = namespace.getDeclarations(); +// for( int i = 0; i < decls.length; i++ ){ +// if( !visitDeclaration( decls[i], action ) ) return false; +// } +// return true; +// } +// /** +// * @param declaration +// * @param action +// * @return +// */ +// public boolean visitDeclaration(IASTDeclaration declaration, ASTVisitor action) { +// if( declaration instanceof ICPPASTNamespaceDefinition ) +// return visitNamespaceDefinition( (ICPPASTNamespaceDefinition) declaration, action ); +// +// if( action.processDeclarations ) { +// switch( action.processDeclaration( declaration ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( declaration instanceof IASTSimpleDeclaration ){ +// IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration; +// if( !visitDeclSpecifier( simple.getDeclSpecifier(), action ) ) return false; +// IASTDeclarator [] dtors = simple.getDeclarators(); +// for( int i = 0; i < dtors.length; i++ ){ +// if( !visitDeclarator( dtors[i], action) ) return false; +// } +// } else if( declaration instanceof IASTFunctionDefinition ){ +// IASTFunctionDefinition function = (IASTFunctionDefinition) declaration; +// if( !visitDeclSpecifier( function.getDeclSpecifier(), action ) ) return false; +// if( !visitDeclarator( function.getDeclarator(), action ) ) return false; +// if( !visitStatement( function.getBody(), action ) ) return false; +// } else if( declaration instanceof ICPPASTUsingDeclaration ){ +// if( !visitName( ((ICPPASTUsingDeclaration)declaration).getName(), action ) ) return false; +// } else if( declaration instanceof ICPPASTUsingDirective ){ +// if( !visitName( ((ICPPASTUsingDirective)declaration).getQualifiedName(), action ) ) return false; +// } else if( declaration instanceof ICPPASTNamespaceAlias ){ +// ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration; +// if( !visitName( alias.getAlias(), action ) ) return false; +// if( !visitName( alias.getQualifiedName(), action ) ) return false; +// } else if( declaration instanceof ICPPASTLinkageSpecification ){ +// IASTDeclaration [] decls = ((ICPPASTLinkageSpecification) declaration).getDeclarations(); +// for( int i = 0; i < decls.length; i++ ){ +// if( !visitDeclaration( decls[i], action ) ) return false; +// } +// } else if( declaration instanceof ICPPASTTemplateDeclaration ){ +// ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) declaration; +// ICPPASTTemplateParameter [] params = template.getTemplateParameters(); +// for( int i = 0; i < params.length; i++ ){ +// if( !visitTemplateParameter( params[i], action ) ) return false; +// } +// if( !visitDeclaration( template.getDeclaration(), action ) ) return false; +// } else if( declaration instanceof ICPPASTTemplateSpecialization ){ +// if( !visitDeclaration( ((ICPPASTTemplateSpecialization) declaration).getDeclaration(), action ) ) return false; +// } +// return true; +// } +// +// /** +// * @param name +// * @param action +// * @return +// */ +// public boolean visitName(IASTName name, ASTVisitor action) { +// if( action.processNames ){ +// switch( action.processName( name ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( name instanceof ICPPASTQualifiedName ){ +// IASTName [] names = ((ICPPASTQualifiedName)name).getNames(); +// for( int i = 0; i < names.length; i++ ){ +// if( i == names.length - 1 ){ +// if( names[i].toCharArray().length > 0 && !visitName( names[i], action ) ) return false; +// } else if( !visitName( names[i], action ) ) return false; +// } +// } +// return true; +// } +// +// /** +// * @param declSpecifier +// * @param action +// * @return +// */ +// public boolean visitDeclSpecifier(IASTDeclSpecifier declSpecifier, ASTVisitor action) { +// if( action.processDeclSpecifiers ){ +// switch( action.processDeclSpecifier( declSpecifier ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( declSpecifier instanceof ICPPASTCompositeTypeSpecifier ){ +// ICPPASTCompositeTypeSpecifier composite = (ICPPASTCompositeTypeSpecifier) declSpecifier; +// if( !visitName( composite.getName(), action ) ) return false; +// ICPPASTBaseSpecifier [] bases = composite.getBaseSpecifiers(); +// for( int i = 0; i < bases.length; i++ ) { +// if( !visitBaseSpecifier( bases[i], action ) ) return false; +// } +// IASTDeclaration [] decls = composite.getMembers(); +// for( int i = 0; i < decls.length; i++ ){ +// if( !visitDeclaration( decls[i], action ) ) return false; +// } +// } else if( declSpecifier instanceof ICPPASTElaboratedTypeSpecifier ){ +// if( !visitName( ((ICPPASTElaboratedTypeSpecifier) declSpecifier).getName(), action ) ) return false; +// } else if( declSpecifier instanceof IASTEnumerationSpecifier ){ +// IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) declSpecifier; +// if( !visitName( enumeration.getName(), action ) ) return false; +// IASTEnumerator [] etors = enumeration.getEnumerators(); +// for( int i = 0; i < etors.length; i++ ){ +// if( !visitEnumerator( etors[i], action ) ) return false; +// } +// } else if( declSpecifier instanceof ICPPASTNamedTypeSpecifier ){ +// if( !visitName( ((ICPPASTNamedTypeSpecifier)declSpecifier).getName(), action ) ) return false; +// } else if( declSpecifier instanceof IGPPASTSimpleDeclSpecifier ) { +// IASTExpression typeOf = ((IGPPASTSimpleDeclSpecifier)declSpecifier).getTypeofExpression(); +// if( typeOf != null ) +// if( !visitExpression( typeOf, action ) ) return false; +// } +// return true; +// } +// +// /** +// * @param declarator +// * @param action +// * @return +// */ +// public boolean visitDeclarator(IASTDeclarator declarator, ASTVisitor action) { +// if( action.processDeclarators ){ +// switch( action.processDeclarator( declarator ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// IASTPointerOperator [] ptrs = declarator.getPointerOperators(); +// if( ptrs.length > 0 ){ +// for( int i = 0; i < ptrs.length; i++ ){ +// if( ptrs[i] instanceof ICPPASTPointerToMember ){ +// if( !visitName( ((ICPPASTPointerToMember) ptrs[i]).getName(), action ) ) return false; +// } +// } +// } +// +// if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && +// declarator.getNestedDeclarator() == null ) +// { +// if( !visitName( declarator.getName(), action ) ) return false; +// } +// +// if( declarator.getNestedDeclarator() != null ) +// if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false; +// +// if( declarator instanceof ICPPASTFunctionDeclarator ){ +// ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) declarator; +// IASTParameterDeclaration [] list = fdtor.getParameters(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitParameterDeclaration( list[i], action ) ) return false; +// } +// ICPPASTConstructorChainInitializer [] ctorChain = fdtor.getConstructorChain(); +// for( int i = 0; i < ctorChain.length; i++ ){ +// if( !visitName( ctorChain[i].getMemberInitializerId(), action ) ) return false; +// if( !visitExpression( ctorChain[i].getInitializerValue(), action ) ) return false; +// } +// IASTTypeId [] typeIds = fdtor.getExceptionSpecification(); +// for( int i = 0; i < typeIds.length; i++ ){ +// if( !visitTypeId( typeIds[i], action ) ) return false; +// } +// +// if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){ +// ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers(); +// for( int i = 0; i < catchHandlers.length; i++ ){ +// if( !visitStatement( catchHandlers[i], action ) ) return false; +// } +// } +// +// } +// if( declarator instanceof IASTArrayDeclarator ){ +// IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers(); +// for( int i = 0; i < mods.length; i++ ){ +// if( mods[i].getConstantExpression() != null && !visitExpression( mods[i].getConstantExpression(), action ) ) return false; +// } +// } +// +// if( declarator.getInitializer() != null ) +// if( !visitInitializer( declarator.getInitializer(), action ) ) return false; +// +// if( declarator instanceof IASTFieldDeclarator ) +// if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false; +// +// return true; +// } +// +// private boolean visitIfStatement( IASTIfStatement ifStatement, ASTVisitor action ){ +// while( ifStatement != null ){ +// if( action.processStatements ){ +// switch( action.processStatement( ifStatement ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// if( !visitExpression( ifStatement.getCondition(), action ) ) return false; +// if( !visitStatement( ifStatement.getThenClause(), action ) ) return false; +// if( ifStatement.getElseClause() != null ){ +// IASTStatement statement = ifStatement.getElseClause(); +// if( statement instanceof IASTIfStatement ){ +// ifStatement = (IASTIfStatement) statement; +// continue; +// } +// if( !visitStatement( statement, action ) ) return false; +// } +// ifStatement = null; +// } +// return true; +// } +// /** +// * @param body +// * @param action +// * @return +// */ +// public boolean visitStatement(IASTStatement statement, ASTVisitor action) { +// //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses +// if( statement instanceof IASTIfStatement ) +// return visitIfStatement( (IASTIfStatement) statement, action ); +// +// if( action.processStatements ){ +// switch( action.processStatement( statement ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( statement instanceof IASTCompoundStatement ){ +// IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements(); +// for( int i = 0; i < list.length; i++ ){ +// if( list[i] == null ) break; +// if( !visitStatement( list[i], action ) ) return false; +// } +// } else if( statement instanceof IASTDeclarationStatement ){ +// if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false; +// } else if( statement instanceof IASTExpressionStatement ){ +// if( !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false; +// } else if( statement instanceof IASTCaseStatement ){ +// if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false; +// } else if( statement instanceof IASTDoStatement ){ +// if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false; +// if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false; +// } else if( statement instanceof IASTGotoStatement ){ +// if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false; +// } else if( statement instanceof IASTLabelStatement ){ +// if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false; +// } else if( statement instanceof IASTReturnStatement ){ +// if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false; +// } else if( statement instanceof IASTSwitchStatement ){ +// if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false; +// if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false; +// } else if( statement instanceof IASTWhileStatement ){ +// IASTWhileStatement whileStatement = (IASTWhileStatement) statement; +// if( whileStatement.getCondition() != null && !visitExpression( (whileStatement ).getCondition(), action ) ) return false; +// if( !visitStatement( (whileStatement ).getBody(), action ) ) return false; +// if( whileStatement instanceof ICPPASTWhileStatement ) +// { +// ICPPASTWhileStatement cppWhile = ((ICPPASTWhileStatement)whileStatement); +// if ( cppWhile.getConditionDeclaration() != null && !visitDeclaration( cppWhile.getConditionDeclaration(), action ) ) return false; +// } +// } else if( statement instanceof IASTForStatement ){ +// IASTForStatement s = (IASTForStatement) statement; +// if( s.getInitDeclaration() != null ) +// if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false; +// if( s.getInitExpression() != null ) +// if( !visitExpression( s.getInitExpression(), action ) ) return false; +// if( !visitExpression( s.getCondition(), action ) ) return false; +// if( !visitExpression( s.getIterationExpression(), action ) ) return false; +// if( !visitStatement( s.getBody(), action ) ) return false; +// } else if( statement instanceof ICPPASTCatchHandler ){ +// if( !visitDeclaration( ((ICPPASTCatchHandler) statement).getDeclaration(), action ) ) return false; +// if( !visitStatement( ((ICPPASTCatchHandler) statement).getCatchBody(), action ) ) return false; +// } else if( statement instanceof ICPPASTTryBlockStatement ){ +// if( !visitStatement( ((ICPPASTTryBlockStatement)statement).getTryBody(), action ) ) return false; +// ICPPASTCatchHandler [] handlers = ((ICPPASTTryBlockStatement)statement).getCatchHandlers(); +// for( int i = 0; i < handlers.length; i++ ){ +// if( !visitStatement( handlers[i], action ) ) return false; +// } +// } +// +// return true; +// } +// +// /** +// * @param typeOf +// * @param action +// * @return +// */ +// public boolean visitExpression(IASTExpression expression, ASTVisitor action) { +// if( action.processExpressions ){ +// switch( action.processExpression( expression ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( expression instanceof IASTArraySubscriptExpression ){ +// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false; +// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false; +// } else if( expression instanceof IASTBinaryExpression ){ +// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false; +// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false; +// } else if( expression instanceof IASTConditionalExpression){ +// if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false; +// if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false; +// if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false; +// } else if( expression instanceof IASTExpressionList ){ +// IASTExpression[] list = ((IASTExpressionList)expression).getExpressions(); +// for( int i = 0; i < list.length; i++){ +// if( list[i] == null ) break; +// if( !visitExpression( list[i], action ) ) return false; +// } +// } else if( expression instanceof IASTFieldReference ){ +// if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false; +// if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false; +// } else if( expression instanceof IASTFunctionCallExpression ){ +// if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false; +// if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null ) +// if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false; +// } else if( expression instanceof IASTIdExpression ){ +// if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false; +// } else if( expression instanceof IASTTypeIdExpression ){ +// if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false; +// } else if( expression instanceof IASTCastExpression ){ +// if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false; +// if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false; +// } else if( expression instanceof IASTUnaryExpression ){ +// if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false; +// } else if( expression instanceof IGNUASTCompoundStatementExpression ){ +// if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false; +// } else if( expression instanceof ICPPASTDeleteExpression ){ +// if( !visitExpression( ((ICPPASTDeleteExpression)expression).getOperand(), action ) ) return false; +// } else if( expression instanceof ICPPASTNewExpression ) { +// ICPPASTNewExpression newExp = (ICPPASTNewExpression) expression; +// if( newExp.getNewPlacement() != null ) +// if( !visitExpression( newExp.getNewPlacement(), action ) ) return false; +// if( newExp.getTypeId() != null ) +// if( !visitTypeId( newExp.getTypeId(), action ) ) return false; +// IASTExpression [] exps = newExp.getNewTypeIdArrayExpressions(); +// for( int i = 0; i < exps.length; i++ ){ +// if( !visitExpression( exps[i], action ) ) return false; +// } +// if( newExp.getNewInitializer() != null ) +// if( !visitExpression( newExp.getNewInitializer(), action ) ) return false; +// } else if( expression instanceof ICPPASTSimpleTypeConstructorExpression ){ +// if( !visitExpression( ((ICPPASTSimpleTypeConstructorExpression)expression).getInitialValue(), action ) ) return false; +// } else if( expression instanceof ICPPASTTypenameExpression ){ +// if( !visitName( ((ICPPASTTypenameExpression)expression).getName(), action ) ) return false; +// if( !visitExpression( ((ICPPASTTypenameExpression)expression).getInitialValue(), action ) ) return false; +// } +// return true; +// } +// +// /** +// * @param typeId +// * @param action +// * @return +// */ +// public boolean visitTypeId(IASTTypeId typeId, ASTVisitor action) { +// if( action.processTypeIds ){ +// switch( action.processTypeId( typeId ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false; +// if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false; +// return true; +// } +// +// /** +// * @param initializer +// * @param action +// * @return +// */ +// public boolean visitInitializer(IASTInitializer initializer, ASTVisitor action) { +// if( action.processInitializers ){ +// switch( action.processInitializer( initializer ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( initializer instanceof IASTInitializerExpression ){ +// if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false; +// } else if( initializer instanceof IASTInitializerList ){ +// IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers(); +// for( int i = 0; i < list.length; i++ ){ +// if( !visitInitializer( list[i], action ) ) return false; +// } +// } else if( initializer instanceof ICPPASTConstructorInitializer ){ +// if( !visitExpression( ((ICPPASTConstructorInitializer) initializer).getExpression(), action ) ) return false; +// } +// return true; +// } +// +// /** +// * @param enumerator +// * @param action +// * @return +// */ +// public boolean visitEnumerator(IASTEnumerator enumerator, ASTVisitor action) { +// if( action.processEnumerators ){ +// switch( action.processEnumerator( enumerator ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitName( enumerator.getName(), action ) ) return false; +// if( enumerator.getValue() != null ) +// if( !visitExpression( enumerator.getValue(), action ) ) return false; +// return true; +// } +// +// /** +// * @param specifier +// * @param action +// * @return +// */ +// public boolean visitBaseSpecifier(ICPPASTBaseSpecifier specifier, ASTVisitor action) { +// if( action instanceof CPPASTVisitor && ((CPPASTVisitor)action).processBaseSpecifiers ){ +// switch( ((CPPASTVisitor)action).processBaseSpecifier( specifier ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitName( specifier.getName(), action ) ) return false; +// return true; +// } +// +// public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, ASTVisitor action ){ +// if( action.processParameterDeclarations ){ +// switch( action.processParameterDeclaration( parameterDeclaration ) ){ +// case ASTVisitor.PROCESS_ABORT : return false; +// case ASTVisitor.PROCESS_SKIP : return true; +// default : break; +// } +// } +// +// if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false; +// if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false; +// return true; +// } +// +// /** +// * @param parameter +// * @param action +// * @return +// */ +// public boolean visitTemplateParameter(ICPPASTTemplateParameter parameter, ASTVisitor action) { +// return true; +// } /** * Generate a function type for an implicit function. @@ -1931,7 +1903,7 @@ public class CPPVisitor implements ICPPASTVisitor { public static IASTProblem[] getProblems(IASTTranslationUnit tu) { CollectProblemsAction action = new CollectProblemsAction(); - tu.getVisitor().visitTranslationUnit(action); + tu.accept(action); return action.getProblems(); } @@ -1943,13 +1915,13 @@ public class CPPVisitor implements ICPPASTVisitor { */ public static IASTName[] getReferences(IASTTranslationUnit tu, IBinding binding) { CollectReferencesAction action = new CollectReferencesAction( binding ); - tu.getVisitor().visitTranslationUnit( action ); + tu.accept( action ); return action.getReferences(); } public static IASTName[] getDeclarations( IASTTranslationUnit tu, IBinding binding ){ CollectDeclarationsAction action = new CollectDeclarationsAction( binding ); - tu.getVisitor().visitTranslationUnit( action ); + tu.accept( action ); return action.getDeclarations(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java index 8f016327f0a..44758e35a2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; @@ -65,4 +66,17 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier return typeOfExpression; } + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitDeclSpecifiers ){ + switch( action.visit( this ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + if( typeOfExpression != null ) + if( !typeOfExpression.accept( action ) ) return false; + + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 19c55589150..481aa111cbb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.List; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -565,6 +566,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { return (IASTTranslationUnit) node; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#accept(org.eclipse.cdt.core.dom.ast.IASTVisitor.BaseVisitorAction) + */ + public boolean accept( ASTVisitor visitor ) { + return true; + } + } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java index cc618868f9b..eff6837ce2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -305,4 +306,11 @@ public class ScannerASTProblem extends ASTNode implements IASTProblem { return (IASTTranslationUnit) node; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#accept(org.eclipse.cdt.core.dom.ast.IASTVisitor.BaseVisitorAction) + */ + public boolean accept( ASTVisitor visitor ) { + return true; + } + } diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java index bbdc5ad34c0..58f5249df62 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java @@ -31,13 +31,13 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor.CPPBaseVisitorAction; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionStatement; import org.eclipse.core.runtime.IProgressMonitor; @@ -45,21 +45,21 @@ import org.eclipse.core.runtime.IProgressMonitor; /** * @author dsteffle */ -public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IPopulateDOMASTAction { +public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulateDOMASTAction { private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8; { - processNames = true; - processDeclarations = true; - processInitializers = true; - processParameterDeclarations = true; - processDeclarators = true; - processDeclSpecifiers = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; - processEnumerators = true; - processBaseSpecifiers = true; - processNamespaces = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; + shouldVisitInitializers = true; + shouldVisitParameterDeclarations = true; + shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; + shouldVisitEnumerators = true; + shouldVisitBaseSpecifiers = true; + shouldVisitNamespaces = true; } TreeParent root = null; @@ -102,14 +102,14 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { return addRoot(declaration); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ - public int processDeclarator(IASTDeclarator declarator) { + public int visit(IASTDeclarator declarator) { int ret = addRoot(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); @@ -142,42 +142,42 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) */ - public int processBaseSpecifier(ICPPASTBaseSpecifier specifier) { + public int visit(ICPPASTBaseSpecifier specifier) { return addRoot(specifier); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ - public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + public int visit(IASTDeclSpecifier declSpec) { return addRoot(declSpec); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ - public int processEnumerator(IASTEnumerator enumerator) { + public int visit(IASTEnumerator enumerator) { return addRoot(enumerator); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { return addRoot(expression); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ - public int processInitializer(IASTInitializer initializer) { + public int visit(IASTInitializer initializer) { return addRoot(initializer); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) */ - public int processName(IASTName name) { + public int visit(IASTName name) { if (name.toString() != null) return addRoot(name); return PROCESS_CONTINUE; @@ -186,14 +186,14 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) */ - public int processNamespace(ICPPASTNamespaceDefinition namespace) { + public int visit(ICPPASTNamespaceDefinition namespace) { return addRoot(namespace); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ - public int processParameterDeclaration( + public int visit( IASTParameterDeclaration parameterDeclaration) { return addRoot(parameterDeclaration); } @@ -201,14 +201,14 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { return addRoot(statement); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { return addRoot(typeId); } diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java index 1397cc6aad9..694a39185e6 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java @@ -31,8 +31,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; -import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor.CBaseVisitorAction; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionStatement; import org.eclipse.core.runtime.IProgressMonitor; @@ -40,20 +40,20 @@ import org.eclipse.core.runtime.IProgressMonitor; /** * @author dsteffle */ -public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopulateDOMASTAction { +public class CPopulateASTViewAction extends CASTVisitor implements IPopulateDOMASTAction { private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8; { - processNames = true; - processDeclarations = true; - processInitializers = true; - processParameterDeclarations = true; - processDeclarators = true; - processDeclSpecifiers = true; - processDesignators = true; - processExpressions = true; - processStatements = true; - processTypeIds = true; - processEnumerators = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; + shouldVisitInitializers = true; + shouldVisitParameterDeclarations = true; + shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitDesignators = true; + shouldVisitExpressions = true; + shouldVisitStatements = true; + shouldVisitTypeIds = true; + shouldVisitEnumerators = true; } TreeParent root = null; @@ -96,14 +96,14 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ - public int processDeclaration(IASTDeclaration declaration) { + public int visit(IASTDeclaration declaration) { return addRoot(declaration); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ - public int processDeclarator(IASTDeclarator declarator) { + public int visit(IASTDeclarator declarator) { int ret = addRoot(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); @@ -122,42 +122,42 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) */ - public int processDesignator(ICASTDesignator designator) { + public int visit(ICASTDesignator designator) { return addRoot(designator); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ - public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + public int visit(IASTDeclSpecifier declSpec) { return addRoot(declSpec); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ - public int processEnumerator(IASTEnumerator enumerator) { + public int visit(IASTEnumerator enumerator) { return addRoot(enumerator); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ - public int processExpression(IASTExpression expression) { + public int visit(IASTExpression expression) { return addRoot(expression); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ - public int processInitializer(IASTInitializer initializer) { + public int visit(IASTInitializer initializer) { return addRoot(initializer); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) */ - public int processName(IASTName name) { + public int visit(IASTName name) { if ( name.toString() != null ) return addRoot(name); return PROCESS_CONTINUE; @@ -166,7 +166,7 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ - public int processParameterDeclaration( + public int visit( IASTParameterDeclaration parameterDeclaration) { return addRoot(parameterDeclaration); } @@ -174,14 +174,14 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ - public int processStatement(IASTStatement statement) { + public int visit(IASTStatement statement) { return addRoot(statement); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ - public int processTypeId(IASTTypeId typeId) { + public int visit(IASTTypeId typeId) { return addRoot(typeId); } diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java index a0d5ec9b50c..ae7b071df77 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java @@ -32,11 +32,11 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; -import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor.CBaseVisitorAction; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor.CPPBaseVisitorAction; import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.filetype.ICFileTypeConstants; import org.eclipse.cdt.core.model.CModelException; @@ -98,7 +98,6 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.DrillDownAdapter; import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.progress.WorkbenchJob; /** * This is a simple DOM AST View used for development testing. @@ -353,10 +352,10 @@ public class DOMAST extends ViewPart { start=System.currentTimeMillis(); if (lang == ParserLanguage.CPP) { action = new CPPPopulateASTViewAction(tu, monitor); - tu.getVisitor().visitTranslationUnit( (CPPBaseVisitorAction) action); + tu.accept( (CPPASTVisitor) action); } else { action = new CPopulateASTViewAction(tu, monitor); - tu.getVisitor().visitTranslationUnit( (CBaseVisitorAction) action); + tu.accept( (CASTVisitor) action); } monitor.worked(2); System.out.println("[DOM AST View] done " + GENERATING_INITIAL_TREE + ": " + (System.currentTimeMillis()- start) ); diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/FindIASTNameTarget.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/FindIASTNameTarget.java index 48c3366e44b..333fae18574 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/FindIASTNameTarget.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/FindIASTNameTarget.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.ui.tests.DOMAST; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -20,10 +19,10 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.jface.text.IFindReplaceTarget; import org.eclipse.jface.text.IFindReplaceTargetExtension3; import org.eclipse.jface.viewers.IStructuredSelection; @@ -45,11 +44,11 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge boolean wasForward = true; int index = 0; - static protected class CNameCollector extends CVisitor.CBaseVisitorAction { + static protected class CNameCollector extends CASTVisitor { private static final int REGULAR_NAME_ADD = -1; private static final String BLANK_STRING = ""; //$NON-NLS-1$ { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); @@ -100,7 +99,7 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge return PROCESS_CONTINUE; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ return processName(name, REGULAR_NAME_ADD); } public IASTName getName( int idx ){ @@ -121,7 +120,7 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge } } // if couldn't find the proper place to put the name, then add default - processName(name); + visit(name); } } @@ -148,11 +147,11 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge } } - static protected class CPPNameCollector extends CPPVisitor.CPPBaseVisitorAction { + static protected class CPPNameCollector extends CPPASTVisitor { private static final int REGULAR_NAME_ADD = -1; private static final String BLANK_STRING = ""; //$NON-NLS-1$ { - processNames = true; + shouldVisitNames = true; } public List nameList = new ArrayList(); @@ -205,7 +204,7 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge return PROCESS_CONTINUE; } - public int processName( IASTName name ){ + public int visit( IASTName name ){ return processName(name, REGULAR_NAME_ADD); } public IASTName getName( int idx ){ @@ -226,7 +225,7 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge } } // if couldn't find the proper place to put the name, then add default - processName(name); + visit(name); } } @@ -277,11 +276,11 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge if (matchingNames == null && tu != null) { if (lang == ParserLanguage.CPP) { CPPNameCollector col = new CPPNameCollector(findString, caseSensitive, wholeWord, regExSearch); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); matchingNames = col.getNameArray(tu.getAllPreprocessorStatements()); } else { CNameCollector col = new CNameCollector(findString, caseSensitive, wholeWord, regExSearch); - tu.getVisitor().visitTranslationUnit(col); + tu.accept(col); matchingNames = col.getNameArray(tu.getAllPreprocessorStatements()); } }