diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java index fda1349b053..6175ae8d035 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java @@ -35,7 +35,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; @@ -83,7 +83,7 @@ public abstract class CodanFastCxxAstTestCase extends TestCase { protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean gcc) { FileContent codeReader = FileContent.create("code.c", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner = AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner = AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java similarity index 59% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java index 57601678d90..12a869f2466 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java @@ -8,10 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - -/* - * Created on Sept 28, 2004 - */ package org.eclipse.cdt.core.parser.tests; import java.io.ByteArrayInputStream; @@ -36,127 +32,110 @@ import org.eclipse.core.runtime.NullProgressMonitor; /** * @author dsteffle */ -public class FileBasePluginTest extends TestCase { +public class FileBasePluginTestCase extends TestCase { static NullProgressMonitor monitor; static IWorkspace workspace; static IProject project; static FileManager fileManager; - static int numProjects = 0; + static int numProjects; static Class className; static ICProject cPrj; - public FileBasePluginTest() { + public FileBasePluginTestCase() { } - public FileBasePluginTest(String name) { + public FileBasePluginTestCase(String name) { super(name); } - private void initialize(Class aClassName){ - if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + private void initialize(Class aClassName) { + if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null) { //(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); monitor = new NullProgressMonitor(); - + workspace = ResourcesPlugin.getWorkspace(); - + try { cPrj = CProjectHelper.createCCProject("ParserTestProject", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ project = cPrj.getProject(); - + // ugly if (className == null || !className.equals(aClassName)) { className = aClassName; numProjects++; } - } catch ( CoreException e ) { - /*boo*/ + } catch (CoreException e) { + // Ignore } if (project == null) throw new NullPointerException("Unable to create project"); //$NON-NLS-1$ - + //Create file manager fileManager = new FileManager(); } } - public FileBasePluginTest(String name, Class className) - { + public FileBasePluginTestCase(String name, Class className) { super(name); initialize(className); } - + public void cleanupProject() throws Exception { numProjects--; - - try{ + + try { if (numProjects == 0) { - project.delete( true, false, monitor ); + project.delete(true, false, monitor); project = null; } - } catch( Throwable e ){ - /*boo*/ + } catch (Throwable e) { + // Ignore } } @Override protected void tearDown() throws Exception { - if( project == null || !project.exists() ) + if (project == null || !project.exists()) return; - + IResource [] members = project.members(); - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < members.length; i++) { + if (members[i].getName().equals(".project") || members[i].getName().equals(".cproject")) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (members[i].getName().equals(".settings")) continue; - try{ - members[i].delete( false, monitor ); - } catch( Throwable e ){ - /*boo*/ + try { + members[i].delete(false, monitor); + } catch (Throwable e) { + // Ignore } } } - // below can be used to work with large files (too large for memory) -// protected IFile importFile(String fileName) throws Exception { -// IFile file = cPrj.getProject().getFile(fileName); -// if (!file.exists()) { -// try{ -// FileInputStream fileIn = new FileInputStream( -// CTestPlugin.getDefault().getFileInPlugin(new Path("resources/parser/" + fileName))); -// file.create(fileIn,false, monitor); -// } catch (CoreException e) { -// e.printStackTrace(); -// } catch (FileNotFoundException e) { -// e.printStackTrace(); -// } -// } -// -// return file; -// } - protected IFolder importFolder(String folderName) throws Exception { IFolder folder = project.getProject().getFolder(folderName); - - //Create file input stream - if( !folder.exists() ) - folder.create( false, false, monitor ); - + + // Create file input stream + if (!folder.exists()) + folder.create(false, false, monitor); + return folder; } - public IFile importFile(String fileName, String contents ) throws Exception{ - //Obtain file handle + + public IFile importFile(String fileName, String contents) throws Exception { + // Obtain file handle IFile file = project.getProject().getFile(fileName); - - InputStream stream = new ByteArrayInputStream( contents.getBytes() ); - //Create file input stream - if( file.exists() ) - file.setContents( stream, false, false, monitor ); - else - file.create( stream, false, monitor ); - + + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + // Create file input stream + if (file.exists()) { + file.setContents(stream, false, false, monitor); + } else { + file.create(stream, false, monitor); + } + fileManager.addFile(file); - + return file; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java index 002916af926..3d4d2c70d0f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Mike Kucera (IBM) * Sergey Prigogin (Google) * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -28,19 +29,19 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Tests for classes implementing IASTImplicitNameOwner interface. */ -public class AST2CPPImplicitNameTests extends AST2BaseTest { +public class AST2CPPImplicitNameTests extends AST2TestBase { public AST2CPPImplicitNameTests() { } - + public AST2CPPImplicitNameTests(String name) { super(name); } - + public static TestSuite suite() { return suite(AST2CPPImplicitNameTests.class); } - + public IASTImplicitName[] getImplicitNames(IASTTranslationUnit tu, String contents, String section, int len) { final int offset = contents.indexOf(section); assertTrue(offset >= 0); @@ -75,25 +76,25 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { CPPNameCollector col = new CPPNameCollector(); tu.accept(col); IASTImplicitName n; - + n = ba.assertImplicitName("+= 5", 2, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(14).resolveBinding()); - + n = ba.assertImplicitName("+ p", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(4).resolveBinding()); - + n = ba.assertImplicitName("- p", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(8).resolveBinding()); - + n = ba.assertImplicitName("* p", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(17).resolveBinding()); - + n = ba.assertImplicitName("/ p", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(23).resolveBinding()); - + n = ba.assertImplicitName("-p;", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(12).resolveBinding()); - + ba.assertNoImplicitName("<< 6", 2); ba.assertNoImplicitName("+p;", 1); } @@ -136,9 +137,9 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + ba.assertNoImplicitName("&Y::x;", 1); - + IASTImplicitName n = ba.assertImplicitName("&y;", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(9).resolveBinding()); } @@ -165,20 +166,20 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // p2->doA(); // } public void testArrowOperator() throws Exception { - String contents = getAboveComment(); + String contents = getAboveComment(); IASTTranslationUnit tu = parse(contents, ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName[] implicits = getImplicitNames(tu, contents, "->doA();", 2); - + assertNotNull(implicits); assertEquals(2, implicits.length); - + assertSame(implicits[1].getBinding(), col.getName(4).resolveBinding()); assertSame(implicits[0].getBinding(), col.getName(12).resolveBinding()); } - + // struct A { // int x; // }; @@ -224,15 +225,15 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { ba.assertNoImplicitName(", b, c, d); // func", 1); ba.assertNoImplicitName(", c, d); // func", 1); ba.assertNoImplicitName(", d); // func", 1); - + IASTImplicitName opAB = ba.assertImplicitName(", b, c, d; // expr", 1, ICPPFunction.class); IASTImplicitName opCC = ba.assertImplicitName(", c, d; // expr", 1, ICPPFunction.class); ba.assertNoImplicitName(", d; // expr", 1); - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + assertSame(opAB.resolveBinding(), col.getName(5).resolveBinding()); assertSame(opCC.resolveBinding(), col.getName(11).resolveBinding()); } @@ -255,20 +256,20 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // } public void testCommaOperator2() throws Exception { BindingAssertionHelper ba = new BindingAssertionHelper(getAboveComment(), true); - + IASTImplicitName opAB = ba.assertImplicitName(", b, c, d", 1, ICPPMethod.class); IASTImplicitName opCC = ba.assertImplicitName(", c, d", 1, ICPPFunction.class); IASTImplicitName opDD = ba.assertImplicitName(", d", 1, ICPPMethod.class); - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + // 6, 11, 15 assertSame(opAB.resolveBinding(), col.getName(6).resolveBinding()); assertSame(opCC.resolveBinding(), col.getName(15).resolveBinding()); assertSame(opDD.resolveBinding(), col.getName(11).resolveBinding()); - + ba.assertNonProblem("ee;", 2); } @@ -289,7 +290,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName n1 = ba.assertImplicitName("(b); // 1", 1, ICPPMethod.class); IASTImplicitName n2 = ba.assertImplicitName("); // 1", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); @@ -298,14 +299,14 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // there should be no overlap ba.assertNoImplicitName("b); // 1", 1); assertSame(col.getName(1).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("(); // 2", 1, ICPPMethod.class); n2 = ba.assertImplicitName("); // 2", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); assertFalse(n1.isAlternate()); assertTrue(n2.isAlternate()); assertSame(col.getName(3).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("(1, 2); // 3", 1, ICPPMethod.class); n2 = ba.assertImplicitName("); // 3", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); @@ -348,7 +349,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName n1 = ba.assertImplicitName("[0]); //1", 1, ICPPMethod.class); ba.assertNoImplicitName("0]); //1", 1); IASTImplicitName n2 = ba.assertImplicitName("]); //1", 1, ICPPMethod.class); @@ -356,7 +357,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertFalse(n1.isAlternate()); assertTrue(n2.isAlternate()); assertSame(col.getName(1).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("[q]); //2", 1, ICPPMethod.class); ba.assertNoImplicitName("q]); //2", 1); n2 = ba.assertImplicitName("]); //2", 1, ICPPMethod.class); @@ -384,21 +385,21 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertEquals(2, names.length); IASTImplicitName destructor = names[0]; IASTImplicitName delete = names[1]; - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + assertSame(col.getName(1).resolveBinding(), destructor.resolveBinding()); assertSame(col.getName(2).resolveBinding(), delete.resolveBinding()); - + names = ba.getImplicitNames("delete[] x;", 6); assertEquals(1, names.length); assertSame(col.getName(4).resolveBinding(), names[0].resolveBinding()); - + ba.assertNoImplicitName("delete 1;", 6); } - + // struct A { // void operator delete(void * a); // }; @@ -416,15 +417,15 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); IBinding m= bh.assertNonProblem("operator delete(void * a)", 15); IBinding f= bh.assertNonProblem("operator delete(void * b)", 15); - + IASTImplicitName[] names = bh.getImplicitNames("delete a;", 6); - assertEquals(2, names.length); + assertEquals(2, names.length); assertTrue(((ICPPMethod) names[0].resolveBinding()).isDestructor()); assertSame(m, names[1].resolveBinding()); names = bh.getImplicitNames("delete b;", 6); assertTrue(((ICPPMethod) names[0].resolveBinding()).isDestructor()); - assertEquals(2, names.length); + assertEquals(2, names.length); assertSame(f, names[1].resolveBinding()); } @@ -443,13 +444,13 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); IBinding m= bh.assertNonProblem("operator new(size_t a)", 12); IBinding f= bh.assertNonProblem("operator new(size_t b)", 12); - + IASTImplicitName[] names = bh.getImplicitNames("new A;", 3); - assertEquals(1, names.length); + assertEquals(2, names.length); assertSame(m, names[0].resolveBinding()); names = bh.getImplicitNames("new B;", 3); - assertEquals(1, names.length); + assertEquals(2, names.length); assertSame(f, names[0].resolveBinding()); } @@ -461,9 +462,9 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { public void testImplicitNewAndDelete() throws Exception { BindingAssertionHelper ba = new BindingAssertionHelper(getAboveComment(), true); ba.assertNoImplicitName("new X", 3); - ba.assertNoImplicitName("delete[]", 6); + ba.assertNoImplicitName("delete[]", 6); } - + // typedef long unsigned int size_t // struct nothrow_t {}; // extern const nothrow_t nothrow; @@ -491,7 +492,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertSame(col.getName(9).resolveBinding(), n2.resolveBinding()); assertSame(col.getName(14).resolveBinding(), n3.resolveBinding()); } - + // int test() { // throw; // } @@ -551,7 +552,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTImplicitName v = ba.assertImplicitName("v(p)", 1, ICPPConstructor.class); assertSame(ctor1, v.resolveBinding()); } - + // enum A {aa}; // struct B{ operator A();}; // bool operator==(A, A); // overrides the built-in operator. @@ -567,5 +568,5 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { ICPPFunction op = ba.assertNonProblem("operator==", 0); IASTImplicitName a = ba.assertImplicitName("==b", 2, ICPPFunction.class); assertSame(op, a.resolveBinding()); - } + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index ef4f48076d4..5f28ad59cf6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -46,7 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * Examples taken from the c++-specification. */ -public class AST2CPPSpecTest extends AST2SpecBaseTest { +public class AST2CPPSpecTest extends AST2SpecTestBase { public AST2CPPSpecTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 5908699d91c..ff1f4eef230 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -128,6 +128,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; @@ -139,7 +140,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AST2CPPTests extends AST2BaseTest { +public class AST2CPPTests extends AST2TestBase { public AST2CPPTests() { } @@ -260,7 +261,7 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(declNames.length, i); assertEquals(defNames.length, j); } - + @Override protected void assertSameType(IType first, IType second){ assertNotNull(first); @@ -1201,10 +1202,10 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector collector = new CPPNameCollector(); + CPPNameCollector collector = new CPPNameCollector(true); tu.accept(collector); - assertEquals(collector.size(), 15); + assertEquals(collector.size(), 16); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPField x = (ICPPField) collector.getName(1).resolveBinding(); @@ -1215,7 +1216,7 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, D, 3); assertInstances(collector, C, 2); assertInstances(collector, B, 2); - assertInstances(collector, A, 2); + assertInstances(collector, A, 3); assertInstances(collector, ctor, 1); assertInstances(collector, x, 2); } @@ -1230,10 +1231,10 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testAmbiguousVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector collector = new CPPNameCollector(); + CPPNameCollector collector = new CPPNameCollector(true); tu.accept(collector); - assertEquals(collector.size(), 15); + assertEquals(collector.size(), 16); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPField x1 = (ICPPField) collector.getName(1).resolveBinding(); @@ -1241,13 +1242,13 @@ public class AST2CPPTests extends AST2BaseTest { ICPPClassType B = (ICPPClassType) collector.getName(4).resolveBinding(); ICPPClassType A = (ICPPClassType) collector.getName(6).resolveBinding(); ICPPConstructor ctor = A.getConstructors()[0]; - IProblemBinding x2 = (IProblemBinding) collector.getName(14).resolveBinding(); + IProblemBinding x2 = (IProblemBinding) collector.getName(15).resolveBinding(); assertEquals(x2.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); assertInstances(collector, D, 3); assertInstances(collector, C, 2); assertInstances(collector, B, 2); - assertInstances(collector, A, 2); + assertInstances(collector, A, 3); assertInstances(collector, ctor, 1); assertInstances(collector, x1, 1); } @@ -1843,7 +1844,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPMethod dtor = (ICPPMethod) col.getName(13).resolveBinding(); assertNotNull(dtor); assertEquals(dtor.getName(), "~C"); //$NON-NLS-1$ - assertInstances(col, C, 6); + assertInstances(col, C, 7); assertInstances(col, op, 3); assertInstances(col, other, 4); @@ -1993,7 +1994,7 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, pb, 2); assertInstances(col, mutate, 2); - assertInstances(col, B, 2); + assertInstances(col, B, 3); } // struct S { int i; }; @@ -2511,7 +2512,7 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testBug86267() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); ICPPClassType D1 = (ICPPClassType) col.getName(2).resolveBinding(); @@ -2549,7 +2550,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPMethod op = (ICPPMethod) col.getName(3).resolveBinding(); IParameter other = (IParameter) col.getName(5).resolveBinding(); - assertInstances(col, C, 6); + assertInstances(col, C, 7); assertInstances(col, f, 2); assertInstances(col, op, 3); assertInstances(col, other, 4); @@ -4052,11 +4053,11 @@ public class AST2CPPTests extends AST2BaseTest { // X x = new X(y); public void testBug90654_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding(); - ICPPConstructor ctor = (ICPPConstructor) col.getName(11).resolveBinding(); + ICPPConstructor ctor = (ICPPConstructor) col.getName(12).resolveBinding(); assertSame(ctor, ctor1); } @@ -8382,20 +8383,24 @@ public class AST2CPPTests extends AST2BaseTest { // fH({1}); // H(G(1)) // } public void testListInitialization_302412f() throws Exception { - ICPPConstructor ctor; IProblemBinding problem; String code= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(code, true); bh.assertProblem("f({1,1})", 1); - ctor= bh.assertNonProblem("F({1,1})", 1); + bh.assertImplicitName("F({1,1})", 1, ICPPConstructor.class); bh.assertNonProblem("fF({1,1})", 2); bh.assertNonProblem("fG(1)", 2); bh.assertNonProblem("fG({1})", 2); - ctor= bh.assertNonProblem("H(1)", 1); - problem= bh.assertProblem("H({1})", 1); - assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); + bh.assertImplicitName("H(1)", 1, ICPPConstructor.class); + bh.assertNoImplicitName("H({1})", 1); + // TODO(nathanridge): Perhaps we should store implicit names even if they + // resolve to ProblemBindings. Then we can do the stronger check in the + // 3 commented lines below. + //IASTImplicitName n= bh.assertImplicitName("H({1})", 1, IProblemBinding.class); + //problem= (IProblemBinding) n.resolveBinding(); + //assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); bh.assertProblem("fH(1)", 2); bh.assertNonProblem("fH({1})", 2); } @@ -9823,7 +9828,7 @@ public class AST2CPPTests extends AST2BaseTest { } // struct Base { - // virtual void mFuncDecl(); + // virtual void mFuncDecl(); // virtual void mFuncDef(){} // }; // struct S : public Base { @@ -9851,9 +9856,9 @@ public class AST2CPPTests extends AST2BaseTest { assertInstance(declarator, ICPPASTFunctionDeclarator.class); assertVirtualSpecifiers((ICPPASTFunctionDeclarator)declarator, true, false); } - + // struct Base { - // virtual void mFuncDecl(); + // virtual void mFuncDecl(); // virtual void mFuncDef(){} // }; // struct S : public Base { @@ -10025,7 +10030,7 @@ public class AST2CPPTests extends AST2BaseTest { // double vdouble; // long double vlongdouble; // UnscopedEnum vue; - // + // // // Narrowing conversions // fint({vdouble}); // ffloat({vlongdouble}); @@ -10083,7 +10088,7 @@ public class AST2CPPTests extends AST2BaseTest { helper.assertNonProblemOnFirstIdentifier("fint({vbool"); helper.assertNonProblemOnFirstIdentifier("fint({vchar"); } - + // namespace std { // struct string {}; // struct exception {}; @@ -10121,4 +10126,64 @@ public class AST2CPPTests extends AST2BaseTest { parseAndCheckBindings(getAboveComment(), CPP, true); } + // template + // T bar(); + // struct S { + // void waldo(); + // }; + // int main() { + // auto L = [](S s) { return s; }; + // typedef decltype(L) lambda_type; + // decltype(bar()(S())) v; + // v.waldo(); + // } + public void testDecltypeWithConstantLambda_397494() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct enable_if { + // }; + // template <> + // struct enable_if { + // typedef void type; + // }; + // struct base {}; + // struct derived : base {}; + // typedef enable_if<__is_base_of(base, derived)>::type T; + public void testIsBaseOf_399353() throws Exception { + parseAndCheckBindings(getAboveComment(), CPP, true); + } + + // template struct B{}; + // template <> + // struct B { + // void waldo(); + // }; + // typedef char& one; + // int main() { + // B b; + // b.waldo(); + // } + public void testSizeofReference_397342() throws Exception { + parseAndCheckBindings(); + } + + // struct A { + // char a[100]; + // }; + // struct B { + // A& b; + // }; + // A* p; + public void testSizeofStructWithReferenceField_397342() throws Exception { + BindingAssertionHelper bh = getAssertionHelper(); + IASTName nameB = bh.findName("B"); + IASTName namep = bh.findName("p"); + ICPPClassType B = (ICPPClassType) nameB.resolveBinding(); + IPointerType ptrToA = (IPointerType) ((ICPPVariable) namep.resolveBinding()).getType(); + long pointerSize = SizeofCalculator.getSizeAndAlignment(ptrToA, namep).size; + long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size; + assertEquals(pointerSize, BSize); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java index 974728e23da..9ad87f0b996 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java @@ -15,7 +15,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author dsteffle */ -public class AST2CSpecTest extends AST2SpecBaseTest { +public class AST2CSpecTest extends AST2SpecTestBase { public AST2CSpecTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java similarity index 68% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java index 8aa20c65a32..deb5f8f4b80 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java @@ -8,10 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - -/* - * Created on Sept 28, 2004 - */ package org.eclipse.cdt.core.parser.tests.ast2; import java.io.ByteArrayInputStream; @@ -39,116 +35,116 @@ import org.eclipse.core.runtime.NullProgressMonitor; /** * @author dsteffle */ -public class AST2FileBasePluginTest extends TestCase { +public class AST2FileBasePluginTestCase extends TestCase { static NullProgressMonitor monitor; static IWorkspace workspace; static IProject project; static FileManager fileManager; - static int numProjects = 0; + static int numProjects; static Class className; static ICProject cPrj; - public AST2FileBasePluginTest() { + public AST2FileBasePluginTestCase() { } - public AST2FileBasePluginTest(String name) { + public AST2FileBasePluginTestCase(String name) { super(name); } - private void initialize(Class aClassName){ - if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + private void initialize(Class aClassName) { + if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null) { //(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); monitor = new NullProgressMonitor(); - + workspace = ResourcesPlugin.getWorkspace(); - + try { cPrj = CProjectHelper.createCCProject("AST2BasedProjectMofo", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ - + project = cPrj.getProject(); - + // ugly if (className == null || !className.equals(aClassName)) { className = aClassName; numProjects++; } - } catch ( CoreException e ) { - /*boo*/ + } catch (CoreException e) { + // Ignore } if (project == null) throw new NullPointerException("Unable to create project"); //$NON-NLS-1$ - - //Create file manager + + // Create file manager fileManager = new FileManager(); } } - public AST2FileBasePluginTest(String name, Class className) - { + public AST2FileBasePluginTestCase(String name, Class className) { super(name); initialize(className); } - + public void cleanupProject() throws Exception { numProjects--; - - try{ + + try { if (numProjects == 0) { - project.delete( true, false, monitor ); + project.delete(true, false, monitor); project = null; } - } catch( Throwable e ){ - /*boo*/ + } catch (Throwable e) { + // Ignore } } @Override protected void tearDown() throws Exception { - if( project == null || !project.exists() ) + if (project == null || !project.exists()) return; - - IResource [] members = project.members(); - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ + + IResource[] members = project.members(); + for (int i = 0; i < members.length; i++) { + if (members[i].getName().equals(".project") || members[i].getName().equals(".cproject")) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (members[i].getName().equals(".settings")) continue; - try{ - members[i].delete( false, monitor ); - } catch( Throwable e ){ - /*boo*/ + try { + members[i].delete(false, monitor); + } catch (Throwable e) { + // Ignore } } } protected IFolder importFolder(String folderName) throws Exception { IFolder folder = project.getProject().getFolder(folderName); - - //Create file input stream - if( !folder.exists() ) - folder.create( false, false, monitor ); - + + // Create file input stream + if (!folder.exists()) + folder.create(false, false, monitor); + return folder; } - public IFile importFile(String fileName, String contents ) throws Exception{ - //Obtain file handle + + public IFile importFile(String fileName, String contents) throws Exception { + // Obtain file handle IFile file = project.getProject().getFile(fileName); - - InputStream stream = new ByteArrayInputStream( contents.getBytes() ); - //Create file input stream - if( file.exists() ) - file.setContents( stream, false, false, monitor ); - else - file.create( stream, false, monitor ); - + + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + // Create file input stream + if (file.exists()) { + file.setContents(stream, false, false, monitor); + } else { + file.create(stream, false, monitor); + } + fileManager.addFile(file); - + return file; } - + protected StringBuilder[] getContents(int sections) throws IOException { return TestSourceReader.getContentsForTest( CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections); } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index b0717f0aa51..80ee143f853 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -59,7 +59,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; /** * @author dsteffle */ -public class AST2KnRTests extends AST2BaseTest { +public class AST2KnRTests extends AST2TestBase { public AST2KnRTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java index 9ec90bf1263..71ec93a7c7f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IField; @@ -46,7 +48,7 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { +public class AST2SelectionParseTest extends AST2SelectionParseTestBase { public AST2SelectionParseTest() { } @@ -352,9 +354,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { assertTrue(node instanceof IASTTypeId); assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "Gonzo"); //$NON-NLS-1$ name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); - assertNotNull(name.resolveBinding()); - assertTrue(name.resolveBinding() instanceof ICPPConstructor); - assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "Gonzo"); //$NON-NLS-1$ + name = TestUtil.findImplicitName(name); + IBinding binding = name.resolveBinding(); + assertTrue(binding instanceof ICPPConstructor); + assertEquals(((ICPPConstructor)binding).getName(), "Gonzo"); //$NON-NLS-1$ break; default: assertTrue(node instanceof IASTName); @@ -736,9 +739,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { assertTrue(node instanceof IASTTypeId); assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "B"); //$NON-NLS-1$ IASTName name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); - assertNotNull(name.resolveBinding()); - assertTrue(name.resolveBinding() instanceof ICPPConstructor); - assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "B"); //$NON-NLS-1$ + name = TestUtil.findImplicitName(name); + IBinding binding = name.resolveBinding(); + assertTrue(binding instanceof ICPPConstructor); + assertEquals(((ICPPConstructor)binding).getName(), "B"); //$NON-NLS-1$ } public void testBug72712_2() throws Exception{ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java similarity index 94% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java index 8aca7558fa4..851a990f72b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; +import org.eclipse.cdt.core.parser.tests.FileBasePluginTestCase; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; @@ -40,18 +40,18 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class AST2SelectionParseBaseTest extends FileBasePluginTest { +public class AST2SelectionParseTestBase extends FileBasePluginTestCase { - public AST2SelectionParseBaseTest() { + public AST2SelectionParseTestBase() { } - public AST2SelectionParseBaseTest(String name) { + public AST2SelectionParseTestBase(String name) { super(name); } private static final IParserLogService NULL_LOG = new NullLogService(); - public AST2SelectionParseBaseTest(String name, Class className) { + public AST2SelectionParseTestBase(String name, Class className) { super(name, className); } @@ -76,7 +76,7 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java similarity index 97% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java index 5d9942bcf81..9dd536cb736 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java @@ -41,12 +41,12 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * @author dsteffle */ -public class AST2SpecBaseTest extends AST2BaseTest { - public AST2SpecBaseTest() { +public class AST2SpecTestBase extends AST2TestBase { + public AST2SpecTestBase() { super(); } - public AST2SpecBaseTest(String name) { + public AST2SpecTestBase(String name) { super(name); } @@ -101,7 +101,7 @@ public class AST2SpecBaseTest extends AST2BaseTest { boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException { ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 19350ee7d27..f6f66498610 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -44,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; @@ -55,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; @@ -101,7 +103,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AST2TemplateTests extends AST2BaseTest { +public class AST2TemplateTests extends AST2TestBase { public AST2TemplateTests() { } @@ -2371,11 +2373,11 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCPPConstructorTemplateSpecialization() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - ICPPASTTemplateId tid= (ICPPASTTemplateId) col.getName(20); - IASTName cn= col.getName(21); + IASTImplicitName tid= (IASTImplicitName) col.getName(20); + IASTName cn= col.getName(22); assertInstance(cn.resolveBinding(), ICPPClassTemplate.class); // *D*(5, 6) assertInstance(cn.resolveBinding(), ICPPClassType.class); // *D*(5, 6) assertInstance(tid.resolveBinding(), ICPPTemplateInstance.class); // *D*(5, 6) @@ -3840,7 +3842,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testNestedTemplates_259872_1() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); - bh.assertNonProblem("A", 9, ICPPConstructor.class); + bh.assertNonProblem("A", 9, ICPPClassType.class); } // template @@ -3865,7 +3867,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testNestedTemplates_259872_2() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); - bh.assertNonProblem("A", 9, ICPPConstructor.class); + bh.assertNonProblem("A", 9, ICPPClassType.class); } // template @@ -4403,6 +4405,17 @@ public class AST2TemplateTests extends AST2BaseTest { parseAndCheckBindings(); } + // template + // void foo(A); + // template + // void foo(A, B...); + // int main() { + // foo(0); + // } + public void testFunctionTemplatePartialOrdering_388805() throws Exception { + parseAndCheckBindings(); + } + // template class CT {}; // template class CTI {}; // @@ -4828,6 +4841,25 @@ public class AST2TemplateTests extends AST2BaseTest { ub= bh.assertNonProblem("f(h(args...) + args...)", 1); } + // template + // struct contains_waldo; + // template <> + // struct contains_waldo<> { + // static const bool value = false; + // }; + // template + // struct contains_waldo { + // static const bool value = contains_waldo::value; + // }; + // int main() { + // bool b1 = contains_waldo::value; + // bool b2 = contains_waldo::value; + // bool b2 = contains_waldo::value; + // } + public void testRecursiveVariadicTemplate_397828() throws Exception { + parseAndCheckBindings(); + } + // struct Test { // void Update() {} // }; @@ -6219,24 +6251,24 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); - + ICPPClassType S = assertionHelper.assertNonProblem("struct S {", "S", ICPPClassType.class); ICPPField x = assertionHelper.assertNonProblem("int x", "x", ICPPField.class); ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S", "Alias", ITypedef.class); IFunction foo = assertionHelper.assertNonProblem("void foo() {", "foo", IFunction.class); IVariable myA = assertionHelper.assertNonProblem("Alias myA", "myA", IVariable.class); - - + + assertInstances(collector, S, 2); assertInstances(collector, x, 2); assertInstances(collector, Alias, 2); assertInstances(collector, foo, 1); assertInstances(collector, myA, 2); } - + // template // struct S { // T x; @@ -6248,7 +6280,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSpecifiedTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6257,7 +6289,7 @@ public class AST2TemplateTests extends AST2BaseTest { ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S;", "Alias", ITypedef.class); IVariable myA = assertionHelper.assertNonProblem("Alias myA;", "myA", IVariable.class); ICPPSpecialization xRef = assertionHelper.assertNonProblem("myA.x = 42;", "x", ICPPSpecialization.class); - + assertInstances(collector, S, 2); assertInstances(collector, Alias, 2); @@ -6273,13 +6305,13 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasBasicType() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); - + ICPPAliasTemplate Alias = assertionHelper.assertNonProblem("using Alias = int;", "Alias", ICPPAliasTemplate.class); ICPPAliasTemplateInstance aliasFloatInstance = assertionHelper.assertNonProblem("Alias myA;", "Alias", ICPPAliasTemplateInstance.class); - + assertInstances(collector, Alias, 2); assertSameType(aliasFloatInstance, new CPPBasicType(IBasicType.Kind.eInt, 0)); } @@ -6296,7 +6328,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6334,9 +6366,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationMultipleParameters() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t1 = assertionHelper.assertNonProblem("T1 t1;", "t1", ICPPField.class); ICPPField t2 = assertionHelper.assertNonProblem("T2 t2;", "t2", ICPPField.class); ICPPField t3 = assertionHelper.assertNonProblem("T3 t3;", "t3", ICPPField.class); @@ -6377,9 +6409,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPAliasTemplateInstance TAliasSInt = assertionHelper.assertNonProblem("TAlias> myA;", "TAlias>", ICPPAliasTemplateInstance.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S()", "t", ICPPSpecialization.class); @@ -6400,9 +6432,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPTemplateInstance STAliasInt = assertionHelper.assertNonProblem("S> myA;", "S>", ICPPTemplateInstance.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S();", "t", ICPPSpecialization.class); @@ -6423,9 +6455,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationValueArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField buff = assertionHelper.assertNonProblem("int buff [Size];", "buff", ICPPField.class); ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class); @@ -6446,9 +6478,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDefaultArguments() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField buff = assertionHelper.assertNonProblem("T buff [Size];", "buff", ICPPField.class); ICPPAliasTemplateInstance myA = assertionHelper.assertNonProblem("TAlias<> myA;", "TAlias<>", ICPPAliasTemplateInstance.class); ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class); @@ -6470,9 +6502,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem(" myA.t = S();", "t", ICPPSpecialization.class); ICPPClassSpecialization Sint = assertionHelper.assertNonProblem("myA.t = S();", "S", ICPPClassSpecialization.class); @@ -6497,9 +6529,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsFunctionParameter() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPFunction bar = assertionHelper.assertNonProblem("void bar(TAlias arg){", "bar", ICPPFunction.class); ICPPFunction barRefAlias = assertionHelper.assertNonProblem("bar(myA);", "bar", ICPPFunction.class); ICPPFunction barRefSInt = assertionHelper.assertNonProblem("bar(myS);", "bar", ICPPFunction.class); @@ -6522,7 +6554,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsFunctionArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPFunction bar = assertionHelper.assertNonProblem("void bar(S arg){", "bar", ICPPFunction.class); @@ -6571,7 +6603,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6596,7 +6628,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasForTemplateReference() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPClassSpecialization SInt = assertionHelper.assertNonProblem("S myS;", "S", ICPPClassSpecialization.class); @@ -6612,7 +6644,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6632,7 +6664,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionReferenceTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6657,7 +6689,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasTemplateParameter() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); @@ -6680,10 +6712,11 @@ public class AST2TemplateTests extends AST2BaseTest { // Alias intAlias; public void testAliasDeclarationContext() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - ICPPAliasTemplateInstance AliasInt = assertionHelper.assertNonProblem("Alias intAlias;", "Alias", ICPPAliasTemplateInstance.class); + ICPPAliasTemplateInstance AliasInt = + assertionHelper.assertNonProblem("Alias intAlias;", "Alias", ICPPAliasTemplateInstance.class); assertEquals("Alias", AliasInt.getName()); assertEquals("NS", AliasInt.getQualifiedName()[0]); assertEquals("Alias", AliasInt.getQualifiedName()[1]); @@ -7004,4 +7037,92 @@ public class AST2TemplateTests extends AST2BaseTest { public void testDependentExpressions_395243d() throws Exception { parseAndCheckBindings(); } + + // template + // struct B { + // enum { value = 1 }; + // }; + // + // template + // struct C { + // enum { id = B::value }; + // }; + // + // void test() { + // int x = C::id; + // } + public void _testDependentEnumValue_389009() throws Exception { + BindingAssertionHelper ah = getAssertionHelper(); + IEnumerator binding = ah.assertNonProblem("C::id", "id"); + IValue value = binding.getValue(); + Long num = value.numericalValue(); + assertNotNull(num); + assertEquals(1, num.longValue()); + } + + // template struct A {}; + // template void foo(A); + // int main() { + // foo(A<0>()); + // } + public void testVariadicNonTypeTemplateParameter_382074() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct ice_or { + // static const bool value = false; + // }; + // template + // struct is_foo { + // static const bool value = false; + // }; + // template + // struct contains_foo { + // static const bool value = ice_or::value...>::value; + // }; + // template + // struct meta; + // struct S { void bar(); }; + // template <> + // struct meta { + // typedef S type; + // }; + // int main() { + // meta::value>::type t; + // t.bar(); + // } + public void testVariadicNonTypeTemplateParameter_399039() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct common_type; + // template + // struct common_type { + // typedef int type; + // }; + // template + // struct common_type { + // typedef int type; + // }; + // typedef common_type::type type; + public void testClassTemplateSpecializationPartialOrdering_398044a() throws Exception { + parseAndCheckBindings(); + } + + // template + // class A; + // template + // class A { + // }; + // template + // class A { + // }; + // int main() { + // A mf; + // } + public void testClassTemplateSpecializationPartialOrdering_398044b() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java similarity index 97% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java index dff0c031a63..54928023f80 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -95,7 +95,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; /** * @author aniefer */ -public class AST2BaseTest extends BaseTestCase { +public class AST2TestBase extends BaseTestCase { public final static String TEST_CODE = ""; protected static final IParserLogService NULL_LOG = new NullLogService(); protected static boolean sValidateCopy; @@ -110,6 +110,7 @@ public class AST2BaseTest extends BaseTestCase { map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); return map; } @@ -118,17 +119,18 @@ public class AST2BaseTest extends BaseTestCase { map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); return map; } - public AST2BaseTest() { + public AST2TestBase() { super(); } - - public AST2BaseTest(String name) { + + public AST2TestBase(String name) { super(name); } - + @Override protected void setUp() throws Exception { sValidateCopy= true; @@ -138,7 +140,7 @@ public class AST2BaseTest extends BaseTestCase { protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException { return parse(code, lang, false, true); } - + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { return parse(code, lang, useGNUExtensions, true); } @@ -147,10 +149,10 @@ public class AST2BaseTest extends BaseTestCase { boolean expectNoProblems) throws ParserException { return parse(code, lang, useGNUExtensions, expectNoProblems, false); } - + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException { - IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, + IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, createScannerInfo(useGNUExtensions)); configureScanner(scanner); AbstractGNUSourceCodeParser parser = null; @@ -170,12 +172,12 @@ public class AST2BaseTest extends BaseTestCase { } else { config = new ANSICParserExtensionConfiguration(); } - + parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null); } if (skipTrivialInitializers) parser.setSkipTrivialExpressionsInAggregateInitializers(true); - + IASTTranslationUnit tu = parser.parse(); assertTrue(tu.isFrozen()); if (sValidateCopy) @@ -183,7 +185,7 @@ public class AST2BaseTest extends BaseTestCase { if (parser.encounteredError() && expectNoProblems) throw new ParserException("FAILURE"); //$NON-NLS-1$ - + if (lang == ParserLanguage.C && expectNoProblems) { assertEquals(CVisitor.getProblems(tu).length, 0); assertEquals(tu.getPreprocessorProblems().length, 0); @@ -193,7 +195,7 @@ public class AST2BaseTest extends BaseTestCase { } if (expectNoProblems) assertEquals(0, tu.getPreprocessorProblems().length); - + return tu; } @@ -215,7 +217,7 @@ public class AST2BaseTest extends BaseTestCase { configuration= GPPScannerExtensionConfiguration.getInstance(scannerInfo); } IScanner scanner; - scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, + scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, IncludeFileContentProvider.getSavedFilesProvider()); return scanner; } @@ -263,7 +265,7 @@ public class AST2BaseTest extends BaseTestCase { } protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException { - IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); assertEquals(e.getOperator(), operand); IASTIdExpression x = (IASTIdExpression) e.getOperand1(); @@ -290,8 +292,8 @@ public class AST2BaseTest extends BaseTestCase { ASTComparer.assertCopy(tu, copy); return (T) copy; } - - + + static protected class CNameCollector extends ASTVisitor { { shouldVisitNames = true; @@ -309,29 +311,35 @@ public class AST2BaseTest extends BaseTestCase { return null; return nameList.get(idx); } - + public int size() { return nameList.size(); - } + } } protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception { int count = 0; - + assertNotNull(binding); - + for (int i = 0; i < collector.size(); i++) { if (collector.getName(i).resolveBinding() == binding) count++; } - + assertEquals(count, num); } static protected class CPPNameCollector extends ASTVisitor { - { - shouldVisitNames = true; + public CPPNameCollector() { + this(false); // don't visit implicit names by default } + + public CPPNameCollector(boolean shouldVisitImplicitNames) { + this.shouldVisitNames = true; + this.shouldVisitImplicitNames = shouldVisitImplicitNames; + } + public List nameList = new ArrayList(); @Override @@ -349,7 +357,7 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); } - + public void dump() { for (int i= 0; i < size(); i++) { IASTName name= getName(i); @@ -365,7 +373,7 @@ public class AST2BaseTest extends BaseTestCase { if (collector.getName(i).resolveBinding() == binding) count++; } - + assertEquals(num, count); } @@ -386,42 +394,42 @@ public class AST2BaseTest extends BaseTestCase { String expressionString = ASTStringUtil.getExpressionString(exp); assertEquals(str, expressionString); } - + protected void isParameterSignatureEqual(IASTDeclarator decltor, String str) { assertTrue(decltor instanceof IASTFunctionDeclarator); final String[] sigArray = ASTStringUtil.getParameterSignatureArray((IASTFunctionDeclarator) decltor); assertEquals(str, "(" + ASTStringUtil.join(sigArray, ", ") + ")"); } - + protected void isSignatureEqual(IASTDeclarator declarator, String expected) { String signature= ASTStringUtil.getSignatureString(declarator); assertEquals(expected, signature); } - + protected void isSignatureEqual(IASTDeclSpecifier declSpec, String str) { assertEquals(str, ASTStringUtil.getSignatureString(declSpec, null)); } - + protected void isSignatureEqual(IASTTypeId typeId, String str) { assertEquals(str, ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator())); } - + protected void isTypeEqual(IASTDeclarator decltor, String str) { assertEquals(str, ASTTypeUtil.getType(decltor)); } - + protected void isTypeEqual(IASTTypeId typeId, String str) { assertEquals(str, ASTTypeUtil.getType(typeId)); } - + protected void isTypeEqual(IType type, String str) { assertEquals(str, ASTTypeUtil.getType(type)); } - + protected void isParameterTypeEqual(IFunctionType fType, String str) { assertEquals(str, ASTTypeUtil.getParameterTypeString(fType)); } - + static protected class CNameResolver extends ASTVisitor { { shouldVisitNames = true; @@ -449,9 +457,9 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); - } + } } - + static protected class CPPNameResolver extends ASTVisitor { { shouldVisitNames = true; @@ -479,13 +487,13 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); - } + } } - + protected String getAboveComment() throws IOException { return getContents(1)[0].toString(); } - + protected CharSequence[] getContents(int sections) throws IOException { CTestPlugin plugin = CTestPlugin.getDefault(); if (plugin == null) @@ -502,14 +510,14 @@ public class AST2BaseTest extends BaseTestCase { } return clazz.cast(o); } - + protected static void assertField(IBinding binding, String fieldName, String ownerName) { assertInstance(binding, IField.class); assertEquals(fieldName, binding.getName()); ICompositeType struct = ((IField) binding).getCompositeTypeOwner(); assertEquals(ownerName, struct.getName()); } - + protected class BindingAssertionHelper { protected IASTTranslationUnit tu; protected String contents; @@ -562,7 +570,7 @@ public class AST2BaseTest extends BaseTestCase { IBinding binding= binding(section, len); if (binding instanceof IProblemBinding) { IProblemBinding problem= (IProblemBinding) binding; - fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); + fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); } if (binding == null) { fail("Null binding resolved for name: " + section.substring(0, len)); @@ -611,12 +619,12 @@ public class AST2BaseTest extends BaseTestCase { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); assertNotNull("did not find \"" + selection + "\"", name); - + assertInstance(name, IASTImplicitName.class); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); IASTImplicitName[] implicits = owner.getImplicitNames(); assertNotNull(implicits); - + if (implicits.length > 1) { boolean found = false; for (IASTImplicitName n : implicits) { @@ -627,34 +635,34 @@ public class AST2BaseTest extends BaseTestCase { } assertTrue(found); } - + assertEquals(selection, name.getRawSignature()); IBinding binding = name.resolveBinding(); assertNotNull(binding); assertInstance(binding, bindingClass); return (IASTImplicitName) name; } - + public void assertNoImplicitName(String section, int len) { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); assertNull("found name \"" + selection + "\"", name); } - + public IASTImplicitName[] getImplicitNames(String section, int len) { IASTName name = findImplicitName(section, len); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); IASTImplicitName[] implicits = owner.getImplicitNames(); return implicits; } - + public IASTName findName(String section, int len) { final int offset = contents.indexOf(section); assertTrue("Section \"" + section + "\" not found", offset >= 0); IASTNodeSelector selector = tu.getNodeSelector(null); return selector.findName(offset, len); } - + public IASTName findName(String context, String name) { if (context == null) { context = contents; @@ -712,7 +720,7 @@ public class AST2BaseTest extends BaseTestCase { } return "Unknown problem ID"; } - + public T assertNonProblem(String section, int len, Class... cs) { if (len <= 0) len += section.length(); @@ -744,10 +752,10 @@ public class AST2BaseTest extends BaseTestCase { final String selection = section.substring(0, len); assertNotNull("No AST name for \"" + selection + "\"", astName); assertEquals(selection, astName.getRawSignature()); - + IBinding binding = astName.resolveBinding(); assertNotNull("No binding for " + astName.getRawSignature(), binding); - + return astName.resolveBinding(); } @@ -755,10 +763,10 @@ public class AST2BaseTest extends BaseTestCase { IASTName astName = findName(context, name); assertNotNull("No AST name for \"" + name + "\"", astName); assertEquals(name, astName.getRawSignature()); - + IBinding binding = astName.resolveBinding(); assertNotNull("No binding for " + astName.getRawSignature(), binding); - + return astName.resolveBinding(); } } @@ -770,10 +778,10 @@ public class AST2BaseTest extends BaseTestCase { final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception { return parseAndCheckBindings(code, lang, useGnuExtensions, false); } - + final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions, boolean skipTrivialInitializers) throws Exception { - IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); + IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 0a8e2de6c42..096032fb9ab 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; +import static org.eclipse.cdt.core.parser.ParserLanguage.C; import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import java.io.IOException; @@ -56,9 +57,11 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; +import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; @@ -127,7 +130,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * Test cases on the AST. */ -public class AST2Tests extends AST2BaseTest { +public class AST2Tests extends AST2TestBase { private static final int NUM_TESTS = 3; public static TestSuite suite() { @@ -144,21 +147,21 @@ public class AST2Tests extends AST2BaseTest { private void parseAndCheckBindings() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception { - return parseAndCheckBindings(code, ParserLanguage.C); + return parseAndCheckBindings(code, C); } public void testBug75189() throws Exception { parseAndCheckBindings("struct A{};\n typedef int (*F) (struct A*);"); //$NON-NLS-1$ - parseAndCheckBindings("struct A{};\n typedef int (*F) (A*);", ParserLanguage.CPP); //$NON-NLS-1$ + parseAndCheckBindings("struct A{};\n typedef int (*F) (A*);", CPP); //$NON-NLS-1$ } public void testBug75340() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", CPP); //$NON-NLS-1$ IASTSimpleDeclaration sd = (IASTSimpleDeclaration) tu.getDeclarations()[0]; isParameterSignatureEqual(sd.getDeclarators()[0], "(int=0, int*=0)"); //$NON-NLS-1$ } @@ -190,7 +193,7 @@ public class AST2Tests extends AST2BaseTest { // int ((*zzz3)) (char); // int (*(zzz4)) (char); public void testBug40768() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -201,7 +204,7 @@ public class AST2Tests extends AST2BaseTest { // int z = x + y; // } public void testBasicFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IScope globalScope = tu.getScope(); @@ -344,7 +347,7 @@ public class AST2Tests extends AST2BaseTest { // myS.x = 5; // } public void testSimpleStruct() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu @@ -530,7 +533,7 @@ public class AST2Tests extends AST2BaseTest { } public void testMultipleDeclarators() throws Exception { - IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int r, s;", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -568,7 +571,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -647,7 +650,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -712,7 +715,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" a->i; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -818,7 +821,7 @@ public class AST2Tests extends AST2BaseTest { // struct x i; // } public void testStructureNamespace() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -906,7 +909,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testFunctionParameters() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.C); + IASTTranslationUnit tu = parse(code, C); assertTrue(tu.isFrozen()); // void f( @@ -947,7 +950,7 @@ public class AST2Tests extends AST2BaseTest { assertSame(param_2, param_3); assertSame(f_1, f_2); - tu = parse(code, ParserLanguage.C); + tu = parse(code, C); assertTrue(tu.isFrozen()); // void f( f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1011,7 +1014,7 @@ public class AST2Tests extends AST2BaseTest { // void f(int a, int b) { } public void testSimpleFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -1061,7 +1064,7 @@ public class AST2Tests extends AST2BaseTest { // } // void f() { } public void testSimpleFunctionCall() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -1130,7 +1133,7 @@ public class AST2Tests extends AST2BaseTest { // } // } public void testForLoop() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // void f() { @@ -1204,7 +1207,7 @@ public class AST2Tests extends AST2BaseTest { // ((struct A *) 1)->x; // } public void testExpressionFieldReference() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1259,7 +1262,7 @@ public class AST2Tests extends AST2BaseTest { // end: ; // } public void testLabels() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -1294,7 +1297,7 @@ public class AST2Tests extends AST2BaseTest { // typedef struct { } X; // int f(X x); public void testAnonStruct() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // test tu.getDeclarationsInAST(IBinding) @@ -1329,7 +1332,7 @@ public class AST2Tests extends AST2BaseTest { } public void testLongLong() throws ParserException { - IASTTranslationUnit tu = parse("long long x;\n", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("long long x;\n", C); //$NON-NLS-1$ // test tu.getDeclarationsInAST(IBinding) IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu @@ -1350,7 +1353,7 @@ public class AST2Tests extends AST2BaseTest { // return; // } public void testEnumerations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1489,7 +1492,7 @@ public class AST2Tests extends AST2BaseTest { } public void testPointerToFunction() throws Exception { - IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int (*pfi)();", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { assertEquals(tu.getDeclarations().length, 1); @@ -1520,7 +1523,7 @@ public class AST2Tests extends AST2BaseTest { // const char ** e; // const char * const * const volatile ** const * f; public void testBasicTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu @@ -1623,7 +1626,7 @@ public class AST2Tests extends AST2BaseTest { // unsigned int unsignedInt = 99; // noSpec= 12; public void testBug270275_int_is_equivalent_to_signed_int() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); IType plainInt = ((IVariable)((IASTSimpleDeclaration) declarations[0]).getDeclarators()[0].getName().resolveBinding()).getType(); IType signedInt = ((IVariable)((IASTSimpleDeclaration) declarations[1]).getDeclarators()[0].getName().resolveBinding()).getType(); @@ -1640,7 +1643,7 @@ public class AST2Tests extends AST2BaseTest { // struct A * const a2; // AP a3; public void testCompositeTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1717,7 +1720,7 @@ public class AST2Tests extends AST2BaseTest { // const char * const c[][][]; // char* d[const][]; public void testArrayTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1798,7 +1801,7 @@ public class AST2Tests extends AST2BaseTest { // void (*g) (struct A *); // void (* (*h)(struct A**)) (int d); public void testFunctionTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1935,7 +1938,7 @@ public class AST2Tests extends AST2BaseTest { // Point point = {.width = 100, .pos = &xy}; // } public void testDesignatedInitializers() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { assertNotNull(tu); @@ -2041,7 +2044,7 @@ public class AST2Tests extends AST2BaseTest { // struct S s = {.a=1,.b=2}; // } public void testMoregetDeclarationsInAST1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2081,7 +2084,7 @@ public class AST2Tests extends AST2BaseTest { // int b; // } s = {.a=1,.b=2}; public void testMoregetDeclarationsInAST2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2122,7 +2125,7 @@ public class AST2Tests extends AST2BaseTest { // typedef t y; // y x = {.a=1,.b=2}; public void testMoregetDeclarationsInAST3() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2158,7 +2161,7 @@ public class AST2Tests extends AST2BaseTest { public void testFnReturningPtrToFn() throws Exception { IASTTranslationUnit tu = parse( - "void (* f(int))() {}", ParserLanguage.C); //$NON-NLS-1$ + "void (* f(int))() {}", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -2186,7 +2189,7 @@ public class AST2Tests extends AST2BaseTest { // array type derivation. public void testArrayTypeToQualifiedPointerTypeParm() throws Exception { IASTTranslationUnit tu = parse( - "void f(int parm[const 3]);", ParserLanguage.C); //$NON-NLS-1$ + "void f(int parm[const 3]);", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration def = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2225,7 +2228,7 @@ public class AST2Tests extends AST2BaseTest { // int *f2() {} // int (* f3())() {} public void testFunctionDefTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2268,7 +2271,7 @@ public class AST2Tests extends AST2BaseTest { // any parameter to type function returning T is adjusted to be pointer to // function returning T public void testParmToFunction() throws Exception { - IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", ParserLanguage.C); + IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -2304,7 +2307,7 @@ public class AST2Tests extends AST2BaseTest { } public void testArrayPointerFunction() throws Exception { - IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", ParserLanguage.C); + IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2349,7 +2352,7 @@ public class AST2Tests extends AST2BaseTest { // typedef DWORD v; // v signal(int); public void testTypedefExample4a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2404,7 +2407,7 @@ public class AST2Tests extends AST2BaseTest { // typedef DWORD (*pfv)(int); // pfv signal(int, pfv); public void testTypedefExample4b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2486,7 +2489,7 @@ public class AST2Tests extends AST2BaseTest { // fv *signal2(int, fv *); // pfv signal3(int, pfv); public void testTypedefExample4c() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2575,7 +2578,7 @@ public class AST2Tests extends AST2BaseTest { // int y [ const static x ]; public void testBug80992() throws Exception { ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator) ((IASTSimpleDeclaration) parse( - getAboveComment(), ParserLanguage.C).getDeclarations()[1]) + getAboveComment(), C).getDeclarations()[1]) .getDeclarators()[0]).getArrayModifiers()[0]; assertTrue(mod.isConst()); assertTrue(mod.isStatic()); @@ -2588,7 +2591,7 @@ public class AST2Tests extends AST2BaseTest { // int y (int [ const *]); public void testBug80978() throws Exception { ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator) ((IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) parse( - getAboveComment(), ParserLanguage.C).getDeclarations()[0]) + getAboveComment(), C).getDeclarations()[0]) .getDeclarators()[0]).getParameters()[0].getDeclarator()) .getArrayModifiers()[0]; assertTrue(mod.isConst()); @@ -2598,13 +2601,13 @@ public class AST2Tests extends AST2BaseTest { assertFalse(mod.isVolatile()); } - //AJN: bug 77383 don't do external variables + //AJN: bug 77383 don't do external variables // // void f() { // // if (a == 0) // // a = a + 3; // // } // public void testExternalVariable() throws Exception { - // IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + // IASTTranslationUnit tu = parse(getAboveComment(), C); // CNameCollector col = new CNameCollector(); // tu.accept(col); // @@ -2624,7 +2627,7 @@ public class AST2Tests extends AST2BaseTest { // g(*(&a + 2)); // } public void testExternalDefs() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2649,7 +2652,7 @@ public class AST2Tests extends AST2BaseTest { // Coord xy = { .x = 10, .y = 11 }; // } public void testFieldDesignators() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2674,7 +2677,7 @@ public class AST2Tests extends AST2BaseTest { // [member_two] = "two" // }; public void testArrayDesignator() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2700,7 +2703,7 @@ public class AST2Tests extends AST2BaseTest { // g(*(&a + 2)); // } public void testBug83737() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTIfStatement if_statement = (IASTIfStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu @@ -2730,7 +2733,7 @@ public class AST2Tests extends AST2BaseTest { // end: ; // } public void testBug84090_LabelReferences() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2750,7 +2753,7 @@ public class AST2Tests extends AST2BaseTest { // enum col { red, blue }; // enum col c; public void testBug84092_EnumReferences() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -2769,7 +2772,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84096_FieldDesignatorRef() throws Exception { IASTTranslationUnit tu = parse( - "struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$ + "struct s { int a; } ss = { .a = 1 }; \n", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -2789,7 +2792,7 @@ public class AST2Tests extends AST2BaseTest { public void testProblems() throws Exception { IASTTranslationUnit tu = parse( - " a += ;", ParserLanguage.C, true, false); //$NON-NLS-1$ + " a += ;", C, true, false); //$NON-NLS-1$ IASTProblem[] ps = CVisitor.getProblems(tu); assertEquals(ps.length, 1); ps[0].getMessage(); @@ -2798,7 +2801,7 @@ public class AST2Tests extends AST2BaseTest { // enum e; // enum e{ one }; public void testEnumerationForwards() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2821,7 +2824,7 @@ public class AST2Tests extends AST2BaseTest { // (&p)[0] = 1; // } public void testBug84185() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2840,7 +2843,7 @@ public class AST2Tests extends AST2BaseTest { // (&p)[0] = 1; // } public void testBug84185_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2862,14 +2865,14 @@ public class AST2Tests extends AST2BaseTest { // p = &((struct s) { j++ }); // } public void testBug84176() throws Exception { - parse(getAboveComment(), ParserLanguage.C, false, true); + parse(getAboveComment(), C, false, true); } // struct s { double i; } f(void); // struct s f(void) {} public void testBug84266() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.C); + IASTTranslationUnit tu = parse(code, C); CNameCollector col = new CNameCollector(); tu.accept(col); assertEquals(col.size(), 7); @@ -2878,7 +2881,7 @@ public class AST2Tests extends AST2BaseTest { ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding(); assertSame(s_ref, s_decl); - tu = parse(code, ParserLanguage.C); + tu = parse(code, C); col = new CNameCollector(); tu.accept(col); assertEquals(col.size(), 7); @@ -2889,7 +2892,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug84266_2() throws Exception { - IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("struct s f(void);", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2898,7 +2901,7 @@ public class AST2Tests extends AST2BaseTest { ICompositeType s = (ICompositeType) col.getName(0).resolveBinding(); assertNotNull(s); - tu = parse("struct s f(void) {}", ParserLanguage.C); //$NON-NLS-1$ + tu = parse("struct s f(void) {}", C); //$NON-NLS-1$ col = new CNameCollector(); tu.accept(col); @@ -2910,7 +2913,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84250() throws Exception { assertTrue(((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( - "void f() { int (*p) [2]; }", ParserLanguage.C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$ + "void f() { int (*p) [2]; }", C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$ } // struct s1 { struct s2 *s2p; /* ... */ }; // D1 @@ -2945,7 +2948,7 @@ public class AST2Tests extends AST2BaseTest { // funcp()->a; // } public void testBug84267() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2972,7 +2975,7 @@ public class AST2Tests extends AST2BaseTest { // { int x = x; } // } public void testBug84228() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2998,7 +3001,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84236() throws Exception { String code = "double maximum(double a[ ][*]);"; //$NON-NLS-1$ IASTSimpleDeclaration d = (IASTSimpleDeclaration) parse(code, - ParserLanguage.C).getDeclarations()[0]; + C).getDeclarations()[0]; IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) d .getDeclarators()[0]; IASTParameterDeclaration p = fd.getParameters()[0]; @@ -3013,7 +3016,7 @@ public class AST2Tests extends AST2BaseTest { // B * bp; //1 // } public void testBug85049() throws Exception { - IASTTranslationUnit t = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit t = parse(getAboveComment(), C); IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1]; IASTCompoundStatement body = (IASTCompoundStatement) g.getBody(); final IASTStatement statement = body.getStatements()[0]; @@ -3026,7 +3029,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug86766() throws Exception { IASTTranslationUnit tu = parse( - "char foo; void foo() {}", ParserLanguage.C); //$NON-NLS-1$ + "char foo; void foo() {}", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3039,7 +3042,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug88338_C() throws Exception { IASTTranslationUnit tu = parse( - "struct A; struct A* a;", ParserLanguage.C); //$NON-NLS-1$ + "struct A; struct A* a;", C); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3048,7 +3051,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(col.getName(1).isReference()); assertFalse(col.getName(1).isDeclaration()); - tu = parse("struct A* a; struct A;", ParserLanguage.C); //$NON-NLS-1$ + tu = parse("struct A* a; struct A;", C); //$NON-NLS-1$ col = new CPPNameCollector(); tu.accept(col); @@ -3062,7 +3065,7 @@ public class AST2Tests extends AST2BaseTest { } public void test88460() throws Exception { - IASTTranslationUnit tu = parse("void f();", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("void f();", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3072,7 +3075,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug90253() throws Exception { IASTTranslationUnit tu = parse( - "void f(int par) { int v1; };", ParserLanguage.C); //$NON-NLS-1$ + "void f(int par) { int v1; };", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3101,7 +3104,7 @@ public class AST2Tests extends AST2BaseTest { // } // } public void testFind() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3125,14 +3128,14 @@ public class AST2Tests extends AST2BaseTest { public void test92791() throws Exception { IASTTranslationUnit tu = parse( - "void f() { int x, y; x * y; }", ParserLanguage.C); //$NON-NLS-1$ + "void f() { int x, y; x * y; }", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); for (int i = 0; i < col.size(); ++i) assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding); tu = parse( - "int y; void f() { typedef int x; x * y; }", ParserLanguage.C); //$NON-NLS-1$ + "int y; void f() { typedef int x; x * y; }", C); //$NON-NLS-1$ col = new CNameCollector(); tu.accept(col); for (int i = 0; i < col.size(); ++i) @@ -3141,7 +3144,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug85786() throws Exception { IASTTranslationUnit tu = parse( - "void f(int); void foo () { void * p = &f; ((void (*) (int)) p) (1); }", ParserLanguage.C); //$NON-NLS-1$ + "void f(int); void foo () { void * p = &f; ((void (*) (int)) p) (1); }", C); //$NON-NLS-1$ CNameCollector nameResolver = new CNameCollector(); tu.accept(nameResolver); assertNoProblemBindings(nameResolver); @@ -3153,7 +3156,7 @@ public class AST2Tests extends AST2BaseTest { // i= (i)&0x00ff; // } public void testBug95720() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector nameResolver = new CNameCollector(); tu.accept(nameResolver); assertNoProblemBindings(nameResolver); @@ -3168,7 +3171,7 @@ public class AST2Tests extends AST2BaseTest { // return 0; // } public void testBug94365() throws Exception { - parse(getAboveComment(), ParserLanguage.C); + parse(getAboveComment(), C); } // #define MACRO(a) @@ -3176,7 +3179,7 @@ public class AST2Tests extends AST2BaseTest { // MACRO('"'); // } public void testBug95119_a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); assertEquals(declarations.length, 1); assertNotNull(declarations[0]); @@ -3192,7 +3195,7 @@ public class AST2Tests extends AST2BaseTest { // MACRO('X'); // } public void testBug95119_b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); assertEquals(declarations.length, 1); assertNotNull(declarations[0]); @@ -3207,13 +3210,13 @@ public class AST2Tests extends AST2BaseTest { // typedef _TYPE TYPE; // int function(TYPE (* pfv)(int parm)); public void testBug81739() throws Exception { - parse(getAboveComment(), ParserLanguage.C); + parse(getAboveComment(), C); } // float _Complex x; // double _Complex y; public void testBug95757() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true, true); IASTDeclaration[] decls = tu.getDeclarations(); assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[0]).getDeclSpecifier()).isComplex()); @@ -3226,7 +3229,7 @@ public class AST2Tests extends AST2BaseTest { // typeof({ int x = foo(); // x; }) zoot; public void testBug93980() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3240,14 +3243,14 @@ public class AST2Tests extends AST2BaseTest { } public void testBug95866() throws Exception { - IASTTranslationUnit tu = parse("int test[10] = { [0 ... 9] = 2 };", ParserLanguage.C, true, true); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int test[10] = { [0 ... 9] = 2 };", C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); } public void testBug98502() throws Exception { - IASTTranslationUnit tu = parse("typedef enum { ONE } e;", ParserLanguage.C, true, true); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("typedef enum { ONE } e;", C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3263,7 +3266,7 @@ public class AST2Tests extends AST2BaseTest { // PIPERR; // } public void testBug98365() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3272,7 +3275,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug99262() throws Exception { - parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true); //$NON-NLS-1$ + parse("void foo() {void *f; f=__null;}", C, true, true); //$NON-NLS-1$ } // void f1(int*) { @@ -3280,7 +3283,7 @@ public class AST2Tests extends AST2BaseTest { // void f2() { // f1(__null); // } - public void testBug240567() throws Exception { + public void testBug240567() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), false); bh.assertNonProblem("f1(__null", 2, IFunction.class); } @@ -3290,7 +3293,7 @@ public class AST2Tests extends AST2BaseTest { // { a; int a; } // } public void testBug98960() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3303,7 +3306,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug100408() throws Exception { - IASTTranslationUnit tu = parse("int foo() { int x=1; (x)*3; }", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int foo() { int x=1; (x)*3; }", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -3319,7 +3322,7 @@ public class AST2Tests extends AST2BaseTest { // { // } public void testBug98760() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3396,7 +3399,7 @@ public class AST2Tests extends AST2BaseTest { // blah: x; // } public void testBug104390_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3429,9 +3432,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\r\n"); //$NON-NLS-1$ buffer.append("return 0;\r\n"); //$NON-NLS-1$ buffer.append("}\r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); buffer = new StringBuffer(); @@ -3443,9 +3446,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\n"); //$NON-NLS-1$ buffer.append("return 0;\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - tu= parse(buffer.toString(), ParserLanguage.C); + tu= parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu= parse(buffer.toString(), ParserLanguage.CPP); + tu= parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } @@ -3459,10 +3462,10 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\r\n"); //$NON-NLS-1$ buffer.append("return 0;\r\n"); //$NON-NLS-1$ buffer.append("}\r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu= parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu= parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); buffer = new StringBuffer(); @@ -3474,9 +3477,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\n"); //$NON-NLS-1$ buffer.append("return 0;\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - tu = parse(buffer.toString(), ParserLanguage.C); + tu = parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } @@ -3522,7 +3525,7 @@ public class AST2Tests extends AST2BaseTest { // return newWindow; // } public void testBug143502() throws Exception { - parse(getAboveComment(), ParserLanguage.C, true, false); + parse(getAboveComment(), C, true, false); } // void func(int a) { @@ -3537,13 +3540,13 @@ public class AST2Tests extends AST2BaseTest { // } public void testBracketAroundIdentifier_168924() throws IOException, ParserException { String content= getAboveComment(); - IASTTranslationUnit tu= parse(content, ParserLanguage.C, true, true); + IASTTranslationUnit tu= parse(content, C, true, true); IASTFunctionDefinition func= (IASTFunctionDefinition) tu.getDeclarations()[0]; IASTParameterDeclaration[] params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); IBinding binding= params[0].getDeclarator().getName().resolveBinding(); assertEquals(7, tu.getReferences(binding).length); - tu= parse(content, ParserLanguage.CPP, true, true); + tu= parse(content, CPP, true, true); func= (IASTFunctionDefinition) tu.getDeclarations()[0]; params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); binding= params[0].getDeclarator().getName().resolveBinding(); @@ -3555,7 +3558,7 @@ public class AST2Tests extends AST2BaseTest { // MAC("); // } public void testBug179383() throws ParserException, IOException { - parse(getAboveComment(), ParserLanguage.C, false, false); + parse(getAboveComment(), C, false, false); } /** @@ -3572,7 +3575,7 @@ public class AST2Tests extends AST2BaseTest { " return func(LIT); // fails to parse\r\n" + "}\r\n"; - IASTTranslationUnit tu = parse(simple, ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(simple, CPP, true, true); // actual reduced test case, plus extra cases String text = @@ -3594,7 +3597,7 @@ public class AST2Tests extends AST2BaseTest { ; // essential test: this code should be parseable - tu = parse(text, ParserLanguage.CPP, true, true); + tu = parse(text, CPP, true, true); // verify macros IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); @@ -3692,11 +3695,11 @@ public class AST2Tests extends AST2BaseTest { // this should work String textNoComment = noCommentMacro + textTail; - IASTTranslationUnit tu = parse(textNoComment, ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(textNoComment, CPP, true, true); // this fails String textComment = commentMacro + textTail; - tu = parse(textComment, ParserLanguage.CPP, true, true); + tu = parse(textComment, CPP, true, true); } @@ -3716,7 +3719,7 @@ public class AST2Tests extends AST2BaseTest { " } \n" + "}\n"; - parseAndCheckBindings(code, ParserLanguage.C); + parseAndCheckBindings(code, C); } // template @@ -3744,7 +3747,7 @@ public class AST2Tests extends AST2BaseTest { // } // }; public void test186736() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3796,7 +3799,7 @@ public class AST2Tests extends AST2BaseTest { // } // }; public void test186736_variant1() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3834,7 +3837,7 @@ public class AST2Tests extends AST2BaseTest { // (&a)->foo(); // } public void test186736_variant2() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); validateCopy(tu); } @@ -3843,8 +3846,8 @@ public class AST2Tests extends AST2BaseTest { // return *p; // } public void test167833() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); - parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + parseAndCheckBindings(getAboveComment(), CPP); + parseAndCheckBindings(getAboveComment(), C); } // // this is a \ @@ -3885,7 +3888,7 @@ public class AST2Tests extends AST2BaseTest { final IBinding typedef = col.getName(12).resolveBinding(); final IBinding secondJ = col.getName(13).resolveBinding(); assertInstance(typedef, ITypedef.class); - if (lang == ParserLanguage.CPP) { + if (lang == CPP) { assertInstance(secondJ, IProblemBinding.class); } else { // for plain C this is actually not a problem, the second J has to be interpreted as a (useless) @@ -3901,8 +3904,8 @@ public class AST2Tests extends AST2BaseTest { // INVALID(1, 2) // public void test192639() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, false, false); - parse(getAboveComment(), ParserLanguage.C, false, false); + parse(getAboveComment(), CPP, false, false); + parse(getAboveComment(), C, false, false); } public void test195943() throws Exception { @@ -3914,19 +3917,19 @@ public class AST2Tests extends AST2BaseTest { } buffer.append("int a= M" + (depth-1) + ";\n"); long time= System.currentTimeMillis(); - parse(buffer.toString(), ParserLanguage.CPP); - parse(buffer.toString(), ParserLanguage.C); + parse(buffer.toString(), CPP); + parse(buffer.toString(), C); assertTrue(System.currentTimeMillis()-time < 2000); } // int array[12]= {}; public void testBug196468_emptyArrayInitializer() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP, false); - parse(content, ParserLanguage.CPP, true); - parse(content, ParserLanguage.C, true); + parse(content, CPP, false); + parse(content, CPP, true); + parse(content, C, true); try { - parse(content, ParserLanguage.C, false); + parse(content, C, false); fail("C89 does not allow empty braces in array initializer"); } catch (ParserException e) { @@ -3945,16 +3948,16 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug197633_parenthesisInVarargMacros() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP); - parse(content, ParserLanguage.C); + parse(content, CPP); + parse(content, C); } // void (__attribute__((__stdcall__))* foo1) (int); // void (* __attribute__((__stdcall__)) foo2) (int); // void (* __attribute__((__stdcall__))* foo3) (int); public void testBug191450_attributesInBetweenPointers() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, true, true); - parse(getAboveComment(), ParserLanguage.C, true, true); + parse(getAboveComment(), CPP, true, true); + parse(getAboveComment(), C, true, true); } // class NameClash {}; @@ -3962,7 +3965,7 @@ public class AST2Tests extends AST2BaseTest { // namespace NameClash2 {}; // class NameClash2 {}; public void testBug202271_nameClash() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP, true); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3982,7 +3985,7 @@ public class AST2Tests extends AST2BaseTest { // int b= WRAP(MACRO); public void testBug94673_refsForMacrosAsArguments() throws Exception { String content= getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(content, ParserLanguage.CPP, true); + IASTTranslationUnit tu= parseAndCheckBindings(content, CPP, true); IASTPreprocessorMacroDefinition[] defs= tu.getMacroDefinitions(); assertEquals(2, defs.length); IASTPreprocessorMacroDefinition md= defs[1]; @@ -4041,10 +4044,10 @@ public class AST2Tests extends AST2BaseTest { CharSequence[] buffer = getContents(2); final String content1 = buffer[0].toString(); final String content2 = buffer[1].toString(); - parse(content1, ParserLanguage.CPP); - parse(content1, ParserLanguage.C); - parse(content2, ParserLanguage.CPP); - parse(content2, ParserLanguage.C); + parse(content1, CPP); + parse(content1, C); + parse(content2, CPP); + parse(content2, C); } @@ -4065,14 +4068,14 @@ public class AST2Tests extends AST2BaseTest { // // int foo() { // Point p1 = {.x = 1, .y = 2}; - // + // // Line l1 = {.p1 = {.x = 1, .y = 2}, {.x = 1, .y = 2}, {.tag = 5}}; // Line l2 = {.t.tag = 9, .p1.x = 1, .p2.x = 3, .p1.y = 4, .p2.y = 9}; // // Point points[] = {{.x=1, .y=1}, {.x=2, .y=2}}; // } public void _testBug210019_nestedDesignatedInitializers() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -4150,7 +4153,7 @@ public class AST2Tests extends AST2BaseTest { // 3, 4 // }; public void testBug210019_designatedInitializers() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -4189,7 +4192,7 @@ public class AST2Tests extends AST2BaseTest { // externFunc(); // } public void testBug183126_nestedLinkageSpecs() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // int* i= 0; @@ -4203,7 +4206,7 @@ public class AST2Tests extends AST2BaseTest { // f3(&i); // ok // } public void testBug213029_cvConversion() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, false); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, false); CNameCollector col = new CNameCollector(); tu.accept(col); for (Object o : col.nameList) { @@ -4694,8 +4697,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testOmittedPositiveExpression_212905() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // #define __inline__ __inline__ __attribute__((always_inline)) @@ -4705,16 +4708,16 @@ public class AST2Tests extends AST2BaseTest { // } public void testRedefinedGCCKeywords_226112() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // int foo asm ("myfoo") __attribute__((__used__)), ff asm("ss") = 2; // extern void func () asm ("FUNC") __attribute__((__used__)); public void testASMLabels_226121() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -4722,8 +4725,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testCompoundStatementExpression_226274() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4732,8 +4735,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofUnaryExpression_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4741,8 +4744,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofExpression_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void func() { @@ -4750,8 +4753,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofExpressionWithAttribute_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4762,7 +4765,7 @@ public class AST2Tests extends AST2BaseTest { public void testCaseRange_211882() throws Exception { final String code = getAboveComment(); { - IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.C, true); + IASTTranslationUnit tu = parseAndCheckBindings(code, C, true); IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; @@ -4772,7 +4775,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression); } { - IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parseAndCheckBindings(code, CPP, true); IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; @@ -4788,8 +4791,8 @@ public class AST2Tests extends AST2BaseTest { // int x(int(TIntPtr)); public void testInfiniteRecursion_269052() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // template class X { @@ -4799,29 +4802,29 @@ public class AST2Tests extends AST2BaseTest { // }; public void testTypenameInExpression() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } // struct __attribute__((declspec)) bla; public void testAttributeInElaboratedTypeSpecifier_227085() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // struct X; // void test(struct X* __restrict result); public void testRestrictReference_227110() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, CPP, true); } // char buf[256]; // int x= sizeof(buf)[0]; public void testSizeofUnaryWithParenthesis_227122() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // class X { @@ -4835,7 +4838,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testPlacementNewInConditionalExpression_227104() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } // int f(x) { @@ -4843,7 +4846,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug228422_noKnrParam() throws Exception { CharSequence buffer = getContents(1)[0]; - parse(buffer.toString(), ParserLanguage.C, false); + parse(buffer.toString(), C, false); } // struct { @@ -4896,8 +4899,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeOfPointerOperations() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // int globalArray[4] = {1,2,3,4}; @@ -4960,8 +4963,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testReturnTypeOfBuiltin_234309() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // typedef void VOID; @@ -5490,7 +5493,7 @@ public class AST2Tests extends AST2BaseTest { // spinlock_t _lock = (spinlock_t) { }; public void testCompoundInitializer_145387() throws Exception { // valid in C99, not in C++. - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + parseAndCheckBindings(getAboveComment(), C, true); } // enum __declspec(uuid("uuid")) bla { a, b}; @@ -5534,8 +5537,8 @@ public class AST2Tests extends AST2BaseTest { // alloc(__func__); // } public void testPredefinedFunctionName_247747() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, false); + parseAndCheckBindings(getAboveComment(), C, false); + parseAndCheckBindings(getAboveComment(), CPP, false); } // void alloc(const char * id) {} @@ -5545,16 +5548,16 @@ public class AST2Tests extends AST2BaseTest { // alloc(__PRETTY_FUNCTION__); // } public void testPredefinedFunctionNameGcc_247747() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + parseAndCheckBindings(getAboveComment(), C, true); + parseAndCheckBindings(getAboveComment(), CPP, true); } // int foo = 42; // typedef char StupidType; // StupidType const *bar = (StupidType const*)&foo; public void testUnusualDeclSpecOrdering_251514() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + parseAndCheckBindings(getAboveComment(), C, true); + parseAndCheckBindings(getAboveComment(), CPP, true); } // #define IF if @@ -5872,7 +5875,7 @@ public class AST2Tests extends AST2BaseTest { // {1,2,3}, // 1.2, // { - + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // } @@ -5978,8 +5981,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testNestedDeclarator_257540() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // typedef struct { @@ -5992,8 +5995,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testCompoundLiterals_258496() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // __thread int i; @@ -6001,8 +6004,8 @@ public class AST2Tests extends AST2BaseTest { // extern __thread int k; public void testThreadLocalVariables_260387() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -6027,7 +6030,7 @@ public class AST2Tests extends AST2BaseTest { // }; public void testAmbiguousDeclaration_259373() throws Exception { final String code= getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.C, true); + IASTTranslationUnit tu= parseAndCheckBindings(code, C, true); BindingAssertionHelper bh= new BindingAssertionHelper(code, false); ITypedef td= bh.assertNonProblem("TInt; //", 4); IField f= bh.assertNonProblem("a;", 1); @@ -6062,7 +6065,7 @@ public class AST2Tests extends AST2BaseTest { for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true); - BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP); + BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == CPP); ITypedef t= ba.assertNonProblem("A;", 1); ICompositeType s1= ba.assertNonProblem("A; // struct", 1); ICompositeType s2= ba.assertNonProblem("A*", 1); @@ -6072,7 +6075,7 @@ public class AST2Tests extends AST2BaseTest { } // typedef long unsigned int size_t; - // + // // size_t a = 0; // size_t x = a + 5; // size_t y = 2 + a; @@ -6095,7 +6098,7 @@ public class AST2Tests extends AST2BaseTest { // typedef void* VoidPtr; // typedef VoidPtr (*Func)(); - // + // // void test(Func f) { // f(); // } @@ -6127,7 +6130,7 @@ public class AST2Tests extends AST2BaseTest { public void testSizeofFunctionType_252243() throws Exception { final String code= getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { - BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP); + BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == CPP); ba.assertProblem("y));", 1); IVariable v= ba.assertNonProblem("y);", 1); } @@ -6341,7 +6344,7 @@ public class AST2Tests extends AST2BaseTest { // __TIME__; // } public void testPredefinedMacroNamesC() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + parseAndCheckBindings(getAboveComment(), C); } // long double longDouble = 1.0; @@ -6872,7 +6875,7 @@ public class AST2Tests extends AST2BaseTest { // int MyGlobal[10]; // public void testBug273797() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); IASTName n = ((IASTSimpleDeclaration) tu.getDeclarations()[0]).getDeclarators()[0].getName(); IVariable v = (IVariable) n.resolveBinding(); @@ -6894,7 +6897,7 @@ public class AST2Tests extends AST2BaseTest { // (int) value1; // } public void testBug278797() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); IASTFunctionDefinition func = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTExpressionStatement stmt = ((IASTExpressionStatement)((IASTCompoundStatement) func.getBody()).getStatements()[0]); IType t = ((IASTCastExpression) stmt.getExpression()).getOperand().getExpressionType(); @@ -6994,7 +6997,7 @@ public class AST2Tests extends AST2BaseTest { // structure.ptr = goo; // } public void testBindingsOnFields() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, false); + IASTTranslationUnit tu = parse(getAboveComment(), C, false); IASTCompoundStatement bodyStmt = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[2]).getBody(); // Get the IFields bindings from the type used in the declaration of structure @@ -7006,7 +7009,7 @@ public class AST2Tests extends AST2BaseTest { // Get the IField for the first assignment IASTFieldReference ref1 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[1]).getExpression()).getOperand1(); IBinding field1 = ref1.getFieldName().resolveBinding(); - + // Get the IField for the second assignment IASTFieldReference ref2 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[2]).getExpression()).getOperand1(); IBinding field2 = ref2.getFieldName().resolveBinding(); @@ -7014,7 +7017,7 @@ public class AST2Tests extends AST2BaseTest { // Compare the IField from the type and the assignments assertEquals(fields[0], field1); assertEquals(fields[1], field2); // fails - + assertEquals(1, ((ICInternalBinding) field1).getDeclarations().length); assertEquals(1, ((ICInternalBinding) field2).getDeclarations().length); } @@ -7092,8 +7095,8 @@ public class AST2Tests extends AST2BaseTest { // int a[1]; public void testIncompleteArrays_269926() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // void f1(const int* p); @@ -7146,7 +7149,7 @@ public class AST2Tests extends AST2BaseTest { // static a[2]= {0,0}; public void testSkipAggregateInitializer_297550() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, false, true); + parseAndCheckBindings(code, C, false, true); } // typeof(b(1)) b(int); @@ -7187,8 +7190,8 @@ public class AST2Tests extends AST2BaseTest { // void f () __attribute__ ((int)); public void testAttributeSyntax_298841() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void func(int* obj) { @@ -7211,7 +7214,7 @@ public class AST2Tests extends AST2BaseTest { // ONCE() public void testPragmaOperator_294730() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.C); + IASTTranslationUnit tu= parseAndCheckBindings(code, C); IASTPreprocessorStatement[] stmts = tu.getAllPreprocessorStatements(); assertEquals(5, stmts.length); for (int i = 2; i < stmts.length; i++) { @@ -7219,7 +7222,7 @@ public class AST2Tests extends AST2BaseTest { assertInstance(stmt, IASTPreprocessorPragmaStatement.class); assertEquals(i>2, ((IASTPreprocessorPragmaStatement) stmt).isPragmaOperator()); } - tu= parseAndCheckBindings(code, ParserLanguage.CPP); + tu= parseAndCheckBindings(code, CPP); assertEquals(5, stmts.length); for (int i = 2; i < stmts.length; i++) { IASTPreprocessorStatement stmt = stmts[i]; @@ -7234,8 +7237,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testFunctionNameExpression() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // #define MACRO @@ -7264,8 +7267,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testVaArgWithFunctionPtr_311030() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -7308,7 +7311,7 @@ public class AST2Tests extends AST2BaseTest { public void testPtrDiffRecursion_317004() throws Exception { final String comment = getAboveComment(); String code= comment; - parseAndCheckBindings(code, ParserLanguage.C, true); + parseAndCheckBindings(code, C, true); BindingAssertionHelper bh= new BindingAssertionHelper(code, false); ITypedef td= bh.assertNonProblem("ptrdiff_t", 0); assertEquals("int", ASTTypeUtil.getType(td.getType())); @@ -7316,7 +7319,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType())); code= "namespace std {" + comment + "}"; - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, CPP, true); bh= new BindingAssertionHelper(code, true); td= bh.assertNonProblem("ptrdiff_t", 0); assertEquals("int", ASTTypeUtil.getType(td.getType())); @@ -7365,14 +7368,14 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeOfSizeof_355052() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(code, CPP); IASTFunctionDefinition a= getDeclaration(tu, 0); IASTExpressionStatement es= getStatement(a, 1); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); es= getStatement(a, 2); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); - tu= parseAndCheckBindings(code, ParserLanguage.C); + tu= parseAndCheckBindings(code, C); a= getDeclaration(tu, 0); es= getStatement(a, 1); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); @@ -7420,9 +7423,34 @@ public class AST2Tests extends AST2BaseTest { public void testGCCDecltype_397227() throws Exception { parseAndCheckBindings(getAboveComment(), CPP, true); } - + // #define macro(R) #R"" public void testNoRawStringInPlainC_397127() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + parseAndCheckBindings(getAboveComment(), C, true); + } + + // #define X + // int a=X-1;X + public void testMacroReferences_399394() throws Exception { + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment()); + assertEquals(2, countMacroRefs(tu)); + + IASTSimpleDeclaration decl= getDeclaration(tu, 0); + assertEquals(1, countMacroRefs(decl)); + + IASTEqualsInitializer init= (IASTEqualsInitializer) decl.getDeclarators()[0].getInitializer(); + assertEquals(1, countMacroRefs(init)); + + IASTUnaryExpression expr= (IASTUnaryExpression) init.getInitializerClause(); + assertEquals(0, countMacroRefs(expr)); + } + + private int countMacroRefs(IASTNode node) { + int count = 0; + for (IASTNodeLocation loc : node.getNodeLocations()) { + if (loc instanceof IASTMacroExpansionLocation) + count++; + } + return count; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java index 1bf32ed357a..f98a9a69e3a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java @@ -17,7 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.parser.ParserLanguage; -public class AST2UtilOldTests extends AST2BaseTest { +public class AST2UtilOldTests extends AST2TestBase { public AST2UtilOldTests() { } public AST2UtilOldTests(String name) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java index 12f3c43ecc4..d4a7c5802ac 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; /** * @author dsteffle */ -public class AST2UtilTests extends AST2BaseTest { +public class AST2UtilTests extends AST2TestBase { public AST2UtilTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java index 3a67049702c..0c7433d461f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.parser.ParserLanguage; -public class ASTCPPSpecDefectTests extends AST2BaseTest { +public class ASTCPPSpecDefectTests extends AST2TestBase { public ASTCPPSpecDefectTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java index e1ef4945dbb..873b1bda0a8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Testcases for inactive code in ast. */ -public class ASTInactiveCodeTests extends AST2BaseTest { +public class ASTInactiveCodeTests extends AST2TestBase { public static TestSuite suite() { return suite(ASTInactiveCodeTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java index 29ff910dbfb..4bb56ea205e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -public class ASTNodeSelectorTest extends AST2BaseTest { +public class ASTNodeSelectorTest extends AST2TestBase { static public TestSuite suite() { return suite(ASTNodeSelectorTest.class); @@ -55,7 +55,7 @@ public class ASTNodeSelectorTest extends AST2BaseTest { fCode= getContents(1)[0].toString(); FileContent codeReader = FileContent.create("", fCode.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo); GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, new NullLogService(), new GPPParserExtensionConfiguration()); fTu= parser.parse(); fSelector= fTu.getNodeSelector(null); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java index 11bbfd143b2..922026b0dce 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AccessControlTests extends AST2BaseTest { +public class AccessControlTests extends AST2TestBase { protected class AccessAssertionHelper extends BindingAssertionHelper { AccessAssertionHelper(String contents) throws ParserException { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java similarity index 86% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java index c59ded324af..9059c090e2c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java @@ -13,22 +13,22 @@ package org.eclipse.cdt.core.parser.tests.ast2; import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; +import org.eclipse.cdt.core.parser.tests.FileBasePluginTestCase; import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class CDOMBaseTest extends FileBasePluginTest { +public class CDOMTestBase extends FileBasePluginTestCase { - public CDOMBaseTest() { + public CDOMTestBase() { } - public CDOMBaseTest(String name) { + public CDOMTestBase(String name) { super(name); } - public CDOMBaseTest(String name, Class className) { + public CDOMTestBase(String name, Class className) { super(name, className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java index e17d7fd1e6a..e557b30625e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.jobs.Job; /** * @author dsteffle */ -public class CodeReaderCacheTest extends CDOMBaseTest { +public class CodeReaderCacheTest extends CDOMTestBase { public CodeReaderCacheTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java index b60b13cb03c..ca8d20b7f90 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; * @author Guido Zgraggen * */ -public class CommentTests extends AST2BaseTest { +public class CommentTests extends AST2TestBase { public static TestSuite suite() { return suite(CommentTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index d2c052b0c22..b6afaf309c4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -102,9 +103,13 @@ public class CompleteParser2Tests extends BaseTestCase { } static private class CPPNameCollector extends ASTVisitor { - { - shouldVisitNames = true; + public CPPNameCollector() { + this(false); // don't visit implicit names by default } + public CPPNameCollector(boolean shouldVisitImplicitNames) { + this.shouldVisitNames = true; + this.shouldVisitImplicitNames = shouldVisitImplicitNames; + } public List nameList = new ArrayList(); @Override public int visit(IASTName name){ @@ -141,7 +146,7 @@ public class CompleteParser2Tests extends BaseTestCase { if (nameCollector.getName(i).resolveBinding() == binding) count++; - assertEquals(count, num); + assertEquals(num, count); } protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; @@ -149,7 +154,7 @@ public class CompleteParser2Tests extends BaseTestCase { if (nameCollector.getName(i).resolveBinding() == binding) count++; - assertEquals(count, num); + assertEquals(num, count); } protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang) throws Exception { @@ -172,7 +177,7 @@ public class CompleteParser2Tests extends BaseTestCase { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); ISourceCodeParser parser2 = null; - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (gcc) @@ -750,7 +755,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testConstructorChain() throws Exception { - IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); + IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1053,7 +1058,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testScoping() throws Exception { - IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); + IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1098,7 +1103,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testBug42872() throws Exception { - IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); + IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1112,14 +1117,14 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug43503A() throws Exception { IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 8); + assertEquals(col.size(), 9); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - assertInstances(col, SD_01, 2); + assertInstances(col, SD_01, 3); assertInstances(col, ctor, 1); assertInstances(col, f_SD_01, 2); } @@ -1204,10 +1209,10 @@ public class CompleteParser2Tests extends BaseTestCase { buff.append("} \n"); IASTTranslationUnit tu = parse(buff.toString()); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 17); + assertEquals(col.size(), 18); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); @@ -1217,7 +1222,7 @@ public class CompleteParser2Tests extends BaseTestCase { assertInstances(col, SD_02, 2); assertInstances(col, f_SD_02, 2); - assertInstances(col, SD_01, 3); + assertInstances(col, SD_01, 4); assertInstances(col, ctor, 1); assertInstances(col, next, 2); assertInstances(col, f_SD_01, 4); @@ -1268,10 +1273,10 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug44342() throws Exception { IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 10); + assertEquals(col.size(), 11); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); @@ -1279,7 +1284,7 @@ public class CompleteParser2Tests extends BaseTestCase { ICPPConstructor ctor = A.getConstructors()[0]; IVariable a = (IVariable) col.getName(6).resolveBinding(); - assertInstances(col, A, 2); + assertInstances(col, A, 3); assertInstances(col, f1, 2); assertInstances(col, f2, 1); assertInstances(col, ctor, 1); @@ -1288,7 +1293,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testCDesignatedInitializers() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("struct Inner { int a,b,c; };"); + buffer.append("struct Inner { int a,b,c; };"); buffer.append("struct A { int x; int y[]; struct Inner innerArray[]; int z[]; };"); buffer.append("struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); parse(buffer.toString(), true, ParserLanguage.C); @@ -1314,7 +1319,7 @@ public class CompleteParser2Tests extends BaseTestCase { " _Bool b; " + " f(b);" + " f(g((_Bool) 1) );" + - "}", + "}", true, ParserLanguage.C); } @@ -1337,7 +1342,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug44925() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("class MyClass { };"); + buffer.append("class MyClass { };"); buffer.append("class MyClass myObj1;"); buffer.append("enum MyEnum { Item1 };"); buffer.append("enum MyEnum myObj2;"); @@ -1420,23 +1425,23 @@ public class CompleteParser2Tests extends BaseTestCase { buffer.append("void main() { N::A * a = new N::A(); a->f(); } "); IASTTranslationUnit tu = parse(buffer.toString()); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 13); + assertEquals(col.size(), 14); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction f = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); ICPPConstructor ctor = A.getConstructors()[0]; - IProblemBinding fp = (IProblemBinding) col.getName(12).resolveBinding(); + IProblemBinding fp = (IProblemBinding) col.getName(13).resolveBinding(); assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); assertInstances(col, N, 3); assertInstances(col, f, 1); - assertInstances(col, A, 3); - assertInstances(col, ctor, 2); + assertInstances(col, A, 5); + assertInstances(col, ctor, 1); } public void testBug43110() throws Exception { @@ -1994,7 +1999,7 @@ public class CompleteParser2Tests extends BaseTestCase { writer.write("int main(int argc, char **argv) {\n"); writer.write("FILE * file = 0;\n"); writer.write("static_function(file);\n"); - writer.write("return 0;\n"); + writer.write("return 0;\n"); writer.write("}\n"); parse(writer.toString()); } @@ -2046,8 +2051,8 @@ public class CompleteParser2Tests extends BaseTestCase { writer.write("};\n"); writer.write("\n"); writer.write("template\n"); - writer.write("inline T526026< T >\n"); - writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); + writer.write("inline T526026< T >\n"); + writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); writer.write("{ return T526026< T >(); }\n"); writer.write("}\n"); parse(writer.toString(), false); @@ -2055,7 +2060,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug71094() throws Exception { Writer writer = new StringWriter(); - writer.write("using namespace DOESNOTEXIST;\n"); + writer.write("using namespace DOESNOTEXIST;\n"); writer.write("class A { int x; };\n"); parse(writer.toString(), false); } @@ -2223,7 +2228,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug74328() throws Exception { Writer writer = new StringWriter(); - writer.write("int\n"); + writer.write("int\n"); writer.write("main(int argc, char **argv) {\n"); writer.write(" char *sign;\n"); writer.write("sign = \"\"; // IProblem generated here, syntax error\n"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java index f1256dd05a4..f6daa2ad12d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * @author jcamelon * */ -public class DOMGCCSelectionParseExtensionsTest extends DOMSelectionParseBaseTest { +public class DOMGCCSelectionParseExtensionsTest extends DOMSelectionParseTestBase { public DOMGCCSelectionParseExtensionsTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 7c7b93a3234..ddc30d2f5c1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -44,7 +44,7 @@ import org.eclipse.core.runtime.content.IContentType; /** * @author jcamelon */ -public class DOMLocationInclusionTests extends AST2FileBasePluginTest { +public class DOMLocationInclusionTests extends AST2FileBasePluginTestCase { public DOMLocationInclusionTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java index 27c22c01543..c4a25dba2b9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java @@ -35,7 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.parser.ParserException; -public class DOMLocationMacroTests extends AST2BaseTest { +public class DOMLocationMacroTests extends AST2TestBase { final ParserLanguage[] languages = new ParserLanguage[] { ParserLanguage.C, ParserLanguage.CPP }; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 80ec78f9b37..df72e0c9215 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -73,7 +73,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * @author jcamelon */ -public class DOMLocationTests extends AST2BaseTest { +public class DOMLocationTests extends AST2TestBase { public DOMLocationTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java index 325fc03f6dd..716098f44d3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; * @author Emanuel Graf * */ -public class DOMPreprocessorInformationTest extends AST2BaseTest { +public class DOMPreprocessorInformationTest extends AST2TestBase { public void testPragma() throws Exception { String msg = "GCC poison printf sprintf fprintf"; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java index 9d59cf1c8b2..923bdf95206 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2002, 2010 IBM Corporation and others. + * Copyright (c) 2002, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -43,7 +44,7 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { +public class DOMSelectionParseTest extends DOMSelectionParseTestBase { public DOMSelectionParseTest() { } @@ -56,8 +57,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { super(name, DOMSelectionParseTest.class); } - public void testBaseCase_VariableReference() throws Exception - { + public void testBaseCase_VariableReference() throws Exception { String code = "void f() { int x; x=3; }"; //$NON-NLS-1$ int offset1 = code.indexOf( "x=" ); //$NON-NLS-1$ int offset2 = code.indexOf( '='); @@ -72,8 +72,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - public void testBaseCase_FunctionReference() throws Exception - { + public void testBaseCase_FunctionReference() throws Exception { String code = "int x(){x( );}"; //$NON-NLS-1$ int offset1 = code.indexOf( "x( " ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ @@ -87,17 +86,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - - public void testBaseCase_Error() throws Exception - { + + public void testBaseCase_Error() throws Exception { String code = "int x() { y( ) }"; //$NON-NLS-1$ int offset1 = code.indexOf( "y( " ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ assertNull( parse( code, offset1, offset2, false )); } - - public void testBaseCase_FunctionDeclaration() throws Exception - { + + public void testBaseCase_FunctionDeclaration() throws Exception { String code = "int x(); void test() {x( );}"; //$NON-NLS-1$ int offset1 = code.indexOf( "x( )" ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ @@ -111,9 +108,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - - public void testBaseCase_FunctionDeclaration2() throws Exception - { + + public void testBaseCase_FunctionDeclaration2() throws Exception { String code = "int printf( const char *, ... ); "; //$NON-NLS-1$ int offset1 = code.indexOf( "printf" ); //$NON-NLS-1$ int offset2 = code.indexOf( "( const"); //$NON-NLS-1$ @@ -123,8 +119,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((IASTName)node).toString(), "printf" ); //$NON-NLS-1$ } - public void testBaseCase_VariableDeclaration() throws Exception - { + public void testBaseCase_VariableDeclaration() throws Exception { String code = "int x = 3;"; //$NON-NLS-1$ int offset1 = code.indexOf( "x" ); //$NON-NLS-1$ int offset2 = code.indexOf( " ="); //$NON-NLS-1$ @@ -134,9 +129,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ } - - public void testBaseCase_Parameter() throws Exception - { + + public void testBaseCase_Parameter() throws Exception { String code = "int main( int argc ) { int x = argc; }"; //$NON-NLS-1$ int offset1 = code.indexOf( "argc;" ); //$NON-NLS-1$ int offset2 = code.indexOf( ";" ); //$NON-NLS-1$ @@ -151,9 +145,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 14); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - - public void testBug57898() throws Exception - { + + public void testBug57898() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo { public: void playHorn(); };\n" ); //$NON-NLS-1$ writer.write( "void Gonzo::playHorn() { return; }\n" ); //$NON-NLS-1$ @@ -187,9 +180,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 8); } } - - public void testConstructorDestructorDeclaration() throws Exception - { + + public void testConstructorDestructorDeclaration() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo { Gonzo(); ~Gonzo(); };"); //$NON-NLS-1$ String code = writer.toString(); @@ -199,16 +191,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "Gonzo" ); //$NON-NLS-1$ - + offset = code.indexOf( "~Gonzo"); //$NON-NLS-1$ node = parse( code, offset, offset + 6 ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "~Gonzo" ); //$NON-NLS-1$ - } - - public void testBug60264() throws Exception - { + } + + public void testBug60264() throws Exception { Writer writer = new StringWriter(); writer.write( "namespace Muppets { int i; }\n" ); //$NON-NLS-1$ writer.write( "int main(int argc, char **argv) { Muppets::i = 1; }\n" ); //$NON-NLS-1$ @@ -236,9 +227,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 10); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - - public void testBug61613() throws Exception - { + + public void testBug61613() throws Exception { Writer writer = new StringWriter(); writer.write( "class Foo { // ** (A) **\n" ); //$NON-NLS-1$ writer.write( " public:\n" ); //$NON-NLS-1$ @@ -260,9 +250,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug60038() throws Exception - { + + public void testBug60038() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo {\n"); //$NON-NLS-1$ writer.write( "public:\n"); //$NON-NLS-1$ @@ -296,8 +285,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { } IASTNode node = parse( code, startOffset, endOffset ); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); IBinding binding = ((IASTName)node).resolveBinding(); + if (binding instanceof ICPPClassType) { + node = TestUtil.findImplicitName(node); + binding = ((IASTName)node).resolveBinding(); + } + assertTrue( binding instanceof ICPPMethod ); IName[] decls = null; switch( i ) { @@ -309,7 +302,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 53); assertEquals( ((ASTNode)decls[0]).getLength(), 5); break; - case 1: + case 1: assertTrue( binding instanceof ICPPConstructor ); decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); @@ -317,7 +310,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 22); assertEquals( ((ASTNode)decls[0]).getLength(), 5); break; - default: + default: assertFalse( binding instanceof ICPPConstructor ); String name = ((IASTName)node).toString(); assertEquals( name.indexOf("~"), 0); //$NON-NLS-1$ @@ -328,13 +321,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 64); assertEquals( ((ASTNode)decls[0]).getLength(), 6); break; - + } } } - - public void testMethodReference() throws Exception - { + + public void testMethodReference() throws Exception { Writer writer = new StringWriter(); writer.write( "class Sample { public:\n"); //$NON-NLS-1$ writer.write( " int getAnswer() const;\n"); //$NON-NLS-1$ @@ -355,9 +347,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 29); assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - - public void testConstructorDefinition() throws Exception - { + + public void testConstructorDefinition() throws Exception { String code = "class ABC { public: ABC(); }; ABC::ABC(){}"; //$NON-NLS-1$ int startIndex = code.indexOf( "::ABC") + 2; //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); @@ -370,9 +361,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 20); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug63966() throws Exception - { + + public void testBug63966() throws Exception { Writer writer = new StringWriter(); writer.write( "void foo(int a) {}\n" ); //$NON-NLS-1$ writer.write( "void foo(long a) {}\n" ); //$NON-NLS-1$ @@ -382,22 +372,20 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int startIndex = code.indexOf( "foo(1)"); //$NON-NLS-1$ parse( code, startIndex, startIndex + 3 ); } - - public void testBug66744() throws Exception - { + + public void testBug66744() throws Exception { Writer writer = new StringWriter(); writer.write( "enum EColours { RED, GREEN, BLUE }; \n" ); //$NON-NLS-1$ writer.write( "void foo() { EColours color = GREEN; } \n" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "EColours color"); //$NON-NLS-1$ parse( code, startIndex, startIndex + 8 ); } - - - public void testBug68527() throws Exception - { + + + public void testBug68527() throws Exception { Writer writer = new StringWriter(); writer.write("struct X;\n"); //$NON-NLS-1$ writer.write("struct X anA;"); //$NON-NLS-1$ @@ -406,8 +394,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { parse( code, startIndex, startIndex + 1 ); } - public void testBug60407() throws Exception - { + public void testBug60407() throws Exception { Writer writer = new StringWriter(); writer.write( "struct ZZZ { int x, y, z; };\n" ); //$NON-NLS-1$ writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ @@ -422,9 +409,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int startIndex = code.indexOf( "static_function( file )"); //$NON-NLS-1$ parse( code, startIndex, startIndex + "static_function".length() ); //$NON-NLS-1$ } - - public void testBug61800() throws Exception - { + + public void testBug61800() throws Exception { Writer writer = new StringWriter(); writer.write( "class B {};\n"); //$NON-NLS-1$ writer.write( "class ABCDEF {\n"); //$NON-NLS-1$ @@ -443,27 +429,25 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 37); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - - public void testBug68739() throws Exception - { + + public void testBug68739() throws Exception { Writer writer = new StringWriter(); writer.write( "int fprintf( int *, const char *, ... ); \n" ); //$NON-NLS-1$ writer.write( "void boo( int * lcd ) { \n" ); //$NON-NLS-1$ writer.write( " /**/fprintf( lcd, \"%c%s 0x%x\", ' ', \"bbb\", 2 ); \n" ); //$NON-NLS-1$ writer.write( "} \n" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "/**/fprintf") + 4; //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex+ 7 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IFunction ); assertEquals( ((IASTName)node).toString(), "fprintf" ); //$NON-NLS-1$ } - - public void testBug72818() throws Exception - { + + public void testBug72818() throws Exception { Writer writer = new StringWriter(); writer.write( "union Squaw { int x; double u; };\n" ); //$NON-NLS-1$ writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ @@ -482,9 +466,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - - public void test72220() throws Exception - { + + public void test72220() throws Exception { Writer writer = new StringWriter(); writer.write( "const int FOUND_ME = 1;\n" ); //$NON-NLS-1$ writer.write( "class Test{\n" ); //$NON-NLS-1$ @@ -506,7 +489,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 10); assertEquals( ((ASTNode)decls[0]).getLength(), 8); } - + public void testBug72721() throws Exception{ Writer writer = new StringWriter(); writer.write(" class ABC { public: ABC(int); }; \n"); //$NON-NLS-1$ @@ -514,7 +497,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" int j = 1; \n"); //$NON-NLS-1$ writer.write(" new ABC( j + 1 ); \n"); //$NON-NLS-1$ writer.write("} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "ABC(" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); @@ -527,7 +510,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 21); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug72372() throws Exception{ Writer writer = new StringWriter(); writer.write("namespace B { \n"); //$NON-NLS-1$ @@ -535,7 +518,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("} \n"); //$NON-NLS-1$ writer.write("using namespace B; \n"); //$NON-NLS-1$ writer.write("void SD_02::f_SD(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); @@ -559,7 +542,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" using namespace A; \n"); //$NON-NLS-1$ writer.write("} \n"); //$NON-NLS-1$ writer.write("void C::B::f_SD(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); @@ -572,12 +555,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 109); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug72713() throws Exception{ Writer writer = new StringWriter(); writer.write( "class Deck{ void initialize(); }; \n"); //$NON-NLS-1$ writer.write( "void Deck::initialize(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":initialize" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 11 ); @@ -590,34 +573,35 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 17); assertEquals( ((ASTNode)decls[0]).getLength(), 10); } - + public void testBug72712() throws Exception{ Writer writer = new StringWriter(); writer.write( "class B{ public: B(); }; void f(){ B* b; b = new B(); }" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$ - + IASTNode node = parse( code, startIndex, startIndex + 1 ); + node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); + assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "B" ); //$NON-NLS-1$ IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "B" ); //$NON-NLS-1$ - assertEquals( ((ASTNode)decls[0]).getOffset(), 17); - assertEquals( ((ASTNode)decls[0]).getLength(), 1); + assertEquals( 17, ((ASTNode)decls[0]).getOffset() ); + assertEquals( 1, ((ASTNode)decls[0]).getLength() ); } - + public void testBug72712_2() throws Exception{ Writer writer = new StringWriter(); writer.write( "class A {}; \n"); //$NON-NLS-1$ writer.write( "class B{ public: B( A* ); }; \n"); //$NON-NLS-1$ writer.write( "void f(){ B* b; b = new B( (A*)0 ); } \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "(A*)" ) + 1; //$NON-NLS-1$ - + IASTNode node = parse( code, startIndex, startIndex + 1 ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); @@ -628,7 +612,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug72814() throws Exception{ CPPASTNameBase.sAllowNameComputation= true; @@ -637,11 +621,11 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write( " template < class T > class AAA { T _t; };\n"); //$NON-NLS-1$ writer.write( "} \n"); //$NON-NLS-1$ writer.write( "N::AAA a; \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "AAA" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); assertEquals( ((IASTName)node).toString(), "AAA" ); //$NON-NLS-1$ @@ -650,9 +634,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "AAA" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 75); assertEquals( ((ASTNode)decls[0]).getLength(), 3); - + node = parse( code, startIndex, startIndex + 8 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); assertEquals( ((IASTName)node).toString(), "AAA" ); //$NON-NLS-1$ @@ -663,9 +647,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { // assertEquals( ((ASTNode)decls[0]).getOffset(), 15); // assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug72710() throws Exception - { + + public void testBug72710() throws Exception { Writer writer = new StringWriter(); writer.write( "class Card{\n" ); //$NON-NLS-1$ writer.write( " Card( int rank );\n" ); //$NON-NLS-1$ @@ -686,9 +669,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - - - public void testBug75731() throws Exception + + + public void testBug75731() throws Exception { Writer writer = new StringWriter(); writer.write("int rank() {\n"); //$NON-NLS-1$ @@ -705,7 +688,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("this->rank = rank;\n"); //$NON-NLS-1$ writer.write("this->rank = Card::rank;\n"); //$NON-NLS-1$ writer.write("this->rank = getRank();\n}\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "int rank() {") + 4; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -718,7 +701,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "class Card{") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -730,7 +713,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 31); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card( int rank );"); //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -742,7 +725,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 46); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card( int rank );") + 10; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -766,7 +749,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "int getRank();") + 4; //$NON-NLS-1$ node = parse( code, index, index + 7 ); assertTrue( node instanceof IASTName ); @@ -778,7 +761,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "getRank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 86); assertEquals( ((ASTNode)decls[0]).getLength(), 7); - + index = code.indexOf( "Card::Card( int rank )"); //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -790,7 +773,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 31); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card::Card( int rank )") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -802,7 +785,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 46); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card::Card( int rank )") + 16; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -814,7 +797,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 56); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = ::rank();") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -826,7 +809,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = ::rank();") + 15; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -838,7 +821,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = this->rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -850,7 +833,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = this->rank;") + 19; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -862,7 +845,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -874,7 +857,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = rank;") + 13; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -886,7 +869,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 56); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = Card::rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -898,7 +881,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = Card::rank;") + 19; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -910,7 +893,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = getRank();") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -922,7 +905,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = getRank();") + 13; //$NON-NLS-1$ node = parse( code, index, index + 7 ); assertTrue( node instanceof IASTName ); @@ -942,7 +925,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("class C{};\n}\n"); //$NON-NLS-1$ writer.write("using namespace N; /* B */\n"); //$NON-NLS-1$ writer.write("N::C c; /* C */\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "using namespace N;") + 16; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1 ); @@ -959,9 +942,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { public void testBug78435() throws Exception { Writer writer = new StringWriter(); - writer.write("int itself; //A\n"); //$NON-NLS-1$ + writer.write("int itself; //A\n"); //$NON-NLS-1$ writer.write("void f(int itself){} //B\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "void f(int itself){}") + 11; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 6 ); @@ -981,7 +964,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("struct Base {\n"); //$NON-NLS-1$ writer.write("int Data; // 1\n"); //$NON-NLS-1$ writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -995,14 +978,14 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug78231B() throws Exception { Writer writer = new StringWriter(); writer.write("int Data;\n"); //$NON-NLS-1$ writer.write("struct Base {\n"); //$NON-NLS-1$ writer.write("int Data; // 1\n"); //$NON-NLS-1$ writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -1011,7 +994,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((IASTName)node).toString(), "Data" ); //$NON-NLS-1$ assertEquals( ((ASTNode)node).getOffset(), index); } - + public void testBug64326() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1024,7 +1007,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar = 1; // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("f->bar") + 3; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3 ); @@ -1037,7 +1020,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 33); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug92605() throws Exception { Writer writer = new StringWriter(); writer.write("#define UINT32 unsigned int\n"); //$NON-NLS-1$ @@ -1055,14 +1038,14 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "UINT32" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "UINT32" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 8); assertEquals( ((ASTNode)decls[0]).getLength(), 6); } - + public void testBug79877() throws Exception { Writer writer = new StringWriter(); writer.write("int Func2() {\n"); //$NON-NLS-1$ @@ -1072,27 +1055,27 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("}\n"); //$NON-NLS-1$ String code = writer.toString(); IFile test1 = importFile("test1.c", code); //$NON-NLS-1$ - + writer.write("int Func1(void) {\n"); //$NON-NLS-1$ writer.write("return(10);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ importFile("test2.c", writer.toString()); //$NON-NLS-1$ - + int index = code.indexOf("Func1"); //$NON-NLS-1$ IASTNode node = parse( test1, index, index + 5, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICExternalBinding ); assertEquals( ((IASTName)node).toString(), "Func1" ); //$NON-NLS-1$ - + ICElement[] scope = new ICElement[1]; scope[0] = new CProject(null, project); // // TODO need to register to an index and wait for it to finish before this test will work -// +// // Set matches = SearchEngine.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), (IASTName)node, CSearchPattern.DECLARATIONS); // assertEquals(matches.size(), 1); } - + public void testBug78114() throws Exception { Writer writer = new StringWriter(); writer.write("class Point{ //line C\n"); //$NON-NLS-1$ @@ -1106,22 +1089,23 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("Point &p2 = *(new Point(10)); // line A\n"); //$NON-NLS-1$ writer.write("return (0);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("Point(10)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 5, true ); + node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); + assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "Point" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "Point" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 53); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - + public void testBug73398() throws Exception { Writer writer = new StringWriter(); writer.write("int joo=4;\n"); //$NON-NLS-1$ @@ -1129,22 +1113,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ writer.write("return (koo);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("koo);"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "koo" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "koo" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 19); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug() throws Exception { Writer writer = new StringWriter(); writer.write("class Point{ \n"); //$NON-NLS-1$ @@ -1160,22 +1144,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("p2->operator=(zero); // line B\n"); //$NON-NLS-1$ writer.write("return (0); \n"); //$NON-NLS-1$ writer.write(" }\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("operator=(zero)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 9, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "operator =" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "operator =" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 51); assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - + public void testBug80826() throws Exception { Writer writer = new StringWriter(); writer.write("void swapImpl(int& a, int& b) {/*...*/} // line C\n"); //$NON-NLS-1$ @@ -1186,22 +1170,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("swap(x,y); // line A\n"); //$NON-NLS-1$ writer.write(" //...\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("swap(x,y);"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "swap" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "swap" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 58); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug78389() throws Exception { Writer writer = new StringWriter(); writer.write("class A{\n"); //$NON-NLS-1$ @@ -1212,22 +1196,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("A a; \n"); //$NON-NLS-1$ writer.write("a.method1(3); // F3 on method1 in this line should highlight method1 on line B\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("method1(3)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 7, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "method1" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "method1" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 41); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - + public void testBug78625() throws Exception { Writer writer = new StringWriter(); writer.write("class A{ \n"); //$NON-NLS-1$ @@ -1236,22 +1220,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("class B: A{\n"); //$NON-NLS-1$ writer.write("B():A(2) {} //line 5\n"); //$NON-NLS-1$ writer.write("};\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("A(2)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "A" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "A" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 29); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug78656() throws Exception { Writer writer = new StringWriter(); writer.write("class A{\n"); //$NON-NLS-1$ @@ -1261,41 +1245,41 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("A a;\n"); //$NON-NLS-1$ writer.write("int i=a.method1(); //line 6\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("method1();"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 7, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "method1" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "method1" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 21); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - + public void testBug79965() throws Exception { Writer writer = new StringWriter(); writer.write("int i = 2, half_i = i / 2;\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("i / 2"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "i" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "i" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug64326A() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1308,22 +1292,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar(); // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("bar();"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "bar" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "bar" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 34); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug64326B() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1336,22 +1320,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar = 1; // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("bar = "); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPField ); assertEquals( ((IASTName)node).toString(), "bar" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "bar" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 33); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug43128A() throws Exception { Writer writer = new StringWriter(); writer.write("void foo()\n"); //$NON-NLS-1$ @@ -1360,44 +1344,44 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" // ...\n"); //$NON-NLS-1$ writer.write("x++;\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("x++"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "x" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 17); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug43128B() throws Exception { Writer writer = new StringWriter(); writer.write("int\n"); //$NON-NLS-1$ writer.write("main(int argc, char **argv) {\n"); //$NON-NLS-1$ writer.write("int x = argc;\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("argc;"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IParameter ); assertEquals( ((IASTName)node).toString(), "argc" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "argc" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 13); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug43128C() throws Exception { Writer writer = new StringWriter(); writer.write("int j;\n"); //$NON-NLS-1$ @@ -1410,44 +1394,44 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("}\n"); //$NON-NLS-1$ String code = writer.toString(); - + int index = code.indexOf("x ="); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "x" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 19); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - + index = code.indexOf("j ="); //$NON-NLS-1$ node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "j" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "j" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - + index = code.indexOf("y ="); //$NON-NLS-1$ node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "y" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "y" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 30); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } - + } + public void testBug86504() throws Exception { Writer writer = new StringWriter(); writer.write("class C { };\n"); //$NON-NLS-1$ @@ -1457,21 +1441,21 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("void foo() {\n"); //$NON-NLS-1$ writer.write("f(g); // openDeclarations on g causes StackOverflowError\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("g); "); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPFunction ); assertEquals( ((IASTName)node).toString(), "g" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "g" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 89); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } public void testBug79811() throws Exception { Writer writer = new StringWriter(); @@ -1481,21 +1465,21 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("E e; //this one is incorrectly found\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ writer.write("E f; //ok\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("E{E0}"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IEnumeration ); assertEquals( ((IASTName)node).toString(), "E" ); //$NON-NLS-1$ - + IName[] decls = getReferencesOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "E" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 76); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } public void testBugLabelWithMacro() throws Exception { Writer writer = new StringWriter(); @@ -1511,32 +1495,32 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("goto test;\n"); //$NON-NLS-1$ writer.write("return foo();\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("HANDLE h"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 6, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "HANDLE" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "HANDLE" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 6); - + index = code.indexOf("test;"); //$NON-NLS-1$ node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ILabel ); assertEquals( ((IASTName)node).toString(), "test" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "test" ); //$NON-NLS-1$ assertLocation(code, "test:", 4, decls[0]); - } + } public void testBugMethodDef() throws Exception { Writer writer = new StringWriter(); @@ -1552,28 +1536,28 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("void tetrahedron::set() {\n"); //$NON-NLS-1$ writer.write("int color;\n"); //$NON-NLS-1$ writer.write("setColor(color);\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - + writer.write("}\n"); //$NON-NLS-1$ + String code = writer.toString(); - + int index = code.indexOf("setColor(color)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 8, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "setColor" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "setColor" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 67); assertEquals( ((ASTNode)decls[0]).getLength(), 8); - + IName[] refs = getReferencesOffTU((IASTName)node); assertEquals(refs.length, 1); assertEquals( refs[0].toString(), "setColor" ); //$NON-NLS-1$ assertEquals( ((ASTNode)refs[0]).getOffset(), 162); assertEquals( ((ASTNode)refs[0]).getLength(), 8); - } + } public void testBug86698A() throws Exception { Writer writer = new StringWriter(); @@ -1583,22 +1567,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("int c;\n"); //$NON-NLS-1$ writer.write("C() : c(0) { no_opt(this); }\n"); //$NON-NLS-1$ writer.write("};\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("c(0)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "c" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "c" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 42); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } - + } + public void testBug86698B() throws Exception { Writer writer = new StringWriter(); writer.write("int f(int);\n"); //$NON-NLS-1$ @@ -1619,24 +1603,23 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("// handles exceptions thrown from the ctorinitializer\n"); //$NON-NLS-1$ writer.write("// and from the constructor function body\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("i(f(ii)), d(id)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPField ); assertEquals( ((IASTName)node).toString(), "i" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "i" ); //$NON-NLS-1$ assertEquals( code.indexOf("int i") + 4, ((ASTNode)decls[0]).getOffset()); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } - public void testBug64181() throws Exception - { + public void testBug64181() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("namespace Foo { // ** (A) **\n"); //$NON-NLS-1$ buffer.append("int bar;\n"); //$NON-NLS-1$ @@ -1648,7 +1631,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { buffer.append("main(int argc, char **argv) {\n"); //$NON-NLS-1$ buffer.append("Foo::bar; // ** (C) **\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - + String code = buffer.toString(); int index = code.indexOf("Foo::bar;"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); @@ -1664,9 +1647,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[1]).getOffset(), 50); assertEquals( ((ASTNode)decls[1]).getLength(), 3); } - - public void testBug80823() throws Exception - { + + public void testBug80823() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("class MyEggImpl {}; // line A\n"); //$NON-NLS-1$ buffer.append("#define MyChicken MyEggImpl\n"); //$NON-NLS-1$ @@ -1686,8 +1668,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - public void testBug86993() throws Exception - { + public void testBug86993() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("#define _BEGIN_STD_C extern \"C\" {\n"); //$NON-NLS-1$ buffer.append("#define _END_STD_C }\n"); //$NON-NLS-1$ @@ -1696,8 +1677,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { buffer.append("_END_STD_C\n"); //$NON-NLS-1$ buffer.append("char foo() {\n"); //$NON-NLS-1$ buffer.append("return c; // ref \n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - + buffer.append("}\n"); //$NON-NLS-1$ + String code = buffer.toString(); int index = code.indexOf("return c;"); //$NON-NLS-1$ IASTNode node = parse( code, index + 7, index + 8, true ); @@ -1709,7 +1690,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "c" ); //$NON-NLS-1$ assertLocation(code, "c;", 1, decls[0]); - + index = code.indexOf("char c"); //$NON-NLS-1$ node = parse( code, index + 5, index + 6, true ); assertNotNull( node ); @@ -1720,7 +1701,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( refs[0].toString(), "c" ); //$NON-NLS-1$ assertLocation(code, "c; // ref", 1, refs[0]); } - + private void assertLocation(String code, String occur, int length, IName name) { int offset= code.indexOf(occur); final IASTFileLocation loc= name.getFileLocation(); @@ -1728,4 +1709,3 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals(length, loc.getNodeLength()); } } - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java similarity index 90% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java index a54b623bec7..80d7a29a63f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java @@ -23,16 +23,16 @@ import org.eclipse.core.resources.IFile; * @author johnc * */ -public class DOMSelectionParseBaseTest extends DOMFileBasePluginTest { +public class DOMSelectionParseTestBase extends DOMFileBasePluginTest { - public DOMSelectionParseBaseTest() { + public DOMSelectionParseTestBase() { } - public DOMSelectionParseBaseTest(String name) { + public DOMSelectionParseTestBase(String name) { super(name); } - public DOMSelectionParseBaseTest(String name, Class className) { + public DOMSelectionParseTestBase(String name, Class className) { super(name, className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java index 46beb30698f..9493190bb1b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Testcases related to recovery from invalid syntax. */ -public class FaultToleranceTests extends AST2BaseTest { +public class FaultToleranceTests extends AST2TestBase { public static TestSuite suite() { return suite(FaultToleranceTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java index 54ee449ebb2..803f458c1db 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java @@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CFunction; import org.eclipse.cdt.internal.core.model.ASTStringUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class GCCCompleteParseExtensionsTest extends AST2BaseTest { +public class GCCCompleteParseExtensionsTest extends AST2TestBase { public GCCCompleteParseExtensionsTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java index 51515f83f85..4d284afb934 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author aniefer */ -public class GCCTests extends AST2BaseTest { +public class GCCTests extends AST2TestBase { public GCCTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java index 3781b3dcf99..a9b2425d18b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author jcamelon */ -public class ImageLocationTests extends AST2BaseTest { +public class ImageLocationTests extends AST2TestBase { private static final int CODE = IASTImageLocation.REGULAR_CODE; private static final int MACRO = IASTImageLocation.MACRO_DEFINITION; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java index 5ccbc2afdea..80fa8691192 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java @@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; /** * Testcases for non-gnu language extensions. */ -public class LanguageExtensionsTest extends AST2BaseTest { +public class LanguageExtensionsTest extends AST2TestBase { protected static final int SIZEOF_EXTENSION = 0x1; protected static final int FUNCTION_STYLE_ASM = 0x2; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java index 33cc1a0d043..9f33234002f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java @@ -1335,7 +1335,7 @@ public class QuickParser2Tests extends TestCase { ParserLanguage lang, boolean gcc) throws Exception { FileContent codeReader = FileContent.create("", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java index e4d259c68bc..d669ebbea30 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * Directly tests parts of the semantics package */ -public class SemanticsTests extends AST2BaseTest { +public class SemanticsTests extends AST2TestBase { public SemanticsTests() {} public SemanticsTests(String name) { super(name); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java index 381b6965450..bdd5255f575 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser; import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser.Task; -public class TaskParserTest extends AST2BaseTest { +public class TaskParserTest extends AST2TestBase { public static TestSuite suite() { return suite(TaskParserTest.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java new file mode 100644 index 00000000000..5a292b6bd77 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 Nathan Ridge. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nathan Ridge - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import org.eclipse.cdt.core.dom.ast.IASTImplicitName; +import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; + +public class TestUtil { + /** + * Searches the AST upward from the given starting node to find the + * nearest IASTImplicitNameOwner and returns its first implicit name, + * or null if it has no implicit names. + */ + public static IASTName findImplicitName(IASTNode node) { + while (node != null) { + if (node instanceof IASTImplicitNameOwner) { + IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) node).getImplicitNames(); + if (implicitNames != null && implicitNames.length > 0) { + return implicitNames[0]; + } + } + node = node.getParent(); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java index 7fff28bb67d..bb536e69847 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * Tests for ClassTypeHelper class. */ -public class TypeTraitsTests extends AST2BaseTest { +public class TypeTraitsTests extends AST2TestBase { public TypeTraitsTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java index 494d56817d3..3fdf112e2fc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; /** * Unit tests for CPPVariableReadWriteFlags and CVariableReadWriteFlags classes. */ -public class VariableReadWriteFlagsTest extends AST2BaseTest { +public class VariableReadWriteFlagsTest extends AST2TestBase { private static final int READ = PDOMName.READ_ACCESS; private static final int WRITE = PDOMName.WRITE_ACCESS; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java index be9e1b6f112..f6d44ea67ff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java @@ -38,7 +38,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; @@ -53,7 +53,7 @@ public class CompletionTestBase extends BaseTestCase { protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { FileContent codeReader = FileContent.create("", code.trim().toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser = null; if( lang == ParserLanguage.CPP ) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java index 8eea3e22ddf..6576a1f3eb2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest; import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper; import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile; @@ -95,7 +95,7 @@ public class ASTWriterTest extends RewriteBaseTest { ParserLanguage language = getLanguage(testFile); boolean useGNUExtensions = getGNUExtension(testFile); - IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner = AST2TestBase.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser = null; if (language == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 978a6f18bd0..4490da93a26 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Symbian Software Systems and others. + * Copyright (c) 2006, 2013 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * IBM Corporation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -83,7 +84,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { super.tearDown(); } - protected IASTName findName(String section, int len) { + protected IASTName findName(String section, int len, boolean preferImplicitName) { if (len == 0) len= section.length(); for (int i = 0; i < strategy.getAstCount(); i++) { @@ -91,15 +92,27 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { final IASTNodeSelector nodeSelector = ast.getNodeSelector(null); final int offset = strategy.getAstSource(i).indexOf(section); if (offset >= 0) { - IASTName name= nodeSelector.findName(offset, len); - if (name == null) - name= nodeSelector.findImplicitName(offset, len); - return name; + if (preferImplicitName) { + return nodeSelector.findImplicitName(offset, len); + } else { + IASTName name= nodeSelector.findName(offset, len); + if (name == null) + name= nodeSelector.findImplicitName(offset, len); + return name; + } } } return null; } + + protected IASTName findName(String section, int len) { + return findName(section, len, false); + } + + protected IASTName findImplicitName(String section, int len) { + return findName(section, len, true); + } /** * Attempts to get an IBinding from the initial specified number of characters @@ -129,9 +142,37 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertInstance(binding, clazz, cs); return clazz.cast(binding); } + + /** + * Attempts to get an IBinding attached to an implicit name from the initial specified + * number of characters from the specified code fragment. Fails the test if + *
    + *
  • There is not a unique implicit name with the specified criteria + *
  • The binding associated with the implicit name is null or a problem binding + *
  • The binding is not an instance of the specified class + *
+ * @param section the code fragment to search for in the AST. The first occurrence of an identical section is used. + * @param len the length of the specified section to use as a name + * @param clazz an expected class type or interface that the binding should extend/implement + * @return the associated implicit name's binding + */ + protected T getBindingFromImplicitASTName(String section, int len, Class clazz, Class ... cs) { + if (len < 1) { + len= section.length()+len; + } + IASTName name= findImplicitName(section, len); + assertNotNull("Name not found for \"" + section + "\"", name); + assertEquals(section.substring(0, len), name.getRawSignature()); + + IBinding binding = name.resolveBinding(); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + assertInstance(binding, clazz, cs); + return clazz.cast(binding); + } /* - * @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int) + * @see IndexBindingResolutionTestBase#getBindingFromASTName(String, int, Class, Class ...) */ protected T getBindingFromASTName(String section, int len) { if (len <= 0) @@ -146,6 +187,23 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); return (T) binding; } + + /* + * @see IndexBindingResolutionTestBase#getBindingFromImplicitASTName(String, int, Class, Class ...) + */ + protected T getBindingFromImplicitASTName(String section, int len) { + if (len <= 0) + len += section.length(); + + IASTName name= findImplicitName(section, len); + assertNotNull("Name not found for \"" + section + "\"", name); + assertEquals(section.substring(0, len), name.getRawSignature()); + + IBinding binding = name.resolveBinding(); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + return (T) binding; + } /** * Attempts to verify that the resolved binding for a name is a problem binding. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java index c2210a5712e..ea7a3a80dd6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -42,20 +43,20 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase public ProjectWithDepProj() { setStrategy(new ReferencedProject(false)); } public static TestSuite suite() { return suite(ProjectWithDepProj.class); } } - - public static void addTests(TestSuite suite) { + + public static void addTests(TestSuite suite) { suite.addTest(SingleProject.suite()); suite.addTest(ProjectWithDepProj.suite()); } - // #include + // #include // void func1(void) { // int i = 0; // for (i=0; i<10;i++) { // printf("%i", i); // } // } - + // #include "header.h" // // int main(void) { @@ -77,7 +78,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase } // void func1(void); - + // #include "header.h" // // int main(void) { @@ -87,7 +88,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase IBinding b0 = getBindingFromASTName("func1;", 5); assertTrue(b0 instanceof IFunction); } - + // typedef struct { // int utm; // } usertype; @@ -132,7 +133,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertInstance(type, IEnumeration.class); assertTrue(type instanceof IEnumeration); } - + // int globalVar; // // don't include header @@ -268,10 +269,10 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase e= (IEnumeration) b1; ei= e.getEnumerators(); assertEquals(1, ei.length); - } + } // // no header needed - + // typedef struct { // int member; // } t_struct; @@ -289,7 +290,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + IType tAST= ((ITypedef) tdAST).getType(); IType tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -304,7 +305,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -319,7 +320,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof IEnumeration); @@ -327,13 +328,13 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tAST.isSameType(tIndex)); assertTrue(tIndex.isSameType(tAST)); } - + // struct outer { // union { // int var1; // }; // }; - + // #include "header.h" // void test() { // struct outer x; @@ -354,7 +355,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // int var1; // }; // }; - + // #include "header.h" // void test() { // union outer x; @@ -369,14 +370,14 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(outer instanceof ICCompositeTypeScope); assertEquals("outer", outer.getScopeName().toString()); } - + // int myFunc(); - + // int myFunc(var) - // int var; - // { - // return var; - // } + // int var; + // { + // return var; + // } // int main(void) { // return myFunc(0); // } @@ -390,7 +391,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(params[0].getType() instanceof IBasicType); assertEquals(IBasicType.Kind.eInt, ((IBasicType) params[0].getType()).getKind()); } - + // typedef struct S S; // void setValue(S *pSelf, int value); @@ -404,7 +405,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase IBinding b = getBindingFromASTName("value =", 5); assertTrue(b instanceof IField); } - + // void f255( // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, @@ -439,8 +440,8 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); - - // void test() { + + // void test() { // f255( // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -463,8 +464,8 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase public void testFunctionsWithManyParameters_Bug319186() throws Exception { getBindingFromASTName("f255", 0); getBindingFromASTName("f256", 0); - } - + } + // struct B { // float f; // }; @@ -474,5 +475,17 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // }; public void testDesignatedInitializer_Bug210019() throws Exception { IField f= getBindingFromASTName("f", 0); - } + } + + // struct S { + // int data; + // }; + + // void test(void (*f)(void*)) { + // struct S *i; + // f(&i->data); + // } + public void testBug394151() throws Exception { + IParameter f= getBindingFromASTName("f(", 1); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index 2925bf8ffa3..082c99311a4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2013 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -1490,9 +1491,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti assertFalse(b0 instanceof IIndexBinding); ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class); assertFalse(b1 instanceof IIndexBinding); - ICPPConstructor b2 = getBindingFromASTName("B(0)", 1, ICPPConstructor.class); - assertFalse(b2 instanceof IIndexBinding); - assertEquals(b1, b2); + ICPPClassType b2 = getBindingFromASTName("B(0)", 1, ICPPClassType.class); ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class); assertFalse(b3 instanceof IIndexBinding); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 57ffaefda0b..2c1033ffc30 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Symbian Software Systems and others. + * Copyright (c) 2007, 2013 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -300,7 +300,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // X xa= new X(); // } public void testUnindexedConstructorInstance() { - IBinding b0= getBindingFromASTName("X()", 4); + IBinding b0= getBindingFromImplicitASTName("X()", 4); assertInstance(b0, ICPPConstructor.class); } @@ -409,7 +409,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // assertEquals(3, _ctcs.length); // two implicit plus the constructor template IBinding b2= getBindingFromASTName("D(", 1); - IBinding b3= getBindingFromASTName("D(", 6); + IBinding b3= getBindingFromImplicitASTName("D(", 6); assertInstance(b2, ICPPClassTemplate.class); // *D*(5, 6) assertInstance(b2, ICPPClassType.class); // *D*(5, 6) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 42ec1b40b31..f2097edf8d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -45,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMemberClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeOfDependentExpression; /** * This is a utility class to help convert AST elements to Strings corresponding to @@ -408,6 +409,8 @@ public class ASTTypeUtil { IQualifierType qt= (IQualifierType) type; needSpace= appendCVQ(result, needSpace, qt.isConst(), qt.isVolatile(), false); + } else if (type instanceof TypeOfDependentExpression) { + result.append(((TypeOfDependentExpression) type).getSignature()); } else if (type instanceof ISemanticProblem) { result.append('?'); } else if (type != null) { @@ -584,7 +587,7 @@ public class ASTTypeUtil { if (parenthesis == null) { parenthesis= new BitSet(); } - parenthesis.set(postfix.size()-1); + parenthesis.set(postfix.size() - 1); } appendTypeString(tj, normalize, result); needParenthesis= false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java index 32335283083..ff3726895e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -33,11 +34,11 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I setName(name); setValue(value); } - - protected void copyAbstractEnumerator(ASTEnumerator copy, CopyStyle style) { + + protected T copy(T copy, CopyStyle style) { copy.setName(name == null ? null : name.copy(style)); copy.setValue(value == null ? null : value.copy(style)); - copy.setOffsetAndLength(this); + return super.copy(copy, style); } @Override @@ -125,23 +126,26 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I } private void createEnumValues(IASTEnumerationSpecifier parent) { + IValue previousExplicitValue = null; + int delta = 0; IASTEnumerator[] etors= parent.getEnumerators(); - long cv= -1; - boolean isknown= true; for (IASTEnumerator etor : etors) { - cv++; + IValue val; IASTExpression expr= etor.getValue(); if (expr != null) { - IValue val= Value.create(expr, Value.MAX_RECURSION_DEPTH); - Long nv= val.numericalValue(); - isknown= false; - if (nv != null) { - isknown= true; - cv= nv.longValue(); + val= Value.create(expr, Value.MAX_RECURSION_DEPTH); + previousExplicitValue = val; + delta = 1; + } else { + if (previousExplicitValue != null) { + val = Value.incrementedValue(previousExplicitValue, delta); + } else { + val = Value.create(delta); } + delta++; } if (etor instanceof ASTEnumerator) { - ((ASTEnumerator) etor).integralValue= isknown ? Value.create(cv) : Value.UNKNOWN; + ((ASTEnumerator) etor).integralValue= val; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index a084775601e..387da41ee83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc and others. + * Copyright (c) 2011, 2013 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Sergey Prigogin (Google) - initial API and implementation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -129,7 +130,11 @@ public class SizeofCalculator { sizeof_long_long = getSize(sizeofMacros, "__SIZEOF_LONG_LONG__", maxAlignment); //$NON-NLS-1$ sizeof_int128 = getSize(sizeofMacros, "__SIZEOF_INT128__", maxAlignment); //$NON-NLS-1$ sizeof_short = getSize(sizeofMacros, "__SIZEOF_SHORT__", maxAlignment); //$NON-NLS-1$ - sizeof_bool = getSize(sizeofMacros, "__SIZEOF_BOOL__", maxAlignment); //$NON-NLS-1$ + SizeAndAlignment size = getSize(sizeofMacros, "__SIZEOF_BOOL__", maxAlignment); //$NON-NLS-1$ + // __SIZEOF_BOOL__ is not defined by GCC but sizeof(bool) is needed for template resolution. + if (size == null) + size = SIZE_1; + sizeof_bool = size; sizeof_wchar_t = getSize(sizeofMacros, "__SIZEOF_WCHAR_T__", maxAlignment); //$NON-NLS-1$ sizeof_float = getSize(sizeofMacros, "__SIZEOF_FLOAT__", maxAlignment); //$NON-NLS-1$ sizeof_complex_float = getSizeOfPair(sizeof_float); @@ -152,7 +157,7 @@ public class SizeofCalculator { sizeof_long_long = null; sizeof_int128 = size_16; sizeof_short = null; - sizeof_bool = null; + sizeof_bool = SIZE_1; sizeof_wchar_t = null; sizeof_float = null; sizeof_complex_float = null; @@ -178,7 +183,12 @@ public class SizeofCalculator { if (type instanceof IBasicType) { return sizeAndAlignment((IBasicType) type); } - if (type instanceof IPointerType || type instanceof ICPPReferenceType) { + // [expr.sizeof]/2: "When applied to a reference or a reference type, the + // result is the size of the referenced type." + if (type instanceof ICPPReferenceType) { + return sizeAndAlignment(((ICPPReferenceType) type).getType()); + } + if (type instanceof IPointerType) { if (type instanceof ICPPPointerToMemberType) return null; return sizeof_pointer; @@ -310,14 +320,24 @@ public class SizeofCalculator { if (field.isStatic()) continue; IType fieldType = field.getType(); - SizeAndAlignment info = sizeAndAlignment(fieldType); + SizeAndAlignment info; + // sizeof() on a reference type returns the size of the referenced type. + // However, a reference field in a structure only occupies as much space + // as a pointer. + if (fieldType instanceof ICPPReferenceType) { + info = sizeof_pointer; + } else { + info = sizeAndAlignment(fieldType); + } if (info == null) return null; if (union) { if (size < info.size) size = info.size; } else { - size += info.alignment - (size - 1) % info.alignment - 1 + info.size; + if (size > 0) + size += info.alignment - (size - 1) % info.alignment - 1; + size += info.size; } if (maxAlignment < info.alignment) maxAlignment = info.alignment; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 4e5a941bc05..8c074ef9932 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; @@ -53,16 +54,20 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinary; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; @@ -77,6 +82,7 @@ public class Value implements IValue { public static final int MAX_RECURSION_DEPTH = 25; public static final Value UNKNOWN= new Value("".toCharArray(), null); //$NON-NLS-1$ public static final Value NOT_INITIALIZED= new Value("<__>".toCharArray(), null); //$NON-NLS-1$ + private static final IType INT_TYPE= new CPPBasicType(ICPPBasicType.Kind.eInt, 0); private static final Number VALUE_CANNOT_BE_DETERMINED = new Number() { @Override @@ -271,6 +277,16 @@ public class Value implements IValue { return UNKNOWN; } + public static IValue incrementedValue(IValue value, int increment) { + Long val = value.numericalValue(); + if (val != null) { + return create(val.longValue() + increment); + } + ICPPEvaluation arg1 = value.getEvaluation(); + EvalFixed arg2 = new EvalFixed(INT_TYPE, ValueCategory.PRVALUE, create(increment)); + return create(new EvalBinary(IASTBinaryExpression.op_plus, arg1, arg2)); + } + private static Number applyUnaryTypeIdOperator(int operator, IType type, IASTNode point) { switch (operator) { case op_sizeof: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java index a800794bc05..b32d1f97e6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -191,7 +192,7 @@ public abstract class VariableReadWriteFlags { final IType type= functionNameExpression.getExpressionType(); if (type instanceof IFunctionType) { return rwArgumentForFunctionCall((IFunctionType) type, i, indirection); - } else { + } else if (funcCall instanceof IASTImplicitNameOwner) { IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) funcCall).getImplicitNames(); if (implicitNames.length == 1) { IASTImplicitName name = implicitNames[0]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java index b5706d94dac..1b596216df0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation + * John Camelon (IBM Rational Software) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -34,11 +34,6 @@ public class CASTEnumerator extends ASTEnumerator { @Override public CASTEnumerator copy(CopyStyle style) { - CASTEnumerator copy = new CASTEnumerator(); - copyAbstractEnumerator(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new CASTEnumerator(), style); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java index 7b702c2bcf5..e6b02b0356c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Symbian Software Systems and others. + * Copyright (c) 2008, 2013 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial Implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -68,12 +69,18 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements name.setBinding(null); namedTypeSpec.setName(name); } - } else if (node instanceof IASTIdExpression) { - IASTIdExpression id= (IASTIdExpression) node; - final IASTName name = id.getName(); - name.setBinding(null); - id.setName(name); - } + } else { + // Unwrap variadic pack expansion if necessary. + if (node instanceof ICPPASTPackExpansionExpression) + node= ((ICPPASTPackExpansionExpression) node).getPattern(); + + if (node instanceof IASTIdExpression) { + IASTIdExpression id= (IASTIdExpression) node; + final IASTName name = id.getName(); + name.setBinding(null); + id.setName(name); + } + } } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java index 7953101446d..a0a508069fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -124,7 +124,7 @@ public class CPPASTBinaryTypeIdExpression extends ASTNode implements ICPPASTExpr fEvaluation= EvalFixed.INCOMPLETE; } else { IType t1= CPPVisitor.createType(fOperand1); - IType t2= CPPVisitor.createType(fOperand1); + IType t2= CPPVisitor.createType(fOperand2); if (t1 == null || t2 == null) { fEvaluation= EvalFixed.INCOMPLETE; } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index fdd9fef35d6..0eee0c53ec3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -35,11 +35,6 @@ public class CPPASTEnumerator extends ASTEnumerator { @Override public CPPASTEnumerator copy(CopyStyle style) { - CPPASTEnumerator copy = new CPPASTEnumerator(); - copyAbstractEnumerator(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new CPPASTEnumerator(), style); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java index 9b115f02e50..56695296b2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Natan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -74,7 +76,7 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac } else { type= new CPPParameterPackType(type); } - fEvaluation= new EvalFixed(type, PRVALUE, Value.UNKNOWN); + fEvaluation= new EvalFixed(type, PRVALUE, Value.create(((ICPPASTExpression) fPattern).getEvaluation())); } return fEvaluation; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java index 5d45beba891..21c80c020a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java @@ -1,14 +1,15 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM Corporation) - initial API and implementation - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -47,8 +48,10 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase { public IType getBaseClassType() { if (baseClass == null) { IBinding b = base.getName().resolveBinding(); - if (b instanceof IProblemBinding || ! (b instanceof IType)) { + if (b instanceof IProblemBinding) { baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), ((IProblemBinding) b).getID()); + } else if (!(b instanceof IType)) { + baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), ISemanticProblem.BINDING_NO_CLASS); } else { baseClass= (IType) b; IType check= getNestedType(baseClass, TDEF); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index 14e1902fd42..979cc8fd7b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -103,7 +103,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP // Function call operator final IType returnType= getReturnType(); final IType[] parameterTypes= getParameterTypes(); - ft= new CPPFunctionType(returnType, parameterTypes, isMutable(), false, false); + ft= new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false); ICPPParameter[] params = new ICPPParameter[parameterTypes.length]; for (int i = 0; i < params.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 0ed1f673f48..4bff763279a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2012, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -84,8 +85,16 @@ public interface ICPPEvaluation extends ISerializableEvaluation { IASTNode point); /** - * Determines size of the template parameter pack. + * Searches the evaluation for a usage of a template parameter which is a parameter pack, + * and returns the number of arguments bound to that parameter pack in the given + * template parameter map. * + * Can also return one of the special values CPPTemplates.PACK_SIZE_DEFER, + * CPPTemplates.PACK_SIZE_FAIL, and CPPTemplates.PACK_SIZE_NOT_FOUND. See their + * declarations for their meanings. + * + * See also CPPTemplates.determinePackSize(). + * * @noreference This method is not intended to be referenced by clients. */ int determinePackSize(ICPPTemplateParameterMap tpMap); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index d1d279b2628..81a51e64dd1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Google, Inc and others. + * Copyright (c) 2012, 2013 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,207 +11,18 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; -import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; -import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; public abstract class CPPEvaluation implements ICPPEvaluation { - private static class SignatureBuilder implements ITypeMarshalBuffer { - private static final byte NULL_TYPE= 0; - private static final byte UNSTORABLE_TYPE= (byte) -1; - - private final StringBuilder fBuffer; - - /** - * Constructor for input buffer. - */ - public SignatureBuilder() { - fBuffer= new StringBuilder(); - } - - @Override - public String toString() { - return fBuffer.toString(); - } - - public char[] getSignature() { - return CharArrayUtils.extractChars(fBuffer); - } - - @Override - public void marshalBinding(IBinding binding) throws CoreException { - if (binding instanceof ISerializableType) { - ((ISerializableType) binding).marshal(this); - } else if (binding == null) { - putByte(NULL_TYPE); - } else { - appendSeparator(); - if (binding instanceof ICPPBinding) { - if (binding instanceof ICPPTemplateParameter) { - ICPPTemplateParameter param = (ICPPTemplateParameter) binding; - fBuffer.append(param.isParameterPack() ? '*' : '#'); - fBuffer.append(param.getParameterID()); - } else { - fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); - } - } else { - fBuffer.append(binding.getNameCharArray()); - } - } - } - - @Override - public void marshalType(IType type) throws CoreException { - if (type instanceof ISerializableType) { - ((ISerializableType) type).marshal(this); - } else if (type == null) { - putByte(NULL_TYPE); - } else if (type instanceof IBinding) { - marshalBinding((IBinding) type); - } else { - assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - putByte(UNSTORABLE_TYPE); - } - } - - @Override - public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { - if (eval == null) { - putByte(NULL_TYPE); - } else { - eval.marshal(this, includeValues); - } - } - - @Override - public void marshalValue(IValue value) throws CoreException { - if (value instanceof Value) { - ((Value) value).marshall(this); - } else { - putByte(NULL_TYPE); - } - } - - @Override - public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { - if (arg.isNonTypeValue()) { - putByte(VALUE); - arg.getNonTypeEvaluation().marshal(this, true); - } else { - marshalType(arg.getTypeValue()); - } - } - - @Override - public void putByte(byte value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putFixedInt(int value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putInt(int value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putLong(long value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putCharArray(char[] chars) { - appendSeparator(); - for (char c : chars) { - fBuffer.append(c); - } - } - - private void appendSeparator() { - if (fBuffer.length() != 0) - fBuffer.append(' '); - } - - @Override - public IBinding unmarshalBinding() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public IType unmarshalType() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public ISerializableEvaluation unmarshalEvaluation() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public IValue unmarshalValue() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public int getByte() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public CoreException unmarshallingError() { - throw new UnsupportedOperationException(); - } - - @Override - public int getFixedInt() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public int getInt() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public long getLong() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public char[] getCharArray() throws CoreException { - throw new UnsupportedOperationException(); - } - } - CPPEvaluation() { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index a447998e76e..70ca109fd0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -550,14 +550,6 @@ public class CPPSemantics { if (parent instanceof ICPPASTConstructorChainInitializer) { return true; } - if (parent instanceof ICPPASTNamedTypeSpecifier) { - parent= parent.getParent(); - if (parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression) { - IASTDeclarator dtor = ((IASTTypeId) parent).getAbstractDeclarator(); - if (dtor != null && dtor.getPointerOperators().length == 0) - return true; - } - } return false; } @@ -3103,27 +3095,43 @@ public class CPPSemantics { return null; IType type = ((ICPPVariable) binding).getType(); - try { - type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); - if (!(type instanceof ICPPClassType)) - return null; - if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) - return null; + type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); + if (!(type instanceof ICPPClassType)) + return null; + if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) + return null; - final ICPPClassType classType = (ICPPClassType) type; + return findImplicitlyCalledConstructor((ICPPClassType) type, initializer, name); + } + + public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) { + IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE); + if (!(type instanceof IPointerType)) + return null; + type = ((IPointerType) type).getType(); + if (type instanceof ICPPClassType) { + return findImplicitlyCalledConstructor((ICPPClassType) type, + expr.getInitializer(), expr.getTypeId()); + } + return null; + } + + private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType type, IASTInitializer initializer, + IASTNode typeId) { + try { if (initializer instanceof IASTEqualsInitializer) { // Copy initialization. IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer; ICPPASTInitializerClause initClause = (ICPPASTInitializerClause) eqInit.getInitializerClause(); final ICPPEvaluation evaluation = initClause.getEvaluation(); - IType sourceType= evaluation.getTypeOrFunctionSet(name); - ValueCategory isLValue= evaluation.getValueCategory(name); + IType sourceType= evaluation.getTypeOrFunctionSet(typeId); + ValueCategory isLValue= evaluation.getValueCategory(typeId); if (sourceType != null) { Cost c; - if (calculateInheritanceDepth(sourceType, classType, name) >= 0) { - c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false, name); + if (calculateInheritanceDepth(sourceType, type, typeId) >= 0) { + c = Conversions.copyInitializationOfClass(isLValue, sourceType, type, false, typeId); } else { - c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, name); + c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, typeId); } if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); @@ -3136,7 +3144,7 @@ public class CPPSemantics { // List initialization. ICPPEvaluation eval= ((ICPPASTInitializerList) initializer).getEvaluation(); if (eval instanceof EvalInitList) { - Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, name); + Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, typeId); if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); if (f instanceof ICPPConstructor) @@ -3145,35 +3153,22 @@ public class CPPSemantics { } } else if (initializer instanceof ICPPASTConstructorInitializer) { // Direct initialization. - return findImplicitlyCalledConstructor(classType, - (ICPPASTConstructorInitializer) initializer, name); + return findImplicitlyCalledConstructor(type, + (ICPPASTConstructorInitializer) initializer, typeId); } else if (initializer == null) { // Default initialization. - ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); + ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(type, typeId); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; } return null; } - } catch (DOMException e) { + } catch (DOMException e) { } - return null; + return null; } - public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) { - IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE); - if (!(type instanceof IPointerType)) - return null; - type = ((IPointerType) type).getType(); - IASTInitializer initializer = expr.getInitializer(); - if (type instanceof ICPPClassType && initializer instanceof ICPPASTConstructorInitializer) { - return findImplicitlyCalledConstructor((ICPPClassType) type, - (ICPPASTConstructorInitializer) initializer, expr.getTypeId()); - } - return null; - } - private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType classType, ICPPASTConstructorInitializer initializer, IASTNode typeId) { final IASTInitializerClause[] arguments = initializer.getArguments(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 61f55dfe0fe..9e4a6d0a356 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,6 +81,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; @@ -161,9 +162,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMod * type instantiation. */ public class CPPTemplates { + // The three constants below are used as special return values for the various overloads + // of CPPTemplates.determinePackSize() and for ICPPEvaluation.determinePackSize(), which + // search a type, template argument, or value for a usage of a template parameter pack + // and return the number of arguments bound to that parameter pack in an + // ICPPTemplateParameterMap. + + // Used to indicate that the parameter pack is not bound to any arguments in the + // template parameter map. Computation of the pack size needs to be deferred until + // arguments for it become available. static final int PACK_SIZE_DEFER = -1; + + // Used to indicate that two different packs with different sizes were found. static final int PACK_SIZE_FAIL = -2; + + // Used to indicate that no template parameter packs were found. static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; + static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } /** @@ -1958,13 +1973,34 @@ public class CPPTemplates { return arg; } + private static ICPPFunctionType getFunctionTypeIgnoringParametersWithDefaults(ICPPFunction function) { + ICPPParameter[] parameters = function.getParameters(); + IType[] parameterTypes = new IType[parameters.length]; + int i; + for (i = 0; i < parameters.length; ++i) { + ICPPParameter parameter = parameters[i]; + if (!parameter.hasDefaultValue()) { + parameterTypes[i] = parameter.getType(); + } else { + break; + } + } + ICPPFunctionType originalType = function.getType(); + if (i == parameters.length) // no parameters with default arguments + return originalType; + return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes), + originalType.isConst(), originalType.isVolatile(), originalType.takesVarArgs()); + } + private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode, IASTNode point) throws DOMException { ICPPFunction transF1 = transferFunctionTemplate(f1, point); if (transF1 == null) return -1; final ICPPFunctionType ft2 = f2.getType(); - final ICPPFunctionType transFt1 = transF1.getType(); + // Ignore parameters with default arguments in the transformed function template + // as per [temp.func.order] p5. + final ICPPFunctionType transFt1 = getFunctionTypeIgnoringParametersWithDefaults(transF1); IType[] pars; IType[] args; switch(mode) { @@ -2118,8 +2154,6 @@ public class CPPTemplates { final ICPPTemplateParameter[] tpars2 = f2.getTemplateParameters(); final ICPPTemplateArgument[] targs1 = f1.getTemplateArguments(); final ICPPTemplateArgument[] targs2 = f2.getTemplateArguments(); - if (targs1.length != targs2.length) - return false; // Transfer arguments of specialization 1 final int tpars1Len = tpars1.length; @@ -2129,22 +2163,17 @@ public class CPPTemplates { final ICPPTemplateParameter param = tpars1[i]; final ICPPTemplateArgument arg = uniqueArg(param); args[i]= arg; - transferMap.put(param, arg); + if (param.isParameterPack()) { + transferMap.put(param, new ICPPTemplateArgument[] { arg }); + } else { + transferMap.put(param, arg); + } } final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point, false); // Deduce arguments for specialization 2 final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2); - if (!TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point)) - return false; - - // Compare - for (int i = 0; i < targs2.length; i++) { - ICPPTemplateArgument transferredArg2= instantiateArgument(targs2[i], deductionMap, -1, null, point); - if (!transferredArg2.isSameValue(transferredArgs1[i])) - return false; - } - return true; + return TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point); } static boolean isValidType(IType t) { @@ -2226,6 +2255,9 @@ public class CPPTemplates { pType= instantiateType(pType, map, -1, null, point); } + if (argType instanceof ICPPParameterPackType) { + argType = ((ICPPParameterPackType) argType).getType(); + } if (argType instanceof ICPPUnknownType) { return new CPPTemplateNonTypeArgument(arg.getNonTypeValue(), pType); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 74760703536..61c5c7883af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -360,8 +360,13 @@ public class EvalID extends CPPEvaluation { @Override public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = fFieldOwner != null ? fFieldOwner.determinePackSize(tpMap) : CPPTemplates.PACK_SIZE_NOT_FOUND; - for (ICPPTemplateArgument arg : fTemplateArgs) { - r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + if (fNameOwner instanceof ICPPUnknownBinding) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) fNameOwner, tpMap)); + } + if (fTemplateArgs != null) { + for (ICPPTemplateArgument arg : fTemplateArgs) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } } return r; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 5431c752d7c..5e86257e167 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -49,7 +50,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -663,46 +663,7 @@ public class SemanticUtil { return -1; } - public static boolean containsUniqueTypeForParameterPack(IType type) { - if (type instanceof ICPPFunctionType) { - final ICPPFunctionType ft = (ICPPFunctionType) type; - if (containsUniqueTypeForParameterPack(ft.getReturnType())) - return true; - - for (IType pt : ft.getParameterTypes()) { - if (containsUniqueTypeForParameterPack(pt)) - return true; - } - return false; - } - - if (type instanceof ICPPPointerToMemberType) { - if (containsUniqueTypeForParameterPack(((ICPPPointerToMemberType) type).getMemberOfClass())) - return true; - } - - if (type instanceof IBinding) { - IBinding owner = ((IBinding) type).getOwner(); - if (owner instanceof IType) { - if (containsUniqueTypeForParameterPack((IType) owner)) - return true; - } - } - - if (type instanceof ICPPTemplateInstance) { - ICPPTemplateArgument[] args = ((ICPPTemplateInstance) type).getTemplateArguments(); - for (ICPPTemplateArgument arg : args) { - if (containsUniqueTypeForParameterPack(arg.getTypeValue())) - return true; - } - } - - if (type instanceof ITypeContainer) { - final ITypeContainer tc = (ITypeContainer) type; - final IType nestedType= tc.getType(); - return containsUniqueTypeForParameterPack(nestedType); - } - + public static boolean isUniqueTypeForParameterPack(IType type) { if (type instanceof UniqueType) { return ((UniqueType) type).isForParameterPack(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java new file mode 100644 index 00000000000..7ec523e7b46 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; + +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.core.runtime.CoreException; + +class SignatureBuilder implements ITypeMarshalBuffer { + private static final byte NULL_TYPE= 0; + private static final byte UNSTORABLE_TYPE= (byte) -1; + + private final StringBuilder fBuffer; + + /** + * Constructor for input buffer. + */ + public SignatureBuilder() { + fBuffer= new StringBuilder(); + } + + @Override + public String toString() { + return fBuffer.toString(); + } + + public char[] getSignature() { + return CharArrayUtils.extractChars(fBuffer); + } + + @Override + public void marshalBinding(IBinding binding) throws CoreException { + if (binding instanceof ISerializableType) { + ((ISerializableType) binding).marshal(this); + } else if (binding == null) { + putByte(NULL_TYPE); + } else { + appendSeparator(); + if (binding instanceof ICPPBinding) { + if (binding instanceof ICPPTemplateParameter) { + ICPPTemplateParameter param = (ICPPTemplateParameter) binding; + fBuffer.append(param.isParameterPack() ? '*' : '#'); + fBuffer.append(param.getParameterID()); + } else { + fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + } + } else { + fBuffer.append(binding.getNameCharArray()); + } + } + } + + @Override + public void marshalType(IType type) throws CoreException { + if (type instanceof ISerializableType) { + ((ISerializableType) type).marshal(this); + } else if (type == null) { + putByte(NULL_TYPE); + } else if (type instanceof IBinding) { + marshalBinding((IBinding) type); + } else { + assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + putByte(UNSTORABLE_TYPE); + } + } + + @Override + public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { + if (eval == null) { + putByte(NULL_TYPE); + } else { + eval.marshal(this, includeValues); + } + } + + @Override + public void marshalValue(IValue value) throws CoreException { + if (value instanceof Value) { + ((Value) value).marshall(this); + } else { + putByte(NULL_TYPE); + } + } + + @Override + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg.isNonTypeValue()) { + putByte(VALUE); + arg.getNonTypeEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + + @Override + public void putByte(byte value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putFixedInt(int value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putInt(int value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putLong(long value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putCharArray(char[] chars) { + appendSeparator(); + for (char c : chars) { + fBuffer.append(c); + } + } + + private void appendSeparator() { + if (fBuffer.length() != 0) + fBuffer.append(' '); + } + + @Override + public IBinding unmarshalBinding() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public IType unmarshalType() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public ISerializableEvaluation unmarshalEvaluation() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public IValue unmarshalValue() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public int getByte() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public CoreException unmarshallingError() { + throw new UnsupportedOperationException(); + } + + @Override + public int getFixedInt() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public int getInt() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public long getLong() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public char[] getCharArray() throws CoreException { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 4233824ebbd..555f1ec9e77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -36,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IQualifierType; -import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IValue; @@ -431,7 +431,7 @@ public class TemplateArgumentDeduction { deduct.incPackOffset(); } else { if (j >= fnParCount) - return result; + return -1; par= fnPars[j]; if (par instanceof ICPPParameterPackType) { @@ -606,15 +606,36 @@ public class TemplateArgumentDeduction { final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, IASTNode point) throws DOMException { TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(pars, null, map, 0); - final int len= a.length; - if (p == null || p.length != len) { + if (p == null) { return false; } - for (int j= 0; j < len; j++) { - if (!deduct.fromTemplateArgument(p[j], a[j], point)) { - return false; + boolean containsPackExpansion= false; + for (int j= 0; j < p.length; j++) { + if (p[j].isPackExpansion()) { + deduct = new TemplateArgumentDeduction(deduct, a.length - j); + containsPackExpansion= true; + if (j != p.length - 1) { + return false; // A pack expansion must be the last argument to the specialization. + } + ICPPTemplateArgument pattern = p[j].getExpansionPattern(); + for (int i= j; i < a.length; i++) { + if (!deduct.fromTemplateArgument(pattern, a[i], point)) { + return false; + } + deduct.incPackOffset(); + } + break; + } else { + if (j >= a.length) { + return false; // Not enough arguments. + } + if (!deduct.fromTemplateArgument(p[j], a[j], point)) { + return false; + } } } + if (!containsPackExpansion && p.length < a.length) + return false; // Too many arguments. return verifyDeduction(pars, map, false, point); } @@ -636,16 +657,8 @@ public class TemplateArgumentDeduction { deducedArg= tpar.getDefaultValue(); if (deducedArg != null) { deducedArg= CPPTemplates.instantiateArgument(deducedArg, tpMap, -1, null, point); - if (deducedArg != null) { - if (deducedArg instanceof CPPTemplateTypeArgument) { - CPPTemplateTypeArgument deducedTypeArg = (CPPTemplateTypeArgument) deducedArg; - if (!(deducedTypeArg.getTypeValue() instanceof ISemanticProblem)) { - tpMap.put(tpar, deducedArg); - } - } else { - // TODO: Check for problems in non-type or template template parameters? - tpMap.put(tpar, deducedArg); - } + if (CPPTemplates.isValidArgument(deducedArg)) { + tpMap.put(tpar, deducedArg); } } } @@ -957,7 +970,7 @@ public class TemplateArgumentDeduction { return false; return fDeducedArgs.putPackElement(parID, fPackOffset, arg, fPackSize); } - if (SemanticUtil.containsUniqueTypeForParameterPack(arg.getTypeValue())) + if (SemanticUtil.isUniqueTypeForParameterPack(arg.getTypeValue())) return false; fDeducedArgs.put(parID, arg); return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java index 6fdd5259adc..d77e3e96595 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2012, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,9 +7,11 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; @@ -48,6 +50,17 @@ public class TypeOfDependentExpression implements ICPPUnknownType, ISerializable } } + public char[] getSignature() { + SignatureBuilder buf = new SignatureBuilder(); + try { + marshal(buf); + } catch (CoreException e) { + CCorePlugin.log(e); + return new char[] { '?' }; + } + return buf.getSignature(); + } + @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { buffer.putByte(ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java index fee6a0479b0..3c62af24107 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java @@ -130,7 +130,7 @@ abstract class LocationCtx implements ILocationCtx { * Returns the sequence of file locations spanning the given range. * Assumes that the range starts within this context. */ - public abstract boolean collectLocations(int sequenceNumber, int length, ArrayList sofar); + public abstract void collectLocations(int sequenceNumber, int length, ArrayList sofar); /** * Support for the dependency tree, add inclusion statements found in this context. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java index 6323e537149..4e11a04c5fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java @@ -32,7 +32,7 @@ class LocationCtxContainer extends LocationCtx { private int fChildSequenceLength; private ArrayList fChildren; - private AbstractCharArray fSource; + private final AbstractCharArray fSource; private int[] fLineOffsets; public LocationCtxContainer(LocationCtxContainer parent, AbstractCharArray source, @@ -138,47 +138,55 @@ class LocationCtxContainer extends LocationCtx { } @Override - public boolean collectLocations(int sequenceNumber, final int length, ArrayList locations) { + public void collectLocations(int sequenceNumber, final int length, ArrayList locations) { + if (length < 1) + return; + final int endSequenceNumber= sequenceNumber + length; if (fChildren != null) { int childIdx= Math.max(0, findChildIdxLessOrEqualThan(sequenceNumber, false)); for (; childIdx < fChildren.size(); childIdx++) { final LocationCtx child= fChildren.get(childIdx); - // create the location between start and the child + // Create the location between start and the child if (sequenceNumber < child.fSequenceNumber) { - // compute offset backwards from the child's offset + // Compute offset backwards from the child's offset in this location final int offset= child.fEndOffsetInParent - (child.fSequenceNumber - sequenceNumber); - // it the child is not affected, we are done. + + // Requested range ends before the child. if (endSequenceNumber <= child.fSequenceNumber) { addFileLocation(offset, endSequenceNumber - sequenceNumber, locations); - return true; + return; } - if (offset < child.fOffsetInParent) + + final int gapLen = child.fOffsetInParent - offset; + if (gapLen > 0) addFileLocation(offset, child.fOffsetInParent - offset, locations); + sequenceNumber= child.fSequenceNumber; + assert sequenceNumber < endSequenceNumber; } - // let the child create locations + // Let the child create locations final int childEndSequenceNumber= child.fSequenceNumber + child.getSequenceLength(); - if (sequenceNumber < childEndSequenceNumber) { - if (child.collectLocations(sequenceNumber, endSequenceNumber - sequenceNumber, locations)) { - return true; - } + if (sequenceNumber < childEndSequenceNumber + || (sequenceNumber == childEndSequenceNumber && !locations.isEmpty())) { + child.collectLocations(sequenceNumber, endSequenceNumber - sequenceNumber, locations); sequenceNumber= childEndSequenceNumber; + if (sequenceNumber >= endSequenceNumber) + return; } } } - // create the location after the last child. + // Create the location after the last child. final int myEndNumber = fSequenceNumber + getSequenceLength(); final int offset= fSource.getLength() - (myEndNumber - sequenceNumber); if (endSequenceNumber <= myEndNumber) { addFileLocation(offset, endSequenceNumber - sequenceNumber, locations); - return true; + } else { + addFileLocation(offset, fSource.getLength() - offset, locations); } - addFileLocation(offset, fSource.getLength() - offset, locations); - return false; } private ArrayList addFileLocation(int offset, int length, ArrayList sofar) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java index d94e229e8fb..90bba002862 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java @@ -25,7 +25,7 @@ class LocationCtxMacroExpansion extends LocationCtx { private final LocationMap fLocationMap; private final int fLength; private final ImageLocationInfo[] fLocationInfos; - private ASTMacroReferenceName fExpansionName; + private final ASTMacroReferenceName fExpansionName; public LocationCtxMacroExpansion(LocationMap map, LocationCtxContainer parent, int parentOffset, int parentEndOffset, int sequenceNumber, int length, ImageLocationInfo[] imageLocations, ASTMacroReferenceName expansionName) { @@ -45,17 +45,15 @@ class LocationCtxMacroExpansion extends LocationCtx { } @Override - public boolean collectLocations(int start, int length, ArrayList locations) { + public void collectLocations(int start, int length, ArrayList locations) { final int offset= start - fSequenceNumber; assert offset >= 0 && length >= 0; if (offset + length <= fLength) { locations.add(new ASTMacroExpansionLocation(this, offset, length)); - return true; + } else { + locations.add(new ASTMacroExpansionLocation(this, offset, fLength-offset)); } - - locations.add(new ASTMacroExpansionLocation(this, offset, fLength-offset)); - return false; } public ASTMacroExpansion getExpansion() { diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 24270197e2c..b0a0c3a9e7a 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -268,7 +268,7 @@ - + diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java index 4de0f8a1942..8fe56f6fe83 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java @@ -20,7 +20,7 @@ import junit.framework.TestSuite; import org.eclipse.jface.text.IRegion; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.ui.testplugin.CTestPlugin; @@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.ui.search.LinkedNamesFinder; /** * Tests for LinkedNamesFinder class. */ -public class LinkedNamesFinderTest extends AST2BaseTest { +public class LinkedNamesFinderTest extends AST2TestBase { private static class RegionComparator implements Comparator { @Override public int compare(IRegion r1, IRegion r2) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java index a44a925f671..c70d7b77511 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java @@ -1,11 +1,11 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2000, 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) - Adapted for CDT *******************************************************************************/ @@ -20,13 +20,12 @@ import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings; /** * Semantic highlighting tests. - * + * *

Derived from JDT.

* * @since 4.0 */ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { - private static final boolean PRINT_POSITIONS= false; private static final Class THIS= SemanticHighlightingTest.class; @@ -101,7 +100,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(108, 4, 26), createPosition(112, 4, 25), createPosition(117, 4, 32), - }; + }; if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); } @@ -121,10 +120,9 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(108, 4, 26), createPosition(112, 4, 25), createPosition(117, 4, 32), - createPosition(118, 23, 9), createPosition(122, 4, 15), createPosition(130, 13, 9), - }; + }; Position[] actual= getSemanticHighlightingPositions(); if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); @@ -134,7 +132,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { setUpSemanticHighlighting(SemanticHighlightings.STATIC_METHOD_INVOCATION); Position[] expected= new Position[] { createPosition(122, 4, 15), - }; + }; Position[] actual= getSemanticHighlightingPositions(); if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); @@ -256,6 +254,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(112, 4, 14), createPosition(117, 4, 14), createPosition(118, 4, 9), + createPosition(118, 23, 9), createPosition(120, 4, 8), createPosition(129, 4, 8), createPosition(147, 42, 7), @@ -297,7 +296,6 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { assertEqualPositions(expected, actual); } - public void testGlobalVariableHighlighting() throws Exception { setUpSemanticHighlighting(SemanticHighlightings.GLOBAL_VARIABLE); Position[] actual= getSemanticHighlightingPositions(); @@ -421,5 +419,4 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); } - } diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 51c079b50e5..82a725516ba 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -629,9 +629,11 @@ LanguageSettingsProviderAssociationExtensionPoint=Language Settings Provider UI overrideAnnotation.label = C/C++ Override indicators transfer.EditorAppearance.name = C/C++ Editor Appearance -transfer.EditorAppearance.description = Preference related to how the editor presents the edited code to the user (including colors, fonts, hovers, foldings, etc...) +transfer.EditorAppearance.description = Preferences related to how the editor presents the edited code to the user (including colors, fonts, hovers, foldings, etc...) transfer.EditorBehavior.name = C/C++ Editor Behavior -transfer.EditorBehavior.description = Preference related to how the editor process the edited code (typing, save action, etc...) +transfer.EditorBehavior.description = Preferences related to how the editor deals with the edited code (typing, save action, etc...) +transfer.CodeStyle.name = C/C++ Code Style +transfer.CodeStyle.description = C/C++ > Code Style preferences # Refresh Exclusion Contributors RefreshExclusionContributor.name = Resources diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 141ab089c59..d748f309685 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4499,6 +4499,7 @@ @@ -4557,6 +4558,7 @@ @@ -4590,15 +4592,31 @@ - - + %transfer.EditorBehavior.description + + + + + + + + + + + + + %transfer.CodeStyle.description + + , IDialogFieldListener { - @Override public void selectionChanged(TreeListDialogField field) { updateConfigurationBlock(field.getSelectedElements()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java index 73ba44c79ae..432971e4673 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java @@ -32,7 +32,6 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.ui.CUIPlugin; public class CUILabelProvider extends LabelProvider implements IColorProvider, IStyledLabelProvider { - protected CElementImageProvider fImageLabelProvider; protected StorageLabelProvider fStorageLabelProvider; @@ -136,9 +135,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return image; } - /* (non-Javadoc) - * @see ILabelProvider#getImage - */ @Override public Image getImage(Object element) { Image result= fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element)); @@ -159,10 +155,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return text; } - - /* (non-Javadoc) - * @see ILabelProvider#getText - */ @Override public String getText(Object element) { String result= CElementLabels.getTextLabel(element, evaluateTextFlags(element)); @@ -186,10 +178,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return string; } - - /* (non-Javadoc) - * @see IBaseLabelProvider#dispose - */ @Override public void dispose() { if (fLabelDecorators != null) { @@ -203,9 +191,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I fImageLabelProvider.dispose(); } - /* (non-Javadoc) - * @see IBaseLabelProvider#addListener(ILabelProviderListener) - */ @Override public void addListener(ILabelProviderListener listener) { if (fLabelDecorators != null) { @@ -217,17 +202,11 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I super.addListener(listener); } - /* (non-Javadoc) - * @see IBaseLabelProvider#isLabelProperty(Object, String) - */ @Override public boolean isLabelProperty(Object element, String property) { return true; } - /* (non-Javadoc) - * @see IBaseLabelProvider#removeListener(ILabelProviderListener) - */ @Override public void removeListener(ILabelProviderListener listener) { if (fLabelDecorators != null) { @@ -252,9 +231,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return null; } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) - */ @Override public Color getForeground(Object element) { if (element instanceof ISourceReference) { @@ -270,12 +246,8 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return fDefaultColor; } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) - */ @Override public Color getBackground(Object element) { return null; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 9e9bb99d4e3..d7d6f46f710 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -7,9 +7,13 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; @@ -41,7 +45,7 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; /** * LabelDecorator that decorates an element's image with error and warning overlays that * represent the severity of markers attached to the element's underlying resource. To see - * a problem decoration for a marker, the marker needs to be a subtype of IMarker.PROBLEM. + * a problem decoration for a marker, the marker needs to be a subtype of {@code IMarker.PROBLEM}. *

