From 5a668753927ddb7cca06a8713d302170c88651fd Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 7 Jun 2004 19:25:24 +0000 Subject: [PATCH] bug 49990 - ASTUtil.getExpressionString( IASTExpression ) - created ASTUnaryIdExpression classes - improved handling of POSTFIX_TYPENAME_TEMPLATEID expressions - modified handling of initializer clause for new expressions - expression toString() functions use ASTUtil --- .../tests/StructuralCModelElementsTests.java | 174 +++---- .../tests/CompleteParseASTExpressionTest.java | 279 ++++++++++- .../internal/core/model/CModelBuilder.java | 7 +- .../eclipse/cdt/core/parser/ast/ASTUtil.java | 441 +++++++++++++++++- .../core/parser/ExpressionParser.java | 24 +- .../ast/complete/ASTBinaryExpression.java | 5 + .../complete/ASTConditionalExpression.java | 4 + .../ast/complete/ASTEmptyExpression.java | 5 + .../parser/ast/complete/ASTIdExpression.java | 6 +- .../ast/complete/ASTLiteralExpression.java | 6 + .../parser/ast/complete/ASTNewExpression.java | 5 + .../ast/complete/ASTTypeIdExpression.java | 5 + .../ast/complete/ASTUnaryExpression.java | 5 + .../ast/complete/ASTUnaryIdExpression.java | 93 ++++ .../complete/ASTUnaryTypeIdExpression.java | 4 + .../ast/complete/CompleteParseASTFactory.java | 4 +- .../ast/complete/ExpressionFactory.java | 5 +- .../ast/expression/ASTBinaryExpression.java | 5 + .../expression/ASTConditionalExpression.java | 5 + .../ast/expression/ASTEmptyExpression.java | 5 + .../ast/expression/ASTIdExpression.java | 5 + .../ast/expression/ASTLiteralExpression.java | 6 + .../ast/expression/ASTNewExpression.java | 5 + .../ast/expression/ASTTypeIdExpression.java | 5 + .../ast/expression/ASTUnaryExpression.java | 5 + .../ast/expression/ASTUnaryIdExpression.java | 40 ++ .../expression/ASTUnaryTypeIdExpression.java | 5 + .../ast/expression/ExpressionFactory.java | 5 +- 28 files changed, 1037 insertions(+), 126 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryIdExpression.java diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java index ee1e1c7dfa3..ea0c3bcb3c9 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java @@ -58,7 +58,7 @@ public class StructuralCModelElementsTests extends TestCase { public static Test suite() { TestSuite suite= new TestSuite(StructuralCModelElementsTests.class.getName()); - suite.addTest(new StructuralCModelElementsTests("testCModelElements")); + suite.addTest(new StructuralCModelElementsTests("testCModelElements")); //$NON-NLS-1$ return suite; } @@ -68,16 +68,16 @@ public class StructuralCModelElementsTests extends TestCase { protected void setUp() throws Exception { monitor = new NullProgressMonitor(); - fCProject= CProjectHelper.createCCProject("TestProject1", "bin"); - headerFile = fCProject.getProject().getFile("CModelElementsTest.h"); - includedFile = fCProject.getProject().getFile("included.h"); + fCProject= CProjectHelper.createCCProject("TestProject1", "bin"); //$NON-NLS-1$ //$NON-NLS-2$ + headerFile = fCProject.getProject().getFile("CModelElementsTest.h"); //$NON-NLS-1$ + includedFile = fCProject.getProject().getFile("included.h"); //$NON-NLS-1$ if (!headerFile.exists()) { try{ FileInputStream fileIn = new FileInputStream( - CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/CModelElementsTestStart.h"))); + CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/CModelElementsTestStart.h"))); //$NON-NLS-1$ headerFile.create(fileIn,false, monitor); FileInputStream includedFileIn = new FileInputStream( - CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/included.h"))); + CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/included.h"))); //$NON-NLS-1$ includedFile.create(includedFileIn,false, monitor); } catch (CoreException e) { e.printStackTrace(); @@ -110,7 +110,7 @@ public class StructuralCModelElementsTests extends TestCase { // tu ---> namespace: MyPackage List tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); INamespace namespace = (INamespace) tuPackages.get(0); - assertEquals(namespace.getElementName(), new String("MyPackage")); + assertEquals(namespace.getElementName(), new String("MyPackage")); //$NON-NLS-1$ checkElementOffset((CElement)namespace); checkLineNumbers((CElement)namespace, 8, 130); checkClass(namespace); @@ -137,7 +137,7 @@ public class StructuralCModelElementsTests extends TestCase { private void checkInclude(IParent tu) throws CModelException{ List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); IInclude inc1 = (IInclude) tuIncludes.get(0); - assertEquals(inc1.getElementName(), new String("included.h")); + assertEquals(inc1.getElementName(), new String("included.h")); //$NON-NLS-1$ checkElementOffset((CElement)inc1); checkLineNumbers((CElement)inc1, 2, 2); } @@ -145,7 +145,7 @@ public class StructuralCModelElementsTests extends TestCase { private void checkMacro(IParent tu) throws CModelException{ List tuMacros = tu.getChildrenOfType(ICElement.C_MACRO); IMacro mac1 = (IMacro) tuMacros.get(0); - assertEquals(mac1.getElementName(), new String("PRINT")); + assertEquals(mac1.getElementName(), new String("PRINT")); //$NON-NLS-1$ checkElementOffset((CElement)mac1); checkLineNumbers((CElement)mac1, 5, 5); } @@ -154,35 +154,35 @@ public class StructuralCModelElementsTests extends TestCase { // MyPackage ---> class: Hello List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); IStructure classHello = (IStructure) nsClasses.get(0); - assertEquals(classHello.getElementName(), new String("Hello")); + assertEquals(classHello.getElementName(), new String("Hello")); //$NON-NLS-1$ checkElementOffset((CElement)classHello); checkLineNumbers((CElement)classHello, 12, 53); // Hello --> field: int x List helloFields = classHello.getChildrenOfType(ICElement.C_FIELD); IField intX = (IField) helloFields.get(0); - assertEquals(intX.getElementName(), new String("x")); + assertEquals(intX.getElementName(), new String("x")); //$NON-NLS-1$ checkElementOffset((CElement)intX); - assertEquals(intX.getTypeName(), new String("int")); + assertEquals(intX.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)intX, 17, 17); ASTAccessVisibility xVisibility = intX.getVisibility(); if (xVisibility != ASTAccessVisibility.PROTECTED) - fail("visibility should be protected!"); + fail("visibility should be protected!"); //$NON-NLS-1$ // Hello ---> method: void setX(int X) List helloMethods = classHello.getChildrenOfType(ICElement.C_METHOD); IMethod setX = (IMethod) helloMethods.get(0); - assertEquals(setX.getElementName(), new String("setX")); + assertEquals(setX.getElementName(), new String("setX")); //$NON-NLS-1$ checkElementOffset((CElement)setX); - assertEquals(setX.getReturnType(), new String("void")); + assertEquals(setX.getReturnType(), new String("void")); //$NON-NLS-1$ checkLineNumbers((CElement)setX, 19, 22); int setXNumOfParam = setX.getNumberOfParameters(); if(setXNumOfParam != 1) - fail("setX should have one parameter!"); + fail("setX should have one parameter!"); //$NON-NLS-1$ String[] setXParamTypes = setX.getParameterTypes(); String firstParamType = setXParamTypes[0]; - assertEquals(firstParamType, new String("int")); + assertEquals(firstParamType, new String("int")); //$NON-NLS-1$ // TODO : check for the inline here checkNestedNamespace(classHello); @@ -191,7 +191,7 @@ public class StructuralCModelElementsTests extends TestCase { // Hello ---> namespace: MyNestedPackage List helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE); INamespace myNestedPackage = (INamespace) helloNamespaces.get(0); - assertEquals(myNestedPackage.getElementName(), new String("MyNestedPackage")); + assertEquals(myNestedPackage.getElementName(), new String("MyNestedPackage")); //$NON-NLS-1$ checkElementOffset((CElement)myNestedPackage); checkLineNumbers((CElement)myNestedPackage, 25, 52); @@ -202,21 +202,21 @@ public class StructuralCModelElementsTests extends TestCase { // MyNestedPackage ---> class: Y List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classY = (IStructure) nestedClasses.get(0); - assertEquals(classY.getElementName(), new String("Y")); + assertEquals(classY.getElementName(), new String("Y")); //$NON-NLS-1$ checkElementOffset((CElement)classY); checkLineNumbers((CElement)classY, 28, 35); // Y ---> constructor: Y List yMethods = classY.getChildrenOfType(ICElement.C_METHOD_DECLARATION); IMethodDeclaration constructor = (IMethodDeclaration) yMethods.get(0); - assertEquals(constructor.getElementName(), new String("Y")); + assertEquals(constructor.getElementName(), new String("Y")); //$NON-NLS-1$ checkElementOffset((CElement)constructor); assertTrue (constructor.isConstructor()); checkLineNumbers((CElement)constructor, 32, 32); // Y ---> destructor: ~Y IMethodDeclaration destructor = (IMethodDeclaration) yMethods.get(1); - assertEquals(destructor.getElementName(), new String("~Y")); + assertEquals(destructor.getElementName(), new String("~Y")); //$NON-NLS-1$ checkElementOffset((CElement)destructor); assertTrue (destructor.isDestructor()); checkLineNumbers((CElement)destructor, 34, 34); @@ -228,7 +228,7 @@ public class StructuralCModelElementsTests extends TestCase { // MyNestedPackage ---> class: X public Y List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classX = (IStructure) nestedClasses.get(1); - assertEquals(classX.getElementName(), new String("X")); + assertEquals(classX.getElementName(), new String("X")); //$NON-NLS-1$ checkElementOffset((CElement)classX); checkLineNumbers((CElement)classX, 38, 51); // TODO : Check for base classes here @@ -236,18 +236,18 @@ public class StructuralCModelElementsTests extends TestCase { // X --> field: B b List xFieldChildren = classX.getChildrenOfType(ICElement.C_FIELD); IField bB = (IField) xFieldChildren.get(0); - assertEquals(bB.getElementName(), new String("b")); + assertEquals(bB.getElementName(), new String("b")); //$NON-NLS-1$ checkElementOffset((CElement)bB); - assertEquals(bB.getTypeName(), new String("B")); + assertEquals(bB.getTypeName(), new String("B")); //$NON-NLS-1$ checkLineNumbers((CElement)bB, 42, 42); ASTAccessVisibility bVisibility = bB.getVisibility(); if (bVisibility != ASTAccessVisibility.PRIVATE) - fail("visibility should be private!"); + fail("visibility should be private!"); //$NON-NLS-1$ // X ---> constructor chain: X List xMethodChildren = classX.getChildrenOfType(ICElement.C_METHOD); IMethod xconstructor = (IMethod) xMethodChildren.get(0); - assertEquals(xconstructor.getElementName(), new String("X")); + assertEquals(xconstructor.getElementName(), new String("X")); //$NON-NLS-1$ checkElementOffset((CElement)xconstructor); assertTrue (xconstructor.isConstructor()); checkLineNumbers((CElement)xconstructor, 46, 48); @@ -255,9 +255,9 @@ public class StructuralCModelElementsTests extends TestCase { // X ---> method declaration: doNothing List xMethodDeclarations = classX.getChildrenOfType(ICElement.C_METHOD_DECLARATION); IMethodDeclaration xDoNothing = (IMethodDeclaration) xMethodDeclarations.get(0); - assertEquals(xDoNothing.getElementName(), new String("doNothing")); + assertEquals(xDoNothing.getElementName(), new String("doNothing")); //$NON-NLS-1$ checkElementOffset((CElement)xDoNothing); - assertEquals(xDoNothing.getReturnType(), new String("int")); + assertEquals(xDoNothing.getReturnType(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)xDoNothing, 50, 50); } @@ -265,44 +265,44 @@ public class StructuralCModelElementsTests extends TestCase { // MyPackage ---> enum: Noname List nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION); IEnumeration enum = (IEnumeration) nsEnums.get(0); - assertEquals(enum.getElementName(), new String("")); + assertEquals(enum.getElementName(), new String("")); //$NON-NLS-1$ checkElementOffset((CElement)enum); checkLineNumbers((CElement)enum, 57, 61); // enum ---> enumerator: first = 1 List enumEnumerators = enum.getChildrenOfType(ICElement.C_ENUMERATOR); IEnumerator first = (IEnumerator) enumEnumerators.get(0); - assertEquals(first.getElementName(), new String("first")); - assertEquals("1", first.getConstantExpression()); + assertEquals(first.getElementName(), new String("first")); //$NON-NLS-1$ + assertEquals("1", first.getConstantExpression()); //$NON-NLS-1$ checkElementOffset((CElement)first); // enum ---> enumerator: second IEnumerator second = (IEnumerator) enumEnumerators.get(1); - assertEquals(second.getElementName(), new String("second")); + assertEquals(second.getElementName(), new String("second")); //$NON-NLS-1$ checkElementOffset((CElement)second); // enum ---> enumerator: third IEnumerator third = (IEnumerator) enumEnumerators.get(2); checkElementOffset((CElement)third); - assertEquals(third.getElementName(), new String("third")); + assertEquals(third.getElementName(), new String("third")); //$NON-NLS-1$ checkElementOffset((CElement)third); // MyPackage ---> enum: MyEnum IEnumeration myEnum = (IEnumeration) nsEnums.get(1); - assertEquals(myEnum.getElementName(), new String("MyEnum")); + assertEquals(myEnum.getElementName(), new String("MyEnum")); //$NON-NLS-1$ checkElementOffset((CElement)myEnum); checkLineNumbers((CElement)myEnum, 64, 67); // enum ---> enumerator: first List myEnumEnumerators = myEnum.getChildrenOfType(ICElement.C_ENUMERATOR); IEnumerator f = (IEnumerator) myEnumEnumerators.get(0); - assertEquals(f.getElementName(), new String("f")); + assertEquals(f.getElementName(), new String("f")); //$NON-NLS-1$ checkElementOffset((CElement)f); // enum ---> enumerator: second IEnumerator s = (IEnumerator) myEnumEnumerators.get(1); - assertEquals(s.getElementName(), new String("s")); + assertEquals(s.getElementName(), new String("s")); //$NON-NLS-1$ checkElementOffset((CElement)s); // enum ---> enumerator: third IEnumerator t = (IEnumerator) myEnumEnumerators.get(2); - assertEquals(t.getElementName(), new String("t")); + assertEquals(t.getElementName(), new String("t")); //$NON-NLS-1$ checkElementOffset((CElement)t); } @@ -310,30 +310,30 @@ public class StructuralCModelElementsTests extends TestCase { // MyPackage ---> int v List nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE); IVariable var1 = (IVariable) nsVars.get(0); - assertEquals(var1.getElementName(), new String("v")); + assertEquals(var1.getElementName(), new String("v")); //$NON-NLS-1$ checkElementOffset((CElement)var1); - assertEquals(var1.getTypeName(), new String("int")); + assertEquals(var1.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)var1, 71, 71); // MyPackage ---> unsigned long vuLong IVariable var2 = (IVariable) nsVars.get(1); - assertEquals(var2.getElementName(), new String("vuLong")); + assertEquals(var2.getElementName(), new String("vuLong")); //$NON-NLS-1$ checkElementOffset((CElement)var2); - assertEquals(var2.getTypeName(), new String("unsigned long")); + assertEquals(var2.getTypeName(), new String("unsigned long")); //$NON-NLS-1$ checkLineNumbers((CElement)var2, 73, 73); // MyPackage ---> unsigned short vuShort IVariable var3 = (IVariable) nsVars.get(2); - assertEquals(var3.getElementName(), new String("vuShort")); + assertEquals(var3.getElementName(), new String("vuShort")); //$NON-NLS-1$ checkElementOffset((CElement)var3); - assertEquals(var3.getTypeName(), new String("unsigned short")); + assertEquals(var3.getTypeName(), new String("unsigned short")); //$NON-NLS-1$ checkLineNumbers((CElement)var3, 75, 75); // MyPackage ---> function pointer: orig_malloc_hook IVariable vDecl2 = (IVariable) nsVars.get(3); - assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook")); + assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook")); //$NON-NLS-1$ checkElementOffset((CElement)vDecl2); - assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, int)")); + assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, int)")); //$NON-NLS-1$ checkLineNumbers((CElement)vDecl2, 81, 81); } @@ -342,9 +342,9 @@ public class StructuralCModelElementsTests extends TestCase { // MyPackage ---> extern int evar List nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION); IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0); - assertEquals(vDecl1.getElementName(), new String("evar")); + assertEquals(vDecl1.getElementName(), new String("evar")); //$NON-NLS-1$ checkElementOffset((CElement)vDecl1); - assertEquals(vDecl1.getTypeName(), new String("int")); + assertEquals(vDecl1.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)vDecl1, 79, 79); } @@ -353,30 +353,30 @@ public class StructuralCModelElementsTests extends TestCase { // MyPackage ---> function: void foo() IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(0); - assertEquals(f1.getElementName(), new String("foo")); + assertEquals(f1.getElementName(), new String("foo")); //$NON-NLS-1$ checkElementOffset((CElement)f1); - assertEquals(f1.getReturnType(), new String("void")); + assertEquals(f1.getReturnType(), new String("void")); //$NON-NLS-1$ checkLineNumbers((CElement)f1, 85, 85); // MyPackage ---> function: char* foo(int&, char**) IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(1); - assertEquals(f2.getElementName(), new String("foo")); + assertEquals(f2.getElementName(), new String("foo")); //$NON-NLS-1$ checkElementOffset((CElement)f2); - assertEquals(f2.getReturnType(), new String("char*")); + assertEquals(f2.getReturnType(), new String("char*")); //$NON-NLS-1$ checkLineNumbers((CElement)f2, 87, 88); int fooNumOfParam = f2.getNumberOfParameters(); if(fooNumOfParam != 2) - fail("foo should have two parameter!"); + fail("foo should have two parameter!"); //$NON-NLS-1$ String[] paramTypes = f2.getParameterTypes(); - assertEquals(paramTypes[0], new String("int&")); - assertEquals(paramTypes[1], new String("char**")); + assertEquals(paramTypes[0], new String("int&")); //$NON-NLS-1$ + assertEquals(paramTypes[1], new String("char**")); //$NON-NLS-1$ // MyPackage ---> function: void boo() {} List nsFunctions = namespace.getChildrenOfType(ICElement.C_FUNCTION); IFunction f3 = (IFunction) nsFunctions.get(0); - assertEquals(f3.getElementName(), new String("boo")); + assertEquals(f3.getElementName(), new String("boo")); //$NON-NLS-1$ checkElementOffset((CElement)f3); - assertEquals(f3.getReturnType(), new String("void")); + assertEquals(f3.getReturnType(), new String("void")); //$NON-NLS-1$ checkLineNumbers((CElement)f3, 90, 92); } @@ -384,70 +384,70 @@ public class StructuralCModelElementsTests extends TestCase { // struct with name List nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT); IStructure struct1 = (IStructure) nsStructs.get(0); - assertEquals(struct1.getElementName(), new String ("MyStruct")); + assertEquals(struct1.getElementName(), new String ("MyStruct")); //$NON-NLS-1$ checkElementOffset((CElement)struct1); checkLineNumbers((CElement)struct1, 95, 97); List struct1Fields = struct1.getChildrenOfType(ICElement.C_FIELD); IField field1 = (IField) struct1Fields.get(0); - assertEquals(field1.getElementName(), new String("sint")); + assertEquals(field1.getElementName(), new String("sint")); //$NON-NLS-1$ checkElementOffset((CElement)field1); - assertEquals(field1.getTypeName(), new String("int")); + assertEquals(field1.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)field1, 96, 96); if(field1.getVisibility() != ASTAccessVisibility.PUBLIC) - fail("field visibility should be public!"); + fail("field visibility should be public!"); //$NON-NLS-1$ // struct no name IStructure struct2 = (IStructure) nsStructs.get(1); - assertEquals(struct2.getElementName(), new String ("")); + assertEquals(struct2.getElementName(), new String ("")); //$NON-NLS-1$ checkElementOffset((CElement)struct2); checkLineNumbers((CElement)struct2, 101, 103); List struct2Fields = struct2.getChildrenOfType(ICElement.C_FIELD); IField field2 = (IField) struct2Fields.get(0); - assertEquals(field2.getElementName(), new String("ss")); + assertEquals(field2.getElementName(), new String("ss")); //$NON-NLS-1$ checkElementOffset((CElement)field2); - assertEquals(field2.getTypeName(), new String("int")); + assertEquals(field2.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)field2, 102, 102); if(field2.getVisibility() != ASTAccessVisibility.PUBLIC) - fail("field visibility should be public!"); + fail("field visibility should be public!"); //$NON-NLS-1$ // typedefs List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); ITypeDef td1 = (ITypeDef) nsTypeDefs.get(0); - assertEquals(td1.getElementName(), new String ("myStruct")); + assertEquals(td1.getElementName(), new String ("myStruct")); //$NON-NLS-1$ checkElementOffset((CElement)td1); - assertEquals(td1.getTypeName(), new String ("struct MyStruct")); + assertEquals(td1.getTypeName(), new String ("struct MyStruct")); //$NON-NLS-1$ checkLineNumbers((CElement)td1, 99, 99); ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1); - assertEquals(td2.getElementName(), new String ("myTypedef")); + assertEquals(td2.getElementName(), new String ("myTypedef")); //$NON-NLS-1$ checkElementOffset((CElement)td2); - assertEquals(td2.getTypeName(), new String ("")); + assertEquals(td2.getTypeName(), new String ("")); //$NON-NLS-1$ checkLineNumbers((CElement)td2, 101, 103); // union List nsUnions = namespace.getChildrenOfType(ICElement.C_UNION); IStructure u0 = (IStructure) nsUnions.get(0); - assertEquals(u0.getElementName(), new String("U")); + assertEquals(u0.getElementName(), new String("U")); //$NON-NLS-1$ checkElementOffset((CElement)u0); checkLineNumbers((CElement)u0, 105, 107); List u0Fields = u0.getChildrenOfType(ICElement.C_FIELD); IField field3 = (IField) u0Fields.get(0); - assertEquals(field3.getElementName(), new String("U1")); + assertEquals(field3.getElementName(), new String("U1")); //$NON-NLS-1$ checkElementOffset((CElement)field3); - assertEquals(field3.getTypeName(), new String("int")); + assertEquals(field3.getTypeName(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)field3, 106, 106); if(field3.getVisibility() != ASTAccessVisibility.PUBLIC) - fail("field visibility should be public!"); + fail("field visibility should be public!"); //$NON-NLS-1$ } private void checkTemplates(IParent namespace) throws CModelException{ // template function List functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION); FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0); - assertEquals(ft.getElementName(), new String("aTemplatedFunction")); + assertEquals(ft.getElementName(), new String("aTemplatedFunction")); //$NON-NLS-1$ checkElementOffset(ft); ft.getTemplateSignature(); - assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction(B) : A")); + assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction(B) : A")); //$NON-NLS-1$ checkLineNumbers(ft, 112, 113); // template method @@ -456,26 +456,26 @@ public class StructuralCModelElementsTests extends TestCase { checkLineNumbers((CElement)enclosingClass, 115, 120); List methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); MethodTemplate mt = (MethodTemplate)methodTemplates.get(0); - assertEquals(mt.getElementName(), new String("aTemplatedMethod")); + assertEquals(mt.getElementName(), new String("aTemplatedMethod")); //$NON-NLS-1$ checkElementOffset(mt); - assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod(B) : A")); + assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod(B) : A")); //$NON-NLS-1$ checkLineNumbers(mt, 118, 119 ); assertEquals(mt.getVisibility(), ASTAccessVisibility.PUBLIC); // template class List classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS); StructureTemplate ct = (StructureTemplate)classTemplates.get(0); - assertEquals(ct.getElementName(), new String("myarray")); + assertEquals(ct.getElementName(), new String("myarray")); //$NON-NLS-1$ checkElementOffset(ct); - assertEquals(ct.getTemplateSignature(), new String("myarray")); + assertEquals(ct.getTemplateSignature(), new String("myarray")); //$NON-NLS-1$ checkLineNumbers(ct, 122, 123); // template struct List structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); StructureTemplate st = (StructureTemplate)structTemplates.get(0); - assertEquals(st.getElementName(), new String("mystruct")); + assertEquals(st.getElementName(), new String("mystruct")); //$NON-NLS-1$ checkElementOffset(st); - assertEquals(st.getTemplateSignature(), new String("mystruct")); + assertEquals(st.getTemplateSignature(), new String("mystruct")); //$NON-NLS-1$ checkLineNumbers(st, 125, 126); // moved to failed tests @@ -493,24 +493,24 @@ public class StructuralCModelElementsTests extends TestCase { // array variable List variables = tu.getChildrenOfType(ICElement.C_VARIABLE); IVariable arrayVar = (IVariable) variables.get(0); - assertEquals(arrayVar.getElementName(), new String("myArray")); + assertEquals(arrayVar.getElementName(), new String("myArray")); //$NON-NLS-1$ checkElementOffset((CElement)arrayVar); - assertEquals(arrayVar.getTypeName(), new String("int[][]")); + assertEquals(arrayVar.getTypeName(), new String("int[][]")); //$NON-NLS-1$ checkLineNumbers((CElement)arrayVar, 133, 133); // array parameter in function main List functions = tu.getChildrenOfType(ICElement.C_FUNCTION); IFunction mainFunction = (IFunction) functions.get(0); - assertEquals(mainFunction.getElementName(), new String("main")); + assertEquals(mainFunction.getElementName(), new String("main")); //$NON-NLS-1$ checkElementOffset((CElement)mainFunction); - assertEquals(mainFunction.getReturnType(), new String("int")); + assertEquals(mainFunction.getReturnType(), new String("int")); //$NON-NLS-1$ checkLineNumbers((CElement)mainFunction, 134, 136); int NumOfParam = mainFunction.getNumberOfParameters(); if(NumOfParam != 2) - fail("main should have two parameter!"); + fail("main should have two parameter!"); //$NON-NLS-1$ String[] paramTypes = mainFunction.getParameterTypes(); - assertEquals(paramTypes[0], new String("int")); - assertEquals(paramTypes[1], new String("char*[]")); + assertEquals(paramTypes[0], new String("int")); //$NON-NLS-1$ + assertEquals(paramTypes[1], new String("char*[]")); //$NON-NLS-1$ } private void checkLineNumbers(CElement element, int startLine, int endLine){ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java index fe009127b0f..9c063a351cc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java @@ -14,9 +14,12 @@ import java.util.Iterator; import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTVariable; /** @@ -39,6 +42,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences(1, createTaskList( new Task( f2 ) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f()" ); //$NON-NLS-1$ } // Kind PRIMARY_INTEGER_LITERAL : int public void testPrimaryIntegerLiteral() throws Exception @@ -48,6 +54,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f1 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(1, 2 + 3)" ); //$NON-NLS-1$ } // Kind PRIMARY_CHAR_LITERAL : char public void testPrimaryCharLiteral() throws Exception @@ -57,6 +66,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f('c')" ); //$NON-NLS-1$ } // Kind PRIMARY_FLOAT_LITERAL : float public void testPrimaryFloatLiteral() throws Exception @@ -66,6 +78,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(1.13)" ); //$NON-NLS-1$ } // Kind PRIMARY_STRING_LITERAL : char* public void testPrimaryStringLiteral() throws Exception @@ -75,6 +90,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(\"str\")" ); //$NON-NLS-1$ } // Kind PRIMARY_BOOLEAN_LITERAL : bool public void testPrimaryBooleanLiteral() throws Exception @@ -84,6 +102,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f1 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(true)" ); //$NON-NLS-1$ } // Kind PRIMARY_THIS : type of inner most enclosing structure scope public void testPrimaryThis() throws Exception @@ -98,6 +119,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTMethod m = (IASTMethod) i.next(); Iterator r = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl, 3 ), new Task( f2 ))); + + Iterator body = getDeclarations( m ); + IASTVariable x = (IASTVariable) body.next(); + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(this)" ); //$NON-NLS-1$ } // Kind PRIMARY_BRACKETED_EXPRESSION : LHS public void testPrimaryBracketedExpression() throws Exception @@ -107,6 +133,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f1 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(1, (2 + 3))" ); //$NON-NLS-1$ } // Kind ID_EXPRESSION : type of the ID public void testIdExpression() throws Exception @@ -120,6 +149,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 3, createTaskList( new Task( cl ), new Task( f1 ),new Task( a ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(a)" ); //$NON-NLS-1$ } // Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID public void testIdExpressionToPointer() throws Exception @@ -131,7 +163,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( f1 ), new Task( a ) ) ); - + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(pa)" ); //$NON-NLS-1$ } // Kind POSTFIX_SUBSCRIPT public void testPostfixSubscript() throws Exception @@ -142,6 +176,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(pa[1])" ); //$NON-NLS-1$ } public void testPostfixSubscriptA() throws Exception @@ -152,6 +189,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ } public void testPostfixSubscriptB() throws Exception @@ -162,6 +202,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ } public void testPostfixSubscriptWithReferences() throws Exception @@ -181,9 +224,14 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ Iterator i = parse( "int foo( float b ); int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations(); //$NON-NLS-1$ IASTFunction foo = (IASTFunction)i.next(); IASTFunction bar = (IASTFunction)i.next(); - i.next(); + IASTFunction test = (IASTFunction) i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( bar ), new Task( foo, 2 ))); + + i = getDeclarations( test ); + IASTVariable x = (IASTVariable) i.next(); + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "bar(foo(3.0), foo(5.0))" ); //$NON-NLS-1$ } // Kind POSTFIX_SIMPLETYPE_* : simple type public void testPostfixSimpletypesBug42823() throws Exception @@ -196,6 +244,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction test = (IASTFunction)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 1, createTaskList( new Task( foo ))); + + i = getDeclarations( test ); + IASTVariable someInt = (IASTVariable) i.next(); + IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3))" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPENAME_IDENTIFIER @@ -206,9 +259,39 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 3, createTaskList( new Task( cl, 2 ), new Task( f2) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typename A())" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPENAME_TEMPLATEID + public void testPostfixTypeNameTemplateId() throws Exception{ + Iterator i = parse( " template class A {}; int foo( A a ); \n int x = foo( typename template A< int >() );").getDeclarations(); //$NON-NLS-1$ + IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); + IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); + IASTFunction f = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( f ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typename template A())" ); //$NON-NLS-1$ + } + + public void testPostfixTypeNameTemplateId_2() throws Exception{ + Iterator i = parse( "namespace NS{ template class A {}; } int foo( NS::A a ); \n int x = foo( typename NS::template A< int >() );").getDeclarations(); //$NON-NLS-1$ + IASTNamespaceDefinition NS = (IASTNamespaceDefinition) i.next(); + IASTFunction f = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + + i = getDeclarations( NS ); + IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); + IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); + + assertAllReferences( 5, createTaskList( new Task( NS, 2 ), new Task( A, 2 ), new Task( f ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typename NS::template A())" ); //$NON-NLS-1$ + } // Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container public void testPostfixDotExpression() throws Exception{ @@ -221,6 +304,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ Iterator members = getDeclarations(cl); IASTField m = (IASTField)members.next(); assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a.m)" ); //$NON-NLS-1$ } // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container public void testPostfixArrowExpression() throws Exception{ @@ -233,6 +319,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ Iterator members = getDeclarations(cl); IASTField m = (IASTField)members.next(); assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a->m)" ); //$NON-NLS-1$ } // Kind POSTFIX_DOT_TEMPL_IDEXPRESS // Kind POSTFIX_ARROW_TEMPL_IDEXP @@ -253,6 +342,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( subDecls.hasNext() ); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(x++)" ); //$NON-NLS-1$ } // Kind POSTFIX_DECREMENT : LHS public void testPostfixDecrement() throws Exception @@ -267,6 +361,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( subDecls.hasNext() ); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(x--)" ); //$NON-NLS-1$ } // Kind POSTFIX_DYNAMIC_CAST public void testPostfixDynamicCast() throws Exception{ @@ -279,6 +378,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertFalse( i.hasNext() ); assertAllReferences( 6, createTaskList( new Task( cla, 2 ), new Task( clb, 2), new Task(a), new Task(f2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(dynamic_cast(a))" ); //$NON-NLS-1$ } // Kind POSTFIX_REINTERPRET_CAST public void testPostfixReinterpretCast() throws Exception{ @@ -288,7 +390,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(reinterpret_cast(a))" ); //$NON-NLS-1$ } // Kind POSTFIX_STATIC_CAST public void testPostfixStaticCast() throws Exception{ @@ -299,6 +404,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(static_cast(a))" ); //$NON-NLS-1$ } // Kind POSTFIX_CONST_CAST public void testPostfixConstCast() throws Exception{ @@ -309,6 +417,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(const_cast(&a))" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPEID_EXPRESSION : LHS public void testPostfixTypeIdExpression() throws Exception{ @@ -316,7 +427,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); + assertAllReferences( 1, createTaskList( new Task( f2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typeid(5))" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPEID_EXPRESSION : type of the ID public void testPostfixTypeIdExpression2() throws Exception{ @@ -327,6 +441,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typeid(a))" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPEID_TYPEID : type of the ID public void testPostfixTypeIdTypeId() throws Exception{ @@ -336,7 +453,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); + assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typeid(A))" ); //$NON-NLS-1$ } // Kind POSTFIX_TYPEID_TYPEID : type of the ID public void testPostfixTypeIdTypeId2() throws Exception{ @@ -347,6 +467,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(typeid(const A))" ); //$NON-NLS-1$ } // Kind UNARY_INCREMENT : LHS public void testUnaryIncrement() throws Exception @@ -361,6 +484,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( subDecls.hasNext() ); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(++x)" ); //$NON-NLS-1$ } // Kind UNARY_DECREMENT : LHS public void testUnaryDecrement() throws Exception @@ -375,6 +503,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( subDecls.hasNext() ); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(--x)" ); //$NON-NLS-1$ } // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer public void testUnaryStarCastExpression() throws Exception @@ -386,6 +519,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(*pa)" ); //$NON-NLS-1$ } // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference public void testUnaryAmpersandCastExpression() throws Exception @@ -397,6 +533,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "f(&pa)" ); //$NON-NLS-1$ } // Kind UNARY_PLUS_CASTEXPRESSION : LHS public void testUnaryPlusCastExpression() throws Exception { @@ -406,6 +545,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 1, createTaskList( new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(+5)" ); //$NON-NLS-1$ } // Kind UNARY_MINUS_CASTEXPRESSION : LHS public void testUnaryMinusCastExpression() throws Exception { @@ -415,6 +557,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 1, createTaskList( new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(-5)" ); //$NON-NLS-1$ } // Kind UNARY_NOT_CASTEXPRESSION : LHS public void testUnaryNotCastExpression() throws Exception { @@ -425,6 +570,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( b ), new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(!b)" ); //$NON-NLS-1$ } // Kind UNARY_TILDE_CASTEXPRESSION : LHS public void testTildeNotCastExpression() throws Exception { @@ -435,6 +583,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable y = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(~x)" ); //$NON-NLS-1$ } // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int public void testUnarySizeofUnaryExpression() throws Exception { @@ -445,6 +598,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable y = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 1, createTaskList( new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(sizeof (5))" ); //$NON-NLS-1$ } // Kind UNARY_SIZEOF_TYPEID : unsigned int public void testUnarySizeofTypeId() throws Exception { @@ -455,6 +613,11 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable y = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ + exp = y.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(sizeof (x))" ); //$NON-NLS-1$ } // Kind NEW_NEWTYPEID // Kind NEW_TYPEID @@ -466,6 +629,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(new A())" ); //$NON-NLS-1$ } // Kind DELETE_CASTEXPRESSION @@ -481,7 +647,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertFalse( i.hasNext() ); - assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2))); + assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2))); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo((A*)b)" ); //$NON-NLS-1$ } // Kind PM_DOTSTAR @@ -501,6 +670,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a * b)" ); //$NON-NLS-1$ } // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions public void testMultiplicativeDivide() throws Exception { @@ -512,6 +684,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b / a)" ); //$NON-NLS-1$ } // Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions public void testMultiplicativeModulus() throws Exception { @@ -523,6 +698,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b % a)" ); //$NON-NLS-1$ } // Kind ADDITIVE_PLUS : usual arithmetic conversions public void testAdditivePlus() throws Exception { @@ -534,6 +712,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b + a)" ); //$NON-NLS-1$ } // Kind ADDITIVE_MINUS : usual arithmetic conversions public void testAdditiveMinus() throws Exception { @@ -545,6 +726,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b - a)" ); //$NON-NLS-1$ } // Kind SHIFT_LEFT : LHS public void testShiftLeft() throws Exception { @@ -555,6 +739,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a << 5)" ); //$NON-NLS-1$ } // Kind SHIFT_RIGHT : LHS public void testShiftRight() throws Exception { @@ -565,6 +752,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a >> 5)" ); //$NON-NLS-1$ } // Kind RELATIONAL_LESSTHAN : bool public void testRelationalLessThan() throws Exception { @@ -575,6 +765,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b < 3)" ); //$NON-NLS-1$ } // Kind RELATIONAL_GREATERTHAN : bool public void testRelationalGreaterThan() throws Exception { @@ -585,6 +778,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b > 3)" ); //$NON-NLS-1$ } // Kind RELATIONAL_LESSTHANEQUALTO : bool public void testRelationalLessThanOrEqual() throws Exception { @@ -595,6 +791,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b <= 3)" ); //$NON-NLS-1$ } // Kind RELATIONAL_GREATERTHANEQUALTO : bool public void testRelationalGreaterThanOrEqual() throws Exception { @@ -605,6 +804,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b >= 3)" ); //$NON-NLS-1$ } // Kind EQUALITY_EQUALS : bool public void testEqualityEquals() throws Exception { @@ -615,6 +817,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b == 3)" ); //$NON-NLS-1$ } // Kind EQUALITY_NOTEQUALS : bool public void testEqualityNotEquals() throws Exception { @@ -625,6 +830,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(b != 3)" ); //$NON-NLS-1$ } // Kind ANDEXPRESSION : usual arithmetic conversions public void testAndExpression() throws Exception { @@ -636,6 +844,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a & b)" ); //$NON-NLS-1$ } // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions public void testExclusiveOrExpression() throws Exception { @@ -647,6 +858,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a ^ b)" ); //$NON-NLS-1$ } // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions public void testInclusiveOrExpression() throws Exception { @@ -658,6 +872,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a | b)" ); //$NON-NLS-1$ } // Kind LOGICALANDEXPRESSION : bool public void testLogicalAndExpression() throws Exception { @@ -669,6 +886,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a && b)" ); //$NON-NLS-1$ } // Kind LOGICALOREXPRESSION : bool public void testLogicalOrExpression() throws Exception { @@ -679,7 +899,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable b = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a || b)" ); //$NON-NLS-1$ } // Kind CONDITIONALEXPRESSION : conditional Expression Conversions public void testConditionalExpression() throws Exception { @@ -692,6 +915,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 4, createTaskList( new Task( a ), new Task(b), new Task( c ), new Task( foo2 ) ) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a > 5 ? b : c)" ); //$NON-NLS-1$ } // Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions public void testConditionalExpressionWithReferencesA() throws Exception { @@ -706,6 +932,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) ); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ } public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); //$NON-NLS-1$ @@ -720,6 +949,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences( 8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ } // Kind THROWEXPRESSION @@ -732,6 +964,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a = 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_PLUS : LHS public void testAssignmentExpressionPlus() throws Exception { @@ -742,6 +977,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a += 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_MINUS : LHS public void testAssignmentExpressionMinus() throws Exception { @@ -752,6 +990,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a -= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_MULT : LHS public void testAssignmentExpressionMulti() throws Exception { @@ -762,6 +1003,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a *= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_DIV : LHS public void testAssignmentExpressionDiv() throws Exception { @@ -772,6 +1016,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a /= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_MOD : LHS public void testAssignmentExpressionMod() throws Exception { @@ -782,6 +1029,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a %= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS public void testAssignmentExpressionLShift() throws Exception { @@ -792,6 +1042,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a >>= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS public void testAssignmentExpressionRShift() throws Exception { @@ -802,6 +1055,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a <<= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_AND : LHS public void testAssignmentExpressionAnd() throws Exception { @@ -812,6 +1068,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a &= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_OR : LHS public void testAssignmentExpressionOr() throws Exception { @@ -822,6 +1081,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a |= 5)" ); //$NON-NLS-1$ } // Kind ASSIGNMENTEXPRESSION_XOR : LHS public void testAssignmentExpressionXOr() throws Exception { @@ -832,6 +1094,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); + + IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.toString(), "foo(a ^= 5)" ); //$NON-NLS-1$ } // Kind EXPRESSIONLIST : list of LHS, RHS // Already tested with each test trying to find a reference to function. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java index c0bc437bbb4..1215a5150a1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -302,7 +302,7 @@ public class CModelBuilder { private void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws CModelException, ASTNotImplementedException { // Template Declaration - IASTDeclaration declaration = (IASTDeclaration)templateDeclaration.getOwnedDeclaration(); + IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration(); if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){ IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ; CElement element = createAbstractElement(parent, abstractDeclaration , true); @@ -478,10 +478,7 @@ public class CModelBuilder { Enumerator element = new Enumerator (enum, enumDef.getName().toString()); IASTExpression initialValue = enumDef.getInitialValue(); if(initialValue != null){ - if(initialValue.getLiteralString().length() > 0) - element.setConstantExpression(initialValue.getLiteralString()); - else - element.setConstantExpression(initialValue.getIdExpression()); + element.setConstantExpression( ASTUtil.getExpressionString( initialValue ) ); } // add to parent enum.addChild(element); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java index 158658afadd..797d79cd7ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java @@ -11,8 +11,14 @@ package org.eclipse.cdt.core.parser.ast; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.core.parser.Keywords; +import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; +import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; /** @@ -94,12 +100,10 @@ public class ASTUtil { if(clause != null){ IASTExpression expression = clause.getAssigmentExpression(); if(expression != null){ - String literal = (expression.getLiteralString().length() > 0 - ? expression.getLiteralString() - : expression.getIdExpression() ); - if(literal.length() > 0){ + String init = getExpressionString( expression ); + if(init.length() > 0){ initializer.append("="); //$NON-NLS-1$ - initializer.append(literal); + initializer.append(init); } } } @@ -235,4 +239,431 @@ public class ASTUtil { return parameters.toString(); } + public static String getTypeId( IASTTypeId id ){ + StringBuffer type = new StringBuffer(); + + if( id.isTypename() ){ + type.append( Keywords.TYPENAME ); + type.append( ' ' ); + } + type.append( id.getFullSignature() ); + + Iterator i = id.getPointerOperators(); + while(i.hasNext()){ + ASTPointerOperator po = (ASTPointerOperator) i.next(); + type.append(getPointerOperator(po)); + } + + i = id.getArrayModifiers(); + while (i.hasNext()){ + i.next(); + type.append("[]"); //$NON-NLS-1$ + } + + return type.toString(); + } + + public static final String EMPTY_STRING = ""; //$NON-NLS-1$ + public static String getExpressionString( IASTExpression expression ){ + String literal = expression.getLiteralString(); + String idExpression = expression.getIdExpression(); + + IASTExpression lhs = expression.getLHSExpression(); + IASTExpression rhs = expression.getRHSExpression(); + IASTExpression third = expression.getThirdExpression(); + IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor(); + IASTTypeId typeId = expression.getTypeId(); + + if( literal != null && !literal.equals( EMPTY_STRING ) && ( idExpression == null || idExpression.equals( EMPTY_STRING ) ) ) + return getLiteralExpression( expression ); + + if( idExpression != null && !idExpression.equals( EMPTY_STRING ) && lhs == null ) + return getIdExpression( expression ); + + if( third != null ) + return getConditionalExpression( expression ); + + if( descriptor != null ) + return getNewExpression( expression ); + + if( lhs != null && rhs != null ) + return getBinaryExpression( expression ); + + if( lhs != null && typeId != null ) + return getUnaryTypeIdExpression( expression ); + + if( lhs != null && ( idExpression != null && !idExpression.equals( EMPTY_STRING ) ) ) + return getUnaryIdExpression( expression ); + + if( lhs != null ) + return getUnaryExpression( expression ); + + if( typeId != null ) + return getTypeIdExpression( expression ); + + return getEmptyExpression( expression ); + } + + private static String getEmptyExpression( IASTExpression expression ){ + if( expression.getExpressionKind() == Kind.PRIMARY_THIS ) + return Keywords.THIS; + + return EMPTY_STRING; + } + + private static String getLiteralExpression( IASTExpression expression ){ + Kind kind = expression.getExpressionKind(); + + if( kind != Kind.PRIMARY_CHAR_LITERAL && kind != Kind.PRIMARY_STRING_LITERAL ) + return expression.getLiteralString(); + + StringBuffer buffer = new StringBuffer(); + if( kind == Kind.PRIMARY_CHAR_LITERAL ){ + buffer.append( '\'' ); + buffer.append( expression.getLiteralString() ); + buffer.append( '\'' ); + } else if( kind == Kind.PRIMARY_STRING_LITERAL ) { + buffer.append( '"' ); + buffer.append( expression.getLiteralString() ); + buffer.append( '"' ); + } + return buffer.toString(); + } + + private static String getIdExpression( IASTExpression expression ){ + return expression.getIdExpression(); + } + private static String getConditionalExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + buffer.append( " ? " ); //$NON-NLS-1$ + buffer.append( getExpressionString( expression.getRHSExpression() ) ); + buffer.append( " : " ); //$NON-NLS-1$ + buffer.append( getExpressionString( expression.getThirdExpression() ) ); + + return buffer.toString(); + } + private static String getNewExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + + buffer.append( Keywords.NEW ); + buffer.append( ' ' ); + + IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor(); + Iterator iter = descriptor.getNewPlacementExpressions(); + if( iter.hasNext() ){ + buffer.append( '(' ); + buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); + buffer.append( ") " ); //$NON-NLS-1$ + } + + iter = descriptor.getNewTypeIdExpressions(); + if( iter.hasNext() ){ + buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); + buffer.append( ' ' ); + } + + if( expression.getTypeId() != null ){ + buffer.append( getTypeId( expression.getTypeId() ) ); + } + + iter = descriptor.getNewInitializerExpressions(); + if( iter.hasNext() ){ + buffer.append( '(' ); + buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); + buffer.append( ')' ); + } + + return buffer.toString(); + } + private static String getBinaryExpression( IASTExpression expression ){ + Kind kind = expression.getExpressionKind(); + StringBuffer buffer = new StringBuffer(); + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + + boolean appendSpace = false; + if( kind != Kind.EXPRESSIONLIST && + kind != Kind.PM_DOTSTAR && + kind != Kind.PM_ARROWSTAR && + kind != Kind.POSTFIX_SUBSCRIPT && + kind != Kind.POSTFIX_FUNCTIONCALL && + kind != Kind.POSTFIX_DOT_TEMPL_IDEXPRESS && + kind != Kind.POSTFIX_DOT_IDEXPRESSION && + kind != Kind.POSTFIX_DOT_DESTRUCTOR && + kind != Kind.POSTFIX_ARROW_TEMPL_IDEXP && + kind != Kind.POSTFIX_ARROW_IDEXPRESSION && + kind != Kind.POSTFIX_ARROW_DESTRUCTOR) + { + appendSpace = true; + buffer.append( ' ' ); + } + + if( kind == Kind.ANDEXPRESSION || + kind == Kind.EXPRESSIONLIST || + kind == Kind.EXCLUSIVEOREXPRESSION || + kind == Kind.PM_DOTSTAR || + kind == Kind.PM_ARROWSTAR || + kind == Kind.LOGICALANDEXPRESSION || + kind == Kind.LOGICALOREXPRESSION || + kind == Kind.RELATIONAL_GREATERTHAN || + kind == Kind.RELATIONAL_LESSTHAN || + kind == Kind.RELATIONAL_LESSTHANEQUALTO || + kind == Kind.RELATIONAL_GREATERTHANEQUALTO || + kind == Kind.EQUALITY_EQUALS || + kind == Kind.EQUALITY_NOTEQUALS || + kind == Kind.ADDITIVE_PLUS || + kind == Kind.ADDITIVE_MINUS || + kind == Kind.INCLUSIVEOREXPRESSION || + kind == Kind.MULTIPLICATIVE_MULTIPLY || + kind == Kind.MULTIPLICATIVE_DIVIDE || + kind == Kind.MULTIPLICATIVE_MODULUS || + kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS || + kind == Kind.POSTFIX_DOT_IDEXPRESSION || + kind == Kind.POSTFIX_DOT_DESTRUCTOR || + kind == Kind.POSTFIX_ARROW_TEMPL_IDEXP || + kind == Kind.POSTFIX_ARROW_IDEXPRESSION || + kind == Kind.POSTFIX_ARROW_DESTRUCTOR || + kind == Kind.ASSIGNMENTEXPRESSION_NORMAL || + kind == Kind.ASSIGNMENTEXPRESSION_MULT || + kind == Kind.ASSIGNMENTEXPRESSION_DIV || + kind == Kind.ASSIGNMENTEXPRESSION_MOD || + kind == Kind.ASSIGNMENTEXPRESSION_PLUS || + kind == Kind.ASSIGNMENTEXPRESSION_MINUS || + kind == Kind.ASSIGNMENTEXPRESSION_RSHIFT || + kind == Kind.ASSIGNMENTEXPRESSION_LSHIFT || + kind == Kind.ASSIGNMENTEXPRESSION_AND || + kind == Kind.ASSIGNMENTEXPRESSION_XOR || + kind == Kind.ASSIGNMENTEXPRESSION_OR || + kind == Kind.SHIFT_LEFT || + kind == Kind.SHIFT_RIGHT) + { + buffer.append( ASTUtil.getStringForKind( kind ) ); + } else if( kind == Kind.POSTFIX_SUBSCRIPT ) + buffer.append( '[' ); + else if( kind == Kind.POSTFIX_FUNCTIONCALL ) + buffer.append( '(' ); + + if( kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS || + kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP) + { + buffer.append( ' ' ); + buffer.append( Keywords.TEMPLATE ); + buffer.append( ' ' ); + } + + if( appendSpace || kind == Kind.EXPRESSIONLIST ) + buffer.append( ' ' ); + + buffer.append( getExpressionString( expression.getRHSExpression() ) ); + + if( kind == Kind.POSTFIX_SUBSCRIPT ) + buffer.append( ']' ); + else if( kind == Kind.POSTFIX_FUNCTIONCALL ) + buffer.append( ')' ); + + return buffer.toString(); + } + + private static String getUnaryTypeIdExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + + Kind kind = expression.getExpressionKind(); + if( kind == Kind.CASTEXPRESSION ){ + buffer.append( '(' ); + buffer.append( getTypeId( expression.getTypeId() ) ); + buffer.append( ')' ); + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + + } else if ( kind == Kind.POSTFIX_DYNAMIC_CAST || + kind == Kind.POSTFIX_STATIC_CAST || + kind == Kind.POSTFIX_REINTERPRET_CAST || + kind == Kind.POSTFIX_CONST_CAST ) + { + buffer.append( ASTUtil.getStringForKind( kind ) ); + buffer.append( '<' ); + buffer.append( getTypeId( expression.getTypeId() ) ); + buffer.append( ">(" ); //$NON-NLS-1$ + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + buffer.append( ')' ); + } + + return buffer.toString(); + } + + private static String getUnaryIdExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + + buffer.append( Keywords.TYPENAME ); + buffer.append( ' ' ); + if( expression.getExpressionKind() == Kind.POSTFIX_TYPENAME_TEMPLATEID ){ + buffer.append( Keywords.TEMPLATE ); + buffer.append( ' ' ); + } + buffer.append( expression.getIdExpression() ); + buffer.append( '(' ); + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + buffer.append( ')' ); + + return buffer.toString(); + } + private static String getUnaryExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + Kind kind = expression.getExpressionKind(); + + boolean bracketsAroundExpression = ( kind == Kind.PRIMARY_BRACKETED_EXPRESSION ); + + if ( kind == Kind.UNARY_SIZEOF_UNARYEXPRESSION ){ + buffer.append( Keywords.SIZEOF ); + buffer.append( ' ' ); + } + else if ( kind == Kind.UNARY_STAR_CASTEXPRESSION || + kind == Kind.UNARY_AMPSND_CASTEXPRESSION || + kind == Kind.UNARY_PLUS_CASTEXPRESSION || + kind == Kind.UNARY_MINUS_CASTEXPRESSION || + kind == Kind.UNARY_NOT_CASTEXPRESSION || + kind == Kind.UNARY_TILDE_CASTEXPRESSION || + kind == Kind.UNARY_DECREMENT || + kind == Kind.THROWEXPRESSION + ) + { + buffer.append( ASTUtil.getStringForKind( kind ) ); + } + else if ( kind == Kind.UNARY_INCREMENT ) + buffer.append( "++" ); //$NON-NLS-1$ + else if( kind == Kind.DELETE_VECTORCASTEXPRESSION || kind == Kind.DELETE_CASTEXPRESSION ){ + buffer.append( Keywords.DELETE ); + buffer.append(' '); + if( kind == Kind.DELETE_VECTORCASTEXPRESSION ) + buffer.append( "[ ] " ); //$NON-NLS-1$ + } else if( kind == Kind.POSTFIX_SIMPLETYPE_CHAR || + kind == Kind.POSTFIX_SIMPLETYPE_WCHART || + kind == Kind.POSTFIX_SIMPLETYPE_BOOL || + kind == Kind.POSTFIX_SIMPLETYPE_SHORT || + kind == Kind.POSTFIX_SIMPLETYPE_INT || + kind == Kind.POSTFIX_SIMPLETYPE_LONG || + kind == Kind.POSTFIX_SIMPLETYPE_SIGNED || + kind == Kind.POSTFIX_SIMPLETYPE_UNSIGNED || + kind == Kind.POSTFIX_SIMPLETYPE_FLOAT || + kind == Kind.POSTFIX_SIMPLETYPE_DOUBLE + ) + { + buffer.append( ASTUtil.getStringForKind( kind ) ); + bracketsAroundExpression = true; + } else if( kind == Kind.POSTFIX_TYPEID_EXPRESSION ) + { + buffer.append( Keywords.TYPEID ); + bracketsAroundExpression = true; + } + + if( bracketsAroundExpression ) + buffer.append( '(' ); + + buffer.append( getExpressionString( expression.getLHSExpression() ) ); + + if( bracketsAroundExpression ) + buffer.append( ')' ); + + if( kind == Kind.POSTFIX_INCREMENT || + kind == Kind.POSTFIX_DECREMENT ) + { + buffer.append( ASTUtil.getStringForKind( kind ) ); + } + + return buffer.toString(); + } + private static String getTypeIdExpression( IASTExpression expression ){ + StringBuffer buffer = new StringBuffer(); + + Kind kind = expression.getExpressionKind(); + + boolean addBrackets = false; + if( kind == Kind.UNARY_SIZEOF_TYPEID ){ + buffer.append( Keywords.SIZEOF ); + buffer.append( ' ' ); + addBrackets = true; + } else if( kind == Kind.POSTFIX_TYPEID_TYPEID ){ + buffer.append( Keywords.TYPEID ); + addBrackets = true; + } + + if( addBrackets ) + buffer.append( '(' ); + buffer.append( ASTUtil.getTypeId( expression.getTypeId() ) ); + if( addBrackets ) + buffer.append( ')' ); + + return buffer.toString(); + } + + private static final Map expressionKindStringMap = new HashMap(); + static { + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DYNAMIC_CAST, Keywords.DYNAMIC_CAST ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_STATIC_CAST, Keywords.STATIC_CAST ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_REINTERPRET_CAST, Keywords.REINTERPRET_CAST ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_CONST_CAST, Keywords.CONST_CAST ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR, Keywords.CHAR ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART, Keywords.WCHAR_T ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL, Keywords.BOOL ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT, Keywords.SHORT ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT, Keywords.INT ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG, Keywords.LONG ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED, Keywords.SIGNED ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED, Keywords.UNSIGNED ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT, Keywords.FLOAT ); + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE, Keywords.DOUBLE ); + expressionKindStringMap.put( IASTExpression.Kind.THROWEXPRESSION, Keywords.THROW ); + expressionKindStringMap.put( IASTExpression.Kind.ANDEXPRESSION, "&" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, "&" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.EXPRESSIONLIST, "," ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.EXCLUSIVEOREXPRESSION, "^" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.PM_DOTSTAR, ".*" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.PM_ARROWSTAR, "->*" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.LOGICALANDEXPRESSION, "&&" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.LOGICALOREXPRESSION, "||" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHAN, ">" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHAN, "<" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO, "<=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO, ">=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_EQUALS, "==" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_NOTEQUALS, "!=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, "*" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY, "*" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, "+" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_PLUS, "+" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, "-" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_MINUS, "-" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, "!" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, "~" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_DECREMENT, "--" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DECREMENT, "--" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.UNARY_INCREMENT, "++" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_INCREMENT, "++" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.INCLUSIVEOREXPRESSION, "|" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_DIVIDE, "/" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MODULUS, "%" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS, "." ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION, "." ); //$NON-NLS-1$ | + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR, "." ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP, "->" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR, "->" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION, "->" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL, "=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT, "*=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV, "/=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD, "%=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS, "+=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS, "-=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT, ">>=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT, "<<=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND, "&=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR, "^=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR, "|=" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.SHIFT_LEFT, "<<" ); //$NON-NLS-1$ + expressionKindStringMap.put( IASTExpression.Kind.SHIFT_RIGHT, ">>" ); //$NON-NLS-1$ + + } + private static String getStringForKind( IASTExpression.Kind kind ){ + return (String) expressionKindStringMap.get( kind ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java index 413cd0bbe71..a9e0e04a78e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java @@ -1966,8 +1966,9 @@ public class ExpressionParser implements IExpressionParser, IParserData { setCompletionValues( scope, CompletionKind.CONSTRUCTOR_REFERENCE ); if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } - if ( queryLookaheadCapability() && (LT(1) != IToken.tRPAREN)) - newInitializerExpressions.add(expression(scope, CompletionKind.CONSTRUCTOR_REFERENCE, key)); + //we want to know the difference between no newInitializer and an empty new Initializer + //if the next token is the RPAREN, then we have an Empty expression in our list. + newInitializerExpressions.add(expression(scope, CompletionKind.CONSTRUCTOR_REFERENCE, key)); setCurrentFunctionName( EMPTY_STRING ); consume(IToken.tRPAREN); @@ -2139,26 +2140,15 @@ public class ExpressionParser implements IExpressionParser, IParserData { { case IToken.t_typename : consume(IToken.t_typename); - ITokenDuple nestedName = name(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.EMPTY); + boolean templateTokenConsumed = false; if( LT(1) == IToken.t_template ) { consume( IToken.t_template ); templateTokenConsumed = true; } - IToken current = mark(); - ITokenDuple templateId = null; - try - { - templateId = TokenFactory.createTokenDuple( current, templateId(scope, CompletionKind.SINGLE_NAME_REFERENCE ) ); - } - catch( BacktrackException bt ) - { - if( templateTokenConsumed ) - throw bt; - backup( current ); - } - current = null; + ITokenDuple nestedName = name(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.EMPTY); + consume( IToken.tLPAREN ); if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } IASTExpression expressionList = expression( scope, CompletionKind.TYPE_REFERENCE, key ); @@ -2167,7 +2157,7 @@ public class ExpressionParser implements IExpressionParser, IParserData { try { firstExpression = astFactory.createExpression( scope, - (( templateId != null )? IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID : IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER ), + ( templateTokenConsumed ? IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID : IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER ), expressionList, null, null, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java index 2679c2c857b..b2360f31f0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -88,4 +89,8 @@ public class ASTBinaryExpression extends ASTUnaryExpression { super.freeReferences(manager); rhs.freeReferences(manager); } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java index 56128b05e6f..5b488c99699 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -92,4 +93,7 @@ public class ASTConditionalExpression extends ASTBinaryExpression { super.freeReferences(manager); thirdExpression.freeReferences(manager); } + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java index 1dac71a7d1d..d824f08ae88 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.List; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IReferenceManager; /** @@ -32,4 +33,8 @@ public class ASTEmptyExpression extends ASTExpression { */ public void freeReferences(IReferenceManager manager) { } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java index 3ae2cfbc290..279688c35ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.List; import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ast.ASTUtil; /** * @author jcamelon @@ -44,6 +45,7 @@ public class ASTIdExpression extends ASTExpression { return idExpression; } - - + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java index 1dd7aa2d6c8..bbfacfd27d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.List; +import org.eclipse.cdt.core.parser.ast.ASTUtil; + /** * @author jcamelon * @@ -35,4 +37,8 @@ public class ASTLiteralExpression extends ASTExpression { public String getLiteralString() { return literal; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java index 75cd20407bd..77ca9067c46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java @@ -14,6 +14,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTTypeId; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -80,4 +81,8 @@ public class ASTNewExpression extends ASTExpression { super.freeReferences(manager); typeId.freeReferences( manager ); } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java index d09a4988e16..c4b055d489b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTTypeId; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -51,4 +52,8 @@ public class ASTTypeIdExpression extends ASTExpression { super.freeReferences(manager); typeId.freeReferences(manager); } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java index 27b367458f6..e05524bd182 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -84,4 +85,8 @@ public class ASTUnaryExpression extends ASTExpression { super.freeReferences(manager); lhs.freeReferences(manager); } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java new file mode 100644 index 00000000000..85ab5530e32 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java @@ -0,0 +1,93 @@ +/********************************************************************** + * Copyright (c) 2004 IBM - Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +/* + * Created on Jun 7, 2004 + */ +package org.eclipse.cdt.internal.core.parser.ast.complete; + +import java.util.List; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.ASTUtil; +import org.eclipse.cdt.core.parser.ast.IASTExpression; +import org.eclipse.cdt.core.parser.ast.IReferenceManager; + +/** + * @author aniefer + */ +public class ASTUnaryIdExpression extends ASTIdExpression { + private final IASTExpression lhs; + + /** + * @param kind + * @param references + * @param idExpression + */ + public ASTUnaryIdExpression(Kind kind, List references, IASTExpression lhs, ITokenDuple idExpression) { + super(kind, references, idExpression); + this.lhs = lhs; + } + + public IASTExpression getLHSExpression(){ + return lhs; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) + */ + public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { + if( isIDExpressionForDuple( lhs, duple ) ) + return this; + ASTExpression result = recursiveFindExpressionForDuple(lhs, duple); + return result; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() + */ + public void reconcileReferences(IReferenceManager manager) throws ASTNotImplementedException { + lhs.reconcileReferences(manager); + reconcileSubExpression((ASTExpression) lhs, manager); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() + */ + public void purgeReferences() throws ASTNotImplementedException { + lhs.purgeReferences(); + purgeSubExpression( (ASTExpression) lhs ); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() + */ + protected void processCallbacks( ISourceElementRequestor requestor, IReferenceManager manager ) { + super.processCallbacks(requestor, manager); + lhs.acceptElement( requestor, manager ); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) + */ + public void freeReferences(IReferenceManager manager) { + super.freeReferences(manager); + lhs.freeReferences(manager); + } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java index c39438b527b..3c47b59efdf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTTypeId; import org.eclipse.cdt.core.parser.ast.IReferenceManager; @@ -57,4 +58,7 @@ public class ASTUnaryTypeIdExpression extends ASTUnaryExpression { typeId.acceptElement( requestor, manager ); } + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 4886ac89294..da42071be26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -373,7 +373,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( t.getType() == IToken.tCOLONCOLON ){ idx++; continue; - } + } else if( t.getType() == IToken.t_template ){ + continue; + } if( t.isPointer() ) break; image = t.getImage(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java index 3ad05e16856..90edea9921a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java @@ -29,7 +29,7 @@ public class ExpressionFactory { if( !literal.equals( "") && idExpression == null ) //$NON-NLS-1$ return new ASTLiteralExpression( kind, references, literal ); - if( idExpression != null ) + if( idExpression != null && lhs == null ) return new ASTIdExpression( kind, references, idExpression ); if( thirdExpression != null ) @@ -44,6 +44,9 @@ public class ExpressionFactory { if( lhs != null && typeId != null ) return new ASTUnaryTypeIdExpression( kind, references, lhs, typeId ); + if( lhs != null && idExpression != null ) + return new ASTUnaryIdExpression( kind, references, lhs, idExpression ); + if( lhs != null ) return new ASTUnaryExpression( kind, references, lhs ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTBinaryExpression.java index 37a117d1985..328a1765dd2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTBinaryExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; /** @@ -37,4 +38,8 @@ public class ASTBinaryExpression extends ASTUnaryExpression public IASTExpression getRHSExpression() { return rhs; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTConditionalExpression.java index 595d5a8f863..993e87efd66 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTConditionalExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; /** @@ -38,4 +39,8 @@ public class ASTConditionalExpression extends ASTBinaryExpression public IASTExpression getThirdExpression() { return thirdExpression; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTEmptyExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTEmptyExpression.java index 33179093438..7805bce617b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTEmptyExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTEmptyExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; /** @@ -25,4 +26,8 @@ public class ASTEmptyExpression extends ASTExpression implements IASTExpression super(kind); // TODO Auto-generated constructor stub } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTIdExpression.java index 208245d0b5a..45105c88de1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTIdExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; /** @@ -37,4 +38,8 @@ public class ASTIdExpression extends ASTExpression implements IASTExpression { public String getIdExpression() { return idExpression; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTLiteralExpression.java index 7c94bb6a617..904e107f65e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTLiteralExpression.java @@ -10,6 +10,8 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; + /** * @author jcamelon @@ -33,4 +35,8 @@ public class ASTLiteralExpression extends ASTExpression { public String getLiteralString() { return literal; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTNewExpression.java index 691b043622a..29bf7dccc01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTNewExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTTypeId; @@ -44,4 +45,8 @@ public class ASTNewExpression extends ASTExpression implements IASTExpression { public IASTTypeId getTypeId() { return typeId; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTTypeIdExpression.java index 0018222e6eb..dd348e570a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTTypeIdExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTTypeId; @@ -39,4 +40,8 @@ public class ASTTypeIdExpression extends ASTExpression public IASTTypeId getTypeId() { return typeId; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryExpression.java index 78a8bcc0acc..650babf5957 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; /** @@ -34,4 +35,8 @@ public class ASTUnaryExpression extends ASTExpression implements IASTExpression public IASTExpression getLHSExpression() { return lhs; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryIdExpression.java new file mode 100644 index 00000000000..3195615d7f4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryIdExpression.java @@ -0,0 +1,40 @@ +/********************************************************************** + * Copyright (c) 2004 IBM - Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +/* + * Created on Jun 7, 2004 + */ +package org.eclipse.cdt.internal.core.parser.ast.expression; + +import org.eclipse.cdt.core.parser.ast.ASTUtil; +import org.eclipse.cdt.core.parser.ast.IASTExpression; + +/** + * @author aniefer + */ +public class ASTUnaryIdExpression extends ASTIdExpression { + private final IASTExpression lhs; + /** + * @param kind + * @param idExpression + */ + public ASTUnaryIdExpression(Kind kind, IASTExpression lhs, String idExpression) { + super(kind, idExpression); + this.lhs = lhs; + } + + public IASTExpression getLHSExpression(){ + return lhs; + } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryTypeIdExpression.java index 7ee172affa9..1a80cb53e0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTUnaryTypeIdExpression.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.internal.core.parser.ast.expression; +import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTTypeId; @@ -40,4 +41,8 @@ public class ASTUnaryTypeIdExpression extends ASTUnaryExpression public IASTTypeId getTypeId() { return typeId; } + + public String toString(){ + return ASTUtil.getExpressionString( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionFactory.java index 5f70d62dabf..259772173d1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionFactory.java @@ -43,7 +43,7 @@ public class ExpressionFactory { if( !literal.equals( EMPTY_STRING ) && idExpression.equals( EMPTY_STRING )) //$NON-NLS-1$ return new ASTLiteralExpression( kind, literal ); - if( !idExpression.equals( EMPTY_STRING ) ) + if( !idExpression.equals( EMPTY_STRING ) && lhs == null ) return new ASTIdExpression( kind, idExpression ); if( thirdExpression != null ) @@ -58,6 +58,9 @@ public class ExpressionFactory { if( lhs != null && typeId != null ) return new ASTUnaryTypeIdExpression( kind, lhs, typeId ); + if( lhs != null && !idExpression.equals( EMPTY_STRING ) ) + return new ASTUnaryIdExpression( kind, lhs, idExpression ); + if( lhs != null ) return new ASTUnaryExpression( kind, lhs );