* Note: Only images for elements in Java projects are currently updated on marker changes. *

@@ -49,23 +53,20 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; * @since 2.0 */ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator { - /** - * This is a special LabelProviderChangedEvent carring additional - * information whether the event orgins from a maker change. + * This is a special {@code LabelProviderChangedEvent} carrying additional + * information whether the event originates from a maker change. *

- * ProblemsLabelChangedEvents are only generated by - * ProblemsLabelDecorators. - *

+ * {@code ProblemsLabelChangedEvent}s are only generated by {@code ProblemsLabelDecorator}s. */ public static class ProblemsLabelChangedEvent extends LabelProviderChangedEvent { - private boolean fMarkerChange; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ - public ProblemsLabelChangedEvent(IBaseLabelProvider source, IResource[] changedResource, boolean isMarkerChange) { + public ProblemsLabelChangedEvent(IBaseLabelProvider source, IResource[] changedResource, + boolean isMarkerChange) { super(source, changedResource); fMarkerChange= isMarkerChange; } @@ -80,17 +81,45 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe public boolean isMarkerChange() { return fMarkerChange; } + } + private static class MarkersCacheKey { + private IResource res; + private int depth; + + public MarkersCacheKey(IResource res, int depth) { + this.res = res; + this.depth = depth; + } + + @Override + public int hashCode() { + return res.hashCode() + 31 * depth; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MarkersCacheKey other = (MarkersCacheKey) obj; + return depth == other.depth && res.equals(other.res); + } } private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING; private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR; + private static final IMarker[] EMPTY_MARKER_ARRAY = {}; private ImageDescriptorRegistry fRegistry; - private boolean fUseNewRegistry= false; + private boolean fUseNewRegistry; private IProblemChangedListener fProblemChangedListener; private ListenerList fListeners; + private Map fMarkersCache = new HashMap(); /** * Creates a new ProblemsLabelDecorator. @@ -119,7 +148,6 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return fRegistry; } - @Override public String decorateText(String text, Object element) { return text; @@ -175,23 +203,29 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return 0; } - private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException { + private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) + throws CoreException { if (res == null || !res.isAccessible()) { return 0; } int info= 0; - IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth); - if (markers != null) { - for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { - IMarker curr= markers[i]; - if (sourceElement == null || isMarkerInRange(curr, sourceElement)) { - int priority= curr.getAttribute(IMarker.SEVERITY, -1); - if (priority == IMarker.SEVERITY_WARNING) { - info= ERRORTICK_WARNING; - } else if (priority == IMarker.SEVERITY_ERROR) { - info= ERRORTICK_ERROR; - } + MarkersCacheKey cacheKey = new MarkersCacheKey(res, depth); + IMarker[] markers = fMarkersCache .get(cacheKey); + if (markers == null) { + markers= res.findMarkers(IMarker.PROBLEM, true, depth); + if (markers == null) + markers = EMPTY_MARKER_ARRAY; + fMarkersCache.put(cacheKey, markers); + } + for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { + IMarker curr= markers[i]; + if (sourceElement == null || isMarkerInRange(curr, sourceElement)) { + int priority= curr.getAttribute(IMarker.SEVERITY, -1); + if (priority == IMarker.SEVERITY_WARNING) { + info= ERRORTICK_WARNING; + } else if (priority == IMarker.SEVERITY_ERROR) { + info= ERRORTICK_ERROR; } } } @@ -228,7 +262,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException { ISourceRange range= sourceElement.getSourceRange(); if (range != null) { - if (offSet ==-1) { + if (offSet == -1) { return (line >= range.getStartLine() && line <= range.getEndLine()); } int rangeOffset= range.getStartPos(); @@ -282,6 +316,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) { + fMarkersCache.clear(); if (fListeners != null && !fListeners.isEmpty()) { LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange); Object[] listeners= fListeners.getListeners(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java index b2cd29b36cf..c4d0357ad3d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 QNX Software Systems and others. + * Copyright (c) 2004, 2013 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,7 +29,6 @@ public final class NewClassWizardMessages extends NLS { public static String NewClassCreationWizardPage_namespace_label; public static String NewClassCreationWizardPage_namespace_button; public static String NewClassCreationWizardPage_error_EnterNamespace; - public static String NewClassCreationWizardPage_error_EnclosingNamespaceNotExists; public static String NewClassCreationWizardPage_error_NamespaceExistsDifferentCase; public static String NewClassCreationWizardPage_error_TypeMatchingNamespaceExists; public static String NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties index ff35ba93539..34b3bdbb72e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2004, 2011 QNX Software Systems and others. +# Copyright (c) 2004, 2013 QNX Software Systems and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -34,11 +34,10 @@ NewClassCreationWizardPage_namespace_label=&Namespace: NewClassCreationWizardPage_namespace_button=Bro&wse... NewClassCreationWizardPage_error_EnterNamespace=Namespace is empty. -NewClassCreationWizardPage_error_EnclosingNamespaceNotExists=Enclosing namespace does not exist. NewClassCreationWizardPage_error_NamespaceExistsDifferentCase=Namespace with the same name exists in a different scope. NewClassCreationWizardPage_error_TypeMatchingNamespaceExists=Another type with the same name as specified namespace exists. NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase=Another type with the same name as specified namespace exists in a different scope. -NewClassCreationWizardPage_warning_NamespaceNotExists=Namespace does not exist. A new namespace will be created. +NewClassCreationWizardPage_warning_NamespaceNotExists=Namespace ''{0}'' does not exist. A new namespace will be created. NewClassCreationWizardPage_error_InvalidNamespace=Namespace is not valid. {0}. NewClassCreationWizardPage_warning_NamespaceDiscouraged=Namespace is discouraged. {0}. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java index 4ce3ebc734d..58b995452c2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 QNX Software Systems and others. + * Copyright (c) 2004, 2013 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1591,17 +1591,8 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { ICProject project = getCurrentProject(); if (project != null) { - /* search for parent name space first */ - int searchResult; - if (typeName.isQualified()) { - searchResult = NewClassWizardUtil.searchForCppType(typeName.getEnclosingTypeName(),project, ICPPNamespace.class); - if (searchResult != NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT) { - status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_EnclosingNamespaceNotExists); - return status; - } - } - searchResult = NewClassWizardUtil.searchForCppType(typeName, project, ICPPNamespace.class); - switch(searchResult) { + int searchResult = NewClassWizardUtil.searchForCppType(typeName, project, ICPPNamespace.class); + switch (searchResult) { case NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT: status.setOK(); return status; @@ -1615,7 +1606,17 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { status.setWarning(NewClassWizardMessages.NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase); return status; case NewClassWizardUtil.SEARCH_MATCH_NOTFOUND: - status.setWarning(NewClassWizardMessages.NewClassCreationWizardPage_warning_NamespaceNotExists); + // Find the highest ancestor namespace that does not exist. + IQualifiedTypeName ns = typeName; + while (ns.isQualified()) { + IQualifiedTypeName ns1 = ns.getEnclosingTypeName(); + if (NewClassWizardUtil.searchForCppType(ns1, project, ICPPNamespace.class) == NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT) { + break; + } + ns = ns1; + } + status.setWarning(NLS.bind(NewClassWizardMessages.NewClassCreationWizardPage_warning_NamespaceNotExists, + ns.getFullyQualifiedName())); break; } } @@ -1638,7 +1639,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { StatusInfo status = new StatusInfo(); String className = getClassName(); - // must not be empty + // Must not be empty. if (className == null || className.length() == 0) { status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_EnterClassName); return status; @@ -1669,7 +1670,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { } } int searchResult = NewClassWizardUtil.searchForCppType(fullyQualifiedName, project, ICPPClassType.class); - switch(searchResult) { + switch (searchResult) { case NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT: status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_ClassNameExists); return status; @@ -1729,7 +1730,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { MultiStatus status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project.getProject()); if (provider != null) { - //TODO get the scanner info for the actual source folder + // TODO Get the scanner info for the actual source folder. IScannerInfo info = provider.getScannerInformation(project.getProject()); if (info != null) { String[] includePaths = info.getIncludePaths(); diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java index a9516535121..2cf7e37db34 100644 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java +++ b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.utils.ui.controls; - import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -22,34 +21,33 @@ import org.eclipse.swt.widgets.Layout; * @noextend This class is not intended to be subclassed by clients. */ public class TabFolderLayout extends Layout { - @Override - protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) return new Point(wHint, hHint); - - Control [] children = composite.getChildren (); + + Control[] children = composite.getChildren(); int count = children.length; int maxWidth = 0, maxHeight = 0; - for (int i=0; i - + + @@ -2079,6 +2084,10 @@ class="org.eclipse.cdt.debug.internal.ui.commands.ConnectCommandHandler" commandId="org.eclipse.cdt.debug.ui.command.connect"> + + @@ -2520,6 +2529,28 @@ + + + + + getCommandType() { + return IDebugNewExecutableHandler.class; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java index dd917d98ddc..64f1a4e5cc3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java @@ -124,6 +124,12 @@ public class ReverseToggleCommandHandler extends DebugCommandHandler implements return adapter; } + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.actions.DebugCommandHandler#postExecute(org.eclipse.debug.core.IRequest, java.lang.Object[]) + * + * We keep this logic for users that may not do the refresh themselves. + */ @Override protected void postExecute(IRequest request, Object[] targets) { super.postExecute(request, targets); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java index a35c0913306..51d5f2ea88b 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java @@ -19,6 +19,7 @@ import java.util.WeakHashMap; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.IConnectHandler; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; import org.eclipse.cdt.debug.core.model.IResumeWithoutSignalHandler; import org.eclipse.cdt.debug.core.model.IReverseResumeHandler; import org.eclipse.cdt.debug.core.model.IReverseStepIntoHandler; @@ -49,6 +50,7 @@ import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbDisconnectCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbRestartCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbSteppingModeTarget; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbConnectCommand; +import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbDebugNewExecutableCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbResumeWithoutSignalCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbReverseResumeCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbReverseStepIntoCommand; @@ -114,6 +116,7 @@ public class GdbAdapterFactory final GdbResumeWithoutSignalCommand fResumeWithoutSignalCommand; final GdbRestartCommand fRestartCommand; final DsfTerminateCommand fTerminateCommand; + final GdbDebugNewExecutableCommand fDebugNewExecutableCommand; final GdbConnectCommand fConnectCommand; final GdbDisconnectCommand fDisconnectCommand; final IDebugModelProvider fDebugModelProvider; @@ -162,7 +165,8 @@ public class GdbAdapterFactory fResumeWithoutSignalCommand = new GdbResumeWithoutSignalCommand(session); fRestartCommand = new GdbRestartCommand(session, fLaunch); fTerminateCommand = new DsfTerminateCommand(session); - fConnectCommand = new GdbConnectCommand(session); + fDebugNewExecutableCommand = new GdbDebugNewExecutableCommand(session, fLaunch); + fConnectCommand = new GdbConnectCommand(session, fLaunch); fDisconnectCommand = new GdbDisconnectCommand(session); fSuspendTrigger = new GdbSuspendTrigger(session, fLaunch); fModelSelectionPolicyFactory = new DefaultDsfModelSelectionPolicyFactory(); @@ -189,6 +193,7 @@ public class GdbAdapterFactory session.registerModelAdapter(IRestartHandler.class, fRestartCommand); session.registerModelAdapter(ITerminateHandler.class, fTerminateCommand); session.registerModelAdapter(IConnectHandler.class, fConnectCommand); + session.registerModelAdapter(IDebugNewExecutableHandler.class, fDebugNewExecutableCommand); session.registerModelAdapter(IDisconnectHandler.class, fDisconnectCommand); session.registerModelAdapter(IModelSelectionPolicyFactory.class, fModelSelectionPolicyFactory); session.registerModelAdapter(IRefreshAllTarget.class, fRefreshAllTarget); @@ -249,6 +254,7 @@ public class GdbAdapterFactory session.unregisterModelAdapter(IRestartHandler.class); session.unregisterModelAdapter(ITerminateHandler.class); session.unregisterModelAdapter(IConnectHandler.class); + session.unregisterModelAdapter(IDebugNewExecutableHandler.class); session.unregisterModelAdapter(IDisconnectHandler.class); session.unregisterModelAdapter(IModelSelectionPolicyFactory.class); session.unregisterModelAdapter(IRefreshAllTarget.class); @@ -279,6 +285,7 @@ public class GdbAdapterFactory fRestartCommand.dispose(); fTerminateCommand.dispose(); fConnectCommand.dispose(); + fDebugNewExecutableCommand.dispose(); fDisconnectCommand.dispose(); fSuspendTrigger.dispose(); fReverseToggleTarget.dispose(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java index d797a6e48ae..5a50b774632 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java @@ -20,6 +20,7 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.model.IConnectHandler; import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; @@ -35,9 +36,11 @@ import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMData; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.actions.IConnect; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.ProcessInfo; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.LaunchUIMessages; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter.PrompterInfo; @@ -68,7 +71,8 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.progress.UIJob; public class GdbConnectCommand extends AbstractDebugCommand implements IConnectHandler, IConnect { - + + private final GdbLaunch fLaunch; private final DsfExecutor fExecutor; private final DsfServicesTracker fTracker; @@ -82,7 +86,8 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH // the binary location for a local attach session. private Map fProcessNameToBinaryMap = new HashMap(); - public GdbConnectCommand(DsfSession session) { + public GdbConnectCommand(DsfSession session, GdbLaunch launch) { + fLaunch = launch; fExecutor = session.getExecutor(); fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId()); } @@ -143,10 +148,12 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH IProcessExtendedInfo[] fProcessList = null; DataRequestMonitor fRequestMonitor; boolean fNewProcessSupported; + boolean fRemote; - public PromptForPidJob(String name, boolean newProcessSupported, IProcessExtendedInfo[] procs, DataRequestMonitor rm) { + public PromptForPidJob(String name, boolean newProcessSupported, boolean remote, IProcessExtendedInfo[] procs, DataRequestMonitor rm) { super(name); fNewProcessSupported = newProcessSupported; + fRemote = remote; fProcessList = procs; fRequestMonitor = rm; } @@ -158,11 +165,11 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH null); try { - PrompterInfo info = new PrompterInfo(fNewProcessSupported, fProcessList); + PrompterInfo info = new PrompterInfo(fNewProcessSupported, fRemote, fProcessList); Object result = new ProcessPrompter().handleStatus(null, info); if (result == null) { fRequestMonitor.cancel(); - } else if (result instanceof IProcessExtendedInfo[] || result instanceof String) { + } else if (result instanceof IProcessExtendedInfo[] || result instanceof NewExecutableInfo) { fRequestMonitor.setData(result); } else if (result instanceof Integer) { // This is the case where the user typed in a pid number directly @@ -288,9 +295,11 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH public void run() { final IProcesses procService = fTracker.getService(IProcesses.class); ICommandControlService commandControl = fTracker.getService(ICommandControlService.class); + IGDBBackend backend = fTracker.getService(IGDBBackend.class); - if (procService != null && commandControl != null) { + if (procService != null && commandControl != null && backend != null) { final ICommandControlDMContext controlCtx = commandControl.getContext(); + final boolean remote = backend.getSessionType() == SessionType.REMOTE; // First check if the "New..." button should be enabled. procService.isDebugNewProcessSupported(controlCtx, new DataRequestMonitor(fExecutor, rm) { @@ -314,7 +323,8 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH // Prompt the user to choose one or more processes, or to start a new one new PromptForPidJob( LaunchUIMessages.getString("ProcessPrompter.PromptJob"), //$NON-NLS-1$ - newProcessSupported, + newProcessSupported, + remote, procInfoList.toArray(new IProcessExtendedInfo[procInfoList.size()]), new DataRequestMonitor(fExecutor, rm) { @Override @@ -325,9 +335,9 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH @Override protected void handleSuccess() { Object data = getData(); - if (data instanceof String) { + if (data instanceof NewExecutableInfo) { // User wants to start a new process - startNewProcess(controlCtx, (String)data, rm); + startNewProcess(controlCtx, (NewExecutableInfo)data, rm); } else if (data instanceof IProcessExtendedInfo[]) { attachToProcesses(controlCtx, (IProcessExtendedInfo[])data, rm); } else { @@ -412,11 +422,23 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH }); } - private void startNewProcess(ICommandControlDMContext controlDmc, String binaryPath, RequestMonitor rm) { + private void startNewProcess(ICommandControlDMContext controlDmc, NewExecutableInfo info, RequestMonitor rm) { IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); - procService.debugNewProcess( - controlDmc, binaryPath, - new HashMap(), new DataRequestMonitor(fExecutor, rm)); + try { + @SuppressWarnings("unchecked") + Map attributes = fLaunch.getLaunchConfiguration().getAttributes(); + attributes.put(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, info.getTargetPath()); + attributes.put(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, info.getArguments()); + procService.debugNewProcess( + controlDmc, + info.getHostPath(), + attributes, + new DataRequestMonitor(fExecutor, rm)); + } + catch(CoreException e) { + rm.setStatus(e.getStatus()); + rm.done(); + } } private void attachToProcesses(final ICommandControlDMContext controlDmc, IProcessExtendedInfo[] processes, final RequestMonitor rm) { diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java new file mode 100644 index 00000000000..4631445ea5c --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; + +import java.util.Map; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.RejectedExecutionException; + +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.DsfExecutor; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.Query; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.debug.service.IProcesses; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableDialog; +import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; +import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; +import org.eclipse.cdt.dsf.gdb.service.SessionType; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.IRequest; +import org.eclipse.debug.core.commands.AbstractDebugCommand; +import org.eclipse.debug.core.commands.IEnabledStateRequest; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.progress.UIJob; + +public class GdbDebugNewExecutableCommand extends AbstractDebugCommand implements IDebugNewExecutableHandler { + + private class PromptJob extends UIJob { + + private DataRequestMonitor fRequestMonitor; + private boolean fRemote = false; + + private PromptJob( boolean remote, DataRequestMonitor rm ) { + super( Messages.GdbDebugNewExecutableCommand_New_Executable_Prompt_Job ); + fRemote = remote; + fRequestMonitor = rm; + } + + @Override + public IStatus runInUIThread( IProgressMonitor monitor ) { + int flags = ( fRemote ) ? NewExecutableDialog.REMOTE : 0; + NewExecutableDialog dialog = new NewExecutableDialog( GdbUIPlugin.getShell(), flags ); + final boolean canceled = dialog.open() == Window.CANCEL; + final NewExecutableInfo info = dialog.getExecutableInfo(); + fExecutor.execute( new DsfRunnable() { + + @Override + public void run() { + if ( canceled ) + fRequestMonitor.cancel(); + else + fRequestMonitor.setData( info ); + fRequestMonitor.done(); + } + } ); + return Status.OK_STATUS; + } + } + + private final GdbLaunch fLaunch; + private final DsfExecutor fExecutor; + private final DsfServicesTracker fTracker; + + public GdbDebugNewExecutableCommand( DsfSession session, GdbLaunch launch ) { + super(); + fLaunch = launch; + fExecutor = session.getExecutor(); + fTracker = new DsfServicesTracker( GdbUIPlugin.getBundleContext(), session.getId() ); + } + + public boolean canDebugNewExecutable() { + + Query canDebugQuery = new Query() { + @Override + public void execute( DataRequestMonitor rm ) { + IProcesses procService = fTracker.getService( IProcesses.class ); + ICommandControlService commandControl = fTracker.getService( ICommandControlService.class ); + + if ( procService == null || commandControl == null ) { + rm.setData( false ); + rm.done(); + return; + } + procService.isDebugNewProcessSupported( commandControl.getContext(), rm ); + } + }; + try { + fExecutor.execute( canDebugQuery ); + return canDebugQuery.get(); + } + catch( InterruptedException e ) { + } + catch( ExecutionException e ) { + } + catch( RejectedExecutionException e ) { + // Can be thrown if the session is shutdown + } + return false; + } + + public void debugNewExecutable( final RequestMonitor rm ) { + IGDBBackend backend = fTracker.getService( IGDBBackend.class ); + final IProcesses procService = fTracker.getService( IProcesses.class ); + final ICommandControlService commandControl = fTracker.getService( ICommandControlService.class ); + if ( backend == null || procService == null || commandControl == null ) { + rm.setStatus( new Status( IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, "Service is not available" ) ); //$NON-NLS-1$ + rm.done(); + return; + } + + PromptJob job = new PromptJob( + backend.getSessionType() == SessionType.REMOTE, + new DataRequestMonitor( fExecutor, rm ){ + + @Override + protected void handleCancel() { + rm.cancel(); + rm.done(); + }; + + @Override + protected void handleSuccess() { + try { + @SuppressWarnings( "unchecked" ) + Map attributes = getLaunchConfiguration().getAttributes(); + attributes.put( IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, getData().getTargetPath() ); + attributes.put( ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getData().getArguments() ); + procService.debugNewProcess( + commandControl.getContext(), + getData().getHostPath(), + attributes, + new ImmediateDataRequestMonitor( rm ) ); + } + catch( CoreException e ) { + rm.setStatus( e.getStatus() ); + rm.done(); + } + }; + } ); + job.schedule(); + } + + @Override + protected void doExecute( Object[] targets, IProgressMonitor monitor, IRequest request ) throws CoreException { + Query query = new Query() { + + @Override + protected void execute( DataRequestMonitor rm ) { + debugNewExecutable( rm ); + } + }; + try { + fExecutor.execute( query ); + query.get(); + } + catch( InterruptedException e ) { + } + catch( ExecutionException e ) { + } + catch( CancellationException e ) { + // Nothing to do, just ignore the command since the user + // cancelled it. + } + catch( RejectedExecutionException e ) { + // Can be thrown if the session is shutdown + } + } + + @Override + protected boolean isExecutable( Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request ) throws CoreException { + return canDebugNewExecutable(); + } + + @Override + protected Object getTarget( Object element ) { + if ( element instanceof GdbLaunch || element instanceof IDMVMContext ) + return element; + return null; + } + + public void dispose() { + fTracker.dispose(); + } + + private ILaunchConfiguration getLaunchConfiguration() { + return fLaunch.getLaunchConfiguration(); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java index dd236ed83d0..d02a5008215 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson and others. + * Copyright (c) 2009, 2013 Ericsson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Ericsson - initial API and implementation + * Marc Khouzam (Ericsson) - Listen for IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.commands; @@ -16,6 +17,7 @@ import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.core.model.IReverseToggleHandler; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; @@ -24,15 +26,23 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl.IReverseModeChangedDMEvent; +import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.IRequest; import org.eclipse.debug.core.commands.AbstractDebugCommand; import org.eclipse.debug.core.commands.IDebugCommandRequest; import org.eclipse.debug.core.commands.IEnabledStateRequest; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.progress.WorkbenchJob; +import org.eclipse.ui.services.IEvaluationService; /** * Command that toggles the Reverse Debugging feature @@ -42,13 +52,33 @@ import org.eclipse.debug.core.commands.IEnabledStateRequest; public class GdbReverseToggleCommand extends AbstractDebugCommand implements IReverseToggleHandler { private final DsfExecutor fExecutor; private final DsfServicesTracker fTracker; + private final DsfSession fSession; public GdbReverseToggleCommand(DsfSession session) { fExecutor = session.getExecutor(); fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId()); + fSession = session; + try { + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + fSession.addServiceEventListener(GdbReverseToggleCommand.this, null); + } + }); + } catch(RejectedExecutionException e) {} } public void dispose() { + try { + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + fSession.removeServiceEventListener(GdbReverseToggleCommand.this); + } + }); + } catch (RejectedExecutionException e) { + // Session already gone. + } fTracker.dispose(); } @@ -195,4 +225,30 @@ public class GdbReverseToggleCommand extends AbstractDebugCommand implements IRe return false; } + + /** + * @noreference This method is not intended to be referenced by clients. + */ + @DsfServiceEventHandler + public void eventDispatched(IReverseModeChangedDMEvent e) { + new WorkbenchJob("") { //$NON-NLS-1$ + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + // Request re-evaluation of property "org.eclipse.cdt.debug.ui.isReverseDebuggingEnabled" to update + // visibility of reverse stepping commands. + IEvaluationService exprService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class); + if (exprService != null) { + exprService.requestEvaluation("org.eclipse.cdt.debug.ui.isReverseDebuggingEnabled"); //$NON-NLS-1$ + } + // Refresh reverse toggle commands with the new state of reverse enabled. + // This is in order to keep multiple toggle actions in UI in sync. + ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + if (commandService != null) { + commandService.refreshElements("org.eclipse.cdt.debug.ui.command.reverseToggle", null); //$NON-NLS-1$ + } + + return Status.OK_STATUS; + } + }.schedule(); + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java index 6087a96b686..c0c89fd2251 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java @@ -7,6 +7,7 @@ * * Contributors: * Ericsson - initial API and implementation + * Marc Khouzam (Ericsson) - Instruction-level step-return does not make sense (bug 399123) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.commands; @@ -26,7 +27,6 @@ public class GdbUncallCommand extends GdbAbstractReverseStepCommand implements I @Override protected final StepType getStepType() { - boolean instructionSteppingEnabled = getSteppingMode() != null && getSteppingMode().isInstructionSteppingEnabled(); - return instructionSteppingEnabled ? StepType.INSTRUCTION_STEP_RETURN : StepType.STEP_RETURN; + return StepType.STEP_RETURN; } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java new file mode 100644 index 00000000000..a8d5629cd7f --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + public static String GdbDebugNewExecutableCommand_Arguments; + + public static String GdbDebugNewExecutableCommand_Binary; + + public static String GdbDebugNewExecutableCommand_Binary_file_does_not_exist; + + public static String GdbDebugNewExecutableCommand_Binary_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Binary_on_host; + + public static String GdbDebugNewExecutableCommand_Binary_on_target; + + public static String GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Browse; + + public static String GdbDebugNewExecutableCommand_Debug_New_Executable; + + public static String GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist; + + public static String GdbDebugNewExecutableCommand_Host_binary_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Invalid_binary; + + public static String GdbDebugNewExecutableCommand_Invalid_host_binary; + + public static String GdbDebugNewExecutableCommand_New_Executable_Prompt_Job; + + public static String GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target; + + public static String GdbDebugNewExecutableCommand_Select_Binary; + + public static String GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments; + static { + // initialize resource bundle + NLS.initializeMessages( Messages.class.getName(), Messages.class ); + } + + private Messages() { + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties new file mode 100644 index 00000000000..d601bc6d839 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties @@ -0,0 +1,28 @@ +############################################################################### +# Copyright (c) 2012 Mentor Graphics and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Mentor Graphics - Initial API and implementation +############################################################################### + +GdbDebugNewExecutableCommand_Arguments=Arguments: +GdbDebugNewExecutableCommand_Binary=Binary: +GdbDebugNewExecutableCommand_Binary_file_does_not_exist=Binary file does not exist +GdbDebugNewExecutableCommand_Binary_must_be_specified=Binary must be specified +GdbDebugNewExecutableCommand_Binary_on_host=Binary on host: +GdbDebugNewExecutableCommand_Binary_on_target=Binary on target: +GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified=Binary on target must be specified +GdbDebugNewExecutableCommand_Browse=Browse... +GdbDebugNewExecutableCommand_Debug_New_Executable=Debug New Executable +GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist=Host binary file does not exist +GdbDebugNewExecutableCommand_Host_binary_must_be_specified=Host binary must be specified +GdbDebugNewExecutableCommand_Invalid_binary=Invalid binary +GdbDebugNewExecutableCommand_Invalid_host_binary=Invalid host binary +GdbDebugNewExecutableCommand_New_Executable_Prompt_Job=New Executable Prompt Job +GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target=Select binaries on the host and the target and specify the arguments +GdbDebugNewExecutableCommand_Select_Binary=Select Binary +GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments=Select a binary and specify the arguments diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java new file mode 100644 index 00000000000..7c65e7be5eb --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2013 Mentor Graphics and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.launching; + +import java.io.File; + +import org.eclipse.cdt.dsf.gdb.internal.ui.commands.Messages; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class NewExecutableDialog extends TitleAreaDialog { + + public static final int REMOTE = 0x1; + + private int fFlags = 0; + private NewExecutableInfo fInfo = null; + + private Text fHostBinaryText; + private Text fTargetBinaryText; + private Text fArgumentsText; + + public NewExecutableDialog( Shell parentShell, int flags ) { + super( parentShell ); + setShellStyle( getShellStyle() | SWT.RESIZE ); + fFlags = flags; + } + + @Override + protected Control createContents( Composite parent ) { + Control control = super.createContents( parent ); + validate(); + return control; + } + + @Override + protected Control createDialogArea( Composite parent ) { + boolean remote = (fFlags & REMOTE) > 0; + + getShell().setText( Messages.GdbDebugNewExecutableCommand_Debug_New_Executable ); + setTitle( Messages.GdbDebugNewExecutableCommand_Select_Binary ); + String message = ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target : + Messages.GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments; + setMessage( message ); + + Composite control = (Composite)super.createDialogArea( parent ); + Composite comp = new Composite( control, SWT.NONE ); + GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); + GridLayout layout = new GridLayout( 3, false ); + comp.setLayout( layout ); + comp.setLayoutData( gd ); + + new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugNewExecutableCommand_Binary ); + fHostBinaryText = new Text( comp, SWT.BORDER ); + fHostBinaryText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); + fHostBinaryText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + Button browseButton = new Button( comp, SWT.PUSH ); + browseButton.setText( Messages.GdbDebugNewExecutableCommand_Browse ); + browseButton.setFont( JFaceResources.getDialogFont() ); + setButtonLayoutData( browseButton ); + browseButton.addSelectionListener( new SelectionAdapter() { + + @Override + public void widgetSelected( SelectionEvent e ) { + FileDialog dialog = new FileDialog( getShell() ); + dialog.setFileName( fHostBinaryText.getText() ); + String result = dialog.open(); + if ( result != null ) { + fHostBinaryText.setText( result ); + } + } + } ); + + if ( remote ) { + new Label( comp, SWT.None ).setText( Messages.GdbDebugNewExecutableCommand_Binary_on_target ); + fTargetBinaryText = new Text( comp, SWT.BORDER ); + fTargetBinaryText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + fTargetBinaryText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + } + + new Label( comp, SWT.None ).setText( Messages.GdbDebugNewExecutableCommand_Arguments ); + fArgumentsText = new Text( comp, SWT.BORDER ); + fArgumentsText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + + return control; + } + + @Override + protected void okPressed() { + String targetPath = ( fTargetBinaryText != null ) ? fTargetBinaryText.getText().trim() : null; + String args = fArgumentsText.getText().trim(); + fInfo = new NewExecutableInfo( fHostBinaryText.getText().trim(), targetPath, args ); + super.okPressed(); + } + + public NewExecutableInfo getExecutableInfo() { + return fInfo; + } + + private void validate() { + boolean remote = (fFlags & REMOTE) > 0; + StringBuilder sb = new StringBuilder(); + String hostBinary = fHostBinaryText.getText().trim(); + if ( hostBinary.isEmpty() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Host_binary_must_be_specified : + Messages.GdbDebugNewExecutableCommand_Binary_must_be_specified ); + } + else { + File file = new File( hostBinary ); + if ( !file.exists() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist : + Messages.GdbDebugNewExecutableCommand_Binary_file_does_not_exist ); + } + else if ( file.isDirectory() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Invalid_host_binary : + Messages.GdbDebugNewExecutableCommand_Invalid_binary ); + } + } + if ( fTargetBinaryText != null ) { + if ( fTargetBinaryText.getText().trim().length() == 0 ) { + if ( sb.length() != 0 ) { + sb.append( "\n " ); //$NON-NLS-1$ + } + sb.append( Messages.GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified ); + } + } + setErrorMessage( ( sb.length() != 0 ) ? sb.toString() : null ); + getButton( IDialogConstants.OK_ID ).setEnabled( getErrorMessage() == null ); + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java new file mode 100644 index 00000000000..1f88a279bde --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 Mentor Graphics and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.launching; + +/** + * This class provides information required to start + * debugging an executable. + */ +public class NewExecutableInfo { + private String fHostPath; + private String fTargetPath; + private String fArguments; + + public NewExecutableInfo(String hostPath, String targetPath, String args) { + super(); + fHostPath = hostPath; + fTargetPath = targetPath; + fArguments = args; + } + + /** + * Returns the path of the executable on the host + */ + public String getHostPath() { + return fHostPath; + } + + /** + * For remote sessions returns the path of the executable + * on the target. Otherwise returns null. + */ + public String getTargetPath() { + return fTargetPath; + } + + /** + * Returns the arguments to pass to the executable, or null + */ + public String getArguments() { + return fArguments; + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java index 8df673aa10c..b50e0ce4a68 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java @@ -34,10 +34,12 @@ public class ProcessPrompter implements IStatusHandler { public static class PrompterInfo { public boolean supportsNewProcess; + public boolean remote; public IProcessExtendedInfo[] processList; - public PrompterInfo(boolean supportsNew, IProcessExtendedInfo[] list) { + public PrompterInfo(boolean supportsNew, boolean remote, IProcessExtendedInfo[] list) { supportsNewProcess = supportsNew; + this.remote = remote; processList = list; } } @@ -162,7 +164,8 @@ public class ProcessPrompter implements IStatusHandler { }; // Display the list of processes and have the user choose - ProcessPrompterDialog dialog = new ProcessPrompterDialog(shell, provider, qprovider, prompterInfo.supportsNewProcess); + ProcessPrompterDialog dialog = + new ProcessPrompterDialog(shell, provider, qprovider, prompterInfo.supportsNewProcess, prompterInfo.remote); dialog.setTitle(LaunchUIMessages.getString("LocalAttachLaunchDelegate.Select_Process")); //$NON-NLS-1$ dialog.setMessage(LaunchUIMessages.getString("LocalAttachLaunchDelegate.Select_Process_to_attach_debugger_to")); //$NON-NLS-1$ @@ -172,9 +175,9 @@ public class ProcessPrompter implements IStatusHandler { dialog.setElements(plist); if (dialog.open() == Window.OK) { // First check if the user pressed the New button - String binaryPath = dialog.getBinaryPath(); - if (binaryPath != null) { - return binaryPath; + NewExecutableInfo execInfo = dialog.getExecutableInfo(); + if (execInfo != null) { + return execInfo; } Object[] results = dialog.getResult(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java index 92f6ee216bd..623c148e386 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java @@ -13,12 +13,12 @@ package org.eclipse.cdt.dsf.gdb.internal.ui.launching; import java.util.Arrays; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; @@ -42,13 +42,15 @@ import org.eclipse.ui.dialogs.TwoPaneElementSelector; */ public class ProcessPrompterDialog extends TwoPaneElementSelector { private static final int NEW_BUTTON_ID = 9876; - private String fBinaryPath; + private NewExecutableInfo fExecInfo; private boolean fSupportsNewProcess; + private boolean fRemote; public ProcessPrompterDialog(Shell parent, ILabelProvider elementRenderer, - ILabelProvider qualifierRenderer, boolean supportsNewProcess) { + ILabelProvider qualifierRenderer, boolean supportsNewProcess, boolean remote) { super(parent, elementRenderer, qualifierRenderer); fSupportsNewProcess = supportsNewProcess; + fRemote = remote; } @Override @@ -62,19 +64,16 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector { @Override protected void buttonPressed(int buttonId) { if (buttonId == NEW_BUTTON_ID) { - FileDialog fd = new FileDialog(getShell(), SWT.NONE); - fBinaryPath = fd.open(); - - setReturnCode(OK); - close(); + NewExecutableDialog dialog = new NewExecutableDialog(getShell(), (fRemote) ? NewExecutableDialog.REMOTE : 0); + if (dialog.open() == IDialogConstants.OK_ID) { + fExecInfo = dialog.getExecutableInfo(); + setReturnCode(OK); + close(); + } } super.buttonPressed(buttonId); } - public String getBinaryPath() { - return fBinaryPath; - } - /* * The result should be every selected element. */ @@ -116,4 +115,8 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector { }); return list; } + + public NewExecutableInfo getExecutableInfo() { + return fExecInfo; + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java index 0f1cf56d63b..74bdabda65e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java @@ -114,6 +114,13 @@ public class IGDBLaunchConfigurationConstants { */ public static final String ATTR_DEBUGGER_TRACEPOINT_MODE = GdbPlugin.PLUGIN_ID + ".TRACEPOINT_MODE"; //$NON-NLS-1$ + /** + * Launch configuration attribute key. The value is a String specifying the path of the executable + * on the target. + * @since 4.2 + */ + public static final String ATTR_DEBUGGER_REMOTE_BINARY = GdbPlugin.PLUGIN_ID + ".REMOTE_BINARY"; //$NON-NLS-1$ + /** * Launch configuration attribute value. The key is ATTR_DEBUG_NAME. */ diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java index 87c79a79e94..efaa5bdb475 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java @@ -19,6 +19,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.core.model.IConnectHandler; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; @@ -295,7 +296,10 @@ public class GdbLaunch extends DsfLaunch if (adapter.equals(IConnectHandler.class)) return getSession().getModelAdapter(adapter); - // Must force adapters to be loaded. + if (adapter.equals(IDebugNewExecutableHandler.class)) + return getSession().getModelAdapter(adapter); + + // Must force adapters to be loaded. Platform.getAdapterManager().loadAdapter(this, adapter.getName()); return super.getAdapter(adapter); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java index ba0797d0f3b..acd2c10c2cc 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java @@ -200,9 +200,13 @@ public class DebugNewProcessSequence extends ReflectionSequence { @Execute public void stepSetArguments(RequestMonitor rm) { try { - String args = fBackend.getProgramArguments(); + String args = CDebugUtils.getAttribute( + fAttributes, + ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, + ""); //$NON-NLS-1$ - if (args != null) { + if (args.length() != 0) { + args = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(args); String[] argArray = CommandLineUtil.argumentsToArray(args); fCommandControl.queueCommand( fCommandFactory.createMIGDBSetArgs(getContainerContext(), argArray), diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java index c7238712b59..40685bb3d89 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java @@ -15,15 +15,19 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -40,14 +44,23 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { private IGDBControl fGdbControl; private IGDBProcesses fProcService; + private IGDBBackend fBackend; + private CommandFactory fCommandFactory; private String fSessionId; private final boolean fInitialProcess; + private final Map fAttributes; - public DebugNewProcessSequence_7_2(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file, - Map attributes, DataRequestMonitor rm) { + public DebugNewProcessSequence_7_2( + DsfExecutor executor, + boolean isInitial, + IDMContext dmc, + String file, + Map attributes, + DataRequestMonitor rm) { super(executor, isInitial, dmc, file, attributes, rm); fSessionId = dmc.getSessionId(); fInitialProcess = isInitial; + fAttributes = attributes; } @Override @@ -60,13 +73,14 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { // Now insert our steps right after the initialization of the base class. orderList.add(orderList.indexOf("stepInitializeBaseSequence") + 1, "stepInitializeSequence_7_2"); //$NON-NLS-1$ //$NON-NLS-2$ orderList.add(orderList.indexOf("stepInitializeSequence_7_2") + 1, "stepAddInferior"); //$NON-NLS-1$ //$NON-NLS-2$ + orderList.add(orderList.indexOf("stepSetExecutable") + 1, "stepSetRemoteExecutable"); //$NON-NLS-1$ //$NON-NLS-2$ return orderList.toArray(new String[orderList.size()]); } return null; } - + /** * Initialize the members of the DebugNewProcessSequence_7_2 class. * This step is mandatory for the rest of the sequence to complete. @@ -76,14 +90,17 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { DsfServicesTracker tracker = new DsfServicesTracker(GdbPlugin.getBundleContext(), fSessionId); fGdbControl = tracker.getService(IGDBControl.class); fProcService = tracker.getService(IGDBProcesses.class); + fBackend = tracker.getService(IGDBBackend.class); tracker.dispose(); - if (fGdbControl == null || fProcService == null) { + if (fGdbControl == null || fProcService == null || fBackend == null) { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Cannot obtain service", null)); //$NON-NLS-1$ rm.done(); return; } + fCommandFactory = fGdbControl.getCommandFactory(); + rm.done(); } @@ -119,5 +136,37 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { rm.done(); } }); + } + + /** + * Set remote executable. + * @since 4.2 + */ + @Execute + public void stepSetRemoteExecutable(final RequestMonitor rm) { + if (fBackend.getSessionType() == SessionType.REMOTE && fBackend.getIsAttachSession()) { + String remoteBinary = CDebugUtils.getAttribute( + fAttributes, + IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, + ""); //$NON-NLS-1$ + if (remoteBinary.length() == 0) { + rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "Binary on host is not specified")); //$NON-NLS-1$ + rm.done(); + return; + } + + fGdbControl.queueCommand( + fCommandFactory.createMIGDBSet( + getContainerContext(), + new String[] { + "remote", //$NON-NLS-1$ + "exec-file", //$NON-NLS-1$ + remoteBinary, + }), + new ImmediateDataRequestMonitor(rm)); + } + else { + rm.done(); } } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java new file mode 100644 index 00000000000..3c4dd5475e2 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.service; + +import java.util.Hashtable; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.DMContexts; +import org.eclipse.cdt.dsf.debug.service.IMemory; +import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; +import org.eclipse.cdt.dsf.debug.service.command.IEventListener; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.cdt.dsf.mi.service.IMIProcesses; +import org.eclipse.cdt.dsf.mi.service.MIMemory; +import org.eclipse.cdt.dsf.mi.service.command.output.MIConst; +import org.eclipse.cdt.dsf.mi.service.command.output.MINotifyAsyncOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIResult; +import org.eclipse.cdt.dsf.mi.service.command.output.MIValue; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.utils.Addr64; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * Memory service that uses the enhancements from GDB 7.6: + * =memory-changed MI event + * + * @since 4.2 + */ +public class GDBMemory_7_6 extends GDBMemory_7_0 implements IEventListener { + + private ICommandControlService fConnection; + + public GDBMemory_7_6(DsfSession session) { + super(session); + } + + @Override + public void initialize(final RequestMonitor requestMonitor) { + super.initialize( + new ImmediateRequestMonitor(requestMonitor) { + @Override + public void handleSuccess() { + doInitialize(requestMonitor); + }}); + } + + private void doInitialize(final RequestMonitor requestMonitor) { + register(new String[] { MIMemory.class.getName(), + IMemory.class.getName(), + GDBMemory_7_0.class.getName(), + GDBMemory_7_6.class.getName()}, + new Hashtable()); + + fConnection = getServicesTracker().getService(ICommandControlService.class); + if (fConnection == null) { + requestMonitor.done(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "CommandControl Service is not available")); //$NON-NLS-1$ + return; + } + fConnection.addEventListener(this); + + requestMonitor.done(); + } + + @Override + public void shutdown(final RequestMonitor requestMonitor) { + fConnection.removeEventListener(this); + unregister(); + super.shutdown(requestMonitor); + } + + @Override + public void eventReceived(Object output) { + if (output instanceof MIOutput) { + MIOOBRecord[] records = ((MIOutput)output).getMIOOBRecords(); + for (MIOOBRecord r : records) { + if (r instanceof MINotifyAsyncOutput) { + MINotifyAsyncOutput notifyOutput = (MINotifyAsyncOutput)r; + String asyncClass = notifyOutput.getAsyncClass(); + // These events have been added with GDB 7.6 + if ("memory-changed".equals(asyncClass)) { //$NON-NLS-1$ + String groupId = null; + String addr = null; + int length = 0; + + MIResult[] results = notifyOutput.getMIResults(); + for (int i = 0; i < results.length; i++) { + String var = results[i].getVariable(); + MIValue val = results[i].getMIValue(); + if (var.equals("thread-group")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + groupId = ((MIConst)val).getString(); + } + } else if (var.equals("addr")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + addr = ((MIConst)val).getString(); + } + } else if (var.equals("len")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + try { + String lenStr = ((MIConst)val).getString().trim(); + if (lenStr.startsWith("0x")) { //$NON-NLS-1$ + length = Integer.parseInt(lenStr.substring(2), 16); + } else { + length = Integer.parseInt(lenStr); + } + } catch (NumberFormatException e) { + assert false; + } + } + } else if (var.equals("type")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + if ("code".equals(((MIConst)val).getString())) { //$NON-NLS-1$ + } + } + } + } + + IMIProcesses procService = getServicesTracker().getService(IMIProcesses.class); + if (procService != null && groupId != null && addr != null && length > 0) { + IContainerDMContext containerDmc = + procService.createContainerContextFromGroupId(fConnection.getContext(), groupId); + + // Now refresh our memory cache, it case it contained this address. Don't have + // it send the potential IMemoryChangedEvent as we will send it ourselves (see below). + final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(containerDmc, IMemoryDMContext.class); + final IAddress address = new Addr64(addr); + // The length returned by GDB is in bytes, while the memory cache expects + // a count of number of addresses of 8 bytes. + int count = length/8 + 1; + getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, false, + new RequestMonitor(getExecutor(), null) { + @Override + protected void handleCompleted() { + // Only once the memory cache is updated, we send the IMemoryChangedEvent. If we were to do it + // earlier, the memory view may not show the updated value. + // + // We must always send this event when GDB reports a memory change because it can mean that + // an expression or register has changed, and therefore we must notify the different views + // and services of it. We cannot rely on this event to be sent by the memory cache after being + // refreshed, because if the memory cache does not contain this address, it will not send + // the event. + getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, new IAddress[] { address }), getProperties()); + } + }); + } + } + } + } + } + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java index d9ab8bc5851..4a313fc1d95 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java @@ -469,10 +469,14 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 { return false; } - // We don't yet support starting a new process on a remote target - // Bug 344890 - if (type == SessionType.REMOTE && fBackend.getIsAttachSession()) { - return false; + // Multi-process does not work for all-stop right now + IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class); + if (runControl != null && runControl.getRunMode() == MIRunMode.ALL_STOP) { + // Only one process is allowed in all-stop (for now) + return getNumConnected() == 0; + // NOTE: when we support multi-process in all-stop mode, + // we will need to interrupt the target to when starting + // the new process. } return true; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java index eb6abfb6adf..f5f8f1b8055 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Wind River Systems and others. + * Copyright (c) 2008, 2013 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ * Ericsson - Version 7.0 * Nokia - create and use backend service. * Ericsson - Added IReverseControl support + * Marc Khouzam (Ericsson) - Added IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -21,6 +22,7 @@ import java.util.Hashtable; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; @@ -52,6 +54,22 @@ import org.eclipse.core.runtime.Status; public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunControl { + /** @since 4.2 */ + protected static class GdbReverseModeChangedDMEvent extends AbstractDMEvent + implements IReverseModeChangedDMEvent { + private boolean fIsEnabled; + + public GdbReverseModeChangedDMEvent(ICommandControlDMContext context, boolean enabled) { + super(context); + fIsEnabled = enabled; + } + + @Override + public boolean isReverseModeEnabled() { + return fIsEnabled; + } + } + private static class RunToLineActiveOperation { private IMIExecutionDMContext fThreadContext; private int fBpId; @@ -75,6 +93,7 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro public boolean shouldSkipBreakpoints() { return fSkipBreakpoints; } } + private IMICommandControl fCommandControl; private IGDBBackend fGdb; private IMIProcesses fProcService; private CommandFactory fCommandFactory; @@ -111,7 +130,8 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro fGdb = getServicesTracker().getService(IGDBBackend.class); fProcService = getServicesTracker().getService(IMIProcesses.class); - fCommandFactory = getServicesTracker().getService(IMICommandControl.class).getCommandFactory(); + fCommandControl = getServicesTracker().getService(IMICommandControl.class); + fCommandFactory = fCommandControl.getCommandFactory(); if (fGdb.getSessionType() == SessionType.CORE) { // No execution for core files, so no support for reverse @@ -628,6 +648,10 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro /** @since 2.0 */ public void setReverseModeEnabled(boolean enabled) { - fReverseModeEnabled = enabled; + if (fReverseModeEnabled != enabled) { + fReverseModeEnabled = enabled; + getSession().dispatchEvent(new GdbReverseModeChangedDMEvent(fCommandControl.getContext(), fReverseModeEnabled), + getProperties()); + } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java new file mode 100644 index 00000000000..0e5a3cc3c7a --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.service; + + +import java.util.Hashtable; + +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.debug.service.IRunControl; +import org.eclipse.cdt.dsf.debug.service.IRunControl2; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControl; +import org.eclipse.cdt.dsf.debug.service.command.IEventListener; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.cdt.dsf.mi.service.IMIRunControl; +import org.eclipse.cdt.dsf.mi.service.MIRunControl; +import org.eclipse.cdt.dsf.mi.service.command.output.MINotifyAsyncOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * @since 4.2 + */ +public class GDBRunControl_7_6 extends GDBRunControl_7_0 implements IEventListener { + + private ICommandControl fCommandControl; + + public GDBRunControl_7_6(DsfSession session) { + super(session); + } + + @Override + public void initialize(final RequestMonitor requestMonitor) { + super.initialize( + new ImmediateRequestMonitor(requestMonitor) { + @Override + public void handleSuccess() { + doInitialize(requestMonitor); + }}); + } + + private void doInitialize(final RequestMonitor requestMonitor) { + + fCommandControl = getServicesTracker().getService(ICommandControl.class); + + if (fCommandControl == null) { + requestMonitor.done(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "Service is not available")); //$NON-NLS-1$ + return; + } + + fCommandControl.addEventListener(this); + + register(new String[]{IRunControl.class.getName(), + IRunControl2.class.getName(), + IMIRunControl.class.getName(), + MIRunControl.class.getName(), + GDBRunControl_7_0.class.getName(), + GDBRunControl_7_6.class.getName(), + IReverseRunControl.class.getName()}, + new Hashtable()); + requestMonitor.done(); + } + + @Override + public void shutdown(final RequestMonitor requestMonitor) { + if (fCommandControl != null) { + fCommandControl.removeEventListener(this); + } + unregister(); + super.shutdown(requestMonitor); + } + + @Override + public void eventReceived(Object output) { + if (output instanceof MIOutput) { + MIOOBRecord[] records = ((MIOutput)output).getMIOOBRecords(); + for (MIOOBRecord r : records) { + if (r instanceof MINotifyAsyncOutput) { + MINotifyAsyncOutput notifyOutput = (MINotifyAsyncOutput)r; + String asyncClass = notifyOutput.getAsyncClass(); + // These events have been added with GDB 7.6 + if ("record-started".equals(asyncClass) || //$NON-NLS-1$ + "record-stopped".equals(asyncClass)) { //$NON-NLS-1$ + + boolean enable = "record-started".equals(asyncClass); //$NON-NLS-1$ + setReverseModeEnabled(enable); + } + } + } + } + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java index c1a2647d4c0..d01fcd6e7de 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Ericsson and others. + * Copyright (c) 2008, 2013 Ericsson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ * Marc Khouzam (Ericsson) - Support for GDB 7.4 (Bug 367788) * Marc Khouzam (Ericsson) - Include IGDBHardware service for the multicore visualizer (Bug 335027) * Vladimir Prus (Mentor Graphics) - Support for OS resources. + * Marc Khouzam (Ericsson) - Support for GDB 7.6 memory service *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -67,6 +68,8 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { public static final String GDB_7_4_VERSION = "7.4"; //$NON-NLS-1$ /** @since 4.2*/ public static final String GDB_7_5_VERSION = "7.5"; //$NON-NLS-1$ + /** @since 4.2*/ + public static final String GDB_7_6_VERSION = "7.5.50"; //$NON-NLS-1$ private final String fVersion; @@ -172,6 +175,10 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { @Override protected IMemory createMemoryService(DsfSession session) { + if (GDB_7_6_VERSION.compareTo(fVersion) <= 0) { + return new GDBMemory_7_6(session); + } + if (GDB_7_0_VERSION.compareTo(fVersion) <= 0) { return new GDBMemory_7_0(session); } @@ -208,6 +215,9 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { @Override protected IRunControl createRunControlService(DsfSession session) { + if (GDB_7_6_VERSION.compareTo(fVersion) <= 0) { + return new GDBRunControl_7_6(session); + } if (GDB_7_0_VERSION.compareTo(fVersion) <= 0) { return new GDBRunControl_7_0(session); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java index 6751d3f4ee3..3d03793bc9c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson and others. + * Copyright (c) 2009, 2013 Ericsson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,27 +7,94 @@ * * Contributors: * Ericsson - Initial API and implementation + * Marc Khouzam (Ericsson) - Added IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.IDMEvent; import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; /** + * This interface provides access to controlling and monitoring the reverse execution + * state of a process being debugged. + * * @since 2.0 */ public interface IReverseRunControl { + /** + * Indicates that the enablement of reverse debugging has changed. + * + * @since 4.2 + */ + interface IReverseModeChangedDMEvent extends IDMEvent { + /** + * @return the new state of reverse mode. + */ + boolean isReverseModeEnabled(); + }; + + /** + * Establish if a reverse-resume operation is allowed on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @param rm Will contain the result of the operation, true or false, not null. + */ void canReverseResume(IExecutionDMContext context, DataRequestMonitor rm); + + /** + * Perform a reverse-resume operation on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + */ void reverseResume(IExecutionDMContext context, RequestMonitor requestMonitor); + + /** + * Returns whether a reverse-step operation is on-going for the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @return True if a reverse-steop operation is on-going, false otherwise. + */ boolean isReverseStepping(IExecutionDMContext context); + + /** + * Establish if a reverse-step operation is allowed on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @param rm Will contain the result of the operation, true or false, not null. + */ void canReverseStep(IExecutionDMContext context, StepType stepType, DataRequestMonitor rm); + + /** + * Perform a reverse-step operation on the specified context with the specified step type. + * + * @param context The thread or process on which the reverse operation will apply + * @param stepType The step type to be used for the operation + */ void reverseStep(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor); + /** + * Establish if it is possible to enable reverse debugging. + * + * @param rm Will contain the result of the operation, true or false, not null. + */ void canEnableReverseMode(ICommandControlDMContext context, DataRequestMonitor rm); + + /** + * Establish if reverse debugging is enabled. + * + * @param rm Will contain the result of the operation, true or false, not null. + */ void isReverseModeEnabled(ICommandControlDMContext context, DataRequestMonitor rm); + + /** + * Enable or disable reverse debugging based on the enable parameter. + * + * @param enable True if reverse debugging should enabled, false for disabled. + */ void enableReverseMode(ICommandControlDMContext context, boolean enable, RequestMonitor rm); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java index 6f8a2fd69fd..e88e9b6b3ca 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java @@ -260,10 +260,9 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence { */ @Execute public void stepInitializeInputOutput(final RequestMonitor rm) { - if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { - // Remote non-attach sessions don't support multi-process and therefore will not - // start new processes. Those sessions will only start the one process, which should - // not have a console, because it's output is handled by GDB server. + if (fBackend.getSessionType() == SessionType.REMOTE) { + // The program input and output for a remote session is handled by gdbserver. + // Therefore, no need to create a pty. fPty = null; rm.done(); } else { @@ -296,11 +295,9 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence { */ @Execute public void stepCreateConsole(final RequestMonitor rm) { - if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { - // Remote non-attach sessions don't support multi-process and therefore will not - // start new processes. Those sessions will only start the one process, which should - // not have a console, because it's output is handled by GDB server. Therefore, - // no need to create an inferior process and add it to the launch + if (fBackend.getSessionType() == SessionType.REMOTE) { + // The program output for a remote session is handled by gdbserver. Therefore, + // no need to create an inferior process and add it to the launch. rm.done(); return; } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java index f75beaa1628..67cc4f3da5f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.ICachingService; import org.eclipse.cdt.dsf.debug.service.IExpressions; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IMemory; @@ -92,7 +93,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer // Map of memory caches private Map fMemoryCaches; - private MIMemoryCache getMemoryCache(IMemoryDMContext memoryDMC) { + /** @since 4.2 */ + protected MIMemoryCache getMemoryCache(IMemoryDMContext memoryDMC) { MIMemoryCache cache = fMemoryCaches.get(memoryDMC); if (cache == null) { cache = new MIMemoryCache(); @@ -490,12 +492,19 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer } } - /** - * @nooverride This method is not intended to be re-implemented or extended by clients. - * @noreference This method is not intended to be referenced by clients. - */ - @DsfServiceEventHandler + /** + * @deprecated Replaced by the generic {@link #eventDispatched(IExpressionChangedDMEvent)} + */ + @Deprecated public void eventDispatched(ExpressionChangedEvent e) { + } + + /** + * @noreference This method is not intended to be referenced by clients. + * @since 4.2 + */ + @DsfServiceEventHandler + public void eventDispatched(IExpressionChangedDMEvent e) { // Get the context and expression service handle final IExpressionDMContext context = e.getDMContext(); @@ -518,7 +527,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer address = new Addr64(expAddress.getValue()); final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class); - getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, + getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, true, new RequestMonitor(getExecutor(), null)); } }); @@ -629,7 +638,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer // MIMemoryCache /////////////////////////////////////////////////////////////////////////// - private class MIMemoryCache { + /** @since 4.2 */ + protected class MIMemoryCache { // The memory cache data structure private SortedMemoryBlockList fMemoryBlockList; @@ -965,10 +975,12 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer * @param offset * @param word_size * @param count + * @param sendMemoryEvent Indicates if a IMemoryChangedEvent should be sent if the memory cache has changed. * @param rm */ public void refreshMemory(final IMemoryDMContext memoryDMC, final IAddress address, - final long offset, final int word_size, final int count, final RequestMonitor rm) + final long offset, final int word_size, final int count, final boolean sendMemoryEvent, + final RequestMonitor rm) { // Check if we already cache part of this memory area (which means it // is used by a memory service client that will have to be updated) @@ -983,16 +995,10 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer rm.done(); return; } - - // Prepare the data for the MemoryChangedEvent - final IAddress[] addresses = new IAddress[count]; - for (int i = 0; i < count; i++) { - addresses[i] = address.add(i); - } // Read the corresponding memory block fCommandCache.reset(); - readMemoryBlock(memoryDMC, address, 0, 1, count, + readMemoryBlock(memoryDMC, address, offset, word_size, count, new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleSuccess() { @@ -1006,8 +1012,15 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer } } if (blocksDiffer) { - updateMemoryCache(address, count, newBlock); - getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); + updateMemoryCache(address.add(offset), count, newBlock); + if (sendMemoryEvent) { + // Send the MemoryChangedEvent + final IAddress[] addresses = new IAddress[count]; + for (int i = 0; i < count; i++) { + addresses[i] = address.add(offset + i); + } + getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); + } } rm.done(); } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc new file mode 100644 index 00000000000..2e858e5dd12 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc @@ -0,0 +1,15 @@ +#include + +int testMemoryChanges() { + int i = 8; + + return i; +} + +int main() { + printf("Running ConsoleSyncTestApp\n"); + + testMemoryChanges(); + + return 0; +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java index fb078685198..c6b5f0c0e84 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.dsf.debug.service.IExpressions; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext; +import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.IFormattedDataDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMContext; @@ -432,6 +433,26 @@ public class SyncUtil { return fSession.getExecutor().submit(callable).get(); } + public static String getExpressionValue(final IExpressionDMContext exprDmc, final String format) + throws Throwable { + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + FormattedValueDMContext valueDmc = fExpressions.getFormattedValueContext(exprDmc, format); + fExpressions.getFormattedExpressionValue(valueDmc, + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + rm.done(getData().getFormattedValue()); + } + }); + } + }; + + fSession.getExecutor().execute(query); + return query.get(); + } + public static FormattedValueDMContext getFormattedValue( final IFormattedValues service, final IFormattedDataDMContext dmc, final String formatId) throws Throwable { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java index ad053dda7f4..058f7757b64 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java @@ -45,7 +45,7 @@ import org.junit.runners.Suite; OperationsWhileTargetIsRunningTest_7_5.class, OperationsWhileTargetIsRunningNonStopTest_7_5.class, PostMortemCoreTest_7_5.class, - CommandTimeoutTest_7_5.class, +// CommandTimeoutTest_7_5.class, Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_5.class, /* Add your test class here */ diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java new file mode 100644 index 00000000000..14eeaa21486 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java @@ -0,0 +1,482 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_6; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.Query; +import org.eclipse.cdt.dsf.datamodel.DMContexts; +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.datamodel.IDMEvent; +import org.eclipse.cdt.dsf.debug.service.IExpressions; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; +import org.eclipse.cdt.dsf.debug.service.IFormattedValues; +import org.eclipse.cdt.dsf.debug.service.IMemory; +import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; +import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext; +import org.eclipse.cdt.dsf.debug.service.IRunControl; +import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl.IReverseModeChangedDMEvent; +import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; +import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.framework.BaseTestCase; +import org.eclipse.cdt.tests.dsf.gdb.framework.SyncUtil; +import org.eclipse.cdt.tests.dsf.gdb.launching.TestsPlugin; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.debug.core.model.MemoryByte; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * This test case verifies that different commands issued from the + * GDB console cause proper updating within the CDT views. + */ +@RunWith(BackgroundRunner.class) +public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { + + final static private int DEFAULT_TIMEOUT = 1000; + final static private TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MILLISECONDS; + + private DsfSession fSession; + private DsfServicesTracker fServicesTracker; + private IGDBControl fCommandControl; + private IMemory fMemoryService; + private IExpressions fExprService; + private IRunControl fRunControl; + + private List> fEventsReceived = new ArrayList>(); + + @Override + protected void setGdbVersion() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_6); + } + + @Override + protected void setLaunchAttributes() { + super.setLaunchAttributes(); + + setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "data/launch/bin/ConsoleSyncTestApp.exe"); + } + + @Override + public void doBeforeTest() throws Exception { + super.doBeforeTest(); + + fSession = getGDBLaunch().getSession(); + Runnable runnable = new Runnable() { + @Override + public void run() { + fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); + Assert.assertTrue(fServicesTracker != null); + + fCommandControl = fServicesTracker.getService(IGDBControl.class); + Assert.assertTrue(fCommandControl != null); + + fMemoryService = fServicesTracker.getService(IMemory.class); + Assert.assertTrue(fMemoryService != null); + + fExprService = fServicesTracker.getService(IExpressions.class); + Assert.assertTrue(fExprService != null); + + fRunControl = fServicesTracker.getService(IRunControl.class); + Assert.assertTrue(fRunControl != null); + + // Register to breakpoint events + fSession.addServiceEventListener(GDBConsoleSynchronizingTest_7_6.this, null); + } + }; + fSession.getExecutor().submit(runnable).get(); + } + + @Override + public void doAfterTest() throws Exception { + Runnable runnable = new Runnable() { + @Override + public void run() { + fSession.removeServiceEventListener(GDBConsoleSynchronizingTest_7_6.this); + } + }; + fSession.getExecutor().submit(runnable).get(); + fEventsReceived.clear(); + fServicesTracker.dispose(); + super.doAfterTest(); + } + + ////////////////////////////////////////////////////////////////////////////////////// + // Start of tests + ////////////////////////////////////////////////////////////////////////////////////// + + /** + * This test verifies that setting a variable from the console + * using the set command will properly trigger a DSF event to + * indicate the change. This test makes sure the value that + * changes is in the memory cache also. + */ + @Test + public void testSettingVariableWithSetWithMemory() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + readMemory(memoryDmc, data.getAddress(), 1); + + fEventsReceived.clear(); + + final String newValue = "100"; + queueConsoleCommand("set variable i=" + newValue); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); + } + + /** + * This test verifies that setting a variable from the console + * using the set command will properly trigger a DSF event to + * indicate the change, when the address is not in the memory cache. + */ + @Test + public void testSettingVariableWithSet() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + + final String newValue = "100"; + queueConsoleCommand("set variable i=" + newValue); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); + } + + /** + * This test verifies that setting a variable from the console + * using the print command will properly trigger a DSF event + * to indicate the change. + */ + @Test + public void testSettingVariableWithPrint() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + + final String newValue = "100"; + queueConsoleCommand("print i=" + newValue); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); + } + + /** + * This test verifies that setting a memory location from the + * console will properly trigger a DSF event to indicate the change. + */ + @Test + public void testSettingMemory() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + + final String newValue = "100"; + queueConsoleCommand("set {int}&i=" + newValue); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); + } + + /** + * This test verifies that enabling reverse debugging from the + * console will properly trigger a DSF event to indicate the change and + * will be processed by the service. + */ + @Test + public void testEnableRecord() throws Throwable { + assertTrue("Reverse debugging is not supported", fRunControl instanceof IReverseRunControl); + final IReverseRunControl reverseService = (IReverseRunControl)fRunControl; + + SyncUtil.runToLocation("testMemoryChanges"); + + // check starting state + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + + fSession.getExecutor().execute(query); + Boolean enabled = query.get(); + assertTrue("Reverse debugging should not be enabled", !enabled); + + fEventsReceived.clear(); + + queueConsoleCommand("record"); + + // Wait for the event + IReverseModeChangedDMEvent event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(true, event.isReverseModeEnabled()); + + // Check the service + query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + fSession.getExecutor().execute(query); + enabled = query.get(); + assertTrue("Reverse debugging should be enabled", enabled); + } + + /** + * This test verifies that disabling reverse debugging from the + * console will properly trigger a DSF event to indicate the change and + * will be processed by the service. + */ + @Test + public void testDisableRecord() throws Throwable { + assertTrue("Reverse debugging is not supported", fRunControl instanceof IReverseRunControl); + final IReverseRunControl reverseService = (IReverseRunControl)fRunControl; + + SyncUtil.runToLocation("testMemoryChanges"); + + fEventsReceived.clear(); + + // check starting state + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.enableReverseMode(fCommandControl.getContext(), true, + new ImmediateRequestMonitor(rm) { + @Override + protected void handleSuccess() { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }); + } + }; + + fSession.getExecutor().execute(query); + Boolean enabled = query.get(); + assertTrue("Reverse debugging should be enabled", enabled); + + // Wait for the event to avoid confusing it with the next one + IReverseModeChangedDMEvent event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(true, event.isReverseModeEnabled()); + fEventsReceived.clear(); + + queueConsoleCommand("record stop"); + + // Wait for the event + event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(false, event.isReverseModeEnabled()); + + // Check the service + query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + fSession.getExecutor().execute(query); + enabled = query.get(); + assertTrue("Reverse debugging should not be enabled", !enabled); + } + + ////////////////////////////////////////////////////////////////////////////////////// + // End of tests + ////////////////////////////////////////////////////////////////////////////////////// + + @DsfServiceEventHandler + public void eventDispatched(IDMEvent e) { + synchronized(this) { + fEventsReceived.add(e); + notifyAll(); + } + } + + private MemoryByte[] readMemory(final IMemoryDMContext dmc, final IAddress address, final int count) + throws Throwable + { + Query query = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fMemoryService.getMemory(dmc, address, 0, 1, count, rm); + } + }; + fSession.getExecutor().execute(query); + return query.get(DEFAULT_TIMEOUT, DEFAULT_TIME_UNIT); + } + + private void queueConsoleCommand(String command) throws Throwable { + queueConsoleCommand(command, DEFAULT_TIMEOUT, DEFAULT_TIME_UNIT); + } + + private void queueConsoleCommand(final String command, int timeout, TimeUnit unit) throws Throwable { + Query query = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fCommandControl.queueCommand( + fCommandControl.getCommandFactory().createMIInterpreterExecConsole( + fCommandControl.getContext(), + command), + rm); + } + }; + fSession.getExecutor().execute(query); + query.get(timeout, unit); + } + + private > V waitForEvent(Class eventType) throws Exception { + return waitForEvent(eventType, DEFAULT_TIMEOUT); + } + + @SuppressWarnings("unchecked") + private > V waitForEvent(Class eventType, int timeout) throws Exception { + IDMEvent event = getEvent(eventType); + if (event == null) { + synchronized(this) { + try { + wait(timeout); + } + catch (InterruptedException ex) { + } + } + event = getEvent(eventType); + if (event == null) { + throw new Exception(String.format("Timed out waiting for '%s' to occur.", eventType.getName())); + } + } + return (V)event; + } + + @SuppressWarnings("unchecked") + private synchronized > V getEvent(Class eventType) { + for (IDMEvent e : fEventsReceived) { + if (eventType.isAssignableFrom(e.getClass())) { + fEventsReceived.remove(e); + return (V)e; + } + } + return null; + } + +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java index 983dc915d30..0e364d79885 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java @@ -48,6 +48,7 @@ import org.junit.runners.Suite; GDBMultiNonStopRunControlTest_7_6.class, Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_6.class, + GDBConsoleSynchronizingTest_7_6.class, /* Add your test class here */ }) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java index aa3edd8421e..fc54dbfa84f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java @@ -49,6 +49,7 @@ import org.junit.runners.Suite; Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_6.class, TraceFileTest_7_6.class, + GDBConsoleSynchronizingTest_7_6.class, /* Add your test class here */ }) diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java index c3e4caf2b12..c4d8134cda3 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.core.runtime.CoreException; @@ -136,7 +136,7 @@ public class ParseHelper { public static IASTTranslationUnit parse(char[] code, ILanguage lang, Options options) { - return parse(FileContent.create(AST2BaseTest.TEST_CODE, code), lang, new ScannerInfo(), null, options); + return parse(FileContent.create(AST2TestBase.TEST_CODE, code), lang, new ScannerInfo(), null, options); } @@ -254,7 +254,7 @@ public class ParseHelper { IASTTranslationUnit tu; try { - tu = language.getASTTranslationUnit(FileContent.create(AST2BaseTest.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService()); + tu = language.getASTTranslationUnit(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService()); } catch (CoreException e) { throw new AssertionFailedError(e.toString()); } @@ -273,7 +273,7 @@ public class ParseHelper { public static IASTCompletionNode getCompletionNode(String code, ILanguage language, int offset) { try { - return language.getCompletionNode(FileContent.create(AST2BaseTest.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset); + return language.getCompletionNode(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset); } catch (CoreException e) { throw new RuntimeException(e); }