mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Removal of old parser (bug 209772).
This commit is contained in:
parent
51e8002672
commit
7788841cb3
363 changed files with 117 additions and 73741 deletions
|
@ -9,8 +9,6 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests,
|
||||||
org.eclipse.cdt.core.internal.errorparsers.tests,
|
org.eclipse.cdt.core.internal.errorparsers.tests,
|
||||||
org.eclipse.cdt.core.model.failedTests,
|
org.eclipse.cdt.core.model.failedTests,
|
||||||
org.eclipse.cdt.core.model.tests,
|
org.eclipse.cdt.core.model.tests,
|
||||||
org.eclipse.cdt.core.parser.failedTests,
|
|
||||||
org.eclipse.cdt.core.parser.tests,
|
|
||||||
org.eclipse.cdt.core.parser.tests.ast2,
|
org.eclipse.cdt.core.parser.tests.ast2,
|
||||||
org.eclipse.cdt.core.parser.tests.prefix,
|
org.eclipse.cdt.core.parser.tests.prefix,
|
||||||
org.eclipse.cdt.core.parser.tests.scanner2,
|
org.eclipse.cdt.core.parser.tests.scanner2,
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.failedTests;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.BaseASTTest;
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTFailedTests extends BaseASTTest
|
|
||||||
{
|
|
||||||
|
|
||||||
public ASTFailedTests(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
public void testBug36730() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Here C99-specific section ends
|
|
||||||
//Here GCC-specific section starts
|
|
||||||
public void testBug39676() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("struct { int e1, e2; } v = { e2: 0 }");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testBug39679() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("Foo blat() return f(4) {}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testBug39682() throws Exception
|
|
||||||
{
|
|
||||||
IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)parse("typedef name = (a+1);").getDeclarations().next();
|
|
||||||
assertFalse(
|
|
||||||
"The expected error did not occur.",
|
|
||||||
typedef.getName().equals( "name" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39687() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("struct entry tester (int len; char data[len][len], int len) {}");
|
|
||||||
}
|
|
||||||
// public void testBug39688() throws Exception
|
|
||||||
// {
|
|
||||||
// Writer code = new StringWriter();
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// code.write("#define decl(type, vars...) \\\n");
|
|
||||||
// code.write(" type vars ;\n");
|
|
||||||
// code.write("decl(int, x, y)\n");
|
|
||||||
// }
|
|
||||||
// catch (IOException ioe)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// assertCodeFailsParse(code.toString());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public void testBug39695A() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("int foo asm (\"myfoo\") = 2;");
|
|
||||||
}
|
|
||||||
public void testBug39695B() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("extern func () asm (\"FUNC\");");
|
|
||||||
}
|
|
||||||
public void testBug39695C() throws Exception
|
|
||||||
{
|
|
||||||
assertCodeFailsParse("register int *foo asm (\"a5\");");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39702() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
code.write("signature T {\n");
|
|
||||||
code.write(" int f (int);\n");
|
|
||||||
code.write(" int f0 () { return f (0); };\n");
|
|
||||||
code.write("};\n");
|
|
||||||
}
|
|
||||||
catch (IOException ioe)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
assertCodeFailsFullParse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testBug40422() throws Exception {
|
|
||||||
// Parse and get the translaton unit
|
|
||||||
parse("int A::* x = 0;").getDeclarations().next();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,142 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.failedTests;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FailedCompleteParseASTTest extends CompleteParseBaseTest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public FailedCompleteParseASTTest()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public FailedCompleteParseASTTest(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception
|
|
||||||
{
|
|
||||||
//parse no longer passes
|
|
||||||
try{
|
|
||||||
parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));"); //$NON-NLS-1$
|
|
||||||
fail();
|
|
||||||
} catch ( ParserException e ){
|
|
||||||
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations();
|
|
||||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
|
||||||
// Iterator members = getDeclarations(cl);
|
|
||||||
// IASTMethod method = (IASTMethod)members.next();
|
|
||||||
// IASTVariable a = (IASTVariable) i.next();
|
|
||||||
// IASTVariable pm = (IASTVariable) i.next();
|
|
||||||
// IASTFunction f1 = (IASTFunction) i.next();
|
|
||||||
// IASTFunction f2 = (IASTFunction) i.next();
|
|
||||||
// IASTVariable x = (IASTVariable) i.next();
|
|
||||||
//
|
|
||||||
// assertAllReferences( 5 /* should be 8 */,
|
|
||||||
// createTaskList( new Task( cl, 2 /* should be 3 */ ), new Task( method ), new Task( a ), new Task( pm ) /* should be ,new Task( f2 ) */
|
|
||||||
// ));
|
|
||||||
}
|
|
||||||
public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception
|
|
||||||
{
|
|
||||||
//parse no longer passes
|
|
||||||
try{
|
|
||||||
parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));"); //$NON-NLS-1$
|
|
||||||
fail();
|
|
||||||
} catch ( ParserException e ){
|
|
||||||
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// Iterator i = parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));").getDeclarations();
|
|
||||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
|
||||||
// Iterator members = getDeclarations(cl);
|
|
||||||
// IASTMethod method = (IASTMethod)members.next();
|
|
||||||
// IASTVariable a = (IASTVariable) i.next();
|
|
||||||
// IASTVariable pm = (IASTVariable) i.next();
|
|
||||||
// IASTFunction f1 = (IASTFunction) i.next();
|
|
||||||
// IASTFunction f2 = (IASTFunction) i.next();
|
|
||||||
// IASTVariable x = (IASTVariable) i.next();
|
|
||||||
//
|
|
||||||
// assertAllReferences( 5 /* should be more */,
|
|
||||||
// createTaskList( new Task( cl, 2 ), new Task( method ), new Task( a /*, 2 */), new Task( pm )/* ,new Task( f2 )*/));
|
|
||||||
//
|
|
||||||
}
|
|
||||||
public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse ("int m(int); \n int *pm = &m; \n int f(){} \n int f(int); \n int x = f((*pm)(5));").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTFunction m = (IASTFunction) i.next();
|
|
||||||
IASTVariable pm = (IASTVariable) i.next();
|
|
||||||
IASTFunction f1 = (IASTFunction) i.next();
|
|
||||||
IASTFunction f2 = (IASTFunction) i.next();
|
|
||||||
IASTVariable x = (IASTVariable) i.next();
|
|
||||||
assertAllReferences( 2 /* should be 3 */,
|
|
||||||
createTaskList( new Task( m ), new Task( pm ) /* ,new Task( f2 )*/));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kind DELETE_CASTEXPRESSION
|
|
||||||
// Kind DELETE_VECTORCASTEXPRESSION
|
|
||||||
// Kind CASTEXPRESSION
|
|
||||||
// Kind PM_DOTSTAR
|
|
||||||
public void testPMDotStar_bug43579() throws Exception
|
|
||||||
{
|
|
||||||
//parse no longer passes
|
|
||||||
try{
|
|
||||||
parse ( "class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);" ); //$NON-NLS-1$
|
|
||||||
fail();
|
|
||||||
} catch ( ParserException e ){
|
|
||||||
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations();
|
|
||||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
|
||||||
// IASTVariable a = (IASTVariable) i.next();
|
|
||||||
// IASTVariable pm = (IASTVariable) i.next();
|
|
||||||
// IASTFunction f1 = (IASTFunction) i.next();
|
|
||||||
// IASTFunction f2 = (IASTFunction) i.next();
|
|
||||||
// IASTVariable x = (IASTVariable) i.next();
|
|
||||||
// assertFalse( i.hasNext() );
|
|
||||||
// assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kind PM_ARROWSTAR
|
|
||||||
public void testPMArrowStar_bug43579() throws Exception
|
|
||||||
{
|
|
||||||
//parse no longer passes
|
|
||||||
try{
|
|
||||||
parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);"); //$NON-NLS-1$
|
|
||||||
fail();
|
|
||||||
} catch ( ParserException e ){
|
|
||||||
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations();
|
|
||||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
|
||||||
// IASTVariable a = (IASTVariable) i.next();
|
|
||||||
// IASTVariable pm = (IASTVariable) i.next();
|
|
||||||
// IASTFunction f1 = (IASTFunction) i.next();
|
|
||||||
// IASTFunction f2 = (IASTFunction) i.next();
|
|
||||||
// IASTVariable x = (IASTVariable) i.next();
|
|
||||||
// assertFalse( i.hasNext() );
|
|
||||||
// assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2)));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.failedTests;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.BaseASTTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hamer
|
|
||||||
*/
|
|
||||||
public class STLFailedTests extends BaseASTTest {
|
|
||||||
|
|
||||||
public STLFailedTests(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug36805() throws Exception{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("__STL_BEGIN_NAMESPACE\n");
|
|
||||||
code.write("template <class _CharT> class char_traits\n");
|
|
||||||
code.write(": public __char_traits_base<_CharT, _CharT>\n");
|
|
||||||
code.write("{};\n");
|
|
||||||
assertCodeFailsParse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug40714() throws Exception{
|
|
||||||
// templates of variables
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("template <bool __threads, int __inst>\n");
|
|
||||||
code.write("char* default_alloc_template<__threads, __inst>::_S_start_free = 0;\n");
|
|
||||||
IASTCompilationUnit cu = parse(code.toString());
|
|
||||||
IASTTemplateDeclaration templateDecl = (IASTTemplateDeclaration) cu.getDeclarations().next();
|
|
||||||
// should not get this exception
|
|
||||||
IASTVariable v = (IASTVariable) templateDecl.getOwnedDeclaration();
|
|
||||||
assertEquals( v, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.failedTests;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author johnc
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SelectionParseFailedTest extends SelectionParseBaseTest {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -88,6 +88,7 @@ public class StructuralCModelElementsTests extends TestCase {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2001, 2006 IBM Corporation and others.
|
* Copyright (c) 2001, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -24,9 +24,6 @@ import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*
|
*
|
||||||
|
@ -157,7 +154,6 @@ public abstract class AutomatedFramework extends TestCase {
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ISourceElementRequestor nullCallback = new NullSourceElementRequestor();
|
|
||||||
protected static Properties properties = new Properties();
|
protected static Properties properties = new Properties();
|
||||||
protected static String defaultNature;
|
protected static String defaultNature;
|
||||||
protected static String outputFile = null;
|
protected static String outputFile = null;
|
||||||
|
|
|
@ -1,131 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2005 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 Corp. - Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.testplugin.CTestPlugin;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public class AutomatedTest extends AutomatedFramework {
|
|
||||||
|
|
||||||
public AutomatedTest() {
|
|
||||||
}
|
|
||||||
public AutomatedTest(String name){
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doFile() throws Throwable {
|
|
||||||
assertNotNull( fileList );
|
|
||||||
|
|
||||||
File file = null;
|
|
||||||
IParser parser = null;
|
|
||||||
|
|
||||||
try{
|
|
||||||
file = (File)fileList.removeFirst();
|
|
||||||
|
|
||||||
String filePath = file.getCanonicalPath();
|
|
||||||
ParserLanguage language = ((String)natures.get( filePath )).equalsIgnoreCase("cpp") ? ParserLanguage.CPP : ParserLanguage.C; //$NON-NLS-1$
|
|
||||||
parser = ParserFactory.createParser( ParserFactory.createScanner(filePath, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, null, null ), nullCallback, ParserMode.QUICK_PARSE, language, null);
|
|
||||||
|
|
||||||
assertTrue( parser.parse() );
|
|
||||||
}
|
|
||||||
catch( Throwable e )
|
|
||||||
{
|
|
||||||
String output = null;
|
|
||||||
if( e instanceof AssertionFailedError ){
|
|
||||||
output = file.getCanonicalPath() + ": Parse failed on line "; //$NON-NLS-1$
|
|
||||||
output += parser.getLastErrorLine() + "\n"; //$NON-NLS-1$
|
|
||||||
} else {
|
|
||||||
output = file.getCanonicalPath() + ": " + e.getClass().toString(); //$NON-NLS-1$
|
|
||||||
output += " on line " + parser.getLastErrorLine() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
if( report != null ){
|
|
||||||
report.write( output.getBytes() );
|
|
||||||
}
|
|
||||||
|
|
||||||
fail( output );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AutomatedFramework newTest( String name ){
|
|
||||||
return new AutomatedTest( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
AutomatedFramework frame = new AutomatedTest();
|
|
||||||
|
|
||||||
return frame.createSuite();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void tearDown () throws Exception {
|
|
||||||
if( fileList != null && fileList.size() == 0 && report != null ){
|
|
||||||
report.flush();
|
|
||||||
report.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadProperties() throws Exception{
|
|
||||||
String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
resourcePath += "resources/parser/AutomatedTest"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
try{
|
|
||||||
FileInputStream propertiesIn = new FileInputStream( resourcePath + "/AutomatedTest.properties"); //$NON-NLS-1$
|
|
||||||
properties.load( propertiesIn );
|
|
||||||
|
|
||||||
outputFile = properties.getProperty( "outputFile", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
String sourceInfo = properties.getProperty( "source", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
if( sourceInfo.equals("") ) //$NON-NLS-1$
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$
|
|
||||||
String str = null, val = null;
|
|
||||||
try{
|
|
||||||
while( tokenizer.hasMoreTokens() ){
|
|
||||||
str = tokenizer.nextToken().trim();
|
|
||||||
val = tokenizer.nextToken().trim();
|
|
||||||
|
|
||||||
testSources.put( str, val );
|
|
||||||
}
|
|
||||||
} catch ( NoSuchElementException e ){
|
|
||||||
//only way to get here is to have a missing val, assume cpp for that str
|
|
||||||
testSources.put( str, "cpp" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch ( FileNotFoundException e ){
|
|
||||||
testSources.put( resourcePath + "/defaultCpp", "cpp" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
testSources.put( resourcePath + "/defaultC", "c" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,196 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
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.ast.ASTNotImplementedException;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class BaseASTTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ProblemCallback extends QuickParseCallback implements
|
|
||||||
ISourceElementRequestor {
|
|
||||||
|
|
||||||
List problems = new ArrayList();
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
|
||||||
*/
|
|
||||||
public boolean acceptProblem(IProblem problem) {
|
|
||||||
problems.add( problem );
|
|
||||||
return super.acceptProblem( problem );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public BaseASTTest( String a )
|
|
||||||
{
|
|
||||||
super( a );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ProblemCallback quickParseCallback;
|
|
||||||
protected IParser parser;
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse( String code, boolean quick, boolean throwExceptionOnError, ParserLanguage lang ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
|
||||||
quickParseCallback = new ProblemCallback();
|
|
||||||
parser = ParserFactory.createParser( ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); //$NON-NLS-1$
|
|
||||||
if( ! parser.parse() && throwExceptionOnError )
|
|
||||||
throw new ParserException("Parse failure"); //$NON-NLS-1$
|
|
||||||
return ((QuickParseCallback)quickParseCallback).getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse( String code, boolean quick, boolean throwExceptionOnError ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return parse( code, quick, throwExceptionOnError, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse( String code )throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return parse( code, true, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTCompilationUnit fullParse( String code ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return parse( code, false, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return assertSoleDeclaration( code, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTDeclaration assertSoleDeclaration( String code, ParserLanguage language ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
Iterator declarationIter = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
declarationIter = parse(code, true, true, language).getDeclarations();
|
|
||||||
}
|
|
||||||
catch (ASTNotImplementedException e1)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNotNull( declarationIter );
|
|
||||||
assertTrue( declarationIter.hasNext() );
|
|
||||||
IASTDeclaration returnValue = (IASTDeclaration)declarationIter.next();
|
|
||||||
assertFalse( declarationIter.hasNext() );
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertCodeFailsParse( String code )
|
|
||||||
{
|
|
||||||
assertCodeFailsParse( code, true, true, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertCodeFailsParse(String code, boolean quick, boolean throwOnError, ParserLanguage CPP ) {
|
|
||||||
boolean testPassed = false;
|
|
||||||
try {
|
|
||||||
parse(code, quick, throwOnError, CPP );
|
|
||||||
testPassed = true;
|
|
||||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
|
||||||
} catch (Throwable e) {
|
|
||||||
if (!(e instanceof ParserException))
|
|
||||||
fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
if (testPassed)
|
|
||||||
fail("The expected error did not occur."); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertCodeFailsFullParse(String code) {
|
|
||||||
boolean testPassed = false;
|
|
||||||
try {
|
|
||||||
fullParse(code);
|
|
||||||
testPassed = true;
|
|
||||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
|
||||||
} catch (Throwable e) {
|
|
||||||
if (!(e instanceof ParserException))
|
|
||||||
fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
if (testPassed)
|
|
||||||
fail("The expected error did not occur."); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type)
|
|
||||||
{
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), type );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertSimpleType(IASTTypedefDeclaration variable, IASTSimpleTypeSpecifier.Type type)
|
|
||||||
{
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclarator().getTypeSpecifier()).getType(), type );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void assertSimpleType(IASTVariable variable, IASTSimpleTypeSpecifier.Type type)
|
|
||||||
{
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), type );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertParameterSimpleType(IASTParameterDeclaration variable, IASTSimpleTypeSpecifier.Type type)
|
|
||||||
{
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)variable.getTypeSpecifier()).getType(), type );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void failedAsExpected()
|
|
||||||
{
|
|
||||||
assertFalse( "The expected error did not occur.", false ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertNotReached()
|
|
||||||
{
|
|
||||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertQualifiedName(String [] fromAST, String [] theTruth)
|
|
||||||
{
|
|
||||||
assertNotNull( fromAST );
|
|
||||||
assertNotNull( theTruth );
|
|
||||||
assertEquals( fromAST.length, theTruth.length );
|
|
||||||
for( int i = 0; i < fromAST.length; ++i )
|
|
||||||
{
|
|
||||||
assertEquals( fromAST[i], theTruth[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -13,68 +13,12 @@ package org.eclipse.cdt.core.parser.tests;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayPool;
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*/
|
*/
|
||||||
public class CharArrayUtilsTest extends TestCase {
|
public class CharArrayUtilsTest extends TestCase {
|
||||||
|
|
||||||
public void testPoolAdd() {
|
|
||||||
CharArrayPool dict = new CharArrayPool(1);
|
|
||||||
|
|
||||||
char[] str1 = new char[] {'h', 'e', 'l', 'l', 'o'};
|
|
||||||
char[] str2 = dict.add(str1);
|
|
||||||
assertTrue(CharArrayUtils.equals(str1, str2));
|
|
||||||
assertNotSame(str1, str2);
|
|
||||||
char[] str3 = dict.add(str1);
|
|
||||||
assertSame(str2, str3);
|
|
||||||
|
|
||||||
char[] str4 = new char[] {'w', 'o', 'r', 'l', 'd'};
|
|
||||||
char[] str5 = dict.add(str4, 0, str4.length);
|
|
||||||
assertTrue(CharArrayUtils.equals(str4, str5));
|
|
||||||
assertNotSame(str4, str5);
|
|
||||||
char[] str6 = dict.add(str4);
|
|
||||||
assertSame(str5, str6);
|
|
||||||
|
|
||||||
char[] str7 = dict.add(str1, 0, str1.length);
|
|
||||||
assertTrue(CharArrayUtils.equals(str1, str7));
|
|
||||||
assertNotSame(str1, str7);
|
|
||||||
char[] str8 = dict.add(str1);
|
|
||||||
assertSame(str7, str8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPoolConflict() {
|
|
||||||
CharArrayPool dict = new CharArrayPool(2);
|
|
||||||
|
|
||||||
char[] str1 = new char[] {'h', 'e', 'l', 'l', 'o'};
|
|
||||||
char[] str2 = dict.add(str1);
|
|
||||||
|
|
||||||
// The hash algorithm should give this the same hash code
|
|
||||||
char[] str3 = new char[] {'h', 'o', 'l', 'l', 'e'};
|
|
||||||
char[] str4 = dict.add(str3);
|
|
||||||
assertNotSame(str2, str4);
|
|
||||||
|
|
||||||
char[] str5 = dict.add(str1);
|
|
||||||
assertTrue(CharArrayUtils.equals(str1, str5));
|
|
||||||
|
|
||||||
char[] str6 = new char[] {'w', 'o', 'r', 'l', 'd'};
|
|
||||||
char[] str7 = dict.add(str6);
|
|
||||||
assertTrue(CharArrayUtils.equals(str6, str7));
|
|
||||||
|
|
||||||
char[] str8 = dict.add(str3);
|
|
||||||
assertSame(str4, str8);
|
|
||||||
|
|
||||||
char[] str9 = dict.add(str1);
|
|
||||||
assertNotSame(str2, str9);
|
|
||||||
|
|
||||||
// This should be the same since the removals are done by addition time,
|
|
||||||
// not access time
|
|
||||||
char[] str10 = dict.add(str6);
|
|
||||||
assertSame(str7, str10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMapAdd() {
|
public void testMapAdd() {
|
||||||
CharArrayObjectMap map = new CharArrayObjectMap(4);
|
CharArrayObjectMap map = new CharArrayObjectMap(4);
|
||||||
char[] key1 = "key1".toCharArray();
|
char[] key1 = "key1".toCharArray();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,424 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
/*
|
|
||||||
* Created on Feb 25, 2004
|
|
||||||
*
|
|
||||||
* To change the template for this generated file go to
|
|
||||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
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.ast.IASTBaseSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
|
||||||
*/
|
|
||||||
public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest {
|
|
||||||
public CompleteParseASTSymbolIteratorTest(String a)
|
|
||||||
{
|
|
||||||
super(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CompilationUnitCallback extends NullSourceElementRequestor implements ISourceElementRequestor {
|
|
||||||
IASTCompilationUnit compilationUnit;
|
|
||||||
|
|
||||||
public void enterCompilationUnit(IASTCompilationUnit compUnit)
|
|
||||||
{
|
|
||||||
compilationUnit = compUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTCompilationUnit getCompilationUnit(){
|
|
||||||
return compilationUnit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CompilationUnitCallback localCallback;
|
|
||||||
|
|
||||||
protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
localCallback = new CompilationUnitCallback();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(),
|
|
||||||
ParserMode.COMPLETE_PARSE, language, localCallback, new NullLogService(), null ), localCallback, ParserMode.COMPLETE_PARSE, language, null
|
|
||||||
);
|
|
||||||
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
return localCallback.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Iterator getDeclarations(IASTScope scope)
|
|
||||||
{
|
|
||||||
//don't want to use this
|
|
||||||
assertTrue( false );
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEmptyCompilationUnit() throws Exception
|
|
||||||
{
|
|
||||||
IASTScope compilationUnit = parse( "// no real code "); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertNotNull( compilationUnit );
|
|
||||||
assertFalse( compilationUnit.getDeclarations().hasNext() );
|
|
||||||
try{
|
|
||||||
compilationUnit.getDeclarations().next();
|
|
||||||
assertTrue( false );
|
|
||||||
} catch( NoSuchElementException e ){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleNamespace() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "namespace A { }").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$
|
|
||||||
assertFalse( namespaceDefinition.getDeclarations().hasNext() );
|
|
||||||
|
|
||||||
try{
|
|
||||||
declarations.remove();
|
|
||||||
assertTrue( false );
|
|
||||||
} catch( UnsupportedOperationException e ){
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMultipleNamespaceDefinitions() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "namespace A { } namespace A { }").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNestedNamespaceDefinitions() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "namespace A { namespace B { } }").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
|
|
||||||
Iterator subDeclarations = namespaceDefinition.getDeclarations();
|
|
||||||
IASTNamespaceDefinition subDeclaration = (IASTNamespaceDefinition)subDeclarations.next();
|
|
||||||
assertEquals( subDeclaration.getName(), "B" ); //$NON-NLS-1$
|
|
||||||
assertFalse( subDeclarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEmptyClassDeclaration() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { };").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTClassSpecifier classSpec = (IASTClassSpecifier)declarations.next();
|
|
||||||
assertEquals( classSpec.getName(), "A"); //$NON-NLS-1$
|
|
||||||
assertFalse( classSpec.getDeclarations().hasNext() );
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNestedSubclass() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "namespace N { class A { }; } class B : protected virtual N::A { };").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
|
|
||||||
Iterator nsDecls = namespaceDefinition.getDeclarations();
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier)nsDecls.next();
|
|
||||||
assertFalse( nsDecls.hasNext() );
|
|
||||||
|
|
||||||
IASTClassSpecifier classB = (IASTClassSpecifier)declarations.next();
|
|
||||||
|
|
||||||
Iterator baseClauses = classB.getBaseClauses();
|
|
||||||
IASTBaseSpecifier baseClass = (IASTBaseSpecifier)baseClauses.next();
|
|
||||||
assertEquals( classA, baseClass.getParentClassSpecifier() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleVariable() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "int x;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTVariable v = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( v.getName(), "x"); //$NON-NLS-1$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleClassReferenceVariable() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { } a; A x;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
|
|
||||||
assertFalse( classA.getDeclarations().hasNext() );
|
|
||||||
|
|
||||||
IASTVariable a = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( a.getName(), "a"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTVariable v = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( v.getName(), "x"); //$NON-NLS-1$
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMultipleDeclaratorsVariable() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
|
|
||||||
|
|
||||||
IASTVariable v = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( v.getName(), "x"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
v = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( v.getName(), "y"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
v = (IASTVariable)declarations.next();
|
|
||||||
assertEquals( v.getName(), "z"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
|
|
||||||
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleField() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { double x; };").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
|
|
||||||
|
|
||||||
Iterator fields = classA.getDeclarations();
|
|
||||||
|
|
||||||
IASTField f = (IASTField)fields.next();
|
|
||||||
|
|
||||||
assertEquals( f.getName(), "x" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertFalse( fields.hasNext() );
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void testSimpleFunction() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "void foo( void );").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTFunction function = (IASTFunction)declarations.next();
|
|
||||||
assertEquals( function.getName(), "foo" ); //$NON-NLS-1$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleMethod() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { void foo(); };").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
|
|
||||||
|
|
||||||
IASTMethod method = (IASTMethod) classA.getDeclarations().next();
|
|
||||||
assertEquals( method.getName(), "foo" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testLinkageSpec() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "extern \"C\" { int foo(); }").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
//7.5-4 A linkage specification does not establish a scope
|
|
||||||
IASTFunction f = (IASTFunction)declarations.next();
|
|
||||||
assertEquals( f.getName(),"foo"); //$NON-NLS-1$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleTypedef() throws Exception
|
|
||||||
{
|
|
||||||
Iterator iter = parse( "typedef int myInt;\n myInt var;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)iter.next();
|
|
||||||
|
|
||||||
assertEquals( typedef.getName(), "myInt"); //$NON-NLS-1$
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT );
|
|
||||||
|
|
||||||
IASTVariable v = (IASTVariable)iter.next();
|
|
||||||
assertEquals( v.getName(), "var"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertFalse( iter.hasNext() );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testOverride() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse( "void foo();\n void foo( int );\n").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTFunction f1 = (IASTFunction)i.next();
|
|
||||||
IASTFunction f2 = (IASTFunction)i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEnumerations() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}").getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
|
|
||||||
Iterator namespaceMembers = namespaceA.getDeclarations();
|
|
||||||
|
|
||||||
IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)namespaceMembers.next();
|
|
||||||
|
|
||||||
assertEquals( enumE.getName(), "E"); //$NON-NLS-1$
|
|
||||||
assertQualifiedName( enumE.getFullyQualifiedName(), new String [] { "A", "E" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
Iterator enumerators = enumE.getEnumerators();
|
|
||||||
IASTEnumerator enumerator_e1 = (IASTEnumerator)enumerators.next();
|
|
||||||
IASTEnumerator enumerator_e2 = (IASTEnumerator)enumerators.next();
|
|
||||||
IASTEnumerator enumerator_e3 = (IASTEnumerator)enumerators.next();
|
|
||||||
assertFalse( enumerators.hasNext() );
|
|
||||||
assertEquals( enumerator_e1.getName(), "e1"); //$NON-NLS-1$
|
|
||||||
assertEquals( enumerator_e2.getName(), "e2"); //$NON-NLS-1$
|
|
||||||
assertEquals( enumerator_e3.getName(), "e3"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTVariable varE = (IASTVariable)namespaceMembers.next();
|
|
||||||
assertEquals( ((IASTSimpleTypeSpecifier)varE.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), enumE );
|
|
||||||
|
|
||||||
assertFalse( namespaceMembers.hasNext() );
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMethodDefinitions() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse( " class A { void f(); }; void A::f(){ }" ).getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = classA.getDeclarations();
|
|
||||||
|
|
||||||
IASTMethod f = (IASTMethod)i.next();
|
|
||||||
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConstructorsDestructors() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse( "class A { A(); ~A(); }; A::A(){} A::~A(){}" ).getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTClassSpecifier classA = (IASTClassSpecifier) i.next();
|
|
||||||
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = classA.getDeclarations();
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
|
|
||||||
IASTMethod constructor = (IASTMethod) i.next();
|
|
||||||
assertTrue( constructor.getName().equals( "A" ) ); //$NON-NLS-1$
|
|
||||||
IASTMethod destructor = (IASTMethod) i.next();
|
|
||||||
assertTrue( destructor.getName().equals( "~A" ) ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUsingDirectives() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse( "namespace NS { int i; } using namespace NS;" ).getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next();
|
|
||||||
IASTUsingDirective using = (IASTUsingDirective) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUsingDeclaration() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse( "namespace NS{ void f(); void f( int ); }; using NS::f;" ).getDeclarations(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next();
|
|
||||||
IASTUsingDeclaration using = (IASTUsingDeclaration) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug75482() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "class A { friend class B * helper(); };" ); //$NON-NLS-1$
|
|
||||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
|
||||||
IASTClassSpecifier A = (IASTClassSpecifier) i.next();
|
|
||||||
IASTFunction helper = (IASTFunction) i.next();
|
|
||||||
i = A.getDeclarations();
|
|
||||||
IASTElaboratedTypeSpecifier B = (IASTElaboratedTypeSpecifier) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = A.getFriends();
|
|
||||||
assertEquals( i.next(), helper );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug77010() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write(" struct Example{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int *deref(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int const *deref() const; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int volatile *deref() volatile; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int const volatile *deref() const volatile; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" }; \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
|
||||||
|
|
||||||
IASTClassSpecifier Example = (IASTClassSpecifier) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
i = Example.getDeclarations();
|
|
||||||
IASTMethod deref = (IASTMethod) i.next();
|
|
||||||
assertFalse( deref.getReturnType().isConst() );
|
|
||||||
assertFalse( deref.getReturnType().isVolatile() );
|
|
||||||
assertFalse( deref.isConst() );
|
|
||||||
assertFalse( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertTrue( deref.getReturnType().isConst() );
|
|
||||||
assertFalse( deref.getReturnType().isVolatile() );
|
|
||||||
assertTrue( deref.isConst() );
|
|
||||||
assertFalse( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertFalse( deref.getReturnType().isConst() );
|
|
||||||
assertTrue( deref.getReturnType().isVolatile() );
|
|
||||||
assertFalse( deref.isConst() );
|
|
||||||
assertTrue( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertTrue( deref.getReturnType().isConst() );
|
|
||||||
assertTrue( deref.getReturnType().isVolatile() );
|
|
||||||
assertTrue( deref.isConst() );
|
|
||||||
assertTrue( deref.isVolatile() );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,273 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2005 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created on Aug 23, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*/
|
|
||||||
public class CompleteParsePluginTest extends FileBasePluginTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public CompleteParsePluginTest(String name)
|
|
||||||
{
|
|
||||||
super(name, CompleteParsePluginTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite suite = new TestSuite( CompleteParsePluginTest.class );
|
|
||||||
suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72219() throws Exception {
|
|
||||||
String foo = "int FOO;"; //$NON-NLS-1$
|
|
||||||
String code = "#include \"foo.h\" \n int bar;"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
importFile( "foo.h", foo ); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
Iterator i = parse( cpp, calls ).getDeclarations();
|
|
||||||
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = calls.iterator();
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72219_2() throws Exception {
|
|
||||||
String foo = "int FOO;"; //$NON-NLS-1$
|
|
||||||
String code = "int bar; \n #include \"foo.h\""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
importFile( "foo.h", foo ); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
Iterator i = parse( cpp, calls ).getDeclarations();
|
|
||||||
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = calls.iterator();
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72219_3() throws Exception {
|
|
||||||
String defs = "#define A \n #define B \n"; //$NON-NLS-1$
|
|
||||||
String code = "int foo; \n #include \"defs.h\" \n int bar;"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
importFile( "defs.h", defs); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
Iterator i = parse( cpp, calls ).getDeclarations();
|
|
||||||
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertTrue( i.next() instanceof IASTVariable );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = calls.iterator();
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test72219_4() throws Exception{
|
|
||||||
String code = "int a; \n #define A\n int b;\n #define B\n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$
|
|
||||||
List calls = new ArrayList();
|
|
||||||
|
|
||||||
parse( cpp, calls );
|
|
||||||
|
|
||||||
Iterator i = calls.iterator();
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72506() throws Exception{
|
|
||||||
String vers = "int i;\n"; //$NON-NLS-1$
|
|
||||||
String code = "#define INCFILE(x) vers ## x\n" + //$NON-NLS-1$
|
|
||||||
"#define xstr(x) str(x)\n" + //$NON-NLS-1$
|
|
||||||
"#define str(x) #x\n" + //$NON-NLS-1$
|
|
||||||
"#include xstr(INCFILE(2).h)\n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
importFile( "vers2.h", vers ); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
|
|
||||||
parse( cpp, calls );
|
|
||||||
|
|
||||||
Iterator i = calls.iterator();
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testExpressionEvalProblems() throws Exception
|
|
||||||
{
|
|
||||||
String h = " #if 09 == 9 \n" + //$NON-NLS-1$ //bad octal
|
|
||||||
" #endif \n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
String code = "int i1; \n" + //$NON-NLS-1$
|
|
||||||
"#include \"h.h\"\n" + //$NON-NLS-1$
|
|
||||||
"int i2; \n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
importFile( "h.h", h ); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "c.cpp", code ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
parse( cpp, calls );
|
|
||||||
|
|
||||||
Iterator i = calls.iterator();
|
|
||||||
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_PROBLEM );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug79339() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("#ifndef _HEADER_\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#define _HEADER_\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#define ONE 1\n"); //$NON-NLS-1$
|
|
||||||
writer.write("int foo(int);\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#endif // _HEADER_\n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
importFile( "header.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"header.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int foo2(){\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " return foo(ONE);\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "test.cpp", source ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
int start = source.indexOf( "foo(ONE)" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
IASTNode node = parse( cpp, calls, start, start + 3 ); //$NON-NLS-1$
|
|
||||||
assertTrue(node instanceof IASTFunction);
|
|
||||||
IASTFunction foo = (IASTFunction)node;
|
|
||||||
assertEquals(foo.getStartingLine(), 4);
|
|
||||||
assertEquals(foo.getNameOffset(), 52);
|
|
||||||
assertEquals(foo.getName(), "foo"); //$NON-NLS-1$
|
|
||||||
assertTrue(new String(foo.getFilename()).indexOf("header.h") > 0); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug79810B() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("#define __WTERMSIG(status) ((status) & 0x7f)\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#define __WIFEXITED(status) (__WTERMSIG(status) == 0)\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#define __WAIT_INT(status) (__extension__ ({ union { int __in; int __i; } __u; \\\n"); //$NON-NLS-1$
|
|
||||||
writer.write(" __u.__in = (test); __u.__i; }))\n"); //$NON-NLS-1$
|
|
||||||
writer.write("#define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))\n"); //$NON-NLS-1$
|
|
||||||
importFile( "header.h", writer.toString() ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"header.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write("void foo() {\n"); //$NON-NLS-1$
|
|
||||||
writer.write("int test;\n"); //$NON-NLS-1$
|
|
||||||
writer.write("if (WIFEXITED(test)) {}\n}\n"); //$NON-NLS-1$
|
|
||||||
IFile cpp = importFile( "test.cpp", writer.toString() ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
List calls = new ArrayList();
|
|
||||||
parse( cpp, calls );
|
|
||||||
|
|
||||||
Iterator i = calls.iterator();
|
|
||||||
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_FUNCTION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_CODE_BLOCK );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_CLASS_SPEC );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_FIELD );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_FIELD );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_CLASS );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_CODE_BLOCK );
|
|
||||||
assertEquals( i.next(), CallbackTracker.ENTER_CODE_BLOCK );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_CODE_BLOCK );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_FUNCTION );
|
|
||||||
assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,139 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CompleteParseProblemTest extends CompleteParseBaseTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public CompleteParseProblemTest() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public CompleteParseProblemTest(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBadClassName() throws Exception
|
|
||||||
{
|
|
||||||
validateInvalidClassName("12345"); //$NON-NLS-1$
|
|
||||||
validateInvalidClassName("*"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws ParserException
|
|
||||||
* @throws ParserFactoryError
|
|
||||||
*/
|
|
||||||
protected void validateInvalidClassName( String name ) throws ParserException, ParserFactoryError {
|
|
||||||
StringBuffer buffer = new StringBuffer( "class "); //$NON-NLS-1$
|
|
||||||
|
|
||||||
buffer.append( name );
|
|
||||||
buffer.append( " { };"); //$NON-NLS-1$
|
|
||||||
String code = buffer.toString();
|
|
||||||
parse( code, false );
|
|
||||||
assertFalse( callback.problems.isEmpty() );
|
|
||||||
assertEquals( callback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
|
||||||
assertTrue( p.checkCategory( IProblem.SYNTAX_RELATED ));
|
|
||||||
assertEquals( p.getID(), IProblem.SYNTAX_ERROR );
|
|
||||||
assertEquals( p.getSourceStart(), code.indexOf( name )); //$NON-NLS-1$
|
|
||||||
assertEquals( p.getSourceEnd(), code.indexOf( name ) + name.length() ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug68306() throws Exception
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append( "class Foo { int bar( int ); };\n" ); //$NON-NLS-1$
|
|
||||||
buffer.append( "int Foo::bar( int ){}\n" ); //$NON-NLS-1$
|
|
||||||
buffer.append( "int Foo::bar( int ){} //error\n" ); //$NON-NLS-1$
|
|
||||||
String code = buffer.toString();
|
|
||||||
parse( code, false );
|
|
||||||
assertFalse( callback.problems.isEmpty() );
|
|
||||||
assertEquals( callback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
|
||||||
assertTrue( p.checkCategory( IProblem.SEMANTICS_RELATED ));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug68931() throws Exception
|
|
||||||
{
|
|
||||||
String code = "void foo(){ SomeUnknownType t; } "; //$NON-NLS-1$
|
|
||||||
parse( code, false );
|
|
||||||
|
|
||||||
int start = code.indexOf( "SomeUnknownType" ); //$NON-NLS-1$
|
|
||||||
int end = start + 15;
|
|
||||||
|
|
||||||
assertFalse( callback.problems.isEmpty() );
|
|
||||||
assertEquals( callback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
|
||||||
assertTrue( p.checkCategory( IProblem.SEMANTICS_RELATED ));
|
|
||||||
assertEquals( p.getSourceStart(), start );
|
|
||||||
assertEquals( p.getSourceEnd(), end );
|
|
||||||
assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug69744() throws Exception
|
|
||||||
{
|
|
||||||
String code = "int f() { try { } catch( foo bar ) {} catch ( ... ) {} } int i;"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
Iterator i = parse( code, false ).getDeclarations();
|
|
||||||
|
|
||||||
int start = code.indexOf( "foo" ); //$NON-NLS-1$
|
|
||||||
int end = start + 3;
|
|
||||||
|
|
||||||
assertEquals( callback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
|
||||||
|
|
||||||
assertEquals( p.getSourceStart(), start );
|
|
||||||
assertEquals( p.getSourceEnd(), end );
|
|
||||||
assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND );
|
|
||||||
|
|
||||||
IASTFunction f = (IASTFunction) i.next();
|
|
||||||
IASTVariable varI = (IASTVariable) i.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug69745() throws Exception
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append( "namespace NS{ template < class T > int foo(){}; } \n" ); //$NON-NLS-1$
|
|
||||||
buffer.append( "void f() { using NS::foo; using NS::foo<int>; } \n" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
String code = buffer.toString();
|
|
||||||
|
|
||||||
parse( code, false );
|
|
||||||
|
|
||||||
int start = code.indexOf( "using NS::foo<int>;" ); //$NON-NLS-1$
|
|
||||||
int end = start + "using NS::foo<int>;".length(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertEquals( callback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
|
||||||
|
|
||||||
assertEquals( p.getSourceStart(), start );
|
|
||||||
assertEquals( p.getSourceEnd(), end );
|
|
||||||
assertEquals( p.getID(), IProblem.SEMANTIC_INVALID_USING );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,126 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author johnc
|
|
||||||
*/
|
|
||||||
public class CompletionParseBaseTest extends CompleteParseBaseTest {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public CompletionParseBaseTest() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public CompletionParseBaseTest(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTCompletionNode parse(String code, int offset) throws Exception {
|
|
||||||
callback = new FullParseCallback();
|
|
||||||
IParser parser = null;
|
|
||||||
|
|
||||||
parser =
|
|
||||||
ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
new CodeReader(code.toCharArray()),
|
|
||||||
new ScannerInfo(),
|
|
||||||
ParserMode.COMPLETION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
callback,
|
|
||||||
new NullLogService(), null),
|
|
||||||
callback,
|
|
||||||
ParserMode.COMPLETION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
null);
|
|
||||||
|
|
||||||
return parser.parse( offset );
|
|
||||||
|
|
||||||
}
|
|
||||||
protected IASTCompletionNode parse(String code, int offset, ParserLanguage lang) throws Exception {
|
|
||||||
callback = new FullParseCallback();
|
|
||||||
IParser parser = null;
|
|
||||||
|
|
||||||
parser =
|
|
||||||
ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
new CodeReader(code.toCharArray()),
|
|
||||||
new ScannerInfo(),
|
|
||||||
ParserMode.COMPLETION_PARSE,
|
|
||||||
lang,
|
|
||||||
callback,
|
|
||||||
new NullLogService(), null),
|
|
||||||
callback,
|
|
||||||
ParserMode.COMPLETION_PARSE,
|
|
||||||
lang,
|
|
||||||
null);
|
|
||||||
|
|
||||||
return parser.parse( offset );
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param result
|
|
||||||
*/
|
|
||||||
protected void validateLookupResult(ILookupResult result, Set matches) {
|
|
||||||
|
|
||||||
assertNotNull( matches );
|
|
||||||
assertEquals( result.getResultsSize(), matches.size() );
|
|
||||||
|
|
||||||
Iterator iter = result.getNodes();
|
|
||||||
while( iter.hasNext() )
|
|
||||||
{
|
|
||||||
IASTOffsetableNamedElement element = (IASTOffsetableNamedElement) iter.next();
|
|
||||||
assertTrue( matches.contains( element.getName() ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected IASTCompilationUnit getCompilationUnit() {
|
|
||||||
IASTCompilationUnit compilationUnit = (IASTCompilationUnit) ((Scope) callback.getCompilationUnit()).getScope();
|
|
||||||
return compilationUnit;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param node
|
|
||||||
* @param hasKeywords
|
|
||||||
*/
|
|
||||||
protected void validateCompletionNode(IASTCompletionNode node, String prefix, CompletionKind kind, IASTNode context, boolean hasKeywords) {
|
|
||||||
assertNotNull( node );
|
|
||||||
assertEquals( node.getCompletionPrefix(), prefix);
|
|
||||||
assertEquals( node.getCompletionKind(), kind );
|
|
||||||
assertEquals( node.getCompletionContext(), context );
|
|
||||||
if( hasKeywords )
|
|
||||||
assertTrue( node.getKeywords().hasNext() );
|
|
||||||
else
|
|
||||||
assertFalse( node.getKeywords().hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,206 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*/
|
|
||||||
public class FailingTemplateTests extends TestCase {
|
|
||||||
|
|
||||||
public ParserSymbolTable table = null;
|
|
||||||
|
|
||||||
public FailingTemplateTests( String arg )
|
|
||||||
{
|
|
||||||
super( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParserSymbolTable newTable(){
|
|
||||||
return newTable( ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParserSymbolTable newTable( ParserLanguage language ){
|
|
||||||
table = new ParserSymbolTable( language, ParserMode.COMPLETE_PARSE );
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* These tests represent code snippets from the ANSI C++ spec
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specialization of a member function template does not override a virtual
|
|
||||||
* function from a base class.
|
|
||||||
*
|
|
||||||
* class B {
|
|
||||||
* virtual void f( int );
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* class D : public B{
|
|
||||||
* template < class T > void f( T );
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* template <> void D::f< int > ( int ) {} //does not override B::f( int );
|
|
||||||
*
|
|
||||||
* void main(){
|
|
||||||
* D d;
|
|
||||||
* d.f( 1 ); //calls B::f( int )
|
|
||||||
* d.f<>( 1 ); //calls D::f<int>( int );
|
|
||||||
* }
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void test_14_5_2__4_VirtualBaseClassFunctions() throws Exception{
|
|
||||||
//bug 51483 TBD
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* template < class T = int > struct A {
|
|
||||||
* static int x;
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* template <> struct A< double > {}; //specialize T == double
|
|
||||||
* template <> struct A<> {}; //specialize T == int
|
|
||||||
*
|
|
||||||
* template <> int A< char >::x = 0;
|
|
||||||
* template <> int A< float >::x = 0.5;
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void test_14_7__3_ExplicitSpecialization() throws Exception{
|
|
||||||
//bug 51485
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Each class template specialization instantiated from a template has its own
|
|
||||||
* copy of any static members
|
|
||||||
*
|
|
||||||
* template < class T > class X {
|
|
||||||
* static T s;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* template < class T > T X<T>::s = 0;
|
|
||||||
*
|
|
||||||
* X<int> a; //a.s has type int
|
|
||||||
* X<char *> b; //b.s has type char *
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void test_14_7__6_ExplicitSpecializationStaticMembers() throws Exception{
|
|
||||||
//bug 51485
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* template<class T> void f( void (*) (T, int) );
|
|
||||||
* template<class T> void foo( T, int );
|
|
||||||
*
|
|
||||||
* void g( int, int );
|
|
||||||
* void g( char, int );
|
|
||||||
*
|
|
||||||
* void h( int, int, int );
|
|
||||||
* void h( char, int );
|
|
||||||
*
|
|
||||||
* int m(){
|
|
||||||
* f( &g ); //error, ambiguous
|
|
||||||
* f( &h ); //ok, h(char, int) is a unique match
|
|
||||||
* f( &foo ); //error, foo is a template
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void test_14_8_2_4__16_ArgumentDeduction() throws Exception{
|
|
||||||
//This test will require resolving the address of an overloaded function
|
|
||||||
//without arguments. bug 45764
|
|
||||||
|
|
||||||
// newTable();
|
|
||||||
//
|
|
||||||
// ITemplateSymbol templateF = table.newTemplateSymbol( "f" );
|
|
||||||
//
|
|
||||||
// ISymbol T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
|
||||||
// templateF.addParameter( T );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol fParam = table.newParameterizedSymbol( "", TypeInfo.t_function );
|
|
||||||
// fParam.setIsTemplateMember( true );
|
|
||||||
// fParam.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
|
|
||||||
// fParam.addParameter( T, null, false );
|
|
||||||
// fParam.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// fParam.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
|
|
||||||
//
|
|
||||||
// f.addParameter( fParam );
|
|
||||||
//
|
|
||||||
// templateF.addSymbol( f );
|
|
||||||
// table.getCompilationUnit().addSymbol( templateF );
|
|
||||||
//
|
|
||||||
// ITemplateSymbol templateFoo = table.newTemplateSymbol( "foo" );
|
|
||||||
// T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
|
||||||
// templateFoo.addParameter( T );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function );
|
|
||||||
// foo.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
|
|
||||||
// foo.addParameter( T, null, false );
|
|
||||||
// foo.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
//
|
|
||||||
// templateFoo.addSymbol( foo );
|
|
||||||
// table.getCompilationUnit().addSymbol( templateFoo );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol g1 = table.newParameterizedSymbol( "g", TypeInfo.t_function );
|
|
||||||
// g1.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// g1.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// table.getCompilationUnit().addSymbol( g1 );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol g2 = table.newParameterizedSymbol( "g", TypeInfo.t_function );
|
|
||||||
// g2.addParameter( TypeInfo.t_char, 0, null, false );
|
|
||||||
// g2.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// table.getCompilationUnit().addSymbol( g2 );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol h1 = table.newParameterizedSymbol( "h", TypeInfo.t_function );
|
|
||||||
// h1.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// h1.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// h1.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// table.getCompilationUnit().addSymbol( h1 );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", TypeInfo.t_function );
|
|
||||||
// h2.addParameter( TypeInfo.t_char, 0, null, false );
|
|
||||||
// h2.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// table.getCompilationUnit().addSymbol( h2 );
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// List args = new LinkedList();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args );
|
|
||||||
// assertTrue( look != null );
|
|
||||||
// assertTrue( look.isTemplateInstance() );
|
|
||||||
// assertEquals( look.getInstantiatedSymbol(), f );
|
|
||||||
//
|
|
||||||
// look = table.getCompilationUnit().lookup( "foo" );
|
|
||||||
// assertTrue( look != null );
|
|
||||||
// args.clear();
|
|
||||||
// TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, look );
|
|
||||||
// arg.addOperatorExpression( TypeInfo.OperatorExpression.addressof );
|
|
||||||
// args.add( arg );
|
|
||||||
//
|
|
||||||
// try{
|
|
||||||
// look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args );
|
|
||||||
// assertTrue( false );
|
|
||||||
// }catch ( ParserSymbolTableException e ){
|
|
||||||
// assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateParameter );
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,63 +16,14 @@ package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -207,164 +158,4 @@ public class FileBasePluginTest extends TestCase {
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CallbackTracker implements ISourceElementRequestor{
|
|
||||||
private List callbacks;
|
|
||||||
private IASTScope compUnit;
|
|
||||||
public CallbackTracker( List callbacks ){
|
|
||||||
this.callbacks = callbacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTScope getCompilationUnit()
|
|
||||||
{
|
|
||||||
return compUnit;
|
|
||||||
}
|
|
||||||
public static final String ACCEPT_PROBLEM = "ACCEPT_PROBLEM"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_MACRO = "ACCEPT_MACRO"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_VARIABLE = "ACCEPT_VARIABLE"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_FUNCTION_DECL = "ACCEPT_FUNCTION_DECL"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_USING_DIRECTIVE = "ACCEPT_USING_DIRECTIVE"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_USING_DECL = "ACCEPT_USING_DECL"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_ASM_DEF = "ACCEPT_ASM_DEF"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_TYPEDEF = "ACCEPT_TYPEDEF"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_ENUMERATION = "ACCEPT_ENUMERATION"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_ELABORATED = "ACCEPT_ELABORATED"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_ABSTRACT_TYPESPEC = "ACCEPT_ABSTRACT_TYPESPEC"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_METHOD = "ACCEPT_METHOD"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_FIELD = "ACCEPT_FIELD"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_REFERENCE = "ACCEPT_REFERENCE"; //$NON-NLS-1$
|
|
||||||
public static final String ACCEPT_FRIEND = "ACCEPT_FRIEND"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_FUNCTION = "ENTER_FUNCTION"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_CODE_BLOCK = "ENTER_CODE_BLOCK"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_COMPILATION_UNIT = "ENTER_COMPILATION_UNIT"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_INCLUSION = "ENTER_INCLUSION"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_NAMESPACE = "ENTER_NAMESPACE"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_CLASS_SPEC = "ENTER_CLASS_SPEC"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_LINKAGE = "ENTER_LINKAGE"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_TEMPLATE_DECL = "ENTER_TEMPLATE_DECL"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_TEMPLATE_SPEC = "ENTER_TEMPLATE_SPEC"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_TEMPLATE_INSTANCE = "ENTER_TEMPLATE_INSTANCE"; //$NON-NLS-1$
|
|
||||||
public static final String ENTER_METHOD = "ENTER_METHOD"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_FUNCTION = "EXIT_FUNCTION"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_CODE_BLOCK = "EXIT_CODE_BLOCK"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_METHOD = "EXIT_METHOD"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_TEMPLATE_DECL = "EXIT_TEMPLATE_DECL"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_TEMPLATE_SPEC = "EXIT_TEMPLATE_SPEC"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_TEMPLATE_INSTANCE = "EXIT_TEMPLATE_INSTANCE"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_LINKAGE = "EXIT_LINKAGE"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_CLASS = "EXIT_CLASS"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_NAMESPACE = "EXIT_NAMESPACE"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_INCLUSION = "EXIT_INCLUSION"; //$NON-NLS-1$
|
|
||||||
public static final String EXIT_COMPILATION_UNIT = "EXIT_COMPILATION_UNIT"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
|
|
||||||
public boolean acceptProblem( IProblem problem ) {
|
|
||||||
callbacks.add( ACCEPT_PROBLEM );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public void acceptMacro( IASTMacro macro ) { callbacks.add( ACCEPT_MACRO ); }
|
|
||||||
public void acceptVariable( IASTVariable variable ) { callbacks.add( ACCEPT_VARIABLE ); }
|
|
||||||
public void acceptFunctionDeclaration( IASTFunction function ) { callbacks.add( ACCEPT_FUNCTION_DECL); }
|
|
||||||
public void acceptUsingDirective( IASTUsingDirective usageDirective ) { callbacks.add( ACCEPT_USING_DIRECTIVE ); }
|
|
||||||
public void acceptUsingDeclaration( IASTUsingDeclaration usageDeclaration ) { callbacks.add( ACCEPT_USING_DECL ); }
|
|
||||||
public void acceptASMDefinition( IASTASMDefinition asmDefinition ) { callbacks.add( ACCEPT_ASM_DEF ); }
|
|
||||||
public void acceptTypedefDeclaration( IASTTypedefDeclaration typedef ) { callbacks.add( ACCEPT_TYPEDEF ); }
|
|
||||||
public void acceptEnumerationSpecifier( IASTEnumerationSpecifier enumeration ) { callbacks.add( ACCEPT_ENUMERATION); }
|
|
||||||
public void acceptElaboratedForewardDeclaration( IASTElaboratedTypeSpecifier elaboratedType ) { callbacks.add( ACCEPT_ELABORATED ); }
|
|
||||||
public void acceptAbstractTypeSpecDeclaration( IASTAbstractTypeSpecifierDeclaration abstractDeclaration ) { callbacks.add( ACCEPT_ABSTRACT_TYPESPEC); }
|
|
||||||
public void enterFunctionBody( IASTFunction function ) { callbacks.add( ENTER_FUNCTION ); }
|
|
||||||
public void exitFunctionBody( IASTFunction function ) { callbacks.add( EXIT_FUNCTION ); }
|
|
||||||
public void enterCodeBlock( IASTCodeScope scope ) { callbacks.add( ENTER_CODE_BLOCK ); }
|
|
||||||
public void exitCodeBlock( IASTCodeScope scope ) { callbacks.add( EXIT_CODE_BLOCK ); }
|
|
||||||
public void enterInclusion( IASTInclusion inclusion ) { callbacks.add( ENTER_INCLUSION ); }
|
|
||||||
public void enterNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ) { callbacks.add( ENTER_NAMESPACE ); }
|
|
||||||
public void enterClassSpecifier( IASTClassSpecifier classSpecification ) { callbacks.add( ENTER_CLASS_SPEC ); }
|
|
||||||
public void enterLinkageSpecification( IASTLinkageSpecification linkageSpec ) { callbacks.add( ENTER_LINKAGE ); }
|
|
||||||
public void enterTemplateDeclaration( IASTTemplateDeclaration declaration ) { callbacks.add( ENTER_TEMPLATE_DECL ); }
|
|
||||||
public void enterTemplateSpecialization( IASTTemplateSpecialization specialization ) { callbacks.add( ENTER_TEMPLATE_SPEC ); }
|
|
||||||
public void enterTemplateInstantiation( IASTTemplateInstantiation instantiation ) { callbacks.add( ENTER_TEMPLATE_INSTANCE ); }
|
|
||||||
public void acceptMethodDeclaration( IASTMethod method ) { callbacks.add( ACCEPT_METHOD ); }
|
|
||||||
public void enterMethodBody( IASTMethod method ) { callbacks.add( ENTER_METHOD ); }
|
|
||||||
public void exitMethodBody( IASTMethod method ) { callbacks.add( EXIT_METHOD ); }
|
|
||||||
public void acceptField( IASTField field ) { callbacks.add( ACCEPT_FIELD ); }
|
|
||||||
public void acceptClassReference( IASTClassReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptTypedefReference( IASTTypedefReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptNamespaceReference( IASTNamespaceReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptEnumerationReference( IASTEnumerationReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptVariableReference( IASTVariableReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptFunctionReference( IASTFunctionReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptFieldReference( IASTFieldReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptMethodReference( IASTMethodReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptEnumeratorReference( IASTEnumeratorReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptParameterReference( IASTParameterReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptTemplateParameterReference( IASTTemplateParameterReference reference ) { callbacks.add( ACCEPT_REFERENCE ); }
|
|
||||||
public void acceptFriendDeclaration( IASTDeclaration declaration ) { callbacks.add( ACCEPT_FRIEND ); }
|
|
||||||
public void exitTemplateDeclaration( IASTTemplateDeclaration declaration ) { callbacks.add( EXIT_TEMPLATE_DECL); }
|
|
||||||
public void exitTemplateSpecialization( IASTTemplateSpecialization specialization ) { callbacks.add( EXIT_TEMPLATE_SPEC ); }
|
|
||||||
public void exitTemplateExplicitInstantiation( IASTTemplateInstantiation instantiation ) { callbacks.add( EXIT_TEMPLATE_INSTANCE ); }
|
|
||||||
public void exitLinkageSpecification( IASTLinkageSpecification linkageSpec ) { callbacks.add( ACCEPT_MACRO ); }
|
|
||||||
public void exitClassSpecifier( IASTClassSpecifier classSpecification ) { callbacks.add( EXIT_CLASS ); }
|
|
||||||
public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ) { callbacks.add( EXIT_NAMESPACE); }
|
|
||||||
public void exitInclusion( IASTInclusion inclusion ) { callbacks.add( EXIT_INCLUSION ); }
|
|
||||||
public void exitCompilationUnit( IASTCompilationUnit compilationUnit ) { callbacks.add( EXIT_COMPILATION_UNIT ); }
|
|
||||||
public void enterCompilationUnit( IASTCompilationUnit compilationUnit )
|
|
||||||
{
|
|
||||||
callbacks.add( ENTER_COMPILATION_UNIT );
|
|
||||||
compUnit = compilationUnit;
|
|
||||||
}
|
|
||||||
public CodeReader createReader( String finalPath, Iterator workingCopies ) {
|
|
||||||
return ParserUtil.createReader(finalPath,workingCopies);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public CallbackTracker callback;
|
|
||||||
protected IASTScope parse( IFile code, List callbacks ) throws Exception
|
|
||||||
{
|
|
||||||
return parse( code, callbacks, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTScope parse(IFile code, List callbackList, ParserLanguage language) throws Exception
|
|
||||||
{
|
|
||||||
callback = new CallbackTracker( callbackList );
|
|
||||||
InputStream stream = code.getContents();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), new ScannerInfo(), //$NON-NLS-1$
|
|
||||||
ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null
|
|
||||||
);
|
|
||||||
stream.close();
|
|
||||||
boolean parseResult = parser.parse();
|
|
||||||
// throw exception if there are generated IProblems
|
|
||||||
if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
|
||||||
if( parseResult )
|
|
||||||
{
|
|
||||||
assertTrue( ((Parser)parser).validateCaches());
|
|
||||||
}
|
|
||||||
return callback.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTNode parse(IFile code, List callbacks, int start, int end) throws Exception
|
|
||||||
{
|
|
||||||
return parse(code, callbacks, start, end, true, ParserLanguage.CPP);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTNode parse(IFile code, List callbacks, int offset1, int offset2, boolean expectedToPass, ParserLanguage language) throws Exception {
|
|
||||||
callback = new CallbackTracker( callbacks );
|
|
||||||
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), code.getCharset() ), new ScannerInfo(), //$NON-NLS-1$
|
|
||||||
ParserMode.SELECTION_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.SELECTION_PARSE, language, null
|
|
||||||
);
|
|
||||||
|
|
||||||
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
|
|
||||||
if( expectedToPass )
|
|
||||||
{
|
|
||||||
assertNotNull( result );
|
|
||||||
String filename = result.getFilename();
|
|
||||||
assertNotNull( filename );
|
|
||||||
assertTrue( !filename.equals( "")); //$NON-NLS-1$
|
|
||||||
return (IASTNode) result.getOffsetableNamedElement();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,260 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2005 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 Corp. - Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.testplugin.CTestPlugin;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public class FractionalAutomatedTest extends AutomatedFramework {
|
|
||||||
|
|
||||||
public FractionalAutomatedTest() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public FractionalAutomatedTest(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AutomatedFramework newTest( String name ){
|
|
||||||
return new FractionalAutomatedTest( name );
|
|
||||||
}
|
|
||||||
protected void loadProperties() throws Exception{
|
|
||||||
String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
resourcePath += "resources/parser/AutomatedTest"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
try{
|
|
||||||
FileInputStream propertiesIn = new FileInputStream( resourcePath + "/FractionalAutomatedTest.properties"); //$NON-NLS-1$
|
|
||||||
properties.load( propertiesIn );
|
|
||||||
|
|
||||||
outputFile = properties.getProperty( "outputFile", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
String sourceInfo = properties.getProperty( "source", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
stepSize = Integer.parseInt( properties.getProperty( "stepSize", "50" ) ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
windowSize = Integer.parseInt( properties.getProperty( "windowSize", "200" ) ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
timeOut = Integer.parseInt( properties.getProperty( "timeOut", "5000" )); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
outputDir = properties.getProperty( "outDir", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
if( sourceInfo.equals("") ) //$NON-NLS-1$
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
else{
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$
|
|
||||||
String str = null, val = null;
|
|
||||||
try{
|
|
||||||
while( tokenizer.hasMoreTokens() ){
|
|
||||||
str = tokenizer.nextToken().trim();
|
|
||||||
val = tokenizer.nextToken().trim();
|
|
||||||
|
|
||||||
testSources.put( str, val );
|
|
||||||
}
|
|
||||||
} catch ( NoSuchElementException e ){
|
|
||||||
//only way to get here is to have a missing val, assume cpp for that str
|
|
||||||
testSources.put( str, "cpp" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch ( FileNotFoundException e ){
|
|
||||||
testSources.put( resourcePath + "/defaultCpp", "cpp" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
testSources.put( resourcePath + "/defaultC", "c" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
AutomatedFramework frame = new FractionalAutomatedTest();
|
|
||||||
|
|
||||||
return frame.createSuite();
|
|
||||||
}
|
|
||||||
|
|
||||||
static private String outputFile( String code ) {
|
|
||||||
if( outputDir == null || outputDir.equals("") ) //$NON-NLS-1$
|
|
||||||
return ""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
File output = new File( outputDir );
|
|
||||||
|
|
||||||
try{
|
|
||||||
if( output.exists() ){
|
|
||||||
if( output.isFile() ){
|
|
||||||
output.delete();
|
|
||||||
output.createNewFile();
|
|
||||||
FileOutputStream stream = new FileOutputStream( output );
|
|
||||||
stream.write( code.getBytes() );
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
return outputDir;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
output.mkdir();
|
|
||||||
}
|
|
||||||
File file = new File( outputDir + "/" + failures++ + ".tmp" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
if( file.exists() )
|
|
||||||
file.delete();
|
|
||||||
file.createNewFile();
|
|
||||||
FileOutputStream stream = new FileOutputStream( file );
|
|
||||||
stream.write( code.getBytes() );
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
return file.getCanonicalPath();
|
|
||||||
|
|
||||||
} catch ( Exception e )
|
|
||||||
{}
|
|
||||||
return ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
static public void reportHang( String code, String file ){
|
|
||||||
String output = outputFile( code.toString() );
|
|
||||||
if( output.equals("") ) //$NON-NLS-1$
|
|
||||||
output = "Parser hang while parsing " + file + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
else
|
|
||||||
output = "Parser hang while parsing " + output + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
if( report != null ){
|
|
||||||
try{
|
|
||||||
report.write( output.getBytes() );
|
|
||||||
} catch ( IOException e ) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fail( output );
|
|
||||||
}
|
|
||||||
|
|
||||||
static public void reportException( String code, String file, String exception ){
|
|
||||||
String output = outputFile( code.toString() );
|
|
||||||
|
|
||||||
if( output.equals("") ) //$NON-NLS-1$
|
|
||||||
output = exception.getClass().toString() + " encountered in " + file + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
else
|
|
||||||
output = exception.getClass().toString() + " encountered in " + output + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
if( report != null ){
|
|
||||||
try{
|
|
||||||
report.write( output.getBytes() );
|
|
||||||
} catch ( IOException e ) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fail( output );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doFile() throws Throwable {
|
|
||||||
assertNotNull( fileList );
|
|
||||||
|
|
||||||
File file = (File)fileList.removeFirst();
|
|
||||||
FileInputStream stream = new FileInputStream( file );
|
|
||||||
|
|
||||||
String filePath = file.getCanonicalPath();
|
|
||||||
String nature = (String)natures.get( filePath );
|
|
||||||
|
|
||||||
boolean cppNature = nature.equalsIgnoreCase("cpp"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
StringWriter code = new StringWriter();
|
|
||||||
|
|
||||||
ParseThread thread = new ParseThread();
|
|
||||||
|
|
||||||
byte b[] = new byte[stepSize];
|
|
||||||
int n = stream.read( b );
|
|
||||||
while( n != -1 ){
|
|
||||||
code.write( new String( b ) );
|
|
||||||
|
|
||||||
thread.code = code.toString();
|
|
||||||
thread.cppNature = cppNature;
|
|
||||||
thread.start();
|
|
||||||
thread.join( timeOut );
|
|
||||||
|
|
||||||
if( thread.isAlive() ){
|
|
||||||
//Use deprecated Thread.stop() for now
|
|
||||||
//alternative is to create a callback which could stop the parse on a flag
|
|
||||||
//by throwing something, but that has the disadvantage of being unable to
|
|
||||||
//stop any loops that don't involve callbacks.
|
|
||||||
thread.stop();
|
|
||||||
reportHang( code.toString(), filePath );
|
|
||||||
} else if( thread.result != null ) {
|
|
||||||
reportException( code.toString(), filePath, thread.result );
|
|
||||||
}
|
|
||||||
|
|
||||||
n = stream.read( b );
|
|
||||||
}
|
|
||||||
|
|
||||||
String fullCode = code.toString();
|
|
||||||
String windowedCode = null;
|
|
||||||
int length = fullCode.length();
|
|
||||||
int curPos = 0;
|
|
||||||
|
|
||||||
while( curPos + windowSize < length){
|
|
||||||
windowedCode = fullCode.substring( 0, curPos );
|
|
||||||
windowedCode += "\n" + fullCode.substring( curPos + windowSize, length ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
thread.code = windowedCode;
|
|
||||||
thread.cppNature = cppNature;
|
|
||||||
thread.file = filePath;
|
|
||||||
thread.start();
|
|
||||||
thread.join( timeOut );
|
|
||||||
|
|
||||||
if( thread.isAlive() )
|
|
||||||
{
|
|
||||||
thread.stop();
|
|
||||||
reportHang( windowedCode, filePath );
|
|
||||||
} else if( thread.result != null ) {
|
|
||||||
reportException( windowedCode, filePath, thread.result );
|
|
||||||
}
|
|
||||||
|
|
||||||
curPos += stepSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ParseThread extends Thread{
|
|
||||||
public String code;
|
|
||||||
public boolean cppNature;
|
|
||||||
public String file;
|
|
||||||
public String result;
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
try{
|
|
||||||
result = null;
|
|
||||||
ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C;
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, new NullLogService(), null ), nullCallback, ParserMode.QUICK_PARSE, language, null );
|
|
||||||
|
|
||||||
parser.parse();
|
|
||||||
} catch ( Exception e ){
|
|
||||||
result = e.getClass().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected int stepSize = 50;
|
|
||||||
static protected int windowSize = 200;
|
|
||||||
static protected int timeOut = 5000;
|
|
||||||
static protected String outputDir = null;
|
|
||||||
static protected int failures = 0;
|
|
||||||
}
|
|
|
@ -1,288 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public GCCCompleteParseExtensionsTest() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public GCCCompleteParseExtensionsTest(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39695() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse("int a = __alignof__ (int);").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTVariable a = (IASTVariable) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
IASTExpression exp = a.getInitializerClause().getAssigmentExpression();
|
|
||||||
assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID );
|
|
||||||
assertEquals( exp.toString(), "__alignof__(int)"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39684() throws Exception
|
|
||||||
{
|
|
||||||
IASTFunction bar = (IASTFunction) parse("typeof(foo(1)) bar () { return foo(1); }").getDeclarations().next(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTSimpleTypeSpecifier simpleTypeSpec = ((IASTSimpleTypeSpecifier)bar.getReturnType().getTypeSpecifier());
|
|
||||||
assertEquals( simpleTypeSpec.getType(), IASTGCCSimpleTypeSpecifier.Type.TYPEOF );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39698A() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse("int c = a <? b;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTVariable c = (IASTVariable) i.next();
|
|
||||||
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
|
|
||||||
assertEquals( ASTUtil.getExpressionString( exp ), "a <? b" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39698B() throws Exception
|
|
||||||
{
|
|
||||||
Iterator i = parse("int c = a >? b;").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTVariable c = (IASTVariable) i.next();
|
|
||||||
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
|
|
||||||
assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPredefinedSymbol_bug69791() throws Exception {
|
|
||||||
Iterator i = parse("typedef __builtin_va_list __gnuc_va_list; \n").getDeclarations();//$NON-NLS-1$
|
|
||||||
assertTrue( i.next() instanceof IASTTypedefDeclaration );
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39697() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "__asm__( \"CODE\" );\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "__inline__ int foo() { return 4; }\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "__const__ int constInt;\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "__volatile__ int volInt;\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "__signed__ int signedInt;\n"); //$NON-NLS-1$
|
|
||||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
|
||||||
IASTASMDefinition asmDefinition = (IASTASMDefinition) i.next();
|
|
||||||
assertEquals( asmDefinition.getBody(), "CODE"); //$NON-NLS-1$
|
|
||||||
IASTFunction foo = (IASTFunction) i.next();
|
|
||||||
assertTrue( foo.isInline() );
|
|
||||||
IASTVariable constInt = (IASTVariable) i.next();
|
|
||||||
assertTrue( constInt.getAbstractDeclaration().isConst());
|
|
||||||
IASTVariable volInt = (IASTVariable) i.next();
|
|
||||||
assertTrue( volInt.getAbstractDeclaration().isVolatile() );
|
|
||||||
IASTVariable signedInt = (IASTVariable) i.next();
|
|
||||||
assertTrue( ((IASTSimpleTypeSpecifier) signedInt.getAbstractDeclaration().getTypeSpecifier()).isSigned() );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
for( int j = 0; j < 2; ++j )
|
|
||||||
{
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "int * __restrict__ resPointer1;\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int * __restrict resPointer2;\n"); //$NON-NLS-1$
|
|
||||||
i = parse( writer.toString(), true, ((j == 0 )? ParserLanguage.C : ParserLanguage.CPP) ).getDeclarations();
|
|
||||||
int count = 0;
|
|
||||||
while( i.hasNext() )
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
IASTVariable resPointer = (IASTVariable) i.next();
|
|
||||||
Iterator pOps = resPointer.getAbstractDeclaration().getPointerOperators();
|
|
||||||
assertTrue( pOps.hasNext() );
|
|
||||||
ASTPointerOperator op = (ASTPointerOperator) pOps.next();
|
|
||||||
assertFalse( pOps.hasNext() );
|
|
||||||
assertEquals( op, ASTPointerOperator.RESTRICT_POINTER );
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals( count, 2 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug73954A() throws Exception{
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
writer.write("void f(){ \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_expect( 23, 2); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_prefetch( (const void *)0, 1, 2); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_huge_val(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_huge_valf(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_huge_vall(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_inf(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_inff(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_infl(); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nan(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nanf(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nanl(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nans(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nansf(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_nansl(\"\"); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ffs (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_clz (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ctz (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_popcount (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_parity (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ffsl (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_clzl (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ctzl (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_popcountl (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_parityl (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ffsll (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_clzll (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_ctzll (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_popcountll (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write(" __builtin_parityll (0); \n");//$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
parse( writer.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39686() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ int z = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$
|
|
||||||
code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$
|
|
||||||
code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$
|
|
||||||
parse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39551B() throws Exception
|
|
||||||
{
|
|
||||||
//this used to be 99.99 * __I__, but I don't know where the __I__ came from, its not in C99, nor in GCC
|
|
||||||
IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$
|
|
||||||
assertEquals( variable.getName(), "id"); //$NON-NLS-1$
|
|
||||||
assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39681() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("double\n"); //$NON-NLS-1$
|
|
||||||
code.write("foo (double a, double b)\n"); //$NON-NLS-1$
|
|
||||||
code.write("{\n"); //$NON-NLS-1$
|
|
||||||
code.write(" double square (double z) { return z * z; }\n"); //$NON-NLS-1$
|
|
||||||
code.write(" return square (a) + square (b);\n"); //$NON-NLS-1$
|
|
||||||
code.write("}\n"); //$NON-NLS-1$
|
|
||||||
parse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39677() throws Exception
|
|
||||||
{
|
|
||||||
parse("class B { public: B(); int a;}; B::B() : a(({ 1; })) {}"); //$NON-NLS-1$
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "B::B() : a(( { int y = foo (); int z;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
|
||||||
writer.write( "z; }))\n" );//$NON-NLS-1$
|
|
||||||
parse( writer.toString() );
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
|
||||||
writer.write( "z; });\n" );//$NON-NLS-1$
|
|
||||||
parse( writer.toString() );
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "int foo(); \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "typeof({ int y = foo (); \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " int z; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " if (y > 0) z = y; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " else z = - y; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " z; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " }) zoot; \n" ); //$NON-NLS-1$
|
|
||||||
parse( writer.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug75401() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "#define va_arg __builtin_va_arg \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "#define va_list __builtin_va_list \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void main( int argc, char** argv ) { \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " va_list v; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " long l = va_arg( v, long ); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
parse( writer.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug73954B() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "#define foo(x) \\\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " __builtin_choose_expr( 1, foo_d(x), (void)0 ) \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int foo_d( int x ); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int main() { \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " if( __builtin_constant_p(1) && \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " __builtin_types_compatible_p( 1, 'c') ) \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " foo(1); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
parse( writer.toString(), true, ParserLanguage.C );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGNUExternalTemplate_bug71603() throws Exception {
|
|
||||||
Iterator i = parse("template <typename T> \n class A {}; \n extern template class A<int>; \n").getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next();
|
|
||||||
IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration();
|
|
||||||
IASTTemplateInstantiation ti = (IASTTemplateInstantiation) i.next();
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug74190_g_assert_1() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "void log( int ); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f() { \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " int a = 1; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " (void)({ if( a ){ } \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " else{ log( a ); } \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " }); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
parse( writer.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug74190_g_return_if_fail() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "void f() { \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " (void)({ if( ( ({ 0; }) ) ) \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " { } \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " }); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
parse( writer.toString() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.GCCScannerExtensionsTest;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GCCParserExtensionTestSuite extends TestCase {
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite suite= new TestSuite(GCCParserExtensionTestSuite.class.getName());
|
|
||||||
suite.addTestSuite( GCCScannerExtensionsTest.class );
|
|
||||||
suite.addTestSuite( GCCQuickParseExtensionsTest.class );
|
|
||||||
suite.addTestSuite( GCCCompleteParseExtensionsTest.class );
|
|
||||||
suite.addTestSuite( GCCSelectionParseExtensionsTest.class);
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,184 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GCCQuickParseExtensionsTest extends BaseASTTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param a
|
|
||||||
*/
|
|
||||||
public GCCQuickParseExtensionsTest(String a) {
|
|
||||||
super(a);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39694() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); //$NON-NLS-1$
|
|
||||||
assertEquals( variable.getName(), "ab$cd"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39704A() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable foo = (IASTVariable) assertSoleDeclaration("__declspec (dllimport) int foo;"); //$NON-NLS-1$
|
|
||||||
assertEquals( foo.getName(), "foo"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39704D() throws Exception
|
|
||||||
{
|
|
||||||
IASTFunction func1 = (IASTFunction) assertSoleDeclaration("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$
|
|
||||||
assertEquals( func1.getName(), "func1"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39695() throws Exception
|
|
||||||
{
|
|
||||||
parse("int a = __alignof__ (int);"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39684() throws Exception
|
|
||||||
{
|
|
||||||
parse("typeof(foo(1)) bar () { return foo(1); }"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39703() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); //$NON-NLS-1$
|
|
||||||
code.write("__extension__ struct G {\n"); //$NON-NLS-1$
|
|
||||||
code.write(" struct { char z; };\n"); //$NON-NLS-1$
|
|
||||||
code.write(" char g;\n"); //$NON-NLS-1$
|
|
||||||
code.write("};\n"); //$NON-NLS-1$
|
|
||||||
IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString());
|
|
||||||
IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier());
|
|
||||||
assertEquals( G.getName(), "G" ); //$NON-NLS-1$
|
|
||||||
assertEquals( G.getClassKind(), ASTClassKind.STRUCT );
|
|
||||||
Iterator i = G.getDeclarations();
|
|
||||||
assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" ); //$NON-NLS-1$
|
|
||||||
assertEquals( ((IASTField)i.next()).getName(), "g" ); //$NON-NLS-1$
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39698A() throws Exception
|
|
||||||
{
|
|
||||||
parse("int c = a <? b;"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39698B() throws Exception
|
|
||||||
{
|
|
||||||
parse("int c = a >? b;"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39554() throws Exception
|
|
||||||
{
|
|
||||||
parse("_Pragma(\"foobar\")", true, true, ParserLanguage.C ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39704B() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int (* import) (void) __attribute__((dllimport));"); //$NON-NLS-1$
|
|
||||||
assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39704C() throws Exception
|
|
||||||
{
|
|
||||||
IASTFunction f = (IASTFunction)assertSoleDeclaration("int func2 (void) __attribute__((dllexport));"); //$NON-NLS-1$
|
|
||||||
assertEquals( f.getName(), "func2"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39704E() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int * __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$
|
|
||||||
assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39704F() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$
|
|
||||||
assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39704G() throws Exception
|
|
||||||
{
|
|
||||||
IASTVariable d = (IASTVariable)assertSoleDeclaration("int x __attribute__ ((aligned (16))) = 0;"); //$NON-NLS-1$
|
|
||||||
assertEquals( d.getName(), "x"); // false assertion //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39686() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$
|
|
||||||
code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$
|
|
||||||
code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$
|
|
||||||
code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$
|
|
||||||
parse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39681() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
code.write("double\n"); //$NON-NLS-1$
|
|
||||||
code.write("foo (double a, double b)\n"); //$NON-NLS-1$
|
|
||||||
code.write("{\n"); //$NON-NLS-1$
|
|
||||||
code.write(" double square (double z) { return z * z; }\n"); //$NON-NLS-1$
|
|
||||||
code.write(" return square (a) + square (b);\n"); //$NON-NLS-1$
|
|
||||||
code.write("}\n"); //$NON-NLS-1$
|
|
||||||
parse(code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39677() throws Exception
|
|
||||||
{
|
|
||||||
parse("B::B() : a(({ 1; })) {}"); //$NON-NLS-1$
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "B::B() : a(( { int y = foo (); int z;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
|
||||||
writer.write( "z; }))\n" );//$NON-NLS-1$
|
|
||||||
parse( writer.toString() );
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
|
||||||
writer.write( "z; });\n" );//$NON-NLS-1$
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "typeof({ int y = foo (); int z;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "else z = - y;\n" );//$NON-NLS-1$
|
|
||||||
writer.write( "z; }) zoot;\n" );//$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39701A() throws Exception
|
|
||||||
{
|
|
||||||
parse("extern template int max (int, int);"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39701B() throws Exception
|
|
||||||
{
|
|
||||||
parse("inline template class Foo<int>;"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug39701C() throws Exception
|
|
||||||
{
|
|
||||||
parse("static template class Foo<int>;"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GCCSelectionParseExtensionsTest extends SelectionParseBaseTest {
|
|
||||||
|
|
||||||
public void testBug43021() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "extern int johnc(__const char *__restrict __format, ...);\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "void m() {johnc(\"HI\");}" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "{johnc") + 1; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex + 5 );
|
|
||||||
assertNotNull( node );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,123 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest.Scope;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class IScannerInfoPluginTest extends FileBasePluginTest {
|
|
||||||
|
|
||||||
private static final String [] EMPTY_STRING_ARRAY = new String[0];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
* @param className
|
|
||||||
*/
|
|
||||||
public IScannerInfoPluginTest(String name) {
|
|
||||||
super(name, IScannerInfoPluginTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite suite = new TestSuite( IScannerInfoPluginTest.class );
|
|
||||||
suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Iterator getDeclarations(IASTScope scope)
|
|
||||||
{
|
|
||||||
Scope s = c.lookup( scope );
|
|
||||||
if( s != null )
|
|
||||||
return s.getDeclarations();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompleteParseBaseTest.FullParseCallback c;
|
|
||||||
|
|
||||||
protected IASTScope parse(IFile code, ParserLanguage language, IScannerInfo scannerInfo ) throws Exception
|
|
||||||
{
|
|
||||||
c = new CompleteParseBaseTest.FullParseCallback();
|
|
||||||
InputStream stream = code.getContents();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), scannerInfo,
|
|
||||||
ParserMode.COMPLETE_PARSE, language, c, new NullLogService(), null ), c, ParserMode.COMPLETE_PARSE, language, null
|
|
||||||
);
|
|
||||||
stream.close();
|
|
||||||
boolean parseResult = parser.parse();
|
|
||||||
// throw exception if there are generated IProblems
|
|
||||||
if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
|
||||||
assertTrue( ((Parser)parser).validateCaches());
|
|
||||||
return c.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testMacroFileLoading() throws Exception
|
|
||||||
{
|
|
||||||
String imacroContent = "#define ONE 1\n"; //$NON-NLS-1$
|
|
||||||
IFile imacroFile = importFile( "imacros.h", imacroContent ); //$NON-NLS-1$
|
|
||||||
String code = "int x = ONE;\n"; //$NON-NLS-1$
|
|
||||||
IFile sourceCode = importFile( "source.cpp", code ); //$NON-NLS-1$
|
|
||||||
String[] isp= {imacroFile.getParent().getLocation().toString()};
|
|
||||||
String[] imacroz= {imacroFile.getName()};
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, isp, imacroz, EMPTY_STRING_ARRAY );
|
|
||||||
Iterator i = parse( sourceCode, ParserLanguage.C, scannerInfo ).getDeclarations();
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
IASTVariable x = (IASTVariable) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
assertEquals( x.getName(), "x" ); //$NON-NLS-1$
|
|
||||||
assertNotNull( x.getInitializerClause() );
|
|
||||||
assertNotNull( x.getInitializerClause().getAssigmentExpression() );
|
|
||||||
assertEquals( x.getInitializerClause().getAssigmentExpression().toString(), "1"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testIncludeFileLoading() throws Exception
|
|
||||||
{
|
|
||||||
String inclContent = "int x = 4;\n\n"; //$NON-NLS-1$
|
|
||||||
IFile inclFile = importFile( "includeMe.h", inclContent ); //$NON-NLS-1$
|
|
||||||
String code = "int y = x;\n"; //$NON-NLS-1$
|
|
||||||
IFile sourceCode = importFile( "source.cpp", code ); //$NON-NLS-1$
|
|
||||||
String[] isp= {inclFile.getParent().getLocation().toString()};
|
|
||||||
String [] includez = {inclFile.getName()};
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, isp, EMPTY_STRING_ARRAY, includez );
|
|
||||||
Iterator i = parse( sourceCode, ParserLanguage.C, scannerInfo ).getDeclarations();
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
assertTrue(i.next() instanceof IASTVariable );
|
|
||||||
IASTVariable y = (IASTVariable) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
assertEquals( y.getName(), "y" ); //$NON-NLS-1$
|
|
||||||
assertNotNull( y.getInitializerClause() );
|
|
||||||
assertNotNull( y.getInitializerClause().getAssigmentExpression() );
|
|
||||||
assertEquals( y.getInitializerClause().getAssigmentExpression().toString(), "x"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
/*
|
/*
|
||||||
* Created on Jul 19, 2004
|
* Created on Jul 19, 2004
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2006 IBM Corporation and others.
|
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -19,44 +19,18 @@ import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMGCCParserExtensionTestSuite;
|
import org.eclipse.cdt.core.parser.tests.ast2.DOMGCCParserExtensionTestSuite;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite;
|
import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite;
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner.ScannerTestSuite;
|
import org.eclipse.cdt.core.parser.tests.scanner.ScannerTestSuite;
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.IncludeTest;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* Combines all tests for the parsers.
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
*/
|
||||||
public class ParserTestSuite extends TestCase {
|
public class ParserTestSuite extends TestCase {
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
|
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
|
||||||
suite.addTestSuite(ArrayUtilsTest.class);
|
suite.addTestSuite(ArrayUtilsTest.class);
|
||||||
suite.addTestSuite(Scanner2Test.class );
|
suite.addTestSuite(CharArrayUtilsTest.class);
|
||||||
suite.addTestSuite(QuickParseASTTests.class);
|
|
||||||
suite.addTestSuite(ParserSymbolTableTest.class);
|
|
||||||
suite.addTestSuite(ParserSymbolTableTemplateTests.class );
|
|
||||||
suite.addTestSuite(CModelElementsTests.class);
|
suite.addTestSuite(CModelElementsTests.class);
|
||||||
suite.addTestSuite(StructuralCModelElementsTests.class);
|
suite.addTestSuite(StructuralCModelElementsTests.class);
|
||||||
suite.addTestSuite(CompletionParseTest.class);
|
suite.addTestSuite(ObjectMapTest.class );
|
||||||
suite.addTestSuite(QuickParseProblemTests.class);
|
|
||||||
// suite.addTestSuite(MacroTests.class);
|
|
||||||
suite.addTestSuite( PreprocessorConditionalTest.class );
|
|
||||||
suite.addTestSuite( QuickParseASTQualifiedNameTest.class);
|
|
||||||
suite.addTestSuite( CompleteParseASTTest.class );
|
|
||||||
suite.addTestSuite( CompleteParseProblemTest.class );
|
|
||||||
suite.addTestSuite( SelectionParseTest.class );
|
|
||||||
suite.addTestSuite( CompleteParseASTExpressionTest.class );
|
|
||||||
suite.addTestSuite( CompleteParseASTSymbolIteratorTest.class );
|
|
||||||
suite.addTestSuite( CompleteParseASTTemplateTest.class );
|
|
||||||
suite.addTestSuite( StructuralParseTest.class );
|
|
||||||
suite.addTestSuite( ObjectMapTest.class );
|
|
||||||
suite.addTest( CompleteParsePluginTest.suite() );
|
|
||||||
suite.addTest( IScannerInfoPluginTest.suite() );
|
|
||||||
suite.addTestSuite( IncludeTest.class );
|
|
||||||
suite.addTest( ScannerParserLoopTest.suite() );
|
|
||||||
suite.addTest( GCCParserExtensionTestSuite.suite() );
|
|
||||||
suite.addTest( ScannerTestSuite.suite() );
|
suite.addTest( ScannerTestSuite.suite() );
|
||||||
suite.addTest( DOMParserTestSuite.suite() );
|
suite.addTest( DOMParserTestSuite.suite() );
|
||||||
suite.addTest( DOMGCCParserExtensionTestSuite.suite() );
|
suite.addTest( DOMGCCParserExtensionTestSuite.suite() );
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.tests.BaseASTTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author vmozgin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PerformanceTests extends BaseASTTest
|
|
||||||
{
|
|
||||||
public PerformanceTests(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39523() throws Exception
|
|
||||||
{
|
|
||||||
Writer code = new StringWriter();
|
|
||||||
try {
|
|
||||||
code.write("#define e0 \"a\"\n"); //$NON-NLS-1$
|
|
||||||
code.write("#define e1 e0 e0 e0 e0 e0 e0 e0 e0 e0 e0\n"); //$NON-NLS-1$
|
|
||||||
code.write("#define e2 e1 e1 e1 e1 e1 e1 e1 e1 e1 e1\n"); //$NON-NLS-1$
|
|
||||||
code.write("#define e3 e2 e2 e2 e2 e2 e2 e2 e2 e2 e2\n"); //$NON-NLS-1$
|
|
||||||
code.write("#define e4 e3 e3 e3 e3 e3 e3 e3 e3 e3 e3\n"); //$NON-NLS-1$
|
|
||||||
code.write("#define e5 e4 e4 e4 e4 e4 e4 e4 e4 e4 e4\n"); //$NON-NLS-1$
|
|
||||||
code.write("void foo() { (void)(e5); }\n"); //$NON-NLS-1$
|
|
||||||
} catch( IOException ioe ){}
|
|
||||||
|
|
||||||
parse(code.toString());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.scanner2.BaseScanner2Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PreprocessorConditionalTest extends BaseScanner2Test
|
|
||||||
{
|
|
||||||
|
|
||||||
private ISourceElementRequestor nullSourceElementRequestor = new NullSourceElementRequestor();
|
|
||||||
|
|
||||||
|
|
||||||
protected void initializeScanner(String input, Map definitions ) throws Exception
|
|
||||||
{
|
|
||||||
scanner= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo( definitions ), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void evaluateConditionalsPositive( String conditional, Map definitions ) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
StringBuffer buff = new StringBuffer();
|
|
||||||
buff.append( "#if " ); //$NON-NLS-1$
|
|
||||||
buff.append( conditional );
|
|
||||||
buff.append( "\n int x;\n#else\n#error NEVER\n#endif\n"); //$NON-NLS-1$
|
|
||||||
initializeScanner( buff.toString(), definitions );
|
|
||||||
evaluate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void evaluateConditionalsNegative( String conditional, Map definitions )throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
StringBuffer buff = new StringBuffer();
|
|
||||||
buff.append( "#if " ); //$NON-NLS-1$
|
|
||||||
buff.append( conditional );
|
|
||||||
buff.append( "\n#error NEVER\n#else\n int x;\n#endif\n"); //$NON-NLS-1$
|
|
||||||
initializeScanner( buff.toString(), definitions );
|
|
||||||
evaluate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void evaluate() throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
validateToken( IToken.t_int );
|
|
||||||
validateIdentifier( "x"); //$NON-NLS-1$
|
|
||||||
validateToken( IToken.tSEMI );
|
|
||||||
scanner.nextToken();
|
|
||||||
fail( "Should have hit EOF by now"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
catch( EndOfFileException eof )
|
|
||||||
{
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param x
|
|
||||||
*/
|
|
||||||
public PreprocessorConditionalTest(String x)
|
|
||||||
{
|
|
||||||
super(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConditionals()throws Exception
|
|
||||||
{
|
|
||||||
Map definitions = new HashMap();
|
|
||||||
definitions.put( "DEFED", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
definitions.put( "VALUE", "30 "); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
evaluateConditionalsPositive( "defined( DEFED )", definitions ); //$NON-NLS-1$
|
|
||||||
evaluateConditionalsNegative( "defined( NOTDEFED )", definitions ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
evaluateConditionalsNegative( "! defined( DEFED )", definitions ); //$NON-NLS-1$
|
|
||||||
evaluateConditionalsPositive( "! defined( NOTDEFED )", definitions ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
evaluateConditionalsPositive( "defined( VALUE ) && VALUE == 30", definitions ); //$NON-NLS-1$
|
|
||||||
evaluateConditionalsNegative( "defined( VALUE ) && VALUE == 40", definitions ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,114 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class QuickParseASTQualifiedNameTest extends BaseASTTest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param a
|
|
||||||
*/
|
|
||||||
public QuickParseASTQualifiedNameTest(String a)
|
|
||||||
{
|
|
||||||
super(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNamespace() throws Exception
|
|
||||||
{
|
|
||||||
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)assertSoleDeclaration("namespace A { namespace B { int x; } }"); //$NON-NLS-1$
|
|
||||||
assertQualifiedName( namespace.getFullyQualifiedName(), new String [] {"A" } ); //$NON-NLS-1$
|
|
||||||
IASTNamespaceDefinition namespace2 = (IASTNamespaceDefinition)namespace.getDeclarations().next();
|
|
||||||
assertQualifiedName( namespace2.getFullyQualifiedName(), new String [] { "A", "B" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClass() throws Exception
|
|
||||||
{
|
|
||||||
IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration( "class A { class B { int a; }; };"); //$NON-NLS-1$
|
|
||||||
IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier();
|
|
||||||
assertQualifiedName( classSpec.getFullyQualifiedName(), new String [] { "A" } ); //$NON-NLS-1$
|
|
||||||
Iterator subDecls = classSpec.getDeclarations();
|
|
||||||
abs = (IASTAbstractTypeSpecifierDeclaration)subDecls.next();
|
|
||||||
assertFalse( subDecls.hasNext() );
|
|
||||||
classSpec = (IASTClassSpecifier)abs.getTypeSpecifier();
|
|
||||||
assertQualifiedName( classSpec.getFullyQualifiedName(), new String [] { "A", "B" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEnum() throws Exception
|
|
||||||
{
|
|
||||||
Iterator declarations = parse( "class A { enum E1 { enumerator = 1 }; };\n namespace N { enum E2 { enumerator = 4 }; }\n" ).getDeclarations(); //$NON-NLS-1$
|
|
||||||
IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)declarations.next();
|
|
||||||
IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier();
|
|
||||||
IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)(((IASTAbstractTypeSpecifierDeclaration)classSpec.getDeclarations().next()).getTypeSpecifier());
|
|
||||||
assertQualifiedName( enumSpec.getFullyQualifiedName(), new String[] { "A", "E1" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IASTNamespaceDefinition nms = (IASTNamespaceDefinition)declarations.next();
|
|
||||||
enumSpec = (IASTEnumerationSpecifier)(((IASTAbstractTypeSpecifierDeclaration)nms.getDeclarations().next()).getTypeSpecifier());
|
|
||||||
assertQualifiedName( enumSpec.getFullyQualifiedName(), new String[] { "N", "E2" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
assertFalse( declarations.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testVariable() throws Exception
|
|
||||||
{
|
|
||||||
IASTNamespaceDefinition topNMS = (IASTNamespaceDefinition)assertSoleDeclaration("namespace A { int x; namespace B { int y; } }"); //$NON-NLS-1$
|
|
||||||
Iterator level1 = topNMS.getDeclarations();
|
|
||||||
IASTVariable var = (IASTVariable)level1.next();
|
|
||||||
assertQualifiedName( var.getFullyQualifiedName(), new String[] {"A","x"}); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
Iterator level2 = ((IASTNamespaceDefinition)level1.next()).getDeclarations();
|
|
||||||
assertFalse( level1.hasNext());
|
|
||||||
var = (IASTVariable)level2.next();
|
|
||||||
assertQualifiedName( var.getFullyQualifiedName(), new String[] {"A","B","y"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTypedef() throws Exception
|
|
||||||
{
|
|
||||||
IASTNamespaceDefinition topNMS = (IASTNamespaceDefinition)
|
|
||||||
assertSoleDeclaration("namespace FLEA { typedef int GODS_INT; class ANTHONY { typedef ANTHONY * tonyPointer; }; }"); //$NON-NLS-1$
|
|
||||||
Iterator level1 = topNMS.getDeclarations();
|
|
||||||
assertQualifiedName( ((IASTTypedefDeclaration)level1.next()).getFullyQualifiedName(), new String [] { "FLEA", "GODS_INT" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
assertQualifiedName( ((IASTTypedefDeclaration)((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)level1.next()).getTypeSpecifier()).getDeclarations().next()).getFullyQualifiedName(), new String [] { "FLEA", "ANTHONY", "tonyPointer" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testMembers() throws Exception
|
|
||||||
{
|
|
||||||
IASTNamespaceDefinition topNMS =
|
|
||||||
(IASTNamespaceDefinition)assertSoleDeclaration( "namespace John { class David { int Shannon; void Camelon(); }; } "); //$NON-NLS-1$
|
|
||||||
Iterator members =
|
|
||||||
((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)topNMS.getDeclarations().next()).getTypeSpecifier()).getDeclarations();
|
|
||||||
assertQualifiedName( ((IASTField)members.next()).getFullyQualifiedName(), new String[] { "John", "David", "Shannon" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
assertQualifiedName( ((IASTMethod)members.next()).getFullyQualifiedName(), new String[] { "John", "David", "Camelon" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFunction() throws Exception
|
|
||||||
{
|
|
||||||
IASTNamespaceDefinition topNMS =
|
|
||||||
(IASTNamespaceDefinition)assertSoleDeclaration( "namespace Bogdan { void Wears(); namespace Fancy { int Pants(); } }" ); //$NON-NLS-1$
|
|
||||||
Iterator members = topNMS.getDeclarations();
|
|
||||||
assertQualifiedName( ((IASTFunction)members.next()).getFullyQualifiedName(), new String[] { "Bogdan", "Wears" } ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
assertQualifiedName( ((IASTFunction)((IASTNamespaceDefinition)members.next()).getDeclarations().next()).getFullyQualifiedName(), new String[] { "Bogdan", "Fancy", "Pants" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,42 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class QuickParseProblemTests extends BaseASTTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param a
|
|
||||||
*/
|
|
||||||
public QuickParseProblemTests(String a) {
|
|
||||||
super(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBadClassName() throws Exception
|
|
||||||
{
|
|
||||||
String code = "class 12345 { };";//$NON-NLS-1$
|
|
||||||
parse( code, true, false );
|
|
||||||
assertFalse( quickParseCallback.problems.isEmpty() );
|
|
||||||
assertEquals( quickParseCallback.problems.size(), 1 );
|
|
||||||
IProblem p = (IProblem) quickParseCallback.problems.get( 0 );
|
|
||||||
assertTrue( p.checkCategory( IProblem.SYNTAX_RELATED ));
|
|
||||||
assertEquals( p.getID(), IProblem.SYNTAX_ERROR );
|
|
||||||
assertEquals( p.getSourceStart(), code.indexOf( "12345")); //$NON-NLS-1$
|
|
||||||
assertEquals( p.getSourceEnd(), code.indexOf( "12345") + 5 ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,130 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created on Sept 30, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParseError;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author dsteffle
|
|
||||||
*/
|
|
||||||
public class ScannerParserLoopTest extends FileBasePluginTest {
|
|
||||||
private static final int NUMBER_ITERATIONS = 30000;
|
|
||||||
|
|
||||||
public ScannerParserLoopTest(String name) {
|
|
||||||
super(name, ScannerParserLoopTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite suite = new TestSuite(ScannerParserLoopTest.class);
|
|
||||||
suite.addTest(new ScannerParserLoopTest("cleanupProject")); //$NON-NLS-1$
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
// test scanner cancel()
|
|
||||||
public void testBug72611A() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_ITERATIONS; i++) {
|
|
||||||
writer.write("#define A");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write(" B");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write("\n");
|
|
||||||
writer.write("#define B");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write(" C");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write("\n");
|
|
||||||
writer.write("#define C");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write(" D");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
runCancelTest(writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// test parser cancel()
|
|
||||||
public void testBug72611B() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_ITERATIONS; i++) {
|
|
||||||
writer.write("int a");
|
|
||||||
writer.write(String.valueOf(i));
|
|
||||||
writer.write("; // comment\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
runCancelTest(writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runCancelTest(Writer writer) throws Exception {
|
|
||||||
IFile file = importFile("code.cpp", writer.toString()); //$NON-NLS-1$
|
|
||||||
|
|
||||||
try {
|
|
||||||
TimeoutCallback callback = new TimeoutCallback();
|
|
||||||
IParser parser = ParserFactory.createParser(ParserFactory
|
|
||||||
.createScanner(new CodeReader(file.getRawLocation()
|
|
||||||
.toString()), new ScannerInfo(), //$NON-NLS-1$
|
|
||||||
ParserMode.COMPLETE_PARSE, ParserLanguage.CPP,
|
|
||||||
callback, new NullLogService(), null), callback,
|
|
||||||
ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null);
|
|
||||||
|
|
||||||
callback.setParser(parser);
|
|
||||||
parser.parse();
|
|
||||||
|
|
||||||
assertTrue(false); // fail if parse succeeds before being cancelled
|
|
||||||
} catch (ParseError pe) { // expected
|
|
||||||
assertEquals(pe.getErrorKind(),
|
|
||||||
ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TimeoutCallback extends NullSourceElementRequestor
|
|
||||||
implements ISourceElementRequestor {
|
|
||||||
private IParser parser;
|
|
||||||
// private boolean timerStarted = false;
|
|
||||||
|
|
||||||
public void setParser(IParser parser) {
|
|
||||||
this.parser = parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void acceptMacro(IASTMacro macro) {
|
|
||||||
parser.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void acceptVariable(IASTVariable variable) {
|
|
||||||
parser.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
/*
|
|
||||||
* Created on Jun 8, 2004
|
|
||||||
*
|
|
||||||
* TODO To change the template for this generated file go to
|
|
||||||
* Window - Preferences - Java - Code Style - Code Templates
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Doug Schaefer
|
|
||||||
*
|
|
||||||
* TODO To change the template for this generated type comment go to
|
|
||||||
* Window - Preferences - Java - Code Style - Code Templates
|
|
||||||
*/
|
|
||||||
public class ScannerSpeedTest extends SpeedTest {
|
|
||||||
|
|
||||||
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
|
||||||
private PrintStream stream;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
PrintStream stream = null;
|
|
||||||
if (args.length > 0)
|
|
||||||
stream = new PrintStream(new FileOutputStream(args[0]));
|
|
||||||
|
|
||||||
new ScannerSpeedTest().runTest(stream, 1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test() throws Exception {
|
|
||||||
runTest(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runTest(PrintStream stream, int n) throws Exception {
|
|
||||||
this.stream = stream;
|
|
||||||
runTest(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runTest(int n) throws Exception {
|
|
||||||
String code =
|
|
||||||
"#include <windows.h>\n" +
|
|
||||||
"#include <stdio.h>\n" +
|
|
||||||
"#include <iostream>\n";
|
|
||||||
|
|
||||||
CodeReader reader = new CodeReader(code.toCharArray());
|
|
||||||
IScannerInfo info = getScannerInfo(false);
|
|
||||||
long totalTime = 0;
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
long time = testScan(reader, false, info, ParserLanguage.CPP);
|
|
||||||
if (i > 0)
|
|
||||||
totalTime += time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n > 1) {
|
|
||||||
System.out.println("Average Time: " + (totalTime / (n - 1)) + " millisecs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path
|
|
||||||
* @param quick TODO
|
|
||||||
*/
|
|
||||||
protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
|
||||||
IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
int count = 0;
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
IToken t = scanner.nextToken();
|
|
||||||
|
|
||||||
if (stream != null)
|
|
||||||
stream.println(t.getImage());
|
|
||||||
|
|
||||||
if (t == null)
|
|
||||||
break;
|
|
||||||
++count;
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (EndOfFileException e2) {
|
|
||||||
}
|
|
||||||
long totalTime = System.currentTimeMillis() - startTime;
|
|
||||||
System.out.println( "Resulting scan took " + totalTime + " millisecs " +
|
|
||||||
count + " tokens");
|
|
||||||
return totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.ast.IASTNode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author johnc
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SelectionParseBaseTest extends CompleteParseBaseTest {
|
|
||||||
|
|
||||||
protected IASTNode parse(String code, int offset1, int offset2) throws Exception {
|
|
||||||
return parse( code, offset1, offset2, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param code
|
|
||||||
* @param offset1
|
|
||||||
* @param offset2
|
|
||||||
* @param b
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass) throws Exception {
|
|
||||||
callback = new FullParseCallback();
|
|
||||||
IParser parser = null;
|
|
||||||
|
|
||||||
parser =
|
|
||||||
ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
new CodeReader(code.toCharArray()),
|
|
||||||
new ScannerInfo(),
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
callback,
|
|
||||||
new NullLogService(), null),
|
|
||||||
callback,
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
ParserFactory.createDefaultLogService());
|
|
||||||
|
|
||||||
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
|
|
||||||
if( expectedToPass )
|
|
||||||
{
|
|
||||||
assertNotNull( result );
|
|
||||||
String filename = result.getFilename();
|
|
||||||
assertNotNull( filename );
|
|
||||||
assertTrue( !filename.equals( "")); //$NON-NLS-1$
|
|
||||||
return (IASTNode) result.getOffsetableNamedElement();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,742 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterDeclaration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*/
|
|
||||||
public class SelectionParseTest extends SelectionParseBaseTest {
|
|
||||||
|
|
||||||
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( '=');
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertTrue( node instanceof IASTVariable );
|
|
||||||
assertEquals( ((IASTVariable)node).getName(), "x" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
assertEquals( ((IASTFunction)node).getName(), "x" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
String code = "int x(); x( );"; //$NON-NLS-1$
|
|
||||||
int offset1 = code.indexOf( "x()" ); //$NON-NLS-1$
|
|
||||||
int offset2 = code.indexOf( "()"); //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
assertEquals( ((IASTFunction)node).getName(), "x" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
assertEquals( ((IASTFunction)node).getName(), "printf" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTVariable );
|
|
||||||
assertEquals( ((IASTVariable)node).getName(), "x" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
IASTNode node = parse( code, offset1, offset2 );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTParameterDeclaration );
|
|
||||||
assertEquals( ((IASTParameterDeclaration)node).getName(), "argc" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "int main(int argc, char **argv) { Gonzo gonzo; gonzo.playHorn(); }\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
for( int i = 0; i < 3; ++i )
|
|
||||||
{
|
|
||||||
int start = -1, stop = -1;
|
|
||||||
switch( i )
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
start = code.indexOf( "void playHorn") + 5; //$NON-NLS-1$
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
start = code.indexOf( "::playHorn") + 2; //$NON-NLS-1$
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
start = code.indexOf( ".playHorn") + 1; //$NON-NLS-1$
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
stop = start + 8;
|
|
||||||
IASTNode node = parse( code, start, stop );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod method = (IASTMethod) node;
|
|
||||||
assertEquals( method.getName(), "playHorn"); //$NON-NLS-1$
|
|
||||||
IASTClassSpecifier gonzo = method.getOwnerClassSpecifier();
|
|
||||||
assertEquals( gonzo.getName(), "Gonzo"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConstructorDestructorDeclaration() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "class Gonzo { Gonzo(); ~Gonzo(); };"); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int offset = code.indexOf( " Gonzo()") + 1; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, offset, offset + 5 );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod constructor = ((IASTMethod)node);
|
|
||||||
assertEquals( constructor.getName(), "Gonzo" ); //$NON-NLS-1$
|
|
||||||
assertTrue( constructor.isConstructor() );
|
|
||||||
offset = code.indexOf( "~Gonzo"); //$NON-NLS-1$
|
|
||||||
node = parse( code, offset, offset + 6 );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod destructor = ((IASTMethod)node);
|
|
||||||
assertEquals( destructor.getName(), "~Gonzo" ); //$NON-NLS-1$
|
|
||||||
assertTrue( destructor.isDestructor() );
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
String code = writer.toString();
|
|
||||||
int index = code.indexOf( "Muppets::"); //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, index, index + 7 );
|
|
||||||
assertNotNull( node );
|
|
||||||
assertTrue( node instanceof IASTNamespaceDefinition );
|
|
||||||
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) node;
|
|
||||||
assertEquals( namespace.getName(), "Muppets"); //$NON-NLS-1$
|
|
||||||
assertEquals( namespace.getStartingLine(), 1 );
|
|
||||||
|
|
||||||
index = code.indexOf( "e Muppets") + 2; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 7 );
|
|
||||||
assertTrue( node instanceof IASTNamespaceDefinition );
|
|
||||||
namespace = (IASTNamespaceDefinition) node;
|
|
||||||
assertEquals( namespace.getName(), "Muppets"); //$NON-NLS-1$
|
|
||||||
assertEquals( namespace.getStartingLine(), 1 );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "Foo() {};\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "};\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "int \n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "Foo foo; // ** (B) **\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int index = code.indexOf( "class Foo") + 6; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, index, index + 3 );
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
IASTClassSpecifier foo = (IASTClassSpecifier) node;
|
|
||||||
assertEquals( foo.getName(), "Foo"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug60038() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "class Gonzo {\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "public:\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "Gonzo( const Gonzo & other ){}\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "Gonzo() {}\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "~Gonzo(){}\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "};\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int main(int argc, char **argv) {\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " Gonzo * g = new Gonzo();\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " Gonzo * g2 = new Gonzo( *g );\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " g->~Gonzo();\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " return (int) g2;\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n"); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
for( int i = 0; i < 3; ++i )
|
|
||||||
{
|
|
||||||
int startOffset = 0, endOffset = 0;
|
|
||||||
switch( i )
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
startOffset = code.indexOf( "new Gonzo()") + 4; //$NON-NLS-1$
|
|
||||||
endOffset = startOffset + 5;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
startOffset = code.indexOf( "new Gonzo( ") + 4; //$NON-NLS-1$
|
|
||||||
endOffset = startOffset + 5;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
startOffset = code.indexOf( "->~") + 2; //$NON-NLS-1$
|
|
||||||
endOffset = startOffset + 6;
|
|
||||||
}
|
|
||||||
IASTNode node = parse( code, startOffset, endOffset );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod method = (IASTMethod) node;
|
|
||||||
switch( i )
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
assertTrue( method.isConstructor() );
|
|
||||||
assertFalse( method.isDestructor() );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assertFalse( method.isConstructor() );
|
|
||||||
assertTrue( method.isDestructor() );
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "};\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " Sample * s = new Sample();\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( " return s->getAnswer();\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "->getAnswer") + 2; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex+9);
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
assertEquals( ((IASTMethod)node).getName(), "getAnswer" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod constructor = (IASTMethod) node;
|
|
||||||
assertTrue( constructor.isConstructor() );
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "foo(1); \n }" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "foo(1)"); //$NON-NLS-1$
|
|
||||||
parse( code, startIndex, startIndex + 3 );
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("struct X;\n"); //$NON-NLS-1$
|
|
||||||
writer.write("struct X anA;"); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "X anA"); //$NON-NLS-1$
|
|
||||||
parse( code, startIndex, startIndex + 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "typedef _FILE FILE;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "static void static_function(FILE * lcd){}\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "FILE * file = 0;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "static_function( file );\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "return 0;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
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
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "class B {};\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "class ABCDEF {\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " static B stInt; };\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "B ABCDEF::stInt = 5;\n"); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "::stInt") + 2; //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex+ 5 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
assertEquals( ((IASTField)node).getName(), "stInt" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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 IASTFunction );
|
|
||||||
assertEquals( ((IASTFunction)node).getName(), "fprintf" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "return sizeof( Squaw );\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "sizeof( ") + "sizeof( ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex + 5 );
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) node;
|
|
||||||
assertEquals( classSpecifier.getClassKind(), ASTClassKind.UNION );
|
|
||||||
assertEquals( classSpecifier.getName(), "Squaw"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( "public:\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "const int findCode() const;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "};\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "const int Test::findCode() const {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "return FOUND_ME;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "return ") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex + 8 );
|
|
||||||
assertTrue( node instanceof IASTVariable );
|
|
||||||
assertEquals( ((IASTVariable)node).getName(), "FOUND_ME" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72721() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write(" class ABC { public: ABC(int); }; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("void f() { \n"); //$NON-NLS-1$
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
assertEquals( ((IASTMethod)node).getName(), "ABC" ); //$NON-NLS-1$
|
|
||||||
assertTrue( ((IASTMethod)node).isConstructor() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72372() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace B { \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" class SD_02 { void f_SD(); }; \n"); //$NON-NLS-1$
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
assertEquals( ((IASTMethod)node).getName(), "f_SD" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testBug72372_2() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace A { \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" namespace B { \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" void f_SD(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" } \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
writer.write("namespace C { \n"); //$NON-NLS-1$
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
assertEquals( ((IASTFunction)node).getName(), "f_SD" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
assertFalse( ((IASTMethod)node).previouslyDeclared() );
|
|
||||||
assertEquals( ((IASTMethod) node).getNameOffset(), code.indexOf( " initialize();" ) + 1 ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
assertTrue( ((IASTMethod) node).isConstructor() );
|
|
||||||
}
|
|
||||||
|
|
||||||
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 IASTClassSpecifier );
|
|
||||||
assertEquals( ((IASTClassSpecifier)node).getName(), "A" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug72814() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " template < class T > class AAA { T _t };\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "N::AAA<int> a; \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "AAA<int>" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex + 3 );
|
|
||||||
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
assertEquals( ((IASTClassSpecifier)node).getName(), "AAA" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
node = parse( code, startIndex, startIndex + 8 );
|
|
||||||
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
assertEquals( ((IASTClassSpecifier)node).getName(), "AAA" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
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$
|
|
||||||
writer.write( " int rank;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "};\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "Card::Card( int rank ) {\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "this->rank = rank;\n" ); //$NON-NLS-1$
|
|
||||||
writer.write( "}\n" ); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int index = code.indexOf( "this->rank") + 6; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank = (IASTField) node;
|
|
||||||
assertEquals( rank.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testBug75731() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("int rank() {\n"); //$NON-NLS-1$
|
|
||||||
writer.write("return 5;\n}\n"); //$NON-NLS-1$
|
|
||||||
writer.write("class Card{\n"); //$NON-NLS-1$
|
|
||||||
writer.write("private:\n"); //$NON-NLS-1$
|
|
||||||
writer.write("Card( int rank );\n"); //$NON-NLS-1$
|
|
||||||
writer.write("int rank;\n"); //$NON-NLS-1$
|
|
||||||
writer.write("public:\n"); //$NON-NLS-1$
|
|
||||||
writer.write("int getRank();\n};\n"); //$NON-NLS-1$
|
|
||||||
writer.write("Card::Card( int rank )\n{\n"); //$NON-NLS-1$
|
|
||||||
writer.write("this->rank = ::rank();\n"); //$NON-NLS-1$
|
|
||||||
writer.write("this->rank = this->rank;\n"); //$NON-NLS-1$
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
IASTFunction rank1 = (IASTFunction) node;
|
|
||||||
assertEquals( rank1.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank1.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "class Card{") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
IASTClassSpecifier card1 = (IASTClassSpecifier) node;
|
|
||||||
assertEquals( card1.getName(), "Card"); //$NON-NLS-1$
|
|
||||||
assertEquals( card1.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "Card( int rank );"); //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod card2 = (IASTMethod) node;
|
|
||||||
assertEquals( card2.getName(), "Card"); //$NON-NLS-1$
|
|
||||||
assertEquals( card2.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "Card( int rank );") + 10; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTParameterDeclaration );
|
|
||||||
IASTParameterDeclaration rank2 = (IASTParameterDeclaration) node;
|
|
||||||
assertEquals( rank2.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank2.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "int rank;") + 4; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank3 = (IASTField) node;
|
|
||||||
assertEquals( rank3.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank3.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "int getRank();") + 4; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 7 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod getRank1 = (IASTMethod) node;
|
|
||||||
assertEquals( getRank1.getName(), "getRank"); //$NON-NLS-1$
|
|
||||||
assertEquals( getRank1.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "Card::Card( int rank )"); //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTClassSpecifier );
|
|
||||||
IASTClassSpecifier card3 = (IASTClassSpecifier) node;
|
|
||||||
assertEquals( card3.getName(), "Card"); //$NON-NLS-1$
|
|
||||||
assertEquals( card3.getNameOffset(), card1.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "Card::Card( int rank )") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod card4 = (IASTMethod) node;
|
|
||||||
assertEquals( card4.getName(), "Card"); //$NON-NLS-1$
|
|
||||||
assertEquals( card4.getNameOffset(), card2.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "Card::Card( int rank )") + 16; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTParameterDeclaration );
|
|
||||||
IASTParameterDeclaration rank4 = (IASTParameterDeclaration) node;
|
|
||||||
assertEquals( rank4.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank4.getNameOffset(), index );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = ::rank();") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank5 = (IASTField) node;
|
|
||||||
assertEquals( rank5.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank5.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = ::rank();") + 15; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTFunction );
|
|
||||||
IASTFunction rank6 = (IASTFunction) node;
|
|
||||||
assertEquals( rank6.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank6.getNameOffset(), rank1.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = this->rank;") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank7 = (IASTField) node;
|
|
||||||
assertEquals( rank7.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank7.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = this->rank;") + 19; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank8 = (IASTField) node;
|
|
||||||
assertEquals( rank8.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank8.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = rank;") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank9 = (IASTField) node;
|
|
||||||
assertEquals( rank9.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank9.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = rank;") + 13; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTParameterDeclaration );
|
|
||||||
IASTParameterDeclaration rank10 = (IASTParameterDeclaration) node;
|
|
||||||
assertEquals( rank10.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank10.getNameOffset(), rank4.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = Card::rank;") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank11 = (IASTField) node;
|
|
||||||
assertEquals( rank11.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank11.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = Card::rank;") + 19; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank12 = (IASTField) node;
|
|
||||||
assertEquals( rank12.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank12.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = getRank();") + 6; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 4 );
|
|
||||||
assertTrue( node instanceof IASTField );
|
|
||||||
IASTField rank13 = (IASTField) node;
|
|
||||||
assertEquals( rank13.getName(), "rank"); //$NON-NLS-1$
|
|
||||||
assertEquals( rank13.getNameOffset(), rank3.getNameOffset() );
|
|
||||||
|
|
||||||
index = code.indexOf( "this->rank = getRank();") + 13; //$NON-NLS-1$
|
|
||||||
node = parse( code, index, index + 7 );
|
|
||||||
assertTrue( node instanceof IASTMethod );
|
|
||||||
IASTMethod getRank2 = (IASTMethod) node;
|
|
||||||
assertEquals( getRank2.getName(), "getRank"); //$NON-NLS-1$
|
|
||||||
assertEquals( getRank2.getNameOffset(), getRank1.getNameOffset() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug77989() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace N { /* A */\n"); //$NON-NLS-1$
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof ASTNamespaceDefinition );
|
|
||||||
ASTNamespaceDefinition n = (ASTNamespaceDefinition) node;
|
|
||||||
assertEquals( n.getName(), "N"); //$NON-NLS-1$
|
|
||||||
assertEquals( n.getNameOffset(), 10 );
|
|
||||||
assertEquals( n.getStartingLine(), 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug78435() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
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 );
|
|
||||||
assertTrue( node instanceof ASTParameterDeclaration );
|
|
||||||
ASTParameterDeclaration n = (ASTParameterDeclaration) node;
|
|
||||||
assertEquals( n.getName(), "itself"); //$NON-NLS-1$
|
|
||||||
assertEquals( n.getNameOffset(), 36 );
|
|
||||||
assertEquals( n.getStartingLine(), 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug78231A() throws Exception {
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
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 );
|
|
||||||
assertTrue(node instanceof IASTOffsetableNamedElement);
|
|
||||||
IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node;
|
|
||||||
assertEquals(n.getName(), "Data"); //$NON-NLS-1$
|
|
||||||
assertEquals(n.getNameOffset(), 36);
|
|
||||||
assertEquals(n.getStartingLine(), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
assertTrue(node instanceof IASTOffsetableNamedElement);
|
|
||||||
IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node;
|
|
||||||
assertEquals(n.getName(), "Data"); //$NON-NLS-1$
|
|
||||||
assertEquals(n.getNameOffset(), 46);
|
|
||||||
assertEquals(n.getStartingLine(), 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,191 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
|
||||||
|
|
||||||
// A test that just calculates the speed of the parser
|
|
||||||
// Eventually, we'll peg a max time and fail the test if it exceeds it
|
|
||||||
public class SpeedTest extends TestCase {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
new SpeedTest().runTest(1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test() throws Exception {
|
|
||||||
runTest(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runTest(int n) throws Exception {
|
|
||||||
String code =
|
|
||||||
"#include <windows.h>\n" +
|
|
||||||
"#include <stdio.h>\n" +
|
|
||||||
"#include <iostream>\n";
|
|
||||||
|
|
||||||
CodeReader reader = new CodeReader(code.toCharArray());
|
|
||||||
IScannerInfo info = getScannerInfo(false);
|
|
||||||
long totalTime = 0;
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
long time = testParse(reader, false, info, ParserLanguage.CPP);
|
|
||||||
if (i > 4)
|
|
||||||
totalTime += time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n > 5) {
|
|
||||||
System.out.println("Average Time: " + (totalTime / (n - 5)) + " millisecs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path
|
|
||||||
* @param quick TODO
|
|
||||||
*/
|
|
||||||
protected long testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
|
||||||
IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
|
||||||
IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null);
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
long totalTime;
|
|
||||||
parser.parse();
|
|
||||||
totalTime = System.currentTimeMillis() - startTime;
|
|
||||||
System.out.println( "Resulting parse took " + totalTime + " millisecs " +
|
|
||||||
scanner.getCount() + " tokens");
|
|
||||||
return totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
|
||||||
|
|
||||||
protected IScannerInfo getScannerInfo(boolean quick) {
|
|
||||||
if (quick)
|
|
||||||
return new ScannerInfo();
|
|
||||||
|
|
||||||
String config = System.getProperty("speedTest.config");
|
|
||||||
|
|
||||||
if (config == null)
|
|
||||||
return mingwScannerInfo(false);
|
|
||||||
|
|
||||||
if (config.equals("msvc"))
|
|
||||||
return msvcScannerInfo(false);
|
|
||||||
else if (config.equals("ydl"))
|
|
||||||
return ydlScannerInfo(false);
|
|
||||||
else
|
|
||||||
return mingwScannerInfo(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IScannerInfo msvcScannerInfo(boolean quick) {
|
|
||||||
if( quick )
|
|
||||||
return new ScannerInfo();
|
|
||||||
Map definitions = new Hashtable();
|
|
||||||
//definitions.put( "__GNUC__", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
String [] includePaths = new String[] {
|
|
||||||
"C:\\Program Files\\Microsoft SDK\\Include",
|
|
||||||
"C:\\Program Files\\Microsoft Visual C++ Toolkit 2003\\include"
|
|
||||||
};
|
|
||||||
return new ScannerInfo( definitions, includePaths );
|
|
||||||
}
|
|
||||||
|
|
||||||
private IScannerInfo mingwScannerInfo(boolean quick) {
|
|
||||||
// TODO It would be easier and more flexible if we used discovery for this
|
|
||||||
if( quick )
|
|
||||||
return new ScannerInfo();
|
|
||||||
Map definitions = new Hashtable();
|
|
||||||
definitions.put("__GNUC__", "3");
|
|
||||||
definitions.put("__GNUC_MINOR__", "2");
|
|
||||||
definitions.put("__GNUC_PATCHLEVEL__", "3");
|
|
||||||
definitions.put("__GXX_ABI_VERSION", "102");
|
|
||||||
definitions.put("_WIN32", "");
|
|
||||||
definitions.put("__WIN32", "");
|
|
||||||
definitions.put("__WIN32__", "");
|
|
||||||
definitions.put("WIN32", "");
|
|
||||||
definitions.put("__MINGW32__", "");
|
|
||||||
definitions.put("__MSVCRT__", "");
|
|
||||||
definitions.put("WINNT", "");
|
|
||||||
definitions.put("_X86_", "1");
|
|
||||||
definitions.put("__WINNT", "");
|
|
||||||
definitions.put("_NO_INLINE__", "");
|
|
||||||
definitions.put("__STDC_HOSTED__", "1");
|
|
||||||
definitions.put("i386", "");
|
|
||||||
definitions.put("__i386", "");
|
|
||||||
definitions.put("__i386__", "");
|
|
||||||
definitions.put("__tune_i586__", "");
|
|
||||||
definitions.put("__tune_pentium__", "");
|
|
||||||
definitions.put("__stdcall", "__attribute__((__stdcall__))");
|
|
||||||
definitions.put("__cdecl", "__attribute__((__cdecl__))");
|
|
||||||
definitions.put("__fastcall", "__attribute__((__fastcall__))");
|
|
||||||
definitions.put("_stdcall", "__attribute__((__stdcall__))");
|
|
||||||
definitions.put("_cdecl", "__attribute__((__cdecl__))");
|
|
||||||
definitions.put("_fastcall", "__attribute__((__fastcall__))");
|
|
||||||
definitions.put("__declspec(x)", "__attribute__((x))");
|
|
||||||
definitions.put("__DEPRECATED", "");
|
|
||||||
definitions.put("__EXCEPTIONS", "");
|
|
||||||
|
|
||||||
String [] includePaths = new String[] {
|
|
||||||
"c:/mingw/include/c++/3.2.3",
|
|
||||||
"c:/mingw/include/c++/3.2.3/mingw32",
|
|
||||||
"c:/mingw/include/c++/3.2.3/backward",
|
|
||||||
"c:/mingw/include",
|
|
||||||
"c:/mingw/lib/gcc-lib/mingw32/3.2.3/include"
|
|
||||||
};
|
|
||||||
|
|
||||||
return new ScannerInfo( definitions, includePaths );
|
|
||||||
}
|
|
||||||
|
|
||||||
private IScannerInfo ydlScannerInfo(boolean quick) {
|
|
||||||
// TODO It would be easier and more flexible if we used discovery for this
|
|
||||||
if( quick )
|
|
||||||
return new ScannerInfo();
|
|
||||||
Map definitions = new Hashtable();
|
|
||||||
definitions.put("__GNUC__", "3");
|
|
||||||
definitions.put("__GNUC_MINOR__", "3");
|
|
||||||
definitions.put("__GNUC_PATCHLEVEL__", "3");
|
|
||||||
definitions.put("_GNU_SOURCE", "");
|
|
||||||
definitions.put("__unix__", "");
|
|
||||||
definitions.put("__gnu_linux__", "");
|
|
||||||
definitions.put("__linux__", "");
|
|
||||||
definitions.put("unix", "");
|
|
||||||
definitions.put("__unix", "");
|
|
||||||
definitions.put("linux", "");
|
|
||||||
definitions.put("__linux", "");
|
|
||||||
definitions.put("__GNUG__", "3");
|
|
||||||
|
|
||||||
String [] includePaths = new String[] {
|
|
||||||
"/usr/include/g++",
|
|
||||||
"/usr/include/g++/powerpc-yellowdog-linux",
|
|
||||||
"/usr/include/g++/backward",
|
|
||||||
"/usr/local/include",
|
|
||||||
"/usr/lib/gcc-lib/powerpc-yellowdog-linux/3.3.3/include",
|
|
||||||
"/usr/include"
|
|
||||||
};
|
|
||||||
|
|
||||||
return new ScannerInfo( definitions, includePaths );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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 Corp. - Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
/*
|
|
||||||
* Created on Apr 29, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
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.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*/
|
|
||||||
public class StructuralParseTest extends TestCase {
|
|
||||||
|
|
||||||
public StructuralParseTest()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected StructuralParseCallback callback;
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse( String code ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return parse( code, true, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse( String code, boolean throwOnError ) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
return parse( code, throwOnError, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTCompilationUnit parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError
|
|
||||||
{
|
|
||||||
callback = new StructuralParseCallback();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$
|
|
||||||
ParserMode.STRUCTURAL_PARSE, language, callback, new NullLogService(), null ),
|
|
||||||
callback, ParserMode.STRUCTURAL_PARSE, language, null
|
|
||||||
);
|
|
||||||
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
|
||||||
return callback.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug60149() throws Exception
|
|
||||||
{
|
|
||||||
IASTCompilationUnit cu = parse( "extern \"C\" { int v; } " ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
Iterator i = cu.getDeclarations();
|
|
||||||
|
|
||||||
IASTLinkageSpecification ls = (IASTLinkageSpecification) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
i = ls.getDeclarations();
|
|
||||||
IASTVariable v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "v" ); //$NON-NLS-1$
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug60480() throws Exception
|
|
||||||
{
|
|
||||||
IASTCompilationUnit cu = parse( "template < int > void foo();" ); //$NON-NLS-1$
|
|
||||||
Iterator i = cu.getDeclarations();
|
|
||||||
|
|
||||||
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
IASTFunction foo = (IASTFunction) template.getOwnedDeclaration();
|
|
||||||
assertEquals( foo.getName(), "foo" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug77010() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write(" struct Example{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int *deref(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int const *deref() const; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int volatile *deref() volatile; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" int const volatile *deref() const volatile; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" }; \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
|
||||||
IASTClassSpecifier Ex = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
|
||||||
|
|
||||||
i = Ex.getDeclarations();
|
|
||||||
IASTMethod deref = (IASTMethod) i.next();
|
|
||||||
assertFalse( deref.getReturnType().isConst() );
|
|
||||||
assertFalse( deref.getReturnType().isVolatile() );
|
|
||||||
assertFalse( deref.isConst() );
|
|
||||||
assertFalse( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertTrue( deref.getReturnType().isConst() );
|
|
||||||
assertFalse( deref.getReturnType().isVolatile() );
|
|
||||||
assertTrue( deref.isConst() );
|
|
||||||
assertFalse( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertFalse( deref.getReturnType().isConst() );
|
|
||||||
assertTrue( deref.getReturnType().isVolatile() );
|
|
||||||
assertFalse( deref.isConst() );
|
|
||||||
assertTrue( deref.isVolatile() );
|
|
||||||
|
|
||||||
deref = (IASTMethod) i.next();
|
|
||||||
assertTrue( deref.getReturnType().isConst() );
|
|
||||||
assertTrue( deref.getReturnType().isVolatile() );
|
|
||||||
assertTrue( deref.isConst() );
|
|
||||||
assertTrue( deref.isVolatile() );
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,289 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2006 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 Corp. - Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.testplugin.CTestPlugin;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author vmozgin
|
|
||||||
*
|
|
||||||
* Automated parser test framework, to use with GCC testsuites
|
|
||||||
*/
|
|
||||||
public class TortureTest extends FractionalAutomatedTest {
|
|
||||||
|
|
||||||
static protected boolean isEnabled = false;
|
|
||||||
static protected boolean quickParse = true;
|
|
||||||
|
|
||||||
public TortureTest () {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TortureTest (String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AutomatedFramework newTest (String name){
|
|
||||||
return new TortureTest (name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadProperties() throws Exception{
|
|
||||||
String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
resourcePath += "resources/parser/TortureTest"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileInputStream propertiesIn = new FileInputStream(resourcePath + "/TortureTest.properties"); //$NON-NLS-1$
|
|
||||||
properties.load (propertiesIn);
|
|
||||||
|
|
||||||
isEnabled = properties.getProperty("enabled", "false").equalsIgnoreCase("true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
quickParse = properties.getProperty("quickParse", "true").equalsIgnoreCase("true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
|
|
||||||
String sourceInfo = properties.getProperty("source", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
stepSize = Integer.parseInt(properties.getProperty("stepSize", "25000")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
outputFile = properties.getProperty("outputFile", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
timeOut = Integer.parseInt(properties.getProperty("timeOut", "60000")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
outputDir = properties.getProperty("outDir", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
if (sourceInfo.equals("")) //$NON-NLS-1$
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
|
|
||||||
StringTokenizer tokenizer = new StringTokenizer(sourceInfo, ","); //$NON-NLS-1$
|
|
||||||
String str = null, val = null;
|
|
||||||
try {
|
|
||||||
while (tokenizer.hasMoreTokens()) {
|
|
||||||
str = tokenizer.nextToken().trim();
|
|
||||||
val = tokenizer.nextToken().trim();
|
|
||||||
|
|
||||||
testSources.put(str, val);
|
|
||||||
}
|
|
||||||
} catch (NoSuchElementException e){
|
|
||||||
//only way to get here is to have a missing val, assume cpp for that str
|
|
||||||
testSources.put(str, "cpp"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e){
|
|
||||||
testSources.put(resourcePath, "cpp"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isEnabled) testSources.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
AutomatedFramework frame = new TortureTest();
|
|
||||||
return frame.createSuite();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static protected void reportException (Throwable e, String file, IParser parser){
|
|
||||||
String output = null;
|
|
||||||
int lineNumber = -1;
|
|
||||||
|
|
||||||
lineNumber = parser.getLastErrorLine();
|
|
||||||
|
|
||||||
if (e instanceof AssertionFailedError) {
|
|
||||||
output = file + ": Parse failed on line "; //$NON-NLS-1$
|
|
||||||
output += lineNumber + "\n"; //$NON-NLS-1$
|
|
||||||
} else {
|
|
||||||
output = file + ": " + e.getClass().toString(); //$NON-NLS-1$
|
|
||||||
output += " on line " + lineNumber + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (report != null) {
|
|
||||||
report.write(output.getBytes());
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {}
|
|
||||||
|
|
||||||
fail(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static protected boolean isExpectedToPass (String testCode, File file)
|
|
||||||
{
|
|
||||||
String fileName = file.getName();
|
|
||||||
|
|
||||||
// Filter out gcc-specific tests that are not easy to detect automatically
|
|
||||||
if ( fileName.equals("init-2.c") //$NON-NLS-1$
|
|
||||||
|| fileName.equals("init-3.c") //$NON-NLS-1$
|
|
||||||
|| fileName.equals("struct-ini-4.c")) { //$NON-NLS-1$
|
|
||||||
|
|
||||||
// gcc-specific (and deprecated) designated initializers
|
|
||||||
// struct { int e1, e2; } v = { e2: 0 };
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fileName.equals("stmtexpr3.C")) { //$NON-NLS-1$
|
|
||||||
|
|
||||||
// statements in expressions
|
|
||||||
// B() : a(({ 1; })) {}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fileName.equals("widechar-1.c")) { //$NON-NLS-1$
|
|
||||||
|
|
||||||
// concatenation of incompatible literals
|
|
||||||
// char *s = L"a" "b";
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fileName.equals("bf-common.h") //$NON-NLS-1$
|
|
||||||
|| fileName.equals("class-tests-1.h") //$NON-NLS-1$
|
|
||||||
|| fileName.equals("unclaimed-category-1.h")) { //$NON-NLS-1$
|
|
||||||
|
|
||||||
// ObjectiveC header file
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process some DejaGNU instructions
|
|
||||||
if (testCode.indexOf("{ dg-error") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("// ERROR") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("- ERROR") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("// XFAIL") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("- XFAIL") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("{ xfail") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("{ dg-preprocess") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("{ dg-do preprocess") >= 0) return false; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// gcc extensions
|
|
||||||
if (testCode.indexOf("__attribute") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__extension") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__restrict") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__const") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__declspec") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__alignof") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__label") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__real") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("__imag") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("extern template") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("inline template") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("static template") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("typeof") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf(" asm") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf(") return") >= 0) return false; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("#ident") >= 0) return false; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are expected errors (not marked in the code)
|
|
||||||
if (testCode.indexOf("#include_next") >= 0) return false; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// Long long literals are part of ANSI C99
|
|
||||||
// if (containsLongLongLiterals(testCode)) return false;
|
|
||||||
|
|
||||||
if (testCode.indexOf("{ dg-do run") >= 0) return true; //$NON-NLS-1$
|
|
||||||
if (testCode.indexOf("{ dg-do link") >= 0) return true; //$NON-NLS-1$
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void doFile() throws Throwable {
|
|
||||||
int timeOut = FractionalAutomatedTest.timeOut;
|
|
||||||
|
|
||||||
assertNotNull (fileList);
|
|
||||||
|
|
||||||
File file = (File)fileList.removeFirst();
|
|
||||||
FileInputStream stream = new FileInputStream(file);
|
|
||||||
|
|
||||||
String filePath = file.getCanonicalPath();
|
|
||||||
String nature = (String)natures.get(filePath);
|
|
||||||
|
|
||||||
StringWriter code = new StringWriter();
|
|
||||||
|
|
||||||
byte b[] = new byte[stepSize];
|
|
||||||
int n = stream.read(b);
|
|
||||||
while( n != -1 ){
|
|
||||||
code.write(new String(b));
|
|
||||||
n = stream.read(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
String testCode = code.toString();
|
|
||||||
|
|
||||||
if ( file.getName().equals("concat1.C")) { //$NON-NLS-1$
|
|
||||||
// This is a really time-consuming test,
|
|
||||||
// override timeout
|
|
||||||
timeOut = 600000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isExpectedToPass(testCode, file)) {
|
|
||||||
ParseThread thread = new ParseThread();
|
|
||||||
|
|
||||||
thread.quickParseFlag = quickParse;
|
|
||||||
thread.code = testCode;
|
|
||||||
thread.cppNature = nature.equalsIgnoreCase("cpp"); //$NON-NLS-1$
|
|
||||||
thread.file = filePath;
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
thread.join(timeOut);
|
|
||||||
|
|
||||||
if (thread.isAlive()) {
|
|
||||||
thread.stop();
|
|
||||||
reportHang(testCode, filePath);
|
|
||||||
} else if (thread.result != null) {
|
|
||||||
reportException(thread.result, filePath, thread.parser);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// gcc probably didn't expect this test to pass.
|
|
||||||
// It doesn't mean that it should pass CDT parser,
|
|
||||||
// as it is more relaxed
|
|
||||||
// Result - 'inconclusive', but we report 'pass'
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static class ParseThread extends Thread {
|
|
||||||
public String code;
|
|
||||||
public boolean cppNature;
|
|
||||||
public String file;
|
|
||||||
public Throwable result = null;
|
|
||||||
public IParser parser = null;
|
|
||||||
public boolean quickParseFlag = true;
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
try {
|
|
||||||
ParserMode parserMode = quickParseFlag ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
|
||||||
ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C;
|
|
||||||
parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), parserMode, language, nullCallback, new NullLogService(), null ), nullCallback, parserMode, language, null);
|
|
||||||
|
|
||||||
assertTrue(parser.parse());
|
|
||||||
}
|
|
||||||
catch( Throwable e )
|
|
||||||
{
|
|
||||||
result = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4085,8 +4085,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertField(col.getName(43).resolveBinding(), "y", "Point");
|
assertField(col.getName(43).resolveBinding(), "y", "Point");
|
||||||
assertField(col.getName(44).resolveBinding(), "x", "Point");
|
assertField(col.getName(44).resolveBinding(), "x", "Point");
|
||||||
assertField(col.getName(45).resolveBinding(), "y", "Point");
|
assertField(col.getName(45).resolveBinding(), "y", "Point");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// struct S1 {
|
// struct S1 {
|
||||||
|
|
|
@ -29,10 +29,8 @@ import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
|
@ -91,7 +89,6 @@ public class DOMScannerTests extends BaseTestCase {
|
||||||
try {
|
try {
|
||||||
for(;;) {
|
for(;;) {
|
||||||
IToken t= fScanner.nextToken();
|
IToken t= fScanner.nextToken();
|
||||||
assertTrue(t.getType() <= IToken.tLAST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( EndOfFileException e){
|
catch ( EndOfFileException e){
|
||||||
|
@ -1658,12 +1655,6 @@ public class DOMScannerTests extends BaseTestCase {
|
||||||
StringBuffer buffer = new StringBuffer(
|
StringBuffer buffer = new StringBuffer(
|
||||||
"#if CONST \n #endif \n #elif CONST \n int");
|
"#if CONST \n #endif \n #elif CONST \n int");
|
||||||
final List problems = new ArrayList();
|
final List problems = new ArrayList();
|
||||||
ISourceElementRequestor requestor = new NullSourceElementRequestor() {
|
|
||||||
public boolean acceptProblem(IProblem problem) {
|
|
||||||
problems.add(problem);
|
|
||||||
return super.acceptProblem(problem);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
initializeScanner(buffer.toString());
|
initializeScanner(buffer.toString());
|
||||||
validateToken(IToken.t_int);
|
validateToken(IToken.t_int);
|
||||||
validateProblemCount(1);
|
validateProblemCount(1);
|
||||||
|
|
|
@ -2388,7 +2388,7 @@ public class PortedScannerTests extends PreprocessorTestsBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug39698() throws Exception {
|
public void testBug39698() throws Exception {
|
||||||
initializeScanner( "<? >?"); //$NON-NLS-1$
|
initializeScanner( "<? >?");
|
||||||
validateToken( IGCCToken.tMIN );
|
validateToken( IGCCToken.tMIN );
|
||||||
validateToken( IGCCToken.tMAX );
|
validateToken( IGCCToken.tMAX );
|
||||||
validateEOF();
|
validateEOF();
|
||||||
|
@ -2396,8 +2396,8 @@ public class PortedScannerTests extends PreprocessorTestsBase {
|
||||||
|
|
||||||
public void test__attribute__() throws Exception {
|
public void test__attribute__() throws Exception {
|
||||||
initializeScanner(
|
initializeScanner(
|
||||||
"#define __cdecl __attribute__((cdecl))\n" + //$NON-NLS-1$
|
"#define __cdecl __attribute__((cdecl))\n" +
|
||||||
"__cdecl;"); //$NON-NLS-1$
|
"__cdecl;");
|
||||||
validateToken(IGCCToken.t__attribute__);
|
validateToken(IGCCToken.t__attribute__);
|
||||||
validateToken(IToken.tLPAREN);
|
validateToken(IToken.tLPAREN);
|
||||||
validateToken(IToken.tLPAREN);
|
validateToken(IToken.tLPAREN);
|
||||||
|
@ -2409,8 +2409,8 @@ public class PortedScannerTests extends PreprocessorTestsBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testImaginary() throws Exception {
|
public void testImaginary() throws Exception {
|
||||||
initializeScanner( "3i", ParserLanguage.C ); //$NON-NLS-1$
|
initializeScanner( "3i", ParserLanguage.C );
|
||||||
validateInteger( "3i" ); //$NON-NLS-1$
|
validateInteger( "3i" );
|
||||||
validateEOF();
|
validateEOF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,6 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
||||||
try {
|
try {
|
||||||
for(;;) {
|
for(;;) {
|
||||||
IToken t= fScanner.nextToken();
|
IToken t= fScanner.nextToken();
|
||||||
assertTrue(t.getType() <= IToken.tLAST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( EndOfFileException e){
|
catch ( EndOfFileException e){
|
||||||
|
|
|
@ -1,256 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2007 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 Corp. - Rational Software - initial implementation
|
|
||||||
* Markus Schorn (Wind River Systems)
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.ComparisonFailure;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
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.util.CharArrayUtils;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class BaseScanner2Test extends TestCase {
|
|
||||||
|
|
||||||
protected IScanner scanner;
|
|
||||||
|
|
||||||
public BaseScanner2Test( String x )
|
|
||||||
{
|
|
||||||
super(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initializeScanner( String input, ParserMode mode ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
initializeScanner( input, mode, new NullSourceElementRequestor( mode ));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initializeScanner( String input, ParserMode mode, ISourceElementRequestor requestor ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
scanner = createScanner( new CodeReader(input.toCharArray()), new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initializeScanner( String input, ParserLanguage language ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
scanner = createScanner( new CodeReader(input.toCharArray()),
|
|
||||||
new ScannerInfo(), ParserMode.COMPLETE_PARSE, language,
|
|
||||||
new NullSourceElementRequestor( ParserMode.COMPLETE_PARSE ), null, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initializeScanner(String input) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
initializeScanner( input, ParserMode.COMPLETE_PARSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Scanner2 createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG );
|
|
||||||
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
|
|
||||||
IParserLogService logService = ( log == null ) ? ParserFactory.createDefaultLogService() : log;
|
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
|
||||||
IScannerExtensionConfiguration configuration = null;
|
|
||||||
if( language == ParserLanguage.C )
|
|
||||||
configuration = new GCCScannerExtensionConfiguration();
|
|
||||||
else
|
|
||||||
configuration = new GPPScannerExtensionConfiguration();
|
|
||||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int fullyTokenize() throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
while (t != null)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
System.out.println("Token t = " + t); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if ((t.getType()> IToken.tLAST))
|
|
||||||
System.out.println("Unknown type for token " + t); //$NON-NLS-1$
|
|
||||||
t= scanner.nextToken();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( EndOfFileException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return scanner.getCount();
|
|
||||||
}
|
|
||||||
public void validateIdentifier(String expectedImage) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertNotNull(t);
|
|
||||||
assertEquals(IToken.tIDENTIFIER, t.getType());
|
|
||||||
assertEquals(expectedImage, t.getImage());
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateInteger(String expectedImage) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertTrue(t.getType() == IToken.tINTEGER);
|
|
||||||
assertTrue(t.getImage().equals(expectedImage));
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateFloatingPointLiteral(String expectedImage) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertTrue(t.getType() == IToken.tFLOATINGPT);
|
|
||||||
assertTrue(t.getImage().equals(expectedImage));
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateChar( char expected )throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertTrue(t.getType() == IToken.tCHAR );
|
|
||||||
Character c = new Character( expected );
|
|
||||||
assertEquals( t.getImage(), '\'' + c.toString() + '\'' );
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateChar( String expected ) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertTrue(t.getType() == IToken.tCHAR );
|
|
||||||
assertEquals( t.getImage(), '\'' + expected + '\'');
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateString( String expectedImage ) throws Exception
|
|
||||||
{
|
|
||||||
validateString( expectedImage, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateString(String expectedImage, boolean lString ) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
if( lString )
|
|
||||||
assertEquals(IToken.tLSTRING, t.getType());
|
|
||||||
else
|
|
||||||
assertEquals(IToken.tSTRING, t.getType());
|
|
||||||
assertEquals(expectedImage, t.getImage());
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
fail("EOF received"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateToken(int tokenType) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertEquals(tokenType, t.getType());
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateBalance(int expected)
|
|
||||||
{
|
|
||||||
// This isn't kept track of any more
|
|
||||||
//assertTrue(scanner.getDepth() == expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateEOF() throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
assertNull(scanner.nextToken());
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void assertCharArrayEquals(char[] expected, char[] actual) {
|
|
||||||
if (!CharArrayUtils.equals(expected, actual))
|
|
||||||
throw new ComparisonFailure(null, new String(expected), new String(actual));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateDefinition(String name, String value)
|
|
||||||
{
|
|
||||||
Object expObject = scanner.getRealDefinitions().get(name.toCharArray());
|
|
||||||
assertNotNull(expObject);
|
|
||||||
assertTrue(expObject instanceof ObjectStyleMacro);
|
|
||||||
assertCharArrayEquals(value.toCharArray(), ((ObjectStyleMacro)expObject).getExpansion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateDefinition(String name, int value)
|
|
||||||
{
|
|
||||||
validateDefinition(name, String.valueOf(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validateAsUndefined(String name)
|
|
||||||
{
|
|
||||||
assertNull(scanner.getDefinitions().get(name.toCharArray()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String EXCEPTION_THROWN = "Exception thrown "; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final String EXPECTED_FAILURE = "This statement should not be reached " //$NON-NLS-1$
|
|
||||||
+ "as we sent in bad preprocessor input to the scanner"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final boolean verbose = false;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string
|
|
||||||
*/
|
|
||||||
protected void validateWideChar(String string) throws Exception
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
IToken t= scanner.nextToken();
|
|
||||||
assertEquals(IToken.tLCHAR, t.getType());
|
|
||||||
assertEquals(t.getImage(), "L\'" + string + "\'"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -18,9 +18,7 @@ import java.util.Collections;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||||
|
@ -33,7 +31,6 @@ import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||||
*/
|
*/
|
||||||
public class DOMScannerSpeedTest extends SpeedTest2 {
|
public class DOMScannerSpeedTest extends SpeedTest2 {
|
||||||
|
|
||||||
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
|
||||||
private PrintStream stream;
|
private PrintStream stream;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -83,7 +80,7 @@ public class DOMScannerSpeedTest extends SpeedTest2 {
|
||||||
*/
|
*/
|
||||||
protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
||||||
DOMScanner scanner = createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
DOMScanner scanner = createScanner(reader, info, mode, lang, null, Collections.EMPTY_LIST );
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GCCScannerExtensionsTest extends BaseScanner2Test {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param x
|
|
||||||
*/
|
|
||||||
public GCCScannerExtensionsTest(String x) {
|
|
||||||
super(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug39698() throws Exception
|
|
||||||
{
|
|
||||||
initializeScanner( "<? >?"); //$NON-NLS-1$
|
|
||||||
validateToken( IGCCToken.tMIN );
|
|
||||||
validateToken( IGCCToken.tMAX );
|
|
||||||
validateEOF();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test__attribute__() throws Exception {
|
|
||||||
initializeScanner(
|
|
||||||
"#define __cdecl __attribute__((cdecl))\n" + //$NON-NLS-1$
|
|
||||||
"__cdecl;"); //$NON-NLS-1$
|
|
||||||
validateToken(IGCCToken.t__attribute__);
|
|
||||||
validateToken(IToken.tLPAREN);
|
|
||||||
validateToken(IToken.tLPAREN);
|
|
||||||
validateToken(IToken.tIDENTIFIER);
|
|
||||||
validateToken(IToken.tRPAREN);
|
|
||||||
validateToken(IToken.tRPAREN);
|
|
||||||
validateToken(IToken.tSEMI);
|
|
||||||
validateEOF();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug73954B() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "#define foo(x) \\\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " __builtin_choose_expr( \\\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " __builtin_types_compatible_p( typeof(x), double ), \\\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " foo_double( x ), (void)0 ) \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "__builtin_constant_p(1) \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "foo( 1 ) \n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
initializeScanner( writer.toString(), ParserLanguage.C );
|
|
||||||
validateInteger( "0" ); //$NON-NLS-1$
|
|
||||||
validateToken( IToken.tLPAREN );
|
|
||||||
validateToken( IToken.t_void );
|
|
||||||
validateToken( IToken.tRPAREN );
|
|
||||||
validateInteger( "0" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testImaginary() throws Exception
|
|
||||||
{
|
|
||||||
initializeScanner( "3i", ParserLanguage.C ); //$NON-NLS-1$
|
|
||||||
validateInteger( "3i" ); //$NON-NLS-1$
|
|
||||||
validateEOF();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,186 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2005 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.ast.IASTScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.CompleteParsePluginTest;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.FileBasePluginTest;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.resources.IFolder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class IncludeTest extends FileBasePluginTest {
|
|
||||||
|
|
||||||
private static final String [] EMPTY_STRING_ARRAY = new String[0];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
* @param className
|
|
||||||
*/
|
|
||||||
public IncludeTest(String name) {
|
|
||||||
super(name, IncludeTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
TestSuite suite = new TestSuite( IncludeTest.class );
|
|
||||||
suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
CompleteParseBaseTest.FullParseCallback c;
|
|
||||||
|
|
||||||
protected IASTScope parse(IFile code, ParserLanguage language, IScannerInfo scannerInfo ) throws Exception
|
|
||||||
{
|
|
||||||
c = new CompleteParseBaseTest.FullParseCallback();
|
|
||||||
InputStream stream = code.getContents();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), scannerInfo, //$NON-NLS-1$
|
|
||||||
ParserMode.COMPLETE_PARSE, language, c, new NullLogService(), null ), c, ParserMode.COMPLETE_PARSE, language, null
|
|
||||||
);
|
|
||||||
stream.close();
|
|
||||||
boolean parseResult = parser.parse();
|
|
||||||
// throw exception if there are generated IProblems
|
|
||||||
if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
|
||||||
assertTrue( ((Parser)parser).validateCaches());
|
|
||||||
return c.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testIncludeNext() throws Exception
|
|
||||||
{
|
|
||||||
String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$
|
|
||||||
String i1Next = "int one; \n#include_next <foo.h>"; //$NON-NLS-1$
|
|
||||||
String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$
|
|
||||||
String i3Next = "int three; \n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
|
|
||||||
IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$
|
|
||||||
importFile( "foo.h", i1Next ); //$NON-NLS-1$
|
|
||||||
IFolder twof = importFolder("two"); //$NON-NLS-1$
|
|
||||||
IFolder threef = importFolder("three"); //$NON-NLS-1$
|
|
||||||
importFile( "two/foo.h", i2Next ); //$NON-NLS-1$
|
|
||||||
importFile( "three/foo.h", i3Next ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
String [] path = new String[2];
|
|
||||||
path[0] = twof.getFullPath().toOSString();
|
|
||||||
path[1] = threef.getFullPath().toOSString();
|
|
||||||
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path );
|
|
||||||
Iterator i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations();
|
|
||||||
IASTVariable v;
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "zero" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "one" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "two" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "three" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testIncludePathOrdering() throws Exception
|
|
||||||
{
|
|
||||||
// create directory structure:
|
|
||||||
// project/base.cpp
|
|
||||||
// project/foo.h
|
|
||||||
// project/two/foo.h
|
|
||||||
// project/three/foo.h
|
|
||||||
|
|
||||||
// this test sets the include path to be two;three and include foo.h (we should see the contents of two/foo.h
|
|
||||||
// then we change to three;two and we should see the contents of three/foo.h.
|
|
||||||
|
|
||||||
String baseFile = "#include <foo.h>"; //$NON-NLS-1$
|
|
||||||
String i1Next = "int one;\n"; //$NON-NLS-1$
|
|
||||||
String i2Next = "int two;\n"; //$NON-NLS-1$
|
|
||||||
String i3Next = "int three;\n"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$
|
|
||||||
importFile( "foo.h", i1Next ); //$NON-NLS-1$
|
|
||||||
IFolder twof = importFolder("two"); //$NON-NLS-1$
|
|
||||||
IFolder threef = importFolder("three"); //$NON-NLS-1$
|
|
||||||
importFile( "two/foo.h", i2Next ); //$NON-NLS-1$
|
|
||||||
importFile( "three/foo.h", i3Next ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
String [] path = new String[2];
|
|
||||||
path[0] = twof.getFullPath().toOSString();
|
|
||||||
path[1] = threef.getFullPath().toOSString();
|
|
||||||
|
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path );
|
|
||||||
Iterator i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations();
|
|
||||||
IASTVariable v;
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "two" ); //$NON-NLS-1$
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
|
|
||||||
path[0] = threef.getFullPath().toOSString();
|
|
||||||
path[1] = twof.getFullPath().toOSString();
|
|
||||||
|
|
||||||
scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path );
|
|
||||||
i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations();
|
|
||||||
|
|
||||||
assertTrue( i.hasNext() );
|
|
||||||
v = (IASTVariable) i.next();
|
|
||||||
assertEquals( v.getName(), "three" ); //$NON-NLS-1$
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBug91086() throws Exception {
|
|
||||||
IFile inclusion = importFile( "file.h", "#define FOUND 666\n" ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
StringBuffer buffer = new StringBuffer( "#include \"" ); //$NON-NLS-1$
|
|
||||||
buffer.append( inclusion.getLocation().toOSString() );
|
|
||||||
buffer.append( "\"\n"); //$NON-NLS-1$
|
|
||||||
buffer.append( "int var = FOUND;\n"); //$NON-NLS-1$
|
|
||||||
IFile code = importFile( "code.c", buffer.toString() ); //$NON-NLS-1$
|
|
||||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
|
||||||
: null) {
|
|
||||||
Iterator i = parse( code, p, new ScannerInfo() ).getDeclarations();
|
|
||||||
IASTVariable var = (IASTVariable) i.next();
|
|
||||||
assertEquals( var.getInitializerClause().getAssigmentExpression().getLiteralString(), "666" ); //$NON-NLS-1$
|
|
||||||
assertFalse( i.hasNext() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
package org.eclipse.cdt.core.parser.tests.scanner2;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -21,14 +20,9 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
|
@ -38,63 +32,11 @@ import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory;
|
||||||
// A test that just calculates the speed of the parser
|
// A test that just calculates the speed of the parser
|
||||||
// Eventually, we'll peg a max time and fail the test if it exceeds it
|
// Eventually, we'll peg a max time and fail the test if it exceeds it
|
||||||
public class SpeedTest2 extends TestCase {
|
public class SpeedTest2 extends TestCase {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
new SpeedTest2().runTest(1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test() throws Exception {
|
|
||||||
runTest(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runTest(int n) throws Exception {
|
public static DOMScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, IParserLogService log, List workingCopies )
|
||||||
String code =
|
|
||||||
"#include <windows.h>\n" +
|
|
||||||
"#include <stdio.h>\n" +
|
|
||||||
"#include <iostream>\n";
|
|
||||||
|
|
||||||
CodeReader reader = new CodeReader(code.toCharArray());
|
|
||||||
IScannerInfo info = getScannerInfo(false);
|
|
||||||
long totalTime = 0;
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
long time = testParse(reader, false, info, ParserLanguage.CPP);
|
|
||||||
if (i > 4)
|
|
||||||
totalTime += time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n > 5) {
|
|
||||||
System.out.println("Average Time: " + (totalTime / (n - 5)) + " millisecs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path
|
|
||||||
* @param quick TODO
|
|
||||||
*/
|
|
||||||
protected long testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
|
|
||||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
|
||||||
IScanner scanner = createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
|
|
||||||
IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null);
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
long totalTime;
|
|
||||||
parser.parse();
|
|
||||||
totalTime = System.currentTimeMillis() - startTime;
|
|
||||||
System.out.println( "Resulting parse took " + totalTime + " millisecs " +
|
|
||||||
scanner.getCount() + " tokens");
|
|
||||||
return totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DOMScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError
|
|
||||||
{
|
{
|
||||||
if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG );
|
|
||||||
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
|
|
||||||
IParserLogService logService = ( log == null ) ? ParserFactory.createDefaultLogService() : log;
|
IParserLogService logService = ( log == null ) ? ParserFactory.createDefaultLogService() : log;
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
|
||||||
IScannerExtensionConfiguration configuration = null;
|
IScannerExtensionConfiguration configuration = null;
|
||||||
if( language == ParserLanguage.C )
|
if( language == ParserLanguage.C )
|
||||||
configuration = new GCCScannerExtensionConfiguration();
|
configuration = new GCCScannerExtensionConfiguration();
|
||||||
|
@ -103,7 +45,6 @@ public class SpeedTest2 extends TestCase {
|
||||||
return new DOMScanner( code, config, ourMode, language, logService, configuration, FileCodeReaderFactory.getInstance() );
|
return new DOMScanner( code, config, ourMode, language, logService, configuration, FileCodeReaderFactory.getInstance() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
|
||||||
|
|
||||||
protected IScannerInfo getScannerInfo(boolean quick) {
|
protected IScannerInfo getScannerInfo(boolean quick) {
|
||||||
if (quick)
|
if (quick)
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created on Oct 4, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.tests;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*/
|
|
||||||
public class RegressionTestSuite extends TestSuite {
|
|
||||||
public RegressionTestSuite() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegressionTestSuite(Class theClass, String name) {
|
|
||||||
super(theClass, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegressionTestSuite(Class theClass) {
|
|
||||||
super(theClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegressionTestSuite(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
final RegressionTestSuite suite = new RegressionTestSuite();
|
|
||||||
|
|
||||||
suite.addTest( SelectionRegressionTest.suite( false ) );
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,807 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2004, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created on Nov 1, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.tests;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
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.IParser.ISelectionParseResult;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest.FullParseCallback;
|
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aniefer
|
|
||||||
*/
|
|
||||||
public class SelectionRegressionTest extends BaseTestFramework {
|
|
||||||
|
|
||||||
public SelectionRegressionTest()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public SelectionRegressionTest(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite(){
|
|
||||||
return suite( true );
|
|
||||||
}
|
|
||||||
public static Test suite( boolean cleanup ) {
|
|
||||||
TestSuite suite = new TestSuite("SelectionRegressionTests"); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest("testSimpleOpenDeclaration") ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testClass" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testClassRHS" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testStruct" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testStructRHS" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testEnumeration" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testEnumerationArg" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testEnumerator" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testMethod" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest( new SelectionRegressionTest( "testMethodRHS78656" ), 78656 )); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest( new SelectionRegressionTest( "testMethod78114" ), 78114 )); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testMethod78118" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest( new SelectionRegressionTest( "testOverloadedMethod78389" ), 78389 )); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest( new SelectionRegressionTest( "testConstructor78625" ), 78625) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testClassField" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testStructField" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testNamespace" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testNamespace77989" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testFunction" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testFunctionArg" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest(new SelectionRegressionTest( "testFunctionArg78435" ), 78435 )); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testVariable" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testVariableStruct" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testVariableArg" ) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest (new SelectionRegressionTest( "testVariableArg77996" ), 77996 )); //$NON-NLS-1$
|
|
||||||
suite.addTest( new FailingTest (new SelectionRegressionTest( "testVariable77996" ), 77996) ); //$NON-NLS-1$
|
|
||||||
suite.addTest( new SelectionRegressionTest( "testUnion" ) ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if( cleanup )
|
|
||||||
suite.addTest( new SelectionRegressionTest( "cleanupProject" ) ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
try{
|
|
||||||
if (project == null){
|
|
||||||
cproject = CProjectHelper.createCCProject("RegressionTestProject", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
project = cproject.getProject();
|
|
||||||
}
|
|
||||||
} catch ( CoreException e ) { //boo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
if( project == null || !project.exists() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
try{
|
|
||||||
project.delete(true,true,new NullProgressMonitor());
|
|
||||||
project = null;
|
|
||||||
} catch ( CoreException e ) { //boo
|
|
||||||
}
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTNode getSelection(IFile code, int startOffset, int endOffset) throws Exception {
|
|
||||||
return getSelection( code, startOffset, endOffset, ParserLanguage.CPP );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param code
|
|
||||||
* @param offset1
|
|
||||||
* @param offset2
|
|
||||||
* @param b
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected IASTNode getSelection(IFile file, int startOffset, int endOffset, ParserLanguage language ) throws Exception {
|
|
||||||
FullParseCallback callback = new FullParseCallback();
|
|
||||||
IParser parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
new CodeReader( file.getLocation().toOSString(), file.getContents() ),
|
|
||||||
new ScannerInfo(),
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
callback,
|
|
||||||
new NullLogService(), null),
|
|
||||||
callback,
|
|
||||||
ParserMode.SELECTION_PARSE,
|
|
||||||
ParserLanguage.CPP,
|
|
||||||
ParserFactory.createDefaultLogService()
|
|
||||||
);
|
|
||||||
|
|
||||||
ISelectionParseResult result = parser.parse( startOffset, endOffset );
|
|
||||||
|
|
||||||
return (IASTNode) ( (result != null) ? result.getOffsetableNamedElement() : null );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertNodeLocation( IASTNode result, IFile file, int offset ) throws Exception {
|
|
||||||
if( result != null && result instanceof IASTOffsetableNamedElement ){
|
|
||||||
IASTOffsetableNamedElement el = (IASTOffsetableNamedElement) result;
|
|
||||||
assertEquals( file.getLocation().toOSString(), new String( el.getFilename() ) );
|
|
||||||
assertEquals( offset, el.getNameOffset() );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail("Node not found in " + file.getLocation().toOSString() + " offset " + offset); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
||||||
}
|
|
||||||
protected void assertNodeNull( IASTNode node ) throws Exception {
|
|
||||||
if (node == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (node instanceof IASTOffsetableNamedElement) {
|
|
||||||
IASTOffsetableNamedElement el = (IASTOffsetableNamedElement) node;
|
|
||||||
fail ("node found at " + new String( el.getFilename()) + " offset " + el.getNameOffset() ); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail("Node found when none expected."); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testSimpleOpenDeclaration() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testClass() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("namespace N { \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" class B { \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" class C{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" }; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "A/*vp1*/ a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "N::B/*vp2*/ b; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "using namespace N; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "B::C/*vp3*/ c; \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln global
|
|
||||||
int start = source.indexOf( "A/*vp1*/" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in namespace; Seln global, scoped
|
|
||||||
start = source.indexOf( "N::B/*vp2*/" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 4 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("B")); //$NON-NLS-1$
|
|
||||||
//vp3 Decln in namespace and nested class; Seln in partially scoped ref
|
|
||||||
start = source.indexOf( "C/*vp3*/" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
public void testClassRHS() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" enum{E0}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int a=A::E0; \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp 1 Decln global, Seln global, on rhs of assignment
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testStruct() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("struct A{};//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class B{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: struct C{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" struct A{};//vp3 \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" struct D{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " B::C d;//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " N::A e;//vp3 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " using namespace N; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A/*vp4*/ f; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function
|
|
||||||
int start = source.indexOf( "A a;//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A{};//vp1")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in class; Seln in function, in :: scope
|
|
||||||
start = source.indexOf( "C" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$
|
|
||||||
//vp3 Decln in namespace; Seln in function, fully qualified
|
|
||||||
start = source.indexOf( "N::A" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 4 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A{};//vp3")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
//vp4 Decln ambiguous; Seln in function, unqualified
|
|
||||||
start = source.indexOf( "A/*vp4*/" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeNull( node );
|
|
||||||
}
|
|
||||||
public void testStructRHS() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("struct A{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" static const float pi=3.14; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " float f=A::pi; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function, rhs of assignment
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testEnumeration() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("enum A{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class B{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" enum C {enum2}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" void boo(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A/*vp1*/ a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " B::C/*vp2*/ c; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in class; Seln in function, fully qualified
|
|
||||||
start = source.indexOf( "B::C" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 4 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testEnumerationArg() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("enum A{}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(A a){}; \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in argument list of function
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testEnumerator() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("enum A{enum1}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class B{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" enum {enum2}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" enum {enum3} f1; \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" void boo(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a=enum1;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " int i=B::enum2;//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void B::boo() { \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " f1=enum3;//vp3 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function, on rhs of assignment
|
|
||||||
int start = source.indexOf( "enum1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 5 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("enum1")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in class, in anon enumeration; Seln in function, on rhs of assignment, in :: scope
|
|
||||||
start = source.indexOf( "enum2" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 5 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("enum2")); //$NON-NLS-1$
|
|
||||||
//vp3 Decln in class, in anon enumeration with field; Seln in method, on rhs of assignment
|
|
||||||
start = source.indexOf( "enum3" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 5 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("enum3")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testMethod() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("int method1(){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write("static const int method2(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a.method1();//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A *b=new A(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " b->method1();//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A::method2();//vp3 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln private; Seln in function, in dot reference
|
|
||||||
int start = source.indexOf( "method1();//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 7 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln private; Seln in function, in arrow reference
|
|
||||||
start = source.indexOf( "method1();//vp2" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 7 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$
|
|
||||||
//vp3 Decln private; Seln in function, in scope reference
|
|
||||||
start = source.indexOf( "method2();//vp3" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 7 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("method2")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
public void testMethodRHS78656() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("int method1(){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " int i=a.method1();//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln private; Seln in dot reference, on RHS of assignment
|
|
||||||
//defect is node not found
|
|
||||||
int start = source.indexOf( "method1();//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 7 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testMethod78114() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class Point{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" Point(): xCoord(0){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" private: int xCoord; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " Point &p2 = *(new Point()); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln public; Seln on rhs in code scope
|
|
||||||
//defect is class is found rather than constructor
|
|
||||||
int start = source.indexOf( "Point()" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 5 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("Point()")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testMethod78118() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class Point{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" Point(): xCoord(0){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" Point& operator=(const Point &rhs){return *this}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " Point a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " const Point zero; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a.operator=(zero);//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in class, public; Seln in function, in dot reference
|
|
||||||
//defect is npe; parser field, greaterContextDuple is null
|
|
||||||
int start = source.indexOf( "operator=" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 9 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("operator=")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
public void testOverloadedMethod78389() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class Point{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" void method1(){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" void method1(int i){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " Point a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a.method1(3); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln public; Seln in function, in dot reference
|
|
||||||
//defect is operation unavailable on current selection
|
|
||||||
int start = source.indexOf( "method1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 7 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("method1(int i)")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
}
|
|
||||||
public void testConstructor78625() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class Mammal { \n" ); //$NON-NLS-1$
|
|
||||||
writer.write(" public: \n" ); //$NON-NLS-1$
|
|
||||||
writer.write(" Mammal(bool b): isCarnivore(b){} \n" ); //$NON-NLS-1$
|
|
||||||
writer.write(" private: \n" ); //$NON-NLS-1$
|
|
||||||
writer.write(" bool isCarnivore; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n" ); //$NON-NLS-1$
|
|
||||||
writer.write("class Bear : Mammal{ \n" ); //$NON-NLS-1$
|
|
||||||
writer.write("public: \n" ); //$NON-NLS-1$
|
|
||||||
writer.write(" Bear(int s): Mammal(true){}//vp1 \n" ); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n" ); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln public; Seln in initializer list of derived class cctor
|
|
||||||
int start = source.indexOf( "Mammal(true)" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 6 );
|
|
||||||
assertNodeLocation( node, cpp, source.indexOf("Mammal(bool b)")); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClassField() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class A{; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("int bee; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A *a=new A(); \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a->bee;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A b; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " b.bee;//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in class; Seln in function, in arrow reference
|
|
||||||
int start = source.indexOf( "bee;//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in class; Seln in function, in dot reference
|
|
||||||
start = source.indexOf( "bee;//vp2" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testStructField() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("struct A{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("int bee; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " N::A *a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " a->bee;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " using namespace N; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A b; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " b.bee;//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in struct in namespace; Seln in function, in arrow reference
|
|
||||||
int start = source.indexOf( "bee;//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
//vp2 Decln in struct in namespace; Seln in function, in dot reference
|
|
||||||
start = source.indexOf( "bee;//vp2" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNamespace() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class A{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " N::A a; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function
|
|
||||||
int start = source.indexOf( "N::A a;" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("N")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
}
|
|
||||||
public void testNamespace77989() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class A{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " using namespace N;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function, in using statement
|
|
||||||
//defect is decln found at the selection, not in the header
|
|
||||||
int start = source.indexOf( "N;//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("N")); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
public void testFunction() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("namespace N{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write("char *foo(){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " N::foo();//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " char* x = N::foo();//vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in namespace; Seln in function, in scope reference
|
|
||||||
int start = source.indexOf( "foo();//vp1" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("foo")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in namespace; Seln in function, scoped, on rhs of assignment
|
|
||||||
start = source.indexOf( "N::foo();//vp2" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 6 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("foo")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testFunctionArg() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("double f(double){return 2.0;}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("double g(double){return 2.0;}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "double sum_sq(double (*foo)(double), double d){} \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void hi() {double x = sum_sq(g,g(3.2));} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function, in actual parameter list of caller
|
|
||||||
int start = source.indexOf( "g,g(3.2)" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("g")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln global; Seln in function, in actual parameter list of caller
|
|
||||||
start = source.indexOf( "g(3.2)" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("g")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testFunctionArg78435() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "double sum_sq(double (*foo)/*vp1*/(double), double d){} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln is inside formal parameter list; Seln is declaration
|
|
||||||
//defect is that operation is unavailable on current selection
|
|
||||||
int start = source.indexOf( "foo" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, cpp, source.indexOf("foo")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testVariable() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("char* a_pc=\"hello\"; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("union B{int x; char y;} b_u; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " int s=(sizeof(a_pc));//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " b_u=3; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global, type char*; Seln in function, on rhs, in actual parameter list of caller
|
|
||||||
int start = source.indexOf( "a_pc" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 4 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("a_pc")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln global, type union; Seln in function
|
|
||||||
start = source.indexOf( "b_u" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 3 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("b_u")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testVariableArg78435() throws Exception{
|
|
||||||
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "int aa; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(int aa){} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Variable: Decln is in formal parameter list; Seln is itself
|
|
||||||
//defect is the global aa is found instead
|
|
||||||
int start = source.indexOf( "aa" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 2 );
|
|
||||||
assertNodeLocation( node, cpp, source.indexOf("aa){}")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testVariableStruct() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("struct C {int i;}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("C c; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " c.i/*vp1*/=3; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global, type struct also defined globally; Seln in function
|
|
||||||
int start = source.indexOf( "c.i/*vp1*/" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("c;")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testVariableArg() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "int aa=3; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(int aa){//decl \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " int bb=aa;//vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in formal argument list of function; Seln in function definition, on rhs of assignment
|
|
||||||
int start = source.indexOf( "aa;" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 2 );
|
|
||||||
assertNodeLocation( node, cpp, source.indexOf("aa){//decl")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
public void testVariableClass77996() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("class C {public: int i;}; \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " C c; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " c.i/*vp1*/=3; \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln in function, type declared outside function, Seln in function
|
|
||||||
int start = source.indexOf( "c.i/*vp1*/" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, cpp, source.indexOf("c;")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
public void testUnion() throws Exception{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write("union A{}; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("class B{ \n"); //$NON-NLS-1$
|
|
||||||
writer.write(" union C{} c; \n"); //$NON-NLS-1$
|
|
||||||
writer.write("} \n"); //$NON-NLS-1$
|
|
||||||
String header = writer.toString();
|
|
||||||
IFile h = importFile( "a.h", header ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
writer = new StringWriter();
|
|
||||||
writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "void f(){ \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " A a; //vp1 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( " B::C c; //vp2 \n"); //$NON-NLS-1$
|
|
||||||
writer.write( "} \n"); //$NON-NLS-1$
|
|
||||||
String source = writer.toString();
|
|
||||||
IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$
|
|
||||||
//vp1 Decln global; Seln in function
|
|
||||||
int start = source.indexOf( "A" ); //$NON-NLS-1$
|
|
||||||
IASTNode node = getSelection( cpp, start, start + 1 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$
|
|
||||||
//vp2 Decln in class; Seln in function, scoped
|
|
||||||
start = source.indexOf( "B::C" ); //$NON-NLS-1$
|
|
||||||
node = getSelection( cpp, start, start + 4 );
|
|
||||||
assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,9 +29,6 @@ import org.eclipse.cdt.core.model.tests.AllCoreTests;
|
||||||
import org.eclipse.cdt.core.model.tests.BinaryTests;
|
import org.eclipse.cdt.core.model.tests.BinaryTests;
|
||||||
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
|
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
|
||||||
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
|
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
|
||||||
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
|
|
||||||
import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest;
|
|
||||||
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||||
import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests;
|
import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests;
|
||||||
import org.eclipse.cdt.internal.index.tests.IndexTests;
|
import org.eclipse.cdt.internal.index.tests.IndexTests;
|
||||||
|
@ -72,26 +69,11 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
suite.addTest(WorkingCopyTests.suite());
|
suite.addTest(WorkingCopyTests.suite());
|
||||||
suite.addTest(PositionTrackerTests.suite());
|
suite.addTest(PositionTrackerTests.suite());
|
||||||
suite.addTest(AllLanguageTests.suite());
|
suite.addTest(AllLanguageTests.suite());
|
||||||
|
|
||||||
// TODO turning off indexer/search tests until the PDOM
|
|
||||||
// settles. These'll probably have to be rewritten anyway.
|
|
||||||
// suite.addTest(SearchTestSuite.suite());
|
|
||||||
// suite.addTest(DependencyTests.suite());
|
|
||||||
// suite.addTest(RegressionTestSuite.suite());
|
|
||||||
//Indexer Tests need to be run after any indexer client tests
|
|
||||||
//as the last test shuts down the indexing thread
|
|
||||||
// suite.addTest(DOMSourceIndexerTests.suite());
|
|
||||||
// Last test to trigger report generation
|
|
||||||
|
|
||||||
// Add in PDOM tests
|
// Add in PDOM tests
|
||||||
suite.addTest(PDOMTests.suite());
|
suite.addTest(PDOMTests.suite());
|
||||||
suite.addTest(IndexTests.suite());
|
suite.addTest(IndexTests.suite());
|
||||||
|
|
||||||
// Add all failed tests
|
|
||||||
suite.addTestSuite(ASTFailedTests.class);
|
|
||||||
suite.addTestSuite(STLFailedTests.class);
|
|
||||||
suite.addTestSuite(FailedCompleteParseASTTest.class);
|
|
||||||
|
|
||||||
suite.addTest(AllTemplateEngineTests.suite());
|
suite.addTest(AllTemplateEngineTests.suite());
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
|
|
|
@ -29,8 +29,6 @@ Export-Package: org.eclipse.cdt.core,
|
||||||
org.eclipse.cdt.core.model.util,
|
org.eclipse.cdt.core.model.util,
|
||||||
org.eclipse.cdt.core.parser,
|
org.eclipse.cdt.core.parser,
|
||||||
org.eclipse.cdt.core.parser.ast,
|
org.eclipse.cdt.core.parser.ast,
|
||||||
org.eclipse.cdt.core.parser.ast.gcc,
|
|
||||||
org.eclipse.cdt.core.parser.extension,
|
|
||||||
org.eclipse.cdt.core.parser.util,
|
org.eclipse.cdt.core.parser.util,
|
||||||
org.eclipse.cdt.core.resources,
|
org.eclipse.cdt.core.resources,
|
||||||
org.eclipse.cdt.core.settings.model,
|
org.eclipse.cdt.core.settings.model,
|
||||||
|
@ -54,13 +52,7 @@ Export-Package: org.eclipse.cdt.core,
|
||||||
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||||
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
||||||
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
||||||
org.eclipse.cdt.internal.core.parser.ast;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.ast.complete;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.ast.complete.gcc;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.ast.gcc;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.ast.quick;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
|
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
|
||||||
org.eclipse.cdt.internal.core.parser.pst;x-internal:=true,
|
|
||||||
org.eclipse.cdt.internal.core.parser.scanner;x-internal:=true,
|
org.eclipse.cdt.internal.core.parser.scanner;x-internal:=true,
|
||||||
org.eclipse.cdt.internal.core.parser.scanner2;x-internal:=true,
|
org.eclipse.cdt.internal.core.parser.scanner2;x-internal:=true,
|
||||||
org.eclipse.cdt.internal.core.parser.token;x-friends:="org.eclipse.cdt.ui",
|
org.eclipse.cdt.internal.core.parser.token;x-friends:="org.eclipse.cdt.ui",
|
||||||
|
|
|
@ -1,848 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2007 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:
|
|
||||||
* Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.core.model;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
|
||||||
import org.eclipse.cdt.core.model.IProblemRequestor;
|
|
||||||
import org.eclipse.cdt.core.model.IStructure;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
|
||||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
import org.eclipse.cdt.core.parser.IQuickParseCallback;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
|
||||||
import org.eclipse.cdt.core.parser.NullLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
|
|
||||||
|
|
||||||
public class CModelBuilder {
|
|
||||||
|
|
||||||
private org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
|
||||||
private Map newElements;
|
|
||||||
private IQuickParseCallback quickParseCallback;
|
|
||||||
private static char[] EMPTY_CHAR_ARRAY = {};
|
|
||||||
// indicator if the unit has parse errors
|
|
||||||
private boolean hasNoErrors = false;
|
|
||||||
|
|
||||||
class ProblemCallback extends StructuralParseCallback {
|
|
||||||
IProblemRequestor problemRequestor;
|
|
||||||
|
|
||||||
public ProblemCallback(IProblemRequestor requestor) {
|
|
||||||
problemRequestor = requestor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.parser.QuickParseCallback#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
|
||||||
*/
|
|
||||||
public boolean acceptProblem(IProblem problem) {
|
|
||||||
// Do not worry for now about problems in other files.
|
|
||||||
if (inclusionLevel == 0) {
|
|
||||||
problemRequestor.acceptProblem(problem);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu, Map newElements) {
|
|
||||||
this.translationUnit = tu ;
|
|
||||||
this.newElements = newElements;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IASTCompilationUnit parse(boolean quickParseMode, boolean throwExceptionOnError) throws ParserException
|
|
||||||
{
|
|
||||||
IProject currentProject = null;
|
|
||||||
boolean hasCppNature = true;
|
|
||||||
char[] code = EMPTY_CHAR_ARRAY;
|
|
||||||
|
|
||||||
// get the current project
|
|
||||||
if (translationUnit != null && translationUnit.getCProject() != null) {
|
|
||||||
currentProject = translationUnit.getCProject().getProject();
|
|
||||||
}
|
|
||||||
// check the project's nature
|
|
||||||
if (currentProject != null) {
|
|
||||||
hasCppNature = CoreModel.hasCCNature(currentProject);
|
|
||||||
}
|
|
||||||
// get the code to parse
|
|
||||||
try {
|
|
||||||
code = translationUnit.getBuffer().getCharacters();
|
|
||||||
} catch (CModelException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final IProblemRequestor problemRequestor = translationUnit.getProblemRequestor();
|
|
||||||
// use quick or structural parse mode
|
|
||||||
ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
|
|
||||||
if (problemRequestor == null) {
|
|
||||||
quickParseCallback = (quickParseMode) ? ParserFactory.createQuickParseCallback() :
|
|
||||||
ParserFactory.createStructuralParseCallback();
|
|
||||||
} else {
|
|
||||||
quickParseCallback = new ProblemCallback(problemRequestor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pick the language
|
|
||||||
ParserLanguage language;
|
|
||||||
if (hasCppNature) {
|
|
||||||
language = ParserLanguage.CPP;
|
|
||||||
} else {
|
|
||||||
// for C project try to guess.
|
|
||||||
language = translationUnit.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the parser
|
|
||||||
IParser parser = null;
|
|
||||||
try {
|
|
||||||
IScannerInfo scanInfo = null;
|
|
||||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
|
|
||||||
if (provider != null){
|
|
||||||
IScannerInfo buildScanInfo = null;
|
|
||||||
IResource res = translationUnit.getResource();
|
|
||||||
if (res != null) {
|
|
||||||
buildScanInfo = provider.getScannerInformation(res);
|
|
||||||
}
|
|
||||||
// Technically we should not do this. But the managed scanner providers
|
|
||||||
// may rely on this behaviour i.e. only provide scannerInfo for projects
|
|
||||||
if (buildScanInfo == null) {
|
|
||||||
buildScanInfo = provider.getScannerInformation(currentProject);
|
|
||||||
}
|
|
||||||
if (buildScanInfo != null){
|
|
||||||
scanInfo = new ExtendedScannerInfo(buildScanInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (scanInfo == null) {
|
|
||||||
scanInfo = new ExtendedScannerInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
IResource resource = translationUnit.getUnderlyingResource();
|
|
||||||
CodeReader reader =
|
|
||||||
resource != null && resource.getLocation() != null
|
|
||||||
? new CodeReader(translationUnit.getUnderlyingResource().getLocation().toOSString(), code)
|
|
||||||
: new CodeReader(code);
|
|
||||||
parser = ParserFactory.createParser(
|
|
||||||
ParserFactory.createScanner(
|
|
||||||
reader,
|
|
||||||
scanInfo,
|
|
||||||
mode,
|
|
||||||
language,
|
|
||||||
quickParseCallback,
|
|
||||||
quickParseMode ? new NullLogService() : ParserUtil.getScannerLogService(), null)
|
|
||||||
,quickParseCallback,
|
|
||||||
mode,
|
|
||||||
language,
|
|
||||||
ParserUtil.getParserLogService() );
|
|
||||||
} catch(ParserFactoryError pfe) {
|
|
||||||
throw new ParserException( ""); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
// call parse
|
|
||||||
if (problemRequestor != null) {
|
|
||||||
problemRequestor.beginReporting();
|
|
||||||
}
|
|
||||||
hasNoErrors = parser.parse();
|
|
||||||
if (problemRequestor != null) {
|
|
||||||
problemRequestor.endReporting();
|
|
||||||
}
|
|
||||||
if( (!hasNoErrors) && throwExceptionOnError )
|
|
||||||
throw new ParserException(""); //$NON-NLS-1$
|
|
||||||
return quickParseCallback.getCompilationUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Map parse(boolean quickParseMode) throws Exception {
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
parse(quickParseMode, true);
|
|
||||||
} catch( ParserException e ) {
|
|
||||||
Util.debugLog( "Parse Exception in CModelBuilder", IDebugLogConstants.MODEL ); //$NON-NLS-1$
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
|
||||||
Util.debugLog("CModelBuilder: parsing " //$NON-NLS-1$
|
|
||||||
+ translationUnit.getElementName()
|
|
||||||
+ " mode="+ (quickParseMode ? "quick " : "structural ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
+ " time="+ ( System.currentTimeMillis() - startTime ) + "ms", //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IDebugLogConstants.MODEL, false);
|
|
||||||
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
generateModelElements();
|
|
||||||
// important to know if the unit has parse errors or not
|
|
||||||
translationUnit.getElementInfo().setIsStructureKnown(hasNoErrors && quickParseCallback.hasNoProblems());
|
|
||||||
} catch( NullPointerException npe ) {
|
|
||||||
Util.debugLog( "NullPointer exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the debuglog to take place, you have to call
|
|
||||||
// Util.setDebugging(true);
|
|
||||||
// Or set debug to true in the core plugin preference
|
|
||||||
Util.debugLog("CModelBuilder: building " //$NON-NLS-1$
|
|
||||||
+"children="+ translationUnit.getElementInfo().internalGetChildren().size() //$NON-NLS-1$
|
|
||||||
+" time="+ (System.currentTimeMillis() - startTime) + "ms", //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IDebugLogConstants.MODEL, false);
|
|
||||||
return this.newElements;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements() throws CModelException{
|
|
||||||
Iterator i = quickParseCallback.iterateOffsetableElements();
|
|
||||||
while (i.hasNext()){
|
|
||||||
IASTOffsetableElement offsetable = (IASTOffsetableElement)i.next();
|
|
||||||
if(offsetable instanceof IASTInclusion){
|
|
||||||
IASTInclusion inc = (IASTInclusion) offsetable;
|
|
||||||
if( ! inc.isImplicit() )
|
|
||||||
createInclusion(translationUnit, inc );
|
|
||||||
}
|
|
||||||
else if(offsetable instanceof IASTMacro){
|
|
||||||
|
|
||||||
IASTMacro macro = (IASTMacro) offsetable;
|
|
||||||
if( ! macro.isImplicit() )
|
|
||||||
createMacro(translationUnit, macro);
|
|
||||||
}else if(offsetable instanceof IASTDeclaration){
|
|
||||||
try{
|
|
||||||
generateModelElements (translationUnit, (IASTDeclaration) offsetable);
|
|
||||||
} catch(ASTNotImplementedException e){
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTDeclaration declaration) throws CModelException, ASTNotImplementedException
|
|
||||||
{
|
|
||||||
if(declaration instanceof IASTNamespaceDefinition ) {
|
|
||||||
generateModelElements(parent, (IASTNamespaceDefinition) declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(declaration instanceof IASTAbstractTypeSpecifierDeclaration ) {
|
|
||||||
generateModelElements(parent, (IASTAbstractTypeSpecifierDeclaration) declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(declaration instanceof IASTTemplateDeclaration ) {
|
|
||||||
generateModelElements(parent, (IASTTemplateDeclaration) declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(declaration instanceof IASTTypedefDeclaration ) {
|
|
||||||
generateModelElements(parent, (IASTTypedefDeclaration) declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(declaration instanceof IASTLinkageSpecification) {
|
|
||||||
generateModelElements(parent, (IASTLinkageSpecification)declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (declaration instanceof IASTUsingDirective) {
|
|
||||||
createUsingDirective(parent, (IASTUsingDirective)declaration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (declaration instanceof IASTUsingDeclaration) {
|
|
||||||
createUsingDeclaration(parent, (IASTUsingDeclaration)declaration);
|
|
||||||
}
|
|
||||||
createSimpleElement(parent, declaration, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws CModelException, ASTNotImplementedException{
|
|
||||||
// IASTNamespaceDefinition
|
|
||||||
IParent namespace = createNamespace(parent, declaration);
|
|
||||||
Iterator nsDecls = declaration.getDeclarations();
|
|
||||||
while (nsDecls.hasNext()){
|
|
||||||
IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next();
|
|
||||||
generateModelElements((Parent)namespace, subNsDeclaration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTLinkageSpecification declaration) throws CModelException, ASTNotImplementedException{
|
|
||||||
// IASTLinkageSpecification
|
|
||||||
Iterator nsDecls = declaration.getDeclarations();
|
|
||||||
while (nsDecls.hasNext()){
|
|
||||||
IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next();
|
|
||||||
generateModelElements(parent, subNsDeclaration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws CModelException, ASTNotImplementedException
|
|
||||||
{
|
|
||||||
// IASTAbstractTypeSpecifierDeclaration
|
|
||||||
createAbstractElement(parent, abstractDeclaration, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws CModelException, ASTNotImplementedException
|
|
||||||
{
|
|
||||||
CElement element = null;
|
|
||||||
// Template Declaration
|
|
||||||
IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration();
|
|
||||||
if (declaration instanceof IASTAbstractTypeSpecifierDeclaration){
|
|
||||||
// Class Template Declation ?
|
|
||||||
IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ;
|
|
||||||
element = createAbstractElement(parent, abstractDeclaration , true, true);
|
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
|
||||||
if (element instanceof StructureTemplate) {
|
|
||||||
// set the template parameters
|
|
||||||
StructureTemplate classTemplate = (StructureTemplate) element;
|
|
||||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (element instanceof StructureTemplateDeclaration) {
|
|
||||||
// set the template parameters
|
|
||||||
StructureTemplateDeclaration classTemplate = (StructureTemplateDeclaration) element;
|
|
||||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
}
|
|
||||||
} else if (declaration instanceof IASTClassSpecifier){
|
|
||||||
// special case for Structural parse
|
|
||||||
// Class template definiton ?
|
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ;
|
|
||||||
element = createClassSpecifierElement(parent, classSpecifier , true);
|
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
|
||||||
if (element instanceof StructureTemplate) {
|
|
||||||
// set the template parameters
|
|
||||||
StructureTemplate classTemplate = (StructureTemplate) element;
|
|
||||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (element instanceof StructureTemplateDeclaration) {
|
|
||||||
// set the template parameters
|
|
||||||
StructureTemplateDeclaration classTemplate = (StructureTemplateDeclaration) element;
|
|
||||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
}
|
|
||||||
} else if (declaration instanceof IASTVariable) {
|
|
||||||
// Template variable
|
|
||||||
element = createSimpleElement(parent, declaration, true);
|
|
||||||
// set the template parameters
|
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
|
||||||
VariableTemplate varTemplate = (VariableTemplate) element;
|
|
||||||
varTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (declaration instanceof IASTFunction) {
|
|
||||||
// Function template declaration/Definition
|
|
||||||
element = createSimpleElement(parent, declaration, true);
|
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
|
||||||
if (element instanceof FunctionTemplate) {
|
|
||||||
// set the template parameters
|
|
||||||
FunctionTemplate functionTemplate = (FunctionTemplate) element;
|
|
||||||
functionTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (element instanceof FunctionTemplateDeclaration) {
|
|
||||||
// set the template parameters
|
|
||||||
FunctionTemplateDeclaration functionTemplate = (FunctionTemplateDeclaration) element;
|
|
||||||
functionTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (element instanceof MethodTemplate) {
|
|
||||||
MethodTemplate methodTemplate = (MethodTemplate) element;
|
|
||||||
methodTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
} else if (element instanceof MethodTemplateDeclaration) {
|
|
||||||
MethodTemplateDeclaration methodTemplate = (MethodTemplateDeclaration) element;
|
|
||||||
methodTemplate.setTemplateParameterTypes(parameterTypes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (element instanceof SourceManipulation){
|
|
||||||
SourceManipulation sourceRef = (SourceManipulation)element;
|
|
||||||
// set the element position
|
|
||||||
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
|
||||||
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateModelElements (Parent parent, IASTTypedefDeclaration declaration) throws CModelException, ASTNotImplementedException
|
|
||||||
{
|
|
||||||
Parent typeDef= createTypeDef(parent, declaration);
|
|
||||||
if (typeDef instanceof IParent) {
|
|
||||||
// create nested
|
|
||||||
parent= typeDef;
|
|
||||||
}
|
|
||||||
IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator();
|
|
||||||
if (abstractDeclaration != null && !(abstractDeclaration.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier)) {
|
|
||||||
createAbstractElement(parent, abstractDeclaration, false, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private CElement createClassSpecifierElement(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate)throws ASTNotImplementedException, CModelException{
|
|
||||||
CElement element = null;
|
|
||||||
IParent classElement = createClass(parent, classSpecifier, isTemplate);
|
|
||||||
element = (CElement) classElement;
|
|
||||||
|
|
||||||
// create the sub declarations
|
|
||||||
Iterator j = classSpecifier.getDeclarations();
|
|
||||||
while (j.hasNext()){
|
|
||||||
IASTDeclaration subDeclaration = (IASTDeclaration)j.next();
|
|
||||||
generateModelElements((Parent)classElement, subDeclaration);
|
|
||||||
} // end while j
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate, boolean isDeclaration)throws ASTNotImplementedException, CModelException{
|
|
||||||
CElement element = null;
|
|
||||||
if (abstractDeclaration != null){
|
|
||||||
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier();
|
|
||||||
// IASTEnumerationSpecifier
|
|
||||||
if (typeSpec instanceof IASTEnumerationSpecifier) {
|
|
||||||
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
|
|
||||||
IParent enumElement = createEnumeration (parent, enumSpecifier);
|
|
||||||
element = (CElement) enumElement;
|
|
||||||
} else if (typeSpec instanceof IASTClassSpecifier) {
|
|
||||||
// IASTClassSpecifier
|
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
|
|
||||||
element = createClassSpecifierElement (parent, classSpecifier, isTemplate);
|
|
||||||
} else if (isDeclaration && typeSpec instanceof IASTElaboratedTypeSpecifier) {
|
|
||||||
// This is not a model element, so we don't create anything here.
|
|
||||||
// However, do we need to do anything else?
|
|
||||||
IASTElaboratedTypeSpecifier elabSpecifier = (IASTElaboratedTypeSpecifier) typeSpec;
|
|
||||||
element = createElaboratedTypeSpecifier(parent, elabSpecifier, isTemplate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CElement createSimpleElement(Parent parent, IASTDeclaration declaration, boolean isTemplate)throws CModelException, ASTNotImplementedException{
|
|
||||||
|
|
||||||
CElement element = null;
|
|
||||||
if (declaration instanceof IASTVariable)
|
|
||||||
{
|
|
||||||
element = createVariableSpecification(parent, (IASTVariable)declaration, isTemplate);
|
|
||||||
}
|
|
||||||
// function or method
|
|
||||||
else if(declaration instanceof IASTFunction )
|
|
||||||
{
|
|
||||||
element = createFunctionSpecification(parent, (IASTFunction)declaration, isTemplate);
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private StructureDeclaration createElaboratedTypeSpecifier(Parent parent, IASTElaboratedTypeSpecifier typeSpec, boolean isTemplate) throws CModelException{
|
|
||||||
// create element
|
|
||||||
ASTClassKind classkind = typeSpec.getClassKind();
|
|
||||||
int kind = -1;
|
|
||||||
if (classkind == ASTClassKind.CLASS) {
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_CLASS_DECLARATION : ICElement.C_CLASS_DECLARATION;
|
|
||||||
} else if (classkind == ASTClassKind.STRUCT) {
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_STRUCT_DECLARATION : ICElement.C_STRUCT_DECLARATION;
|
|
||||||
} else if (classkind == ASTClassKind.UNION) {
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_UNION_DECLARATION : ICElement.C_UNION_DECLARATION;
|
|
||||||
}
|
|
||||||
String className = (typeSpec.getName() == null)
|
|
||||||
? "" //$NON-NLS-1$
|
|
||||||
: typeSpec.getName().toString();
|
|
||||||
|
|
||||||
StructureDeclaration element;
|
|
||||||
if (isTemplate) {
|
|
||||||
element = new StructureTemplateDeclaration(parent, kind, className);
|
|
||||||
} else {
|
|
||||||
element = new StructureDeclaration(parent, className, kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
// set position
|
|
||||||
element.setIdPos(typeSpec.getNameOffset(), typeSpec.getNameEndOffset() - typeSpec.getNameOffset());
|
|
||||||
element.setPos(typeSpec.getStartingOffset(), typeSpec.getEndingOffset() - typeSpec.getStartingOffset());
|
|
||||||
element.setLines(typeSpec.getStartingLine(), typeSpec.getEndingLine());
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Include createInclusion(Parent parent, IASTInclusion inclusion) throws CModelException{
|
|
||||||
// create element
|
|
||||||
Include element = new Include(parent, inclusion.getName(), !inclusion.isLocal());
|
|
||||||
element.setFullPathName(inclusion.getFullFileName());
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
// set position
|
|
||||||
element.setIdPos(inclusion.getNameOffset(), inclusion.getNameEndOffset() - inclusion.getNameOffset());
|
|
||||||
element.setPos(inclusion.getStartingOffset(), inclusion.getEndingOffset() - inclusion.getStartingOffset());
|
|
||||||
element.setLines( inclusion.getStartingLine(), inclusion.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Macro createMacro(Parent parent, IASTMacro macro) throws CModelException{
|
|
||||||
// create element
|
|
||||||
org.eclipse.cdt.internal.core.model.Macro element = new Macro(parent, macro.getName());
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
// set position
|
|
||||||
element.setIdPos(macro.getNameOffset(), macro.getNameEndOffset() - macro.getNameOffset());
|
|
||||||
element.setPos(macro.getStartingOffset(), macro.getEndingOffset() - macro.getStartingOffset());
|
|
||||||
element.setLines( macro.getStartingLine(), macro.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef) throws CModelException{
|
|
||||||
// create element
|
|
||||||
String type = "namespace"; //$NON-NLS-1$
|
|
||||||
String nsName = (nsDef.getName() == null )
|
|
||||||
? "" //$NON-NLS-1$
|
|
||||||
: nsDef.getName().toString();
|
|
||||||
Namespace element = new Namespace (parent, nsName );
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
element.setIdPos(nsDef.getNameOffset(),
|
|
||||||
(nsName.length() == 0) ? type.length() : (nsDef.getNameEndOffset() - nsDef.getNameOffset()));
|
|
||||||
element.setPos(nsDef.getStartingOffset(), nsDef.getEndingOffset() - nsDef.getStartingOffset());
|
|
||||||
element.setLines( nsDef.getStartingLine(), nsDef.getEndingLine() );
|
|
||||||
element.setTypeName(type);
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Enumeration createEnumeration(Parent parent, IASTEnumerationSpecifier enumSpecifier) throws CModelException{
|
|
||||||
// create element
|
|
||||||
String type = "enum"; //$NON-NLS-1$
|
|
||||||
String enumName = (enumSpecifier.getName() == null )
|
|
||||||
? "" //$NON-NLS-1$
|
|
||||||
: enumSpecifier.getName().toString();
|
|
||||||
Enumeration element = new Enumeration (parent, enumName );
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
Iterator i = enumSpecifier.getEnumerators();
|
|
||||||
while (i.hasNext()){
|
|
||||||
// create sub element
|
|
||||||
IASTEnumerator enumDef = (IASTEnumerator) i.next();
|
|
||||||
createEnumerator(element, enumDef);
|
|
||||||
}
|
|
||||||
// set enumeration position
|
|
||||||
element.setIdPos(enumSpecifier.getNameOffset(),
|
|
||||||
(enumName.length() == 0) ? type.length() : (enumSpecifier.getNameEndOffset() - enumSpecifier.getNameOffset() ));
|
|
||||||
element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getEndingOffset() - enumSpecifier.getStartingOffset());
|
|
||||||
element.setLines( enumSpecifier.getStartingLine(), enumSpecifier.getEndingLine() );
|
|
||||||
element.setTypeName(type);
|
|
||||||
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Enumerator createEnumerator(Parent enumarator, IASTEnumerator enumDef) throws CModelException{
|
|
||||||
Enumerator element = new Enumerator (enumarator, enumDef.getName().toString());
|
|
||||||
IASTExpression initialValue = enumDef.getInitialValue();
|
|
||||||
if(initialValue != null){
|
|
||||||
element.setConstantExpression( ASTUtil.getExpressionString( initialValue ) );
|
|
||||||
}
|
|
||||||
// add to parent
|
|
||||||
enumarator.addChild(element);
|
|
||||||
// set enumerator position
|
|
||||||
element.setIdPos(enumDef.getStartingOffset(), (enumDef.getNameEndOffset() - enumDef.getNameOffset()));
|
|
||||||
element.setPos(enumDef.getStartingOffset(), enumDef.getEndingOffset() - enumDef.getStartingOffset());
|
|
||||||
element.setLines( enumDef.getStartingLine(), enumDef.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Structure createClass(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate) throws CModelException{
|
|
||||||
// create element
|
|
||||||
String className = ""; //$NON-NLS-1$
|
|
||||||
String type = ""; //$NON-NLS-1$
|
|
||||||
int kind = ICElement.C_CLASS;
|
|
||||||
ASTClassKind classkind = classSpecifier.getClassKind();
|
|
||||||
if(classkind == ASTClassKind.CLASS){
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_CLASS : ICElement.C_CLASS;
|
|
||||||
type = "class"; //$NON-NLS-1$
|
|
||||||
} else if(classkind == ASTClassKind.STRUCT){
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_STRUCT : ICElement.C_STRUCT;
|
|
||||||
type = "struct"; //$NON-NLS-1$
|
|
||||||
} else if(classkind == ASTClassKind.UNION){
|
|
||||||
kind = (isTemplate) ? ICElement.C_TEMPLATE_UNION : ICElement.C_UNION;
|
|
||||||
type = "union"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
className = (classSpecifier.getName() == null ) ? "" : classSpecifier.getName().toString(); //$NON-NLS-1$
|
|
||||||
|
|
||||||
Structure element;
|
|
||||||
if(!isTemplate){
|
|
||||||
Structure classElement = new Structure( parent, kind, className );
|
|
||||||
element = classElement;
|
|
||||||
} else {
|
|
||||||
StructureTemplate classTemplate = new StructureTemplate( parent, kind, className );
|
|
||||||
element = classTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
// store super classes names
|
|
||||||
Iterator baseClauses = classSpecifier.getBaseClauses();
|
|
||||||
while (baseClauses.hasNext()){
|
|
||||||
IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next();
|
|
||||||
element.addSuperClass(baseSpec.getParentClassName(), baseSpec.getAccess());
|
|
||||||
}
|
|
||||||
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
// set element position
|
|
||||||
element.setIdPos( classSpecifier.getNameOffset(),
|
|
||||||
(className.length() == 0) ? type.length() : (classSpecifier.getNameEndOffset() - classSpecifier.getNameOffset() ));
|
|
||||||
element.setTypeName( type );
|
|
||||||
if(!isTemplate){
|
|
||||||
// set the element position
|
|
||||||
element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getEndingOffset() - classSpecifier.getStartingOffset());
|
|
||||||
}
|
|
||||||
element.setLines( classSpecifier.getStartingLine(), classSpecifier.getEndingLine() );
|
|
||||||
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef createTypeDef(Parent parent, IASTTypedefDeclaration typeDefDeclaration) throws CModelException{
|
|
||||||
// create the element
|
|
||||||
String name = typeDefDeclaration.getName();
|
|
||||||
|
|
||||||
TypeDef element = new TypeDef( parent, name );
|
|
||||||
|
|
||||||
StringBuffer typeName = new StringBuffer(ASTUtil.getType(typeDefDeclaration.getAbstractDeclarator()));
|
|
||||||
element.setTypeName(typeName.toString());
|
|
||||||
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
|
|
||||||
// set positions
|
|
||||||
element.setIdPos(typeDefDeclaration.getNameOffset(), (typeDefDeclaration.getNameEndOffset() - typeDefDeclaration.getNameOffset()));
|
|
||||||
element.setPos(typeDefDeclaration.getStartingOffset(), typeDefDeclaration.getEndingOffset() - typeDefDeclaration.getStartingOffset());
|
|
||||||
element.setLines( typeDefDeclaration.getStartingLine(), typeDefDeclaration.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws CModelException, ASTNotImplementedException
|
|
||||||
{
|
|
||||||
String variableName = varDeclaration.getName();
|
|
||||||
if((variableName == null) || (variableName.length() <= 0)){
|
|
||||||
// something is wrong, skip this element
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
IASTAbstractDeclaration abstractDeclaration = varDeclaration.getAbstractDeclaration();
|
|
||||||
createAbstractElement (parent, abstractDeclaration , isTemplate, false);
|
|
||||||
|
|
||||||
VariableDeclaration element = null;
|
|
||||||
if(varDeclaration instanceof IASTField){
|
|
||||||
IASTField fieldDeclaration = (IASTField) varDeclaration;
|
|
||||||
// field
|
|
||||||
Field newElement = new Field( parent, variableName);
|
|
||||||
newElement.setMutable(fieldDeclaration.isMutable());
|
|
||||||
newElement.setVisibility(fieldDeclaration.getVisiblity());
|
|
||||||
element = newElement;
|
|
||||||
} else {
|
|
||||||
if (isTemplate) {
|
|
||||||
// variable
|
|
||||||
VariableTemplate newElement = new VariableTemplate( parent, variableName );
|
|
||||||
element = newElement;
|
|
||||||
} else {
|
|
||||||
if(varDeclaration.isExtern()){
|
|
||||||
// variableDeclaration
|
|
||||||
VariableDeclaration newElement = new VariableDeclaration( parent, variableName );
|
|
||||||
element = newElement;
|
|
||||||
} else {
|
|
||||||
// variable
|
|
||||||
Variable newElement = new Variable( parent, variableName );
|
|
||||||
element = newElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
element.setTypeName ( ASTUtil.getType(varDeclaration.getAbstractDeclaration()) );
|
|
||||||
element.setConst(varDeclaration.getAbstractDeclaration().isConst());
|
|
||||||
element.setVolatile(varDeclaration.getAbstractDeclaration().isVolatile());
|
|
||||||
element.setStatic(varDeclaration.isStatic());
|
|
||||||
// add to parent
|
|
||||||
parent.addChild( element );
|
|
||||||
|
|
||||||
// set position
|
|
||||||
element.setIdPos( varDeclaration.getNameOffset(), (varDeclaration.getNameEndOffset() - varDeclaration.getNameOffset()) );
|
|
||||||
if(!isTemplate){
|
|
||||||
// set element position
|
|
||||||
element.setPos(varDeclaration.getStartingOffset(), varDeclaration.getEndingOffset() - varDeclaration.getStartingOffset());
|
|
||||||
}
|
|
||||||
element.setLines( varDeclaration.getStartingLine(), varDeclaration.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FunctionDeclaration createFunctionSpecification(Parent parent, IASTFunction functionDeclaration, boolean isTemplate) throws CModelException
|
|
||||||
{
|
|
||||||
String name = functionDeclaration.getName();
|
|
||||||
if ((name == null) || (name.length() <= 0)) {
|
|
||||||
// Something is wrong, skip this element
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get parameters types
|
|
||||||
String[] parameterTypes = ASTUtil.getFunctionParameterTypes(functionDeclaration);
|
|
||||||
|
|
||||||
FunctionDeclaration element = null;
|
|
||||||
|
|
||||||
if( functionDeclaration instanceof IASTMethod && parent instanceof IStructure)
|
|
||||||
{
|
|
||||||
IASTMethod methodDeclaration = (IASTMethod) functionDeclaration;
|
|
||||||
MethodDeclaration methodElement = null;
|
|
||||||
if (methodDeclaration.hasFunctionBody())
|
|
||||||
{
|
|
||||||
// method
|
|
||||||
if(!isTemplate){
|
|
||||||
Method newElement = new Method( parent, name );
|
|
||||||
methodElement = newElement;
|
|
||||||
}else {
|
|
||||||
MethodTemplate newElement = new MethodTemplate(parent, name);
|
|
||||||
methodElement = newElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// method declaration
|
|
||||||
if(!isTemplate){
|
|
||||||
MethodDeclaration newElement = new MethodDeclaration( parent, name );
|
|
||||||
methodElement = newElement;
|
|
||||||
}else {
|
|
||||||
MethodTemplateDeclaration newElement = new MethodTemplateDeclaration(parent, name);
|
|
||||||
methodElement = newElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
methodElement.setParameterTypes(parameterTypes);
|
|
||||||
methodElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
|
|
||||||
methodElement.setStatic(functionDeclaration.isStatic());
|
|
||||||
|
|
||||||
// Common settings for method declaration
|
|
||||||
methodElement.setVisibility(methodDeclaration.getVisiblity());
|
|
||||||
methodElement.setVolatile(methodDeclaration.isVolatile());
|
|
||||||
methodElement.setConst(methodDeclaration.isConst());
|
|
||||||
methodElement.setVirtual(methodDeclaration.isVirtual());
|
|
||||||
methodElement.setPureVirtual(methodDeclaration.isPureVirtual());
|
|
||||||
methodElement.setInline(methodDeclaration.isInline());
|
|
||||||
methodElement.setFriend(methodDeclaration.isFriend());
|
|
||||||
methodElement.setConstructor(methodDeclaration.isConstructor());
|
|
||||||
methodElement.setDestructor(methodDeclaration.isDestructor());
|
|
||||||
element = methodElement;
|
|
||||||
}
|
|
||||||
else // instance of IASTFunction
|
|
||||||
{
|
|
||||||
if (parent instanceof ITranslationUnit) {
|
|
||||||
String[] names = functionDeclaration.getFullyQualifiedName();
|
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
for (int i = 0; i < names.length; ++i) {
|
|
||||||
if (buf.length() != 0) {
|
|
||||||
buf.append("::"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
buf.append(names[i]);
|
|
||||||
}
|
|
||||||
name = buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
FunctionDeclaration functionElement = null;
|
|
||||||
if (functionDeclaration.hasFunctionBody())
|
|
||||||
{
|
|
||||||
// function
|
|
||||||
if(!isTemplate){
|
|
||||||
Function newElement = new Function( parent, name );
|
|
||||||
functionElement = newElement;
|
|
||||||
} else {
|
|
||||||
FunctionTemplate newElement = new FunctionTemplate( parent, name );
|
|
||||||
functionElement = newElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// functionDeclaration
|
|
||||||
if(!isTemplate){
|
|
||||||
FunctionDeclaration newElement = new FunctionDeclaration( parent, name );
|
|
||||||
functionElement = newElement;
|
|
||||||
} else {
|
|
||||||
FunctionTemplateDeclaration newElement = new FunctionTemplateDeclaration( parent, name );
|
|
||||||
functionElement = newElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
functionElement.setParameterTypes(parameterTypes);
|
|
||||||
functionElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
|
|
||||||
functionElement.setStatic(functionDeclaration.isStatic());
|
|
||||||
element = functionElement;
|
|
||||||
}
|
|
||||||
// add to parent
|
|
||||||
parent.addChild( element );
|
|
||||||
|
|
||||||
// hook up the offsets
|
|
||||||
element.setIdPos( functionDeclaration.getNameOffset(), (functionDeclaration.getNameEndOffset() - functionDeclaration.getNameOffset()) );
|
|
||||||
if(!isTemplate){
|
|
||||||
// set the element position
|
|
||||||
element.setPos(functionDeclaration.getStartingOffset(), functionDeclaration.getEndingOffset() - functionDeclaration.getStartingOffset());
|
|
||||||
}
|
|
||||||
element.setLines( functionDeclaration.getStartingLine(), functionDeclaration.getEndingLine() );
|
|
||||||
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Using createUsingDirective(Parent parent, IASTUsingDirective usingDirDeclaration) throws CModelException{
|
|
||||||
// create the element
|
|
||||||
String name = usingDirDeclaration.getNamespaceName();
|
|
||||||
|
|
||||||
Using element = new Using( parent, name, true );
|
|
||||||
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
|
|
||||||
// set positions
|
|
||||||
element.setIdPos(usingDirDeclaration.getNameOffset(), (usingDirDeclaration.getNameEndOffset() - usingDirDeclaration.getNameOffset()));
|
|
||||||
element.setPos(usingDirDeclaration.getStartingOffset(), usingDirDeclaration.getEndingOffset() - usingDirDeclaration.getStartingOffset());
|
|
||||||
element.setLines(usingDirDeclaration.getStartingLine(), usingDirDeclaration.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Using createUsingDeclaration(Parent parent, IASTUsingDeclaration usingDeclaration) throws CModelException{
|
|
||||||
// create the element
|
|
||||||
String name = usingDeclaration.usingTypeName();
|
|
||||||
|
|
||||||
Using element = new Using(parent, name, false);
|
|
||||||
|
|
||||||
// add to parent
|
|
||||||
parent.addChild(element);
|
|
||||||
|
|
||||||
// set positions
|
|
||||||
element.setIdPos(usingDeclaration.getNameOffset(), (usingDeclaration.getNameEndOffset() - usingDeclaration.getNameOffset()));
|
|
||||||
element.setPos(usingDeclaration.getStartingOffset(), usingDeclaration.getEndingOffset() - usingDeclaration.getStartingOffset());
|
|
||||||
element.setLines(usingDeclaration.getStartingLine(), usingDeclaration.getEndingLine() );
|
|
||||||
this.newElements.put(element, element.getElementInfo());
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the newElements.
|
|
||||||
*/
|
|
||||||
public Map getNewElements() {
|
|
||||||
return newElements;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,8 +16,6 @@ import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.DynamicFunctionStyleMacro;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.ExpressionEvaluator;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
|
import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,23 +35,6 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
||||||
emptyCharArray,
|
emptyCharArray,
|
||||||
new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$
|
new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$
|
||||||
|
|
||||||
private final DynamicFunctionStyleMacro __builtin_choose_expr =
|
|
||||||
new DynamicFunctionStyleMacro( "__builtin_choose_expr".toCharArray(), //$NON-NLS-1$
|
|
||||||
new char[][] { "const_exp".toCharArray(), "exp1".toCharArray(), "exp2".toCharArray() } ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
||||||
{
|
|
||||||
public char [] execute( CharArrayObjectMap argmap ){
|
|
||||||
ExpressionEvaluator evaluator = new ExpressionEvaluator();
|
|
||||||
char[] const_exp = (char[]) argmap.get( arglist[0] );
|
|
||||||
long exp = 0;
|
|
||||||
if( const_exp != null)
|
|
||||||
exp = evaluator.evaluate( const_exp, 0, const_exp.length, CharArrayObjectMap.EMPTY_MAP );
|
|
||||||
|
|
||||||
if( exp != 0 )
|
|
||||||
return (char[])argmap.get( arglist[1] );
|
|
||||||
return (char[])argmap.get( arglist[2] );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
|
||||||
|
@ -61,7 +42,6 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
||||||
public CharArrayObjectMap getAdditionalMacros() {
|
public CharArrayObjectMap getAdditionalMacros() {
|
||||||
CharArrayObjectMap result = super.getAdditionalMacros();
|
CharArrayObjectMap result = super.getAdditionalMacros();
|
||||||
result.put(_Pragma.name, _Pragma );
|
result.put(_Pragma.name, _Pragma );
|
||||||
result.put( __builtin_choose_expr.name, __builtin_choose_expr );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class DefaultProblemHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.IProblemHandler#ruleOnProblem(org.eclipse.cdt.core.parser.IProblem)
|
|
||||||
*/
|
|
||||||
public static boolean ruleOnProblem( IProblem p, ParserMode mode )
|
|
||||||
{
|
|
||||||
if( p == null ) return true;
|
|
||||||
if( p.checkCategory( IProblem.SCANNER_RELATED ) || p.checkCategory( IProblem.PREPROCESSOR_RELATED ))
|
|
||||||
{
|
|
||||||
switch( p.getID() )
|
|
||||||
{
|
|
||||||
case IProblem.PREPROCESSOR_INVALID_DIRECTIVE:
|
|
||||||
return false;
|
|
||||||
case IProblem.PREPROCESSOR_POUND_ERROR:
|
|
||||||
case IProblem.PREPROCESSOR_UNBALANCE_CONDITION:
|
|
||||||
case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN:
|
|
||||||
// case IProblem.PREPROCESSOR_MACRO_USAGE_ERROR:
|
|
||||||
case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR:
|
|
||||||
case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR:
|
|
||||||
case IProblem.SCANNER_UNEXPECTED_EOF:
|
|
||||||
case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN:
|
|
||||||
if( mode == ParserMode.COMPLETE_PARSE )
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IOffsetDuple
|
|
||||||
{
|
|
||||||
public int getCeilingOffset();
|
|
||||||
public int getFloorOffset();
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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:
|
|
||||||
* Rational Software - Initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the external interface that all C and C++ parsers in the CDT
|
|
||||||
* must implement.
|
|
||||||
*
|
|
||||||
* @author jcamelon
|
|
||||||
*/
|
|
||||||
public interface IParser {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request a parse from a pre-configured parser to parse a whole translation unit or file.
|
|
||||||
*
|
|
||||||
* @return whether or not the parse was successful
|
|
||||||
*/
|
|
||||||
public boolean parse();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param offset offset in the input file where code completion is being requested for
|
|
||||||
* @return an IASTCompletionConstruct that provides a mechanism for determining C/C++ code completion contributions
|
|
||||||
*/
|
|
||||||
public IASTCompletionNode parse( int offset) throws ParseError;
|
|
||||||
|
|
||||||
|
|
||||||
public static interface ISelectionParseResult
|
|
||||||
{
|
|
||||||
public IASTOffsetableNamedElement getOffsetableNamedElement();
|
|
||||||
public String getFilename();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param startingOffset
|
|
||||||
* @param endingOffset
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ISelectionParseResult parse( int startingOffset, int endingOffset ) throws ParseError;
|
|
||||||
|
|
||||||
public void cancel();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If an error was encountered, give us the offset of the token that caused the error.
|
|
||||||
*
|
|
||||||
* @return -1 for no error, otherwise the character offset where we encountered
|
|
||||||
* our first unrecoverable error.
|
|
||||||
*/
|
|
||||||
public int getLastErrorOffset();
|
|
||||||
|
|
||||||
public int getLastErrorLine();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IQuickParseCallback extends ISourceElementRequestor
|
|
||||||
{
|
|
||||||
public abstract Iterator getInclusions();
|
|
||||||
public abstract Iterator getMacros();
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract IASTCompilationUnit getCompilationUnit();
|
|
||||||
public abstract Iterator iterateOffsetableElements();
|
|
||||||
public boolean hasNoProblems();
|
|
||||||
}
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.core.parser;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||||
|
|
||||||
|
@ -30,12 +29,11 @@ import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||||
*/
|
*/
|
||||||
public interface IScanner extends IMacroCollector {
|
public interface IScanner extends IMacroCollector {
|
||||||
|
|
||||||
/** @deprecated */ public static final int tPOUNDPOUND = IToken.tPOUNDPOUND;
|
/**
|
||||||
/** @deprecated */ public static final int tPOUND = IToken.tPOUND;
|
* Puts the scanner into content assist mode.
|
||||||
|
*/
|
||||||
public void setOffsetBoundary( int offset );
|
|
||||||
public void setContentAssistMode( int offset );
|
public void setContentAssistMode( int offset );
|
||||||
public void setASTFactory( IASTFactory f );
|
|
||||||
/**
|
/**
|
||||||
* Turns on/off comment parsing.
|
* Turns on/off comment parsing.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
@ -50,7 +48,6 @@ public interface IScanner extends IMacroCollector {
|
||||||
public void setComputeImageLocations(boolean val);
|
public void setComputeImageLocations(boolean val);
|
||||||
|
|
||||||
public IMacro addDefinition(char[] key, char[] value);
|
public IMacro addDefinition(char[] key, char[] value);
|
||||||
public IMacro addDefinition(char[] name, char[][] params, char[] expansion);
|
|
||||||
public void addDefinition(IMacro macro);
|
public void addDefinition(IMacro macro);
|
||||||
|
|
||||||
public Map getDefinitions();
|
public Map getDefinitions();
|
||||||
|
@ -65,7 +62,6 @@ public interface IScanner extends IMacroCollector {
|
||||||
public boolean isOnTopContext();
|
public boolean isOnTopContext();
|
||||||
public CharArrayObjectMap getRealDefinitions();
|
public CharArrayObjectMap getRealDefinitions();
|
||||||
public void cancel();
|
public void cancel();
|
||||||
public char[] getMainFilename();
|
|
||||||
|
|
||||||
public ILocationResolver getLocationResolver();
|
public ILocationResolver getLocationResolver();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public void acceptElement( ISourceElementRequestor requestor );
|
|
||||||
public void enterScope( ISourceElementRequestor requestor );
|
|
||||||
public void exitScope( ISourceElementRequestor requestor );
|
|
||||||
}
|
|
|
@ -1,118 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface ISourceElementRequestor {
|
|
||||||
|
|
||||||
public boolean acceptProblem( IProblem problem );
|
|
||||||
|
|
||||||
public void acceptMacro( IASTMacro macro );
|
|
||||||
public void acceptVariable( IASTVariable variable );
|
|
||||||
public void acceptFunctionDeclaration( IASTFunction function );
|
|
||||||
public void acceptUsingDirective( IASTUsingDirective usageDirective );
|
|
||||||
public void acceptUsingDeclaration( IASTUsingDeclaration usageDeclaration );
|
|
||||||
public void acceptASMDefinition( IASTASMDefinition asmDefinition );
|
|
||||||
public void acceptTypedefDeclaration( IASTTypedefDeclaration typedef );
|
|
||||||
public void acceptEnumerationSpecifier( IASTEnumerationSpecifier enumeration );
|
|
||||||
public void acceptElaboratedForewardDeclaration( IASTElaboratedTypeSpecifier elaboratedType );
|
|
||||||
public void acceptAbstractTypeSpecDeclaration( IASTAbstractTypeSpecifierDeclaration abstractDeclaration );
|
|
||||||
|
|
||||||
public void enterFunctionBody( IASTFunction function );
|
|
||||||
public void exitFunctionBody( IASTFunction function );
|
|
||||||
|
|
||||||
public void enterCodeBlock( IASTCodeScope scope );
|
|
||||||
public void exitCodeBlock( IASTCodeScope scope );
|
|
||||||
|
|
||||||
public void enterCompilationUnit( IASTCompilationUnit compilationUnit );
|
|
||||||
public void enterInclusion( IASTInclusion inclusion );
|
|
||||||
public void enterNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition );
|
|
||||||
public void enterClassSpecifier( IASTClassSpecifier classSpecification );
|
|
||||||
public void enterLinkageSpecification( IASTLinkageSpecification linkageSpec );
|
|
||||||
|
|
||||||
public void enterTemplateDeclaration( IASTTemplateDeclaration declaration );
|
|
||||||
public void enterTemplateSpecialization( IASTTemplateSpecialization specialization );
|
|
||||||
public void enterTemplateInstantiation( IASTTemplateInstantiation instantiation );
|
|
||||||
|
|
||||||
public void acceptMethodDeclaration( IASTMethod method );
|
|
||||||
public void enterMethodBody( IASTMethod method );
|
|
||||||
public void exitMethodBody( IASTMethod method );
|
|
||||||
public void acceptField( IASTField field );
|
|
||||||
|
|
||||||
public void acceptClassReference( IASTClassReference reference );
|
|
||||||
public void acceptTypedefReference( IASTTypedefReference reference );
|
|
||||||
public void acceptNamespaceReference( IASTNamespaceReference reference );
|
|
||||||
public void acceptEnumerationReference( IASTEnumerationReference reference );
|
|
||||||
public void acceptVariableReference( IASTVariableReference reference );
|
|
||||||
public void acceptFunctionReference( IASTFunctionReference reference );
|
|
||||||
public void acceptFieldReference( IASTFieldReference reference );
|
|
||||||
public void acceptMethodReference( IASTMethodReference reference );
|
|
||||||
public void acceptEnumeratorReference( IASTEnumeratorReference reference );
|
|
||||||
public void acceptParameterReference(IASTParameterReference reference);
|
|
||||||
public void acceptTemplateParameterReference( IASTTemplateParameterReference reference );
|
|
||||||
public void acceptFriendDeclaration( IASTDeclaration declaration );
|
|
||||||
|
|
||||||
public void exitTemplateDeclaration( IASTTemplateDeclaration declaration );
|
|
||||||
public void exitTemplateSpecialization( IASTTemplateSpecialization specialization );
|
|
||||||
public void exitTemplateExplicitInstantiation( IASTTemplateInstantiation instantiation );
|
|
||||||
|
|
||||||
public void exitLinkageSpecification( IASTLinkageSpecification linkageSpec );
|
|
||||||
public void exitClassSpecifier( IASTClassSpecifier classSpecification );
|
|
||||||
public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition );
|
|
||||||
public void exitInclusion( IASTInclusion inclusion );
|
|
||||||
public void exitCompilationUnit( IASTCompilationUnit compilationUnit );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param finalPath
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public CodeReader createReader(String finalPath, Iterator workingCopies );
|
|
||||||
|
|
||||||
}
|
|
|
@ -32,34 +32,6 @@ public interface IToken {
|
||||||
public void setType(int i);
|
public void setType(int i);
|
||||||
|
|
||||||
public boolean isOperator();
|
public boolean isOperator();
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated semantics is unclear, depends on the parser.
|
|
||||||
* will be removed in 5.0
|
|
||||||
*/
|
|
||||||
public boolean isPointer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated semantics is unclear, depends on the parser.
|
|
||||||
* will be removed in 5.0
|
|
||||||
*/
|
|
||||||
public boolean canBeAPrefix();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated semantics is unclear, depends on the parser.
|
|
||||||
* will be removed in 5.0
|
|
||||||
*/
|
|
||||||
public boolean looksLikeExpression();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated will be removed in 5.0
|
|
||||||
*/
|
|
||||||
public int getLineNumber();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated will be removed in 5.0
|
|
||||||
*/
|
|
||||||
public char [] getFilename();
|
|
||||||
|
|
||||||
// Token types
|
// Token types
|
||||||
int FIRST_RESERVED_PREPROCESSOR= -200;
|
int FIRST_RESERVED_PREPROCESSOR= -200;
|
||||||
|
@ -240,8 +212,6 @@ public interface IToken {
|
||||||
static public final int tCOMMENT = 142;
|
static public final int tCOMMENT = 142;
|
||||||
/** @deprecated don't use it */
|
/** @deprecated don't use it */
|
||||||
static public final int tBLOCKCOMMENT = 143;
|
static public final int tBLOCKCOMMENT = 143;
|
||||||
/** @deprecated don't use it */
|
|
||||||
static public final int tLAST = 143;
|
|
||||||
static public final int tEND_OF_INPUT= 144;
|
static public final int tEND_OF_INPUT= 144;
|
||||||
|
|
||||||
int FIRST_RESERVED_IGCCToken = 150;
|
int FIRST_RESERVED_IGCCToken = 150;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2005 IBM Corporation and others.
|
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -36,37 +36,14 @@ public interface ITokenDuple {
|
||||||
public abstract Iterator iterator();
|
public abstract Iterator iterator();
|
||||||
public abstract String toString();
|
public abstract String toString();
|
||||||
public char [] toCharArray();
|
public char [] toCharArray();
|
||||||
|
|
||||||
public char [] getFilename();
|
|
||||||
|
|
||||||
public abstract boolean isIdentifier();
|
|
||||||
public abstract int length();
|
public abstract int length();
|
||||||
|
|
||||||
public abstract ITokenDuple getSubrange( int startIndex, int endIndex );
|
|
||||||
public IToken getToken(int index);
|
public IToken getToken(int index);
|
||||||
public ITokenDuple[] getSegments();
|
public ITokenDuple[] getSegments();
|
||||||
|
|
||||||
public int findLastTokenType( int type );
|
|
||||||
|
|
||||||
public int getStartOffset();
|
public int getStartOffset();
|
||||||
public int getEndOffset();
|
public int getEndOffset();
|
||||||
public int getLineNumber();
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract boolean syntaxOfName();
|
|
||||||
|
|
||||||
public char[] extractNameFromTemplateId();
|
public char[] extractNameFromTemplateId();
|
||||||
/**
|
|
||||||
* @param duple
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean contains(ITokenDuple duple);
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract String [] toQualifiedName();
|
|
||||||
|
|
||||||
public void freeReferences( );
|
|
||||||
public void acceptElement( ISourceElementRequestor requestor );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,491 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2003, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
|
||||||
|
|
||||||
|
|
||||||
public class NullSourceElementRequestor implements ISourceElementRequestor
|
|
||||||
{
|
|
||||||
private ParserMode mode = ParserMode.COMPLETE_PARSE;
|
|
||||||
|
|
||||||
public NullSourceElementRequestor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public NullSourceElementRequestor( ParserMode mode )
|
|
||||||
{
|
|
||||||
this.mode = mode;
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
|
|
||||||
*/
|
|
||||||
public boolean acceptProblem(IProblem problem)
|
|
||||||
{
|
|
||||||
return DefaultProblemHandler.ruleOnProblem( problem, mode );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
|
|
||||||
*/
|
|
||||||
public void acceptMacro(IASTMacro macro)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
|
|
||||||
*/
|
|
||||||
public void acceptVariable(IASTVariable variable)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
|
|
||||||
*/
|
|
||||||
public void acceptFunctionDeclaration(IASTFunction function)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective)
|
|
||||||
*/
|
|
||||||
public void acceptUsingDirective(IASTUsingDirective usageDirective)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration)
|
|
||||||
*/
|
|
||||||
public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition)
|
|
||||||
*/
|
|
||||||
public void acceptASMDefinition(IASTASMDefinition asmDefinition)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef)
|
|
||||||
*/
|
|
||||||
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
|
|
||||||
*/
|
|
||||||
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
|
|
||||||
*/
|
|
||||||
public void enterFunctionBody(IASTFunction function)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
|
|
||||||
*/
|
|
||||||
public void exitFunctionBody(IASTFunction function)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
|
|
||||||
*/
|
|
||||||
public void enterCompilationUnit(IASTCompilationUnit compilationUnit)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
|
|
||||||
*/
|
|
||||||
public void enterInclusion(IASTInclusion inclusion)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
|
|
||||||
*/
|
|
||||||
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
|
|
||||||
*/
|
|
||||||
public void enterClassSpecifier(IASTClassSpecifier classSpecification)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
|
|
||||||
*/
|
|
||||||
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
|
|
||||||
*/
|
|
||||||
public void enterTemplateDeclaration(IASTTemplateDeclaration declaration)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
|
|
||||||
*/
|
|
||||||
public void enterTemplateSpecialization(IASTTemplateSpecialization specialization)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
|
|
||||||
*/
|
|
||||||
public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
|
|
||||||
*/
|
|
||||||
public void acceptMethodDeclaration(IASTMethod method)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
|
|
||||||
*/
|
|
||||||
public void enterMethodBody(IASTMethod method)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
|
|
||||||
*/
|
|
||||||
public void exitMethodBody(IASTMethod method)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
|
|
||||||
*/
|
|
||||||
public void acceptField(IASTField field)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference)
|
|
||||||
*/
|
|
||||||
public void acceptClassReference(IASTClassReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
|
|
||||||
*/
|
|
||||||
public void exitTemplateDeclaration(IASTTemplateDeclaration declaration)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
|
|
||||||
*/
|
|
||||||
public void exitTemplateSpecialization(IASTTemplateSpecialization specialization)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
|
|
||||||
*/
|
|
||||||
public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
|
|
||||||
*/
|
|
||||||
public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
|
|
||||||
*/
|
|
||||||
public void exitClassSpecifier(IASTClassSpecifier classSpecification)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
|
|
||||||
*/
|
|
||||||
public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
|
|
||||||
*/
|
|
||||||
public void exitInclusion(IASTInclusion inclusion)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
|
|
||||||
*/
|
|
||||||
public void exitCompilationUnit(IASTCompilationUnit compilationUnit)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration)
|
|
||||||
*/
|
|
||||||
public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference)
|
|
||||||
*/
|
|
||||||
public void acceptTypedefReference(IASTTypedefReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference)
|
|
||||||
*/
|
|
||||||
public void acceptNamespaceReference(IASTNamespaceReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference)
|
|
||||||
*/
|
|
||||||
public void acceptEnumerationReference(IASTEnumerationReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference)
|
|
||||||
*/
|
|
||||||
public void acceptVariableReference(IASTVariableReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference)
|
|
||||||
*/
|
|
||||||
public void acceptFunctionReference(IASTFunctionReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference)
|
|
||||||
*/
|
|
||||||
public void acceptFieldReference(IASTFieldReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference)
|
|
||||||
*/
|
|
||||||
public void acceptMethodReference(IASTMethodReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
|
|
||||||
*/
|
|
||||||
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope)
|
|
||||||
*/
|
|
||||||
public void enterCodeBlock(IASTCodeScope scope) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope)
|
|
||||||
*/
|
|
||||||
public void exitCodeBlock(IASTCodeScope scope) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumeratorReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference)
|
|
||||||
*/
|
|
||||||
public void acceptEnumeratorReference(IASTEnumeratorReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference)
|
|
||||||
*/
|
|
||||||
public void acceptParameterReference(IASTParameterReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
|
||||||
*/
|
|
||||||
public CodeReader createReader(String finalPath, Iterator workingCopies) {
|
|
||||||
return InternalParserUtil.createFileReader( finalPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTemplateParameterReference(org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference)
|
|
||||||
*/
|
|
||||||
public void acceptTemplateParameterReference(IASTTemplateParameterReference reference)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFriendDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration)
|
|
||||||
*/
|
|
||||||
public void acceptFriendDeclaration(IASTDeclaration declaration) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,11 +6,11 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The exception is thrown, when content-assist is requested within a context that is handled
|
* The exception is thrown, when content-assist is requested within a context that is handled
|
||||||
|
@ -34,13 +34,18 @@ public class OffsetLimitReachedException extends EndOfFileException {
|
||||||
public static final int ORIGIN_INACTIVE_CODE = 3;
|
public static final int ORIGIN_INACTIVE_CODE = 3;
|
||||||
public static final int ORIGIN_MACRO_EXPANSION = 4;
|
public static final int ORIGIN_MACRO_EXPANSION = 4;
|
||||||
|
|
||||||
private final IASTCompletionNode node;
|
private final String prefix;
|
||||||
private final IToken finalToken;
|
private final IToken finalToken;
|
||||||
private final int fOrigin;
|
private final int fOrigin;
|
||||||
|
|
||||||
public OffsetLimitReachedException( IASTCompletionNode node )
|
/**
|
||||||
|
* mstodo- scanner removal
|
||||||
|
* @deprecated
|
||||||
|
* @param prefix
|
||||||
|
*/
|
||||||
|
public OffsetLimitReachedException( String prefix )
|
||||||
{
|
{
|
||||||
this.node = node;
|
this.prefix= prefix;
|
||||||
finalToken = null;
|
finalToken = null;
|
||||||
fOrigin= ORIGIN_UNKNOWN;
|
fOrigin= ORIGIN_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -48,14 +53,14 @@ public class OffsetLimitReachedException extends EndOfFileException {
|
||||||
public OffsetLimitReachedException( IToken token )
|
public OffsetLimitReachedException( IToken token )
|
||||||
{
|
{
|
||||||
fOrigin= ORIGIN_UNKNOWN;
|
fOrigin= ORIGIN_UNKNOWN;
|
||||||
|
prefix= token.getImage();
|
||||||
finalToken = token;
|
finalToken = token;
|
||||||
node = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OffsetLimitReachedException(int origin, IToken lastToken) {
|
public OffsetLimitReachedException(int origin, IToken lastToken) {
|
||||||
fOrigin= origin;
|
fOrigin= origin;
|
||||||
|
prefix= lastToken.getImage();
|
||||||
finalToken= lastToken;
|
finalToken= lastToken;
|
||||||
node= null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,10 +78,11 @@ public class OffsetLimitReachedException extends EndOfFileException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* mstodo- scanner removal
|
||||||
* @return returns the IASTCompletionNode
|
* @return returns the IASTCompletionNode
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public IASTCompletionNode getCompletionNode()
|
public String getPrefix() {
|
||||||
{
|
return prefix;
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,24 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCOldScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPOldScannerExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,81 +20,7 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ParserFactory {
|
public class ParserFactory {
|
||||||
|
|
||||||
private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC );
|
|
||||||
|
|
||||||
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
|
|
||||||
{
|
|
||||||
if( mode == ParserMode.QUICK_PARSE )
|
|
||||||
return new QuickParseASTFactory(extensionFactory.createASTExtension( mode ));
|
|
||||||
return new CompleteParseASTFactory( language, mode, extensionFactory.createASTExtension( mode ));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param scanner tokenizer to retrieve C/C++ tokens
|
|
||||||
* @param callback the callback that reports results to the client
|
|
||||||
* @param mode the parser mode you wish to use
|
|
||||||
* @param language C or C++
|
|
||||||
* @param log a log utility to output errors
|
|
||||||
* @return
|
|
||||||
* @throws ParserFactoryError - erroneous input provided
|
|
||||||
*/
|
|
||||||
public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
if( scanner == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_SCANNER );
|
|
||||||
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
|
|
||||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
|
||||||
ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
|
|
||||||
IParserExtension extension = extensionFactory.createParserExtension();
|
|
||||||
return new Parser( scanner, ourMode, ourCallback, language, logService, extension );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param input the java.io.Reader that reads the source-code input you want parsed
|
|
||||||
* @param fileName the absolute path of the file you are parsing (necessary for determining location of local inclusions)
|
|
||||||
* @param config represents the include-paths and preprocessor definitions you wish to initialize the scanner with
|
|
||||||
* @param mode the parser mode you wish to use
|
|
||||||
* @param language C or C++
|
|
||||||
* @param requestor the callback that reports results to the client
|
|
||||||
* @param log a log utility to output errors
|
|
||||||
* @param workingCopies a java.util.List of IWorkingCopy buffers if you wish for include files to use CDT Working Copies rather than saved files
|
|
||||||
* @return
|
|
||||||
* @throws ParserFactoryError - erroneous input provided
|
|
||||||
*/
|
|
||||||
public static IScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError
|
|
||||||
{
|
|
||||||
if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG );
|
|
||||||
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
|
|
||||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
|
||||||
IScannerExtensionConfiguration configuration = null;
|
|
||||||
if( language == ParserLanguage.C )
|
|
||||||
configuration = new GCCOldScannerExtensionConfiguration();
|
|
||||||
else
|
|
||||||
configuration = new GPPOldScannerExtensionConfiguration();
|
|
||||||
|
|
||||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException
|
|
||||||
{
|
|
||||||
return createScanner(new CodeReader(fileName), config, mode, language, requestor, log, workingCopies);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IQuickParseCallback createQuickParseCallback()
|
|
||||||
{
|
|
||||||
return new QuickParseCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IQuickParseCallback createStructuralParseCallback()
|
|
||||||
{
|
|
||||||
return new StructuralParseCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IParserLogService createDefaultLogService()
|
public static IParserLogService createDefaultLogService()
|
||||||
{
|
{
|
||||||
return defaultLogService;
|
return defaultLogService;
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2007 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ParserFactoryError extends Error {
|
|
||||||
|
|
||||||
private static final long serialVersionUID= -2692315766161768983L;
|
|
||||||
|
|
||||||
public static class Kind extends Enum {
|
|
||||||
|
|
||||||
public static final Kind NULL_READER = new Kind( 1 );
|
|
||||||
public static final Kind NULL_FILENAME = new Kind( 2 );
|
|
||||||
public static final Kind NULL_CONFIG = new Kind( 3 );
|
|
||||||
public static final Kind NULL_LANGUAGE = new Kind( 4 );
|
|
||||||
public static final Kind NULL_SCANNER = new Kind( 5 );
|
|
||||||
public static final Kind BAD_DIALECT = new Kind( 6 );
|
|
||||||
|
|
||||||
protected Kind( int arg )
|
|
||||||
{
|
|
||||||
super( arg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParserFactoryError( Kind e )
|
|
||||||
{
|
|
||||||
kind = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Kind getKind()
|
|
||||||
{
|
|
||||||
return kind;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Kind kind;
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTClassKind extends Enum {
|
|
||||||
|
|
||||||
public final static ASTClassKind CLASS = new ASTClassKind( 1 );
|
|
||||||
public final static ASTClassKind STRUCT = new ASTClassKind( 2 );
|
|
||||||
public final static ASTClassKind UNION = new ASTClassKind( 3 );
|
|
||||||
public final static ASTClassKind ENUM = new ASTClassKind( 4 );
|
|
||||||
|
|
||||||
private ASTClassKind( int value )
|
|
||||||
{
|
|
||||||
super( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTExpressionEvaluationException extends Exception
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTNotImplementedException extends Exception
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTPointerOperator extends Enum
|
|
||||||
{
|
|
||||||
public static final ASTPointerOperator REFERENCE = new ASTPointerOperator( 0 );
|
|
||||||
public static final ASTPointerOperator POINTER = new ASTPointerOperator( 1 );
|
|
||||||
public static final ASTPointerOperator CONST_POINTER = new ASTPointerOperator( 2 );
|
|
||||||
public static final ASTPointerOperator VOLATILE_POINTER = new ASTPointerOperator( 3 );
|
|
||||||
public static final ASTPointerOperator RESTRICT_POINTER = new ASTPointerOperator( 4 );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param enumValue
|
|
||||||
*/
|
|
||||||
protected ASTPointerOperator(int enumValue)
|
|
||||||
{
|
|
||||||
super(enumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStarOperator()
|
|
||||||
{
|
|
||||||
return ( ( this == VOLATILE_POINTER ) || ( this == CONST_POINTER ) || ( this == RESTRICT_POINTER ) || ( this == POINTER ));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReferenceOperator()
|
|
||||||
{
|
|
||||||
return ( this == REFERENCE );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ASTSemanticException extends Exception
|
|
||||||
{
|
|
||||||
private final IProblem theProblem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ASTSemanticException( IProblem reason )
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
theProblem = reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param e
|
|
||||||
*/
|
|
||||||
public ASTSemanticException(ASTSemanticException e) {
|
|
||||||
theProblem = e.getProblem();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IProblem getProblem()
|
|
||||||
{
|
|
||||||
return theProblem;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,700 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2001, 2006 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:
|
|
||||||
* Rational Software - initial implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a utility class to help convert AST elements to Strings.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ASTUtil {
|
|
||||||
public static String[] getTemplateParameters(IASTTemplateDeclaration templateDeclaration){
|
|
||||||
// add the parameters
|
|
||||||
Iterator i = templateDeclaration.getTemplateParameters();
|
|
||||||
return getTemplateParameters(i);
|
|
||||||
}
|
|
||||||
public static String[] getTemplateParameters(Iterator templateParams){
|
|
||||||
List paramList = new ArrayList();
|
|
||||||
while (templateParams.hasNext()){
|
|
||||||
StringBuffer paramType = new StringBuffer();
|
|
||||||
IASTTemplateParameter parameter = (IASTTemplateParameter)templateParams.next();
|
|
||||||
IASTTemplateParameter.ParamKind kind = parameter.getTemplateParameterKind();
|
|
||||||
if(kind == IASTTemplateParameter.ParamKind.CLASS){
|
|
||||||
if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0))
|
|
||||||
{
|
|
||||||
paramType.append(parameter.getIdentifier().toString());
|
|
||||||
}else {
|
|
||||||
paramType.append("class"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(kind == IASTTemplateParameter.ParamKind.TYPENAME){
|
|
||||||
if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0))
|
|
||||||
{
|
|
||||||
paramType.append(parameter.getIdentifier().toString());
|
|
||||||
}else {
|
|
||||||
paramType.append("typename"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(kind == IASTTemplateParameter.ParamKind.TEMPLATE_LIST){
|
|
||||||
paramType.append("template<"); //$NON-NLS-1$
|
|
||||||
String[] subParams = getTemplateParameters(parameter.getTemplateParameters());
|
|
||||||
int p = 0;
|
|
||||||
if ( subParams.length > 0)
|
|
||||||
paramType.append(subParams[p++]);
|
|
||||||
while( p < subParams.length){
|
|
||||||
paramType.append(", "); //$NON-NLS-1$
|
|
||||||
paramType.append(subParams[p++]);
|
|
||||||
}
|
|
||||||
paramType.append(">"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
if(kind == IASTTemplateParameter.ParamKind.PARAMETER){
|
|
||||||
paramType.append(getType(parameter.getParameterDeclaration()));
|
|
||||||
}
|
|
||||||
paramList.add(paramType.toString());
|
|
||||||
}// end while
|
|
||||||
String[] parameterTypes = new String[paramList.size()];
|
|
||||||
for(int j=0; j<paramList.size(); ++j){
|
|
||||||
parameterTypes[j] = (String) paramList.get(j);
|
|
||||||
}
|
|
||||||
return parameterTypes;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getType(IASTAbstractDeclaration declaration)
|
|
||||||
{
|
|
||||||
StringBuffer type = new StringBuffer();
|
|
||||||
|
|
||||||
// get type from declaration
|
|
||||||
type.append(getDeclarationType(declaration));
|
|
||||||
type.append(getPointerOperation(declaration));
|
|
||||||
type.append(getArrayQualifiers(declaration));
|
|
||||||
|
|
||||||
type.append(getPointerToFunctionType(declaration));
|
|
||||||
if (declaration instanceof IASTParameterDeclaration)
|
|
||||||
type.append(getInitializerClause((IASTParameterDeclaration)declaration));
|
|
||||||
return type.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getInitializerClause(IASTParameterDeclaration declaration){
|
|
||||||
StringBuffer initializer = new StringBuffer();
|
|
||||||
if(declaration != null){
|
|
||||||
IASTInitializerClause clause = declaration.getDefaultValue();
|
|
||||||
if(clause != null){
|
|
||||||
IASTExpression expression = clause.getAssigmentExpression();
|
|
||||||
if(expression != null){
|
|
||||||
String init = getExpressionString( expression );
|
|
||||||
if(init.length() > 0){
|
|
||||||
initializer.append("="); //$NON-NLS-1$
|
|
||||||
initializer.append(init);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return initializer.toString();
|
|
||||||
}
|
|
||||||
public static String getPointerToFunctionType(IASTAbstractDeclaration declaration){
|
|
||||||
StringBuffer type = new StringBuffer();
|
|
||||||
ASTPointerOperator po = declaration.getPointerToFunctionOperator();
|
|
||||||
if(po != null){
|
|
||||||
type.append("("); //$NON-NLS-1$
|
|
||||||
type.append(getPointerOperator(po));
|
|
||||||
type.append(")"); //$NON-NLS-1$
|
|
||||||
String[] parameters =getParameterTypes(declaration.getParameters(), false /* replace with takeVarArgs() later*/);
|
|
||||||
type.append(getParametersString(parameters));
|
|
||||||
}
|
|
||||||
return type.toString();
|
|
||||||
}
|
|
||||||
public static String getDeclarationType(IASTAbstractDeclaration declaration){
|
|
||||||
StringBuffer type = new StringBuffer();
|
|
||||||
|
|
||||||
if(declaration.isConst())
|
|
||||||
type.append("const "); //$NON-NLS-1$
|
|
||||||
if(declaration.isVolatile())
|
|
||||||
type.append("volatile "); //$NON-NLS-1$
|
|
||||||
IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier();
|
|
||||||
if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){
|
|
||||||
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier;
|
|
||||||
type.append(getElaboratedTypeSignature(elab));
|
|
||||||
}else if(typeSpecifier instanceof IASTSimpleTypeSpecifier){
|
|
||||||
IASTSimpleTypeSpecifier simpleSpecifier = (IASTSimpleTypeSpecifier) typeSpecifier;
|
|
||||||
type.append(simpleSpecifier.getTypename());
|
|
||||||
}else if(typeSpecifier instanceof IASTClassSpecifier){
|
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpecifier;
|
|
||||||
type.append(classSpecifier.getName());
|
|
||||||
}else if(typeSpecifier instanceof IASTEnumerationSpecifier){
|
|
||||||
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpecifier;
|
|
||||||
type.append(enumSpecifier.getName());
|
|
||||||
}
|
|
||||||
return type.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getElaboratedTypeSignature(IASTElaboratedTypeSpecifier elab){
|
|
||||||
StringBuffer type = new StringBuffer();
|
|
||||||
ASTClassKind t = elab.getClassKind();
|
|
||||||
if( t == ASTClassKind.CLASS){
|
|
||||||
type.append("class"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
else if( t == ASTClassKind.STRUCT){
|
|
||||||
type.append("struct"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
else if( t == ASTClassKind.UNION){
|
|
||||||
type.append("union"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
else if( t == ASTClassKind.STRUCT){
|
|
||||||
type.append("enum"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
type.append(" "); //$NON-NLS-1$
|
|
||||||
type.append(elab.getName().toString());
|
|
||||||
return type.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPointerOperation(IASTAbstractDeclaration declaration){
|
|
||||||
StringBuffer pointerString = new StringBuffer();
|
|
||||||
Iterator i = declaration.getPointerOperators();
|
|
||||||
while(i.hasNext()){
|
|
||||||
ASTPointerOperator po = (ASTPointerOperator) i.next();
|
|
||||||
pointerString.append(getPointerOperator(po));
|
|
||||||
}
|
|
||||||
return pointerString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPointerOperator(ASTPointerOperator po){
|
|
||||||
String pointerString =""; //$NON-NLS-1$
|
|
||||||
if(po == ASTPointerOperator.POINTER)
|
|
||||||
pointerString = ("*"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.REFERENCE)
|
|
||||||
pointerString =("&"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.CONST_POINTER)
|
|
||||||
pointerString =("* const"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.VOLATILE_POINTER)
|
|
||||||
pointerString =("* volatile"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.RESTRICT_POINTER)
|
|
||||||
pointerString =("* restrict"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
return pointerString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getArrayQualifiers(IASTAbstractDeclaration declaration){
|
|
||||||
StringBuffer arrayString = new StringBuffer();
|
|
||||||
Iterator i = declaration.getArrayModifiers();
|
|
||||||
while (i.hasNext()){
|
|
||||||
i.next();
|
|
||||||
arrayString.append("[]"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return arrayString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
|
|
||||||
{
|
|
||||||
Iterator parameters = functionDeclaration.getParameters();
|
|
||||||
return getParameterTypes(parameters, functionDeclaration.takesVarArgs());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getParameterTypes(Iterator parameters, boolean takesVarArgs){
|
|
||||||
List paramList = new ArrayList();
|
|
||||||
while (parameters.hasNext()){
|
|
||||||
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
|
|
||||||
paramList.add(getType(param));
|
|
||||||
}
|
|
||||||
int paramListSize = paramList.size();
|
|
||||||
if(takesVarArgs)
|
|
||||||
paramListSize++;
|
|
||||||
String[] parameterTypes = new String[paramListSize];
|
|
||||||
for(int i=0; i<paramList.size(); ++i){
|
|
||||||
parameterTypes[i] = (String)paramList.get(i);
|
|
||||||
}
|
|
||||||
// add the ellipse to the parameter type list
|
|
||||||
if(takesVarArgs)
|
|
||||||
parameterTypes[paramListSize-1] = "..."; //$NON-NLS-1$
|
|
||||||
return parameterTypes;
|
|
||||||
}
|
|
||||||
public static String getParametersString(String[] parameterTypes)
|
|
||||||
{
|
|
||||||
StringBuffer parameters = new StringBuffer(""); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if ((parameterTypes != null) && (parameterTypes.length > 0)) {
|
|
||||||
parameters.append("("); //$NON-NLS-1$
|
|
||||||
int i = 0;
|
|
||||||
parameters.append(parameterTypes[i++]);
|
|
||||||
while (i < parameterTypes.length) {
|
|
||||||
parameters.append(", "); //$NON-NLS-1$
|
|
||||||
parameters.append(parameterTypes[i++]);
|
|
||||||
}
|
|
||||||
parameters.append(")"); //$NON-NLS-1$
|
|
||||||
} else {
|
|
||||||
if (parameterTypes != null) parameters.append("()"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
return parameters.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTypeId( IASTTypeId id ){
|
|
||||||
StringBuffer type = new StringBuffer();
|
|
||||||
|
|
||||||
if( id.isTypename() ){
|
|
||||||
type.append( Keywords.TYPENAME );
|
|
||||||
type.append( ' ' );
|
|
||||||
}
|
|
||||||
type.append( id.getFullSignature() );
|
|
||||||
|
|
||||||
// Iterator i = id.getPointerOperators();
|
|
||||||
// while(i.hasNext()){
|
|
||||||
// ASTPointerOperator po = (ASTPointerOperator) i.next();
|
|
||||||
// type.append(getPointerOperator(po));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// i = id.getArrayModifiers();
|
|
||||||
// while (i.hasNext()){
|
|
||||||
// i.next();
|
|
||||||
// type.append("[]"); //$NON-NLS-1$
|
|
||||||
// }
|
|
||||||
|
|
||||||
return type.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
|
||||||
/**
|
|
||||||
* Return a string for the given expression. Expressions having an extension kind should
|
|
||||||
* provide their own toString method which will be called by this.
|
|
||||||
* @param expression
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getExpressionString( IASTExpression expression ){
|
|
||||||
|
|
||||||
if( expression.getExpressionKind().isExtensionKind() )
|
|
||||||
return expression.toString();
|
|
||||||
|
|
||||||
String literal = expression.getLiteralString();
|
|
||||||
String idExpression = expression.getIdExpression();
|
|
||||||
|
|
||||||
IASTExpression lhs = expression.getLHSExpression();
|
|
||||||
IASTExpression rhs = expression.getRHSExpression();
|
|
||||||
IASTExpression third = expression.getThirdExpression();
|
|
||||||
IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor();
|
|
||||||
IASTTypeId typeId = expression.getTypeId();
|
|
||||||
|
|
||||||
if( literal != null && !literal.equals( EMPTY_STRING ) && ( idExpression == null || idExpression.equals( EMPTY_STRING ) ) )
|
|
||||||
return getLiteralExpression( expression );
|
|
||||||
|
|
||||||
if( idExpression != null && !idExpression.equals( EMPTY_STRING ) && lhs == null )
|
|
||||||
return getIdExpression( expression );
|
|
||||||
|
|
||||||
if( third != null )
|
|
||||||
return getConditionalExpression( expression );
|
|
||||||
|
|
||||||
if( descriptor != null )
|
|
||||||
return getNewExpression( expression );
|
|
||||||
|
|
||||||
if( lhs != null && rhs != null )
|
|
||||||
return getBinaryExpression( expression );
|
|
||||||
|
|
||||||
if( lhs != null && typeId != null )
|
|
||||||
return getUnaryTypeIdExpression( expression );
|
|
||||||
|
|
||||||
if( lhs != null && ( idExpression != null && !idExpression.equals( EMPTY_STRING ) ) )
|
|
||||||
return getUnaryIdExpression( expression );
|
|
||||||
|
|
||||||
if( lhs != null )
|
|
||||||
return getUnaryExpression( expression );
|
|
||||||
|
|
||||||
if( typeId != null )
|
|
||||||
return getTypeIdExpression( expression );
|
|
||||||
|
|
||||||
return getEmptyExpression( expression );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getEmptyExpression( IASTExpression expression ){
|
|
||||||
if( expression.getExpressionKind() == Kind.PRIMARY_THIS )
|
|
||||||
return Keywords.THIS;
|
|
||||||
|
|
||||||
return EMPTY_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getLiteralExpression( IASTExpression expression ){
|
|
||||||
Kind kind = expression.getExpressionKind();
|
|
||||||
|
|
||||||
if( kind != Kind.PRIMARY_CHAR_LITERAL && kind != Kind.PRIMARY_STRING_LITERAL )
|
|
||||||
return expression.getLiteralString();
|
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
boolean quoted = false;
|
|
||||||
String literalString = expression.getLiteralString();
|
|
||||||
if( kind == Kind.PRIMARY_CHAR_LITERAL ){
|
|
||||||
quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) &&
|
|
||||||
literalString.charAt(0) == '\'' );
|
|
||||||
if( !quoted )
|
|
||||||
buffer.append( '\'' );
|
|
||||||
buffer.append( literalString );
|
|
||||||
if( !quoted )
|
|
||||||
buffer.append( '\'' );
|
|
||||||
} else if( kind == Kind.PRIMARY_STRING_LITERAL ) {
|
|
||||||
quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) &&
|
|
||||||
literalString.charAt(0) == '\"' );
|
|
||||||
if( !quoted )
|
|
||||||
buffer.append( '"' );
|
|
||||||
buffer.append( expression.getLiteralString() );
|
|
||||||
if( !quoted )
|
|
||||||
buffer.append( '"' );
|
|
||||||
}
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getIdExpression( IASTExpression expression ){
|
|
||||||
return expression.getIdExpression();
|
|
||||||
}
|
|
||||||
private static String getConditionalExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
buffer.append( " ? " ); //$NON-NLS-1$
|
|
||||||
buffer.append( getExpressionString( expression.getRHSExpression() ) );
|
|
||||||
buffer.append( " : " ); //$NON-NLS-1$
|
|
||||||
buffer.append( getExpressionString( expression.getThirdExpression() ) );
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
private static String getNewExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append( Keywords.NEW );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
|
|
||||||
IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor();
|
|
||||||
Iterator iter = descriptor.getNewPlacementExpressions();
|
|
||||||
if( iter.hasNext() ){
|
|
||||||
buffer.append( '(' );
|
|
||||||
buffer.append( getExpressionString( (IASTExpression) iter.next() ) );
|
|
||||||
buffer.append( ") " ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
iter = descriptor.getNewTypeIdExpressions();
|
|
||||||
if( iter.hasNext() ){
|
|
||||||
buffer.append( getExpressionString( (IASTExpression) iter.next() ) );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( expression.getTypeId() != null ){
|
|
||||||
buffer.append( getTypeId( expression.getTypeId() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
iter = descriptor.getNewInitializerExpressions();
|
|
||||||
if( iter.hasNext() ){
|
|
||||||
buffer.append( '(' );
|
|
||||||
buffer.append( getExpressionString( (IASTExpression) iter.next() ) );
|
|
||||||
buffer.append( ')' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
private static String getBinaryExpression( IASTExpression expression ){
|
|
||||||
Kind kind = expression.getExpressionKind();
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
|
|
||||||
boolean appendSpace = false;
|
|
||||||
if( kind != Kind.EXPRESSIONLIST &&
|
|
||||||
kind != Kind.PM_DOTSTAR &&
|
|
||||||
kind != Kind.PM_ARROWSTAR &&
|
|
||||||
kind != Kind.POSTFIX_SUBSCRIPT &&
|
|
||||||
kind != Kind.POSTFIX_FUNCTIONCALL &&
|
|
||||||
kind != Kind.POSTFIX_DOT_TEMPL_IDEXPRESS &&
|
|
||||||
kind != Kind.POSTFIX_DOT_IDEXPRESSION &&
|
|
||||||
kind != Kind.POSTFIX_DOT_DESTRUCTOR &&
|
|
||||||
kind != Kind.POSTFIX_ARROW_TEMPL_IDEXP &&
|
|
||||||
kind != Kind.POSTFIX_ARROW_IDEXPRESSION &&
|
|
||||||
kind != Kind.POSTFIX_ARROW_DESTRUCTOR)
|
|
||||||
{
|
|
||||||
appendSpace = true;
|
|
||||||
buffer.append( ' ' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( kind == Kind.ANDEXPRESSION ||
|
|
||||||
kind == Kind.EXPRESSIONLIST ||
|
|
||||||
kind == Kind.EXCLUSIVEOREXPRESSION ||
|
|
||||||
kind == Kind.PM_DOTSTAR ||
|
|
||||||
kind == Kind.PM_ARROWSTAR ||
|
|
||||||
kind == Kind.LOGICALANDEXPRESSION ||
|
|
||||||
kind == Kind.LOGICALOREXPRESSION ||
|
|
||||||
kind == Kind.RELATIONAL_GREATERTHAN ||
|
|
||||||
kind == Kind.RELATIONAL_LESSTHAN ||
|
|
||||||
kind == Kind.RELATIONAL_LESSTHANEQUALTO ||
|
|
||||||
kind == Kind.RELATIONAL_GREATERTHANEQUALTO ||
|
|
||||||
kind == Kind.EQUALITY_EQUALS ||
|
|
||||||
kind == Kind.EQUALITY_NOTEQUALS ||
|
|
||||||
kind == Kind.ADDITIVE_PLUS ||
|
|
||||||
kind == Kind.ADDITIVE_MINUS ||
|
|
||||||
kind == Kind.INCLUSIVEOREXPRESSION ||
|
|
||||||
kind == Kind.MULTIPLICATIVE_MULTIPLY ||
|
|
||||||
kind == Kind.MULTIPLICATIVE_DIVIDE ||
|
|
||||||
kind == Kind.MULTIPLICATIVE_MODULUS ||
|
|
||||||
kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS ||
|
|
||||||
kind == Kind.POSTFIX_DOT_IDEXPRESSION ||
|
|
||||||
kind == Kind.POSTFIX_DOT_DESTRUCTOR ||
|
|
||||||
kind == Kind.POSTFIX_ARROW_TEMPL_IDEXP ||
|
|
||||||
kind == Kind.POSTFIX_ARROW_IDEXPRESSION ||
|
|
||||||
kind == Kind.POSTFIX_ARROW_DESTRUCTOR ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_NORMAL ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_MULT ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_DIV ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_MOD ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_PLUS ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_MINUS ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_RSHIFT ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_LSHIFT ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_AND ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_XOR ||
|
|
||||||
kind == Kind.ASSIGNMENTEXPRESSION_OR ||
|
|
||||||
kind == Kind.SHIFT_LEFT ||
|
|
||||||
kind == Kind.SHIFT_RIGHT)
|
|
||||||
{
|
|
||||||
buffer.append( ASTUtil.getStringForKind( kind ) );
|
|
||||||
} else if( kind == Kind.POSTFIX_SUBSCRIPT )
|
|
||||||
buffer.append( '[' );
|
|
||||||
else if( kind == Kind.POSTFIX_FUNCTIONCALL )
|
|
||||||
buffer.append( '(' );
|
|
||||||
|
|
||||||
if( kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS ||
|
|
||||||
kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP)
|
|
||||||
{
|
|
||||||
buffer.append( ' ' );
|
|
||||||
buffer.append( Keywords.TEMPLATE );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( appendSpace || kind == Kind.EXPRESSIONLIST )
|
|
||||||
buffer.append( ' ' );
|
|
||||||
|
|
||||||
buffer.append( getExpressionString( expression.getRHSExpression() ) );
|
|
||||||
|
|
||||||
if( kind == Kind.POSTFIX_SUBSCRIPT )
|
|
||||||
buffer.append( ']' );
|
|
||||||
else if( kind == Kind.POSTFIX_FUNCTIONCALL )
|
|
||||||
buffer.append( ')' );
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getUnaryTypeIdExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
Kind kind = expression.getExpressionKind();
|
|
||||||
if( kind == Kind.CASTEXPRESSION ){
|
|
||||||
buffer.append( '(' );
|
|
||||||
buffer.append( getTypeId( expression.getTypeId() ) );
|
|
||||||
buffer.append( ')' );
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
|
|
||||||
} else if ( kind == Kind.POSTFIX_DYNAMIC_CAST ||
|
|
||||||
kind == Kind.POSTFIX_STATIC_CAST ||
|
|
||||||
kind == Kind.POSTFIX_REINTERPRET_CAST ||
|
|
||||||
kind == Kind.POSTFIX_CONST_CAST )
|
|
||||||
{
|
|
||||||
buffer.append( ASTUtil.getStringForKind( kind ) );
|
|
||||||
buffer.append( '<' );
|
|
||||||
buffer.append( getTypeId( expression.getTypeId() ) );
|
|
||||||
buffer.append( ">(" ); //$NON-NLS-1$
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
buffer.append( ')' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getUnaryIdExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append( Keywords.TYPENAME );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
if( expression.getExpressionKind() == Kind.POSTFIX_TYPENAME_TEMPLATEID ){
|
|
||||||
buffer.append( Keywords.TEMPLATE );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
}
|
|
||||||
buffer.append( expression.getIdExpression() );
|
|
||||||
buffer.append( '(' );
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
buffer.append( ')' );
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
private static String getUnaryExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
Kind kind = expression.getExpressionKind();
|
|
||||||
|
|
||||||
boolean bracketsAroundExpression = ( kind == Kind.PRIMARY_BRACKETED_EXPRESSION );
|
|
||||||
|
|
||||||
if ( kind == Kind.UNARY_SIZEOF_UNARYEXPRESSION ){
|
|
||||||
buffer.append( Keywords.SIZEOF );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
}
|
|
||||||
else if ( kind == Kind.UNARY_STAR_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_AMPSND_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_PLUS_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_MINUS_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_NOT_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_TILDE_CASTEXPRESSION ||
|
|
||||||
kind == Kind.UNARY_DECREMENT ||
|
|
||||||
kind == Kind.THROWEXPRESSION
|
|
||||||
)
|
|
||||||
{
|
|
||||||
buffer.append( ASTUtil.getStringForKind( kind ) );
|
|
||||||
}
|
|
||||||
else if ( kind == Kind.UNARY_INCREMENT )
|
|
||||||
buffer.append( "++" ); //$NON-NLS-1$
|
|
||||||
else if( kind == Kind.DELETE_VECTORCASTEXPRESSION || kind == Kind.DELETE_CASTEXPRESSION ){
|
|
||||||
buffer.append( Keywords.DELETE );
|
|
||||||
buffer.append(' ');
|
|
||||||
if( kind == Kind.DELETE_VECTORCASTEXPRESSION )
|
|
||||||
buffer.append( "[ ] " ); //$NON-NLS-1$
|
|
||||||
} else if( kind == Kind.POSTFIX_SIMPLETYPE_CHAR ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_WCHART ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_BOOL ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_SHORT ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_INT ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_LONG ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_SIGNED ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_UNSIGNED ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_FLOAT ||
|
|
||||||
kind == Kind.POSTFIX_SIMPLETYPE_DOUBLE
|
|
||||||
)
|
|
||||||
{
|
|
||||||
buffer.append( ASTUtil.getStringForKind( kind ) );
|
|
||||||
bracketsAroundExpression = true;
|
|
||||||
} else if( kind == Kind.POSTFIX_TYPEID_EXPRESSION )
|
|
||||||
{
|
|
||||||
buffer.append( Keywords.TYPEID );
|
|
||||||
bracketsAroundExpression = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( bracketsAroundExpression )
|
|
||||||
buffer.append( '(' );
|
|
||||||
|
|
||||||
buffer.append( getExpressionString( expression.getLHSExpression() ) );
|
|
||||||
|
|
||||||
if( bracketsAroundExpression )
|
|
||||||
buffer.append( ')' );
|
|
||||||
|
|
||||||
if( kind == Kind.POSTFIX_INCREMENT ||
|
|
||||||
kind == Kind.POSTFIX_DECREMENT )
|
|
||||||
{
|
|
||||||
buffer.append( ASTUtil.getStringForKind( kind ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
private static String getTypeIdExpression( IASTExpression expression ){
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
Kind kind = expression.getExpressionKind();
|
|
||||||
|
|
||||||
boolean addBrackets = false;
|
|
||||||
if( kind == Kind.UNARY_SIZEOF_TYPEID ){
|
|
||||||
buffer.append( Keywords.SIZEOF );
|
|
||||||
buffer.append( ' ' );
|
|
||||||
addBrackets = true;
|
|
||||||
} else if( kind == Kind.POSTFIX_TYPEID_TYPEID ){
|
|
||||||
buffer.append( Keywords.TYPEID );
|
|
||||||
addBrackets = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( addBrackets )
|
|
||||||
buffer.append( '(' );
|
|
||||||
buffer.append( ASTUtil.getTypeId( expression.getTypeId() ) );
|
|
||||||
if( addBrackets )
|
|
||||||
buffer.append( ')' );
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Map expressionKindStringMap = new HashMap();
|
|
||||||
static {
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DYNAMIC_CAST, Keywords.DYNAMIC_CAST );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_STATIC_CAST, Keywords.STATIC_CAST );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_REINTERPRET_CAST, Keywords.REINTERPRET_CAST );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_CONST_CAST, Keywords.CONST_CAST );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR, Keywords.CHAR );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART, Keywords.WCHAR_T );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL, Keywords.BOOL );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT, Keywords.SHORT );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT, Keywords.INT );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG, Keywords.LONG );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED, Keywords.SIGNED );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED, Keywords.UNSIGNED );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT, Keywords.FLOAT );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE, Keywords.DOUBLE );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.THROWEXPRESSION, Keywords.THROW );
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ANDEXPRESSION, "&" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, "&" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.EXPRESSIONLIST, "," ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.EXCLUSIVEOREXPRESSION, "^" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.PM_DOTSTAR, ".*" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.PM_ARROWSTAR, "->*" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.LOGICALANDEXPRESSION, "&&" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.LOGICALOREXPRESSION, "||" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHAN, ">" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHAN, "<" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO, "<=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO, ">=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_EQUALS, "==" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_NOTEQUALS, "!=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, "*" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY, "*" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, "+" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_PLUS, "+" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, "-" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_MINUS, "-" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, "!" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, "~" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_DECREMENT, "--" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DECREMENT, "--" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.UNARY_INCREMENT, "++" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_INCREMENT, "++" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.INCLUSIVEOREXPRESSION, "|" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_DIVIDE, "/" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MODULUS, "%" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS, "." ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION, "." ); //$NON-NLS-1$ |
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR, "." ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP, "->" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR, "->" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION, "->" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL, "=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT, "*=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV, "/=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD, "%=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS, "+=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS, "-=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT, ">>=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT, "<<=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND, "&=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR, "^=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR, "|=" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.SHIFT_LEFT, "<<" ); //$NON-NLS-1$
|
|
||||||
expressionKindStringMap.put( IASTExpression.Kind.SHIFT_RIGHT, ">>" ); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
private static String getStringForKind( IASTExpression.Kind kind ){
|
|
||||||
return (String) expressionKindStringMap.get( kind );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTASMDefinition extends IASTOffsetableElement, IASTDeclaration {
|
|
||||||
|
|
||||||
public String getBody();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTAbstractDeclaration extends IASTTypeSpecifierOwner, ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public boolean isConst();
|
|
||||||
public boolean isVolatile();
|
|
||||||
public Iterator getPointerOperators();
|
|
||||||
public Iterator getArrayModifiers();
|
|
||||||
public Iterator getParameters();
|
|
||||||
public ASTPointerOperator getPointerToFunctionOperator();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTAbstractTypeSpecifierDeclaration
|
|
||||||
extends IASTDeclaration, IASTTypeSpecifierOwner, IASTTemplatedDeclaration, IASTOffsetableNamedElement
|
|
||||||
{
|
|
||||||
public boolean isFriendDeclaration();
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTArrayModifier extends ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public IASTExpression getExpression();
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTBaseSpecifier extends ISourceElementCallbackDelegate {
|
|
||||||
|
|
||||||
public ASTAccessVisibility getAccess();
|
|
||||||
public boolean isVirtual();
|
|
||||||
public String getParentClassName();
|
|
||||||
public IASTTypeSpecifier getParentClassSpecifier() throws ASTNotImplementedException;
|
|
||||||
public int getNameOffset();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTClassReference extends IASTReference
|
|
||||||
{
|
|
||||||
public boolean isResolved();
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTClassSpecifier extends IASTScope, IASTOffsetableNamedElement, IASTScopedTypeSpecifier, ISourceElementCallbackDelegate {
|
|
||||||
|
|
||||||
public class ClassNameType extends Enum {
|
|
||||||
|
|
||||||
public static final ClassNameType IDENTIFIER = new ClassNameType( 1 );
|
|
||||||
public static final ClassNameType TEMPLATE = new ClassNameType( 2 );
|
|
||||||
|
|
||||||
private ClassNameType( int t )
|
|
||||||
{
|
|
||||||
super( t );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassNameType getClassNameType();
|
|
||||||
|
|
||||||
public ASTClassKind getClassKind();
|
|
||||||
|
|
||||||
public Iterator getBaseClauses();
|
|
||||||
|
|
||||||
public Iterator getFriends();
|
|
||||||
|
|
||||||
public ASTAccessVisibility getCurrentVisibilityMode();
|
|
||||||
public void setCurrentVisibility( ASTAccessVisibility visibility );
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2003, 2006 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 Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
/*
|
|
||||||
* Created on Sep 2, 2003
|
|
||||||
*
|
|
||||||
* To change the template for this generated file go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
|
||||||
public interface IASTCodeScope extends IASTScope, ISourceElementCallbackDelegate{
|
|
||||||
|
|
||||||
public IASTCodeScope getOwnerCodeScope();
|
|
||||||
public IASTFunction getContainingFunction();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTCompilationUnit extends IASTScope, ISourceElementCallbackDelegate {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2006 IBM Corporation and others.
|
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -10,20 +10,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
package org.eclipse.cdt.core.parser.ast;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
import org.eclipse.cdt.core.parser.Enum;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface IASTCompletionNode {
|
public interface IASTCompletionNode {
|
||||||
|
|
||||||
public static class CompletionKind extends Enum
|
public static class CompletionKind extends Enum {
|
||||||
{
|
|
||||||
// x.[ ] x->[ ]
|
|
||||||
public static final CompletionKind MEMBER_REFERENCE = new CompletionKind( 0 );
|
|
||||||
|
|
||||||
// class member declaration type reference
|
// class member declaration type reference
|
||||||
public static final CompletionKind FIELD_TYPE = new CompletionKind( 2 );
|
public static final CompletionKind FIELD_TYPE = new CompletionKind( 2 );
|
||||||
|
@ -92,42 +88,9 @@ public interface IASTCompletionNode {
|
||||||
* @return kind of completion expected
|
* @return kind of completion expected
|
||||||
*/
|
*/
|
||||||
public CompletionKind getCompletionKind();
|
public CompletionKind getCompletionKind();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the scope the code completion is within
|
|
||||||
* should never be null
|
|
||||||
*/
|
|
||||||
public IASTScope getCompletionScope();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the context (inter-statement)
|
|
||||||
* e.g. LHS of postfix expression a->b, a.b or qualified name a::b is 'a'
|
|
||||||
* this can be null
|
|
||||||
*/
|
|
||||||
public IASTNode getCompletionContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the name of the function/constructor being completed in
|
|
||||||
* CONSTRUCTOR_REFERENCE
|
|
||||||
* FUNCTION_REFERENCE
|
|
||||||
*/
|
|
||||||
public String getFunctionName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return the IASTExpression representing the number of parameters
|
|
||||||
* input in the CONSTRUCTOR_REFERENCE/FUNCTION_REFERENCE context.
|
|
||||||
*/
|
|
||||||
public IASTExpression getFunctionParameters();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the prefix
|
* @return the prefix
|
||||||
*/
|
*/
|
||||||
public String getCompletionPrefix();
|
public String getCompletionPrefix();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return iterator of string keywords
|
|
||||||
*/
|
|
||||||
public Iterator getKeywords();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTConstructorMemberInitializer extends ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public IASTExpression getExpressionList();
|
|
||||||
public String getName();
|
|
||||||
public char[] getNameCharArray();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTDeclaration extends IASTScopedElement, ISourceElementCallbackDelegate {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTDesignator extends ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public static class DesignatorKind extends Enum
|
|
||||||
{
|
|
||||||
public static final DesignatorKind FIELD = new DesignatorKind( 0 );
|
|
||||||
public static final DesignatorKind SUBSCRIPT = new DesignatorKind( 1 );
|
|
||||||
protected static final int LAST_KIND = 1;
|
|
||||||
/**
|
|
||||||
* @param enumValue
|
|
||||||
*/
|
|
||||||
protected DesignatorKind(int enumValue)
|
|
||||||
{
|
|
||||||
super(enumValue);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DesignatorKind getKind();
|
|
||||||
public IASTExpression arraySubscriptExpression();
|
|
||||||
public String fieldName();
|
|
||||||
public int fieldOffset();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTElaboratedTypeSpecifier extends IASTTypeSpecifier, IASTQualifiedNameElement, ISourceElementCallbackDelegate, IASTOffsetableNamedElement {
|
|
||||||
|
|
||||||
public String getName();
|
|
||||||
public ASTClassKind getClassKind();
|
|
||||||
public boolean isResolved() throws ASTNotImplementedException;
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTEnumerationReference extends IASTReference
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTEnumerationSpecifier extends ISourceElementCallbackDelegate, IASTScopedTypeSpecifier, IASTOffsetableNamedElement {
|
|
||||||
|
|
||||||
public Iterator getEnumerators();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param referenceManager
|
|
||||||
*/
|
|
||||||
public void freeReferences();
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTEnumerator extends IASTOffsetableNamedElement, IASTNode, ISourceElementCallbackDelegate {
|
|
||||||
|
|
||||||
public IASTEnumerationSpecifier getOwnerEnumerationSpecifier();
|
|
||||||
public IASTExpression getInitialValue();
|
|
||||||
/**
|
|
||||||
* @param referenceManager
|
|
||||||
*/
|
|
||||||
public void freeReferences();
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTEnumeratorReference extends IASTReference
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTExceptionSpecification
|
|
||||||
{
|
|
||||||
public Iterator getTypeIds();
|
|
||||||
}
|
|
|
@ -1,339 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.Enum;
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTExpression extends ISourceElementCallbackDelegate, IASTNode, IASTOffsetableElement
|
|
||||||
{
|
|
||||||
public class Kind extends Enum
|
|
||||||
{
|
|
||||||
public static final Kind PRIMARY_EMPTY = new Kind( -1 );
|
|
||||||
public static final Kind PRIMARY_INTEGER_LITERAL = new Kind( 0 );
|
|
||||||
public static final Kind PRIMARY_CHAR_LITERAL = new Kind( 1 );
|
|
||||||
public static final Kind PRIMARY_FLOAT_LITERAL = new Kind( 2 );
|
|
||||||
public static final Kind PRIMARY_STRING_LITERAL = new Kind( 3 );
|
|
||||||
public static final Kind PRIMARY_BOOLEAN_LITERAL = new Kind( 4 );
|
|
||||||
public static final Kind PRIMARY_THIS = new Kind( 5 );
|
|
||||||
public static final Kind PRIMARY_BRACKETED_EXPRESSION = new Kind( 6 );
|
|
||||||
public static final Kind ID_EXPRESSION = new Kind( 7 );
|
|
||||||
public static final Kind POSTFIX_SUBSCRIPT = new Kind( 8 );
|
|
||||||
public static final Kind POSTFIX_FUNCTIONCALL = new Kind( 9 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_INT = new Kind( 10 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_SHORT = new Kind( 11 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_DOUBLE = new Kind( 12 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_FLOAT = new Kind( 13 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_CHAR = new Kind( 14 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_WCHART = new Kind( 15 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_SIGNED = new Kind( 16 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_UNSIGNED = new Kind( 17 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_BOOL = new Kind( 18 );
|
|
||||||
public static final Kind POSTFIX_SIMPLETYPE_LONG = new Kind( 19 );
|
|
||||||
public static final Kind POSTFIX_TYPENAME_IDENTIFIER = new Kind( 20 );
|
|
||||||
public static final Kind POSTFIX_TYPENAME_TEMPLATEID = new Kind( 21 );
|
|
||||||
public static final Kind POSTFIX_DOT_IDEXPRESSION = new Kind( 22 );
|
|
||||||
public static final Kind POSTFIX_ARROW_IDEXPRESSION = new Kind( 23 );
|
|
||||||
public static final Kind POSTFIX_DOT_TEMPL_IDEXPRESS = new Kind( 24 );
|
|
||||||
public static final Kind POSTFIX_ARROW_TEMPL_IDEXP = new Kind( 25 );
|
|
||||||
public static final Kind POSTFIX_DOT_DESTRUCTOR = new Kind( 26 );
|
|
||||||
public static final Kind POSTFIX_ARROW_DESTRUCTOR = new Kind( 27 );
|
|
||||||
public static final Kind POSTFIX_INCREMENT = new Kind( 28 );
|
|
||||||
public static final Kind POSTFIX_DECREMENT = new Kind( 29 );
|
|
||||||
public static final Kind POSTFIX_DYNAMIC_CAST = new Kind( 30 );
|
|
||||||
public static final Kind POSTFIX_REINTERPRET_CAST = new Kind( 31 );
|
|
||||||
public static final Kind POSTFIX_STATIC_CAST = new Kind( 32 );
|
|
||||||
public static final Kind POSTFIX_CONST_CAST = new Kind( 33 );
|
|
||||||
public static final Kind POSTFIX_TYPEID_EXPRESSION = new Kind( 34 );
|
|
||||||
public static final Kind POSTFIX_TYPEID_TYPEID = new Kind( 35 );
|
|
||||||
public static final Kind UNARY_INCREMENT = new Kind( 36 );
|
|
||||||
public static final Kind UNARY_DECREMENT = new Kind( 37 );
|
|
||||||
public static final Kind UNARY_STAR_CASTEXPRESSION = new Kind( 38 );
|
|
||||||
public static final Kind UNARY_AMPSND_CASTEXPRESSION = new Kind( 39 );
|
|
||||||
public static final Kind UNARY_PLUS_CASTEXPRESSION = new Kind( 40 );
|
|
||||||
public static final Kind UNARY_MINUS_CASTEXPRESSION = new Kind( 41 );
|
|
||||||
public static final Kind UNARY_NOT_CASTEXPRESSION = new Kind( 42 );
|
|
||||||
public static final Kind UNARY_TILDE_CASTEXPRESSION = new Kind( 43 );
|
|
||||||
public static final Kind UNARY_SIZEOF_UNARYEXPRESSION = new Kind( 44 );
|
|
||||||
public static final Kind UNARY_SIZEOF_TYPEID = new Kind( 45 );
|
|
||||||
public static final Kind NEW_NEWTYPEID = new Kind( 46 );
|
|
||||||
public static final Kind NEW_TYPEID = new Kind( 47 );
|
|
||||||
public static final Kind DELETE_CASTEXPRESSION = new Kind( 48 );
|
|
||||||
public static final Kind DELETE_VECTORCASTEXPRESSION = new Kind( 49 );
|
|
||||||
public static final Kind CASTEXPRESSION = new Kind( 50 );
|
|
||||||
public static final Kind PM_DOTSTAR = new Kind( 51 );
|
|
||||||
public static final Kind PM_ARROWSTAR = new Kind( 52 );
|
|
||||||
public static final Kind MULTIPLICATIVE_MULTIPLY = new Kind( 53 );
|
|
||||||
public static final Kind MULTIPLICATIVE_DIVIDE = new Kind( 54 );
|
|
||||||
public static final Kind MULTIPLICATIVE_MODULUS = new Kind( 55 );
|
|
||||||
public static final Kind ADDITIVE_PLUS = new Kind( 56 );
|
|
||||||
public static final Kind ADDITIVE_MINUS = new Kind( 57 );
|
|
||||||
public static final Kind SHIFT_LEFT = new Kind( 58 );
|
|
||||||
public static final Kind SHIFT_RIGHT = new Kind( 59 );
|
|
||||||
public static final Kind RELATIONAL_LESSTHAN = new Kind( 60 );
|
|
||||||
public static final Kind RELATIONAL_GREATERTHAN = new Kind( 61 );
|
|
||||||
public static final Kind RELATIONAL_LESSTHANEQUALTO = new Kind( 62 );
|
|
||||||
public static final Kind RELATIONAL_GREATERTHANEQUALTO= new Kind( 63 );
|
|
||||||
public static final Kind EQUALITY_EQUALS = new Kind( 64 );
|
|
||||||
public static final Kind EQUALITY_NOTEQUALS = new Kind( 65 );
|
|
||||||
public static final Kind ANDEXPRESSION = new Kind( 66 );
|
|
||||||
public static final Kind EXCLUSIVEOREXPRESSION = new Kind( 67 );
|
|
||||||
public static final Kind INCLUSIVEOREXPRESSION = new Kind( 68 );
|
|
||||||
public static final Kind LOGICALANDEXPRESSION = new Kind( 69 );
|
|
||||||
public static final Kind LOGICALOREXPRESSION = new Kind( 70 );
|
|
||||||
public static final Kind CONDITIONALEXPRESSION = new Kind( 71 );
|
|
||||||
public static final Kind THROWEXPRESSION = new Kind( 72 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_NORMAL = new Kind( 73 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_PLUS = new Kind( 74 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_MINUS = new Kind( 75 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_MULT = new Kind( 76 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_DIV = new Kind( 77 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_MOD = new Kind( 78 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_LSHIFT = new Kind( 79 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_RSHIFT = new Kind( 80 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_AND = new Kind( 81 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_OR = new Kind( 82 );
|
|
||||||
public static final Kind ASSIGNMENTEXPRESSION_XOR = new Kind( 83 );
|
|
||||||
public static final Kind EXPRESSIONLIST = new Kind( 84 );
|
|
||||||
|
|
||||||
protected static final int LAST_KIND = 84;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param enumValue
|
|
||||||
*/
|
|
||||||
protected Kind(int enumValue)
|
|
||||||
{
|
|
||||||
super(enumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExtensionKind(){
|
|
||||||
return getEnumValue() > LAST_KIND;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Hashtable names;
|
|
||||||
static
|
|
||||||
{
|
|
||||||
names = new Hashtable();
|
|
||||||
names.put( PRIMARY_EMPTY, "PRIMARY_EMPTY" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_INTEGER_LITERAL , "PRIMARY_INTEGER_LITERAL" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_CHAR_LITERAL , "PRIMARY_CHAR_LITERAL" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_FLOAT_LITERAL , "PRIMARY_FLOAT_LITERAL" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_STRING_LITERAL , "PRIMARY_STRING_LITERAL" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_BOOLEAN_LITERAL , "PRIMARY_BOOLEAN_LITERAL" ); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_THIS , "PRIMARY_THIS"); //$NON-NLS-1$
|
|
||||||
names.put( PRIMARY_BRACKETED_EXPRESSION , "PRIMARY_BRACKETED_EXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( ID_EXPRESSION , "ID_EXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SUBSCRIPT , "POSTFIX_SUBSCRIPT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_FUNCTIONCALL , "POSTFIX_FUNCTIONCALL"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_INT , "POSTFIX_SIMPLETYPE_INT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_SHORT , "POSTFIX_SIMPLETYPE_SHORT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_DOUBLE , "POSTFIX_SIMPLETYPE_DOUBLE"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_FLOAT , "POSTFIX_SIMPLETYPE_FLOAT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_CHAR , "POSTFIX_SIMPLETYPE_CHAR"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_WCHART , "POSTFIX_SIMPLETYPE_WCHART"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_SIGNED , "POSTFIX_SIMPLETYPE_SIGNED"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_UNSIGNED , "POSTFIX_SIMPLETYPE_UNSIGNED"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_BOOL , "POSTFIX_SIMPLETYPE_BOOL"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_SIMPLETYPE_LONG , "POSTFIX_SIMPLETYPE_LONG"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_TYPENAME_IDENTIFIER , "POSTFIX_TYPENAME_IDENTIFIER"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_TYPENAME_TEMPLATEID, "POSTFIX_TYPENAME_TEMPLATEID" ); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_DOT_IDEXPRESSION , "POSTFIX_DOT_IDEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_ARROW_IDEXPRESSION , "POSTFIX_ARROW_IDEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_DOT_TEMPL_IDEXPRESS , "POSTFIX_DOT_TEMPL_IDEXPRESS"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_ARROW_TEMPL_IDEXP , "POSTFIX_ARROW_TEMPL_IDEXP"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_DOT_DESTRUCTOR , "POSTFIX_DOT_DESTRUCTOR"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_ARROW_DESTRUCTOR , "POSTFIX_ARROW_DESTRUCTOR"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_INCREMENT , "POSTFIX_INCREMENT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_DECREMENT , "POSTFIX_DECREMENT"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_DYNAMIC_CAST , "POSTFIX_DYNAMIC_CAST"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_REINTERPRET_CAST , "POSTFIX_REINTERPRET_CAST"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_STATIC_CAST , "POSTFIX_STATIC_CAST"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_CONST_CAST , "POSTFIX_CONST_CAST"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_TYPEID_EXPRESSION , "POSTFIX_TYPEID_EXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( POSTFIX_TYPEID_TYPEID , "POSTFIX_TYPEID_TYPEID"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_INCREMENT , "UNARY_INCREMENT"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_DECREMENT , "UNARY_DECREMENT"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_STAR_CASTEXPRESSION , "UNARY_STAR_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_AMPSND_CASTEXPRESSION , "UNARY_AMPSND_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_PLUS_CASTEXPRESSION , "UNARY_PLUS_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_MINUS_CASTEXPRESSION , "UNARY_MINUS_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_NOT_CASTEXPRESSION , "UNARY_NOT_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_TILDE_CASTEXPRESSION , "UNARY_TILDE_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_SIZEOF_UNARYEXPRESSION , "UNARY_SIZEOF_UNARYEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( UNARY_SIZEOF_TYPEID , "UNARY_SIZEOF_TYPEID"); //$NON-NLS-1$
|
|
||||||
names.put( NEW_NEWTYPEID , "NEW_NEWTYPEID"); //$NON-NLS-1$
|
|
||||||
names.put( NEW_TYPEID , "NEW_TYPEID"); //$NON-NLS-1$
|
|
||||||
names.put( DELETE_CASTEXPRESSION , "DELETE_CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( DELETE_VECTORCASTEXPRESSION , "DELETE_VECTORCASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( CASTEXPRESSION , "CASTEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( PM_DOTSTAR , "PM_DOTSTAR"); //$NON-NLS-1$
|
|
||||||
names.put( PM_ARROWSTAR , "PM_ARROWSTAR"); //$NON-NLS-1$
|
|
||||||
names.put( MULTIPLICATIVE_MULTIPLY , "MULTIPLICATIVE_MULTIPLY"); //$NON-NLS-1$
|
|
||||||
names.put( MULTIPLICATIVE_DIVIDE , "MULTIPLICATIVE_DIVIDE"); //$NON-NLS-1$
|
|
||||||
names.put( MULTIPLICATIVE_MODULUS , "MULTIPLICATIVE_MODULUS"); //$NON-NLS-1$
|
|
||||||
names.put( ADDITIVE_PLUS , "ADDITIVE_PLUS"); //$NON-NLS-1$
|
|
||||||
names.put( ADDITIVE_MINUS , "ADDITIVE_MINUS"); //$NON-NLS-1$
|
|
||||||
names.put( SHIFT_LEFT , "SHIFT_LEFT"); //$NON-NLS-1$
|
|
||||||
names.put( SHIFT_RIGHT , "SHIFT_RIGHT"); //$NON-NLS-1$
|
|
||||||
names.put( RELATIONAL_LESSTHAN , "RELATIONAL_LESSTHAN"); //$NON-NLS-1$
|
|
||||||
names.put( RELATIONAL_GREATERTHAN , "RELATIONAL_GREATERTHAN"); //$NON-NLS-1$
|
|
||||||
names.put( RELATIONAL_LESSTHANEQUALTO , "RELATIONAL_LESSTHANEQUALTO"); //$NON-NLS-1$
|
|
||||||
names.put( RELATIONAL_GREATERTHANEQUALTO, "RELATIONAL_GREATERTHANEQUALTO" ); //$NON-NLS-1$
|
|
||||||
names.put( EQUALITY_EQUALS , "EQUALITY_EQUALS"); //$NON-NLS-1$
|
|
||||||
names.put( EQUALITY_NOTEQUALS , "EQUALITY_NOTEQUALS"); //$NON-NLS-1$
|
|
||||||
names.put( ANDEXPRESSION , "ANDEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( EXCLUSIVEOREXPRESSION , "EXCLUSIVEOREXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( INCLUSIVEOREXPRESSION , "INCLUSIVEOREXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( LOGICALANDEXPRESSION , "LOGICALANDEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( LOGICALOREXPRESSION , "LOGICALOREXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( CONDITIONALEXPRESSION , "CONDITIONALEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( THROWEXPRESSION , "THROWEXPRESSION"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_NORMAL , "ASSIGNMENTEXPRESSION_NORMAL"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_PLUS , "ASSIGNMENTEXPRESSION_PLUS"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_MINUS , "ASSIGNMENTEXPRESSION_MINUS"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_MULT , "ASSIGNMENTEXPRESSION_MULT"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_DIV , "ASSIGNMENTEXPRESSION_DIV"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_MOD , "ASSIGNMENTEXPRESSION_MOD"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_LSHIFT , "ASSIGNMENTEXPRESSION_LSHIFT"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_RSHIFT , "ASSIGNMENTEXPRESSION_RSHIFT"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_AND , "ASSIGNMENTEXPRESSION_AND"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_OR , "ASSIGNMENTEXPRESSION_OR"); //$NON-NLS-1$
|
|
||||||
names.put( ASSIGNMENTEXPRESSION_XOR , "ASSIGNMENTEXPRESSION_XOR"); //$NON-NLS-1$
|
|
||||||
names.put( EXPRESSIONLIST , "EXPRESSIONLIST"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getKindName() {
|
|
||||||
|
|
||||||
Object check = names.get(this);
|
|
||||||
if( check != null )
|
|
||||||
return (String) check;
|
|
||||||
return "EXTENSION SPECIFIED"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPostfixMemberReference()
|
|
||||||
{
|
|
||||||
if( this == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION ||
|
|
||||||
this == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION ||
|
|
||||||
this == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS ||
|
|
||||||
this == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP ||
|
|
||||||
this == IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR ||
|
|
||||||
this == IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR ||
|
|
||||||
this == IASTExpression.Kind.PM_DOTSTAR ||
|
|
||||||
this == IASTExpression.Kind.PM_ARROWSTAR )
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isLiteral() {
|
|
||||||
if( this == PRIMARY_INTEGER_LITERAL ||
|
|
||||||
this == PRIMARY_CHAR_LITERAL ||
|
|
||||||
this == PRIMARY_FLOAT_LITERAL ||
|
|
||||||
this == PRIMARY_STRING_LITERAL ||
|
|
||||||
this == PRIMARY_BOOLEAN_LITERAL )
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBasicType(){
|
|
||||||
if(this == PRIMARY_EMPTY
|
|
||||||
|| this == THROWEXPRESSION
|
|
||||||
|| this == POSTFIX_DOT_DESTRUCTOR
|
|
||||||
|| this == POSTFIX_ARROW_DESTRUCTOR
|
|
||||||
|| this == DELETE_CASTEXPRESSION
|
|
||||||
|| this == DELETE_VECTORCASTEXPRESSION
|
|
||||||
|| this == PRIMARY_INTEGER_LITERAL
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_INT
|
|
||||||
|| this == UNARY_SIZEOF_TYPEID
|
|
||||||
|| this == UNARY_SIZEOF_UNARYEXPRESSION
|
|
||||||
|| this == PRIMARY_CHAR_LITERAL
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_CHAR
|
|
||||||
|| this == PRIMARY_STRING_LITERAL
|
|
||||||
|| this == PRIMARY_FLOAT_LITERAL
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_FLOAT
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_DOUBLE
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_WCHART
|
|
||||||
|| this == PRIMARY_BOOLEAN_LITERAL
|
|
||||||
|| this == POSTFIX_SIMPLETYPE_BOOL
|
|
||||||
|| this == RELATIONAL_GREATERTHAN
|
|
||||||
|| this == RELATIONAL_GREATERTHANEQUALTO
|
|
||||||
|| this == RELATIONAL_LESSTHAN
|
|
||||||
|| this == RELATIONAL_LESSTHANEQUALTO
|
|
||||||
|| this == EQUALITY_EQUALS
|
|
||||||
|| this == EQUALITY_NOTEQUALS
|
|
||||||
|| this == LOGICALANDEXPRESSION
|
|
||||||
|| this == LOGICALOREXPRESSION
|
|
||||||
)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public boolean isPostfixSimpleType(){
|
|
||||||
if((this == POSTFIX_SIMPLETYPE_INT)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_SHORT)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_DOUBLE)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_FLOAT)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_CHAR)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_WCHART)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_SIGNED)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_UNSIGNED)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_BOOL)
|
|
||||||
|| (this == POSTFIX_SIMPLETYPE_LONG) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IASTNewExpressionDescriptor extends ISourceElementCallbackDelegate
|
|
||||||
{
|
|
||||||
public Iterator getNewPlacementExpressions();
|
|
||||||
public Iterator getNewTypeIdExpressions();
|
|
||||||
public Iterator getNewInitializerExpressions();
|
|
||||||
public void freeReferences( );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Kind getExpressionKind();
|
|
||||||
public IASTExpression getLHSExpression();
|
|
||||||
public IASTExpression getRHSExpression();
|
|
||||||
public IASTExpression getThirdExpression();
|
|
||||||
public String getLiteralString();
|
|
||||||
public String getIdExpression();
|
|
||||||
public char[] getIdExpressionCharArray();
|
|
||||||
public IASTTypeId getTypeId();
|
|
||||||
public IASTNewExpressionDescriptor getNewExpressionDescriptor();
|
|
||||||
|
|
||||||
public long evaluateExpression() throws ASTExpressionEvaluationException;
|
|
||||||
public void reconcileReferences() throws ASTNotImplementedException;
|
|
||||||
public void purgeReferences() throws ASTNotImplementedException;
|
|
||||||
/**
|
|
||||||
* @param manager TODO
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void freeReferences();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,275 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
|
||||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTFactory
|
|
||||||
{
|
|
||||||
public IASTMacro createMacro(
|
|
||||||
char[] name,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine,
|
|
||||||
int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit);
|
|
||||||
|
|
||||||
public IASTInclusion createInclusion(
|
|
||||||
char[] name,
|
|
||||||
char[] fileName,
|
|
||||||
boolean local,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine,
|
|
||||||
int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit) ;
|
|
||||||
|
|
||||||
public IASTUsingDirective createUsingDirective(
|
|
||||||
IASTScope scope,
|
|
||||||
ITokenDuple duple, int startingOffset, int startingLine, int endingOffset, int endingLine)
|
|
||||||
throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTUsingDeclaration createUsingDeclaration(
|
|
||||||
IASTScope scope,
|
|
||||||
boolean isTypeName,
|
|
||||||
ITokenDuple name, int startingOffset, int startingLine, int endingOffset, int endingLine) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTASMDefinition createASMDefinition(
|
|
||||||
IASTScope scope,
|
|
||||||
char[] assembly,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine, int endingOffset, int endingLine, char[] fn);
|
|
||||||
|
|
||||||
public IASTNamespaceDefinition createNamespaceDefinition(
|
|
||||||
IASTScope scope,
|
|
||||||
char[] identifier,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine, int nameOffset, int nameEndOffset, int nameLineNumber, char[] fn) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTNamespaceAlias createNamespaceAlias(
|
|
||||||
IASTScope scope,
|
|
||||||
char[] identifier,
|
|
||||||
ITokenDuple alias,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine,
|
|
||||||
int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endingLine ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTCompilationUnit createCompilationUnit() ;
|
|
||||||
|
|
||||||
public IASTLinkageSpecification createLinkageSpecification(
|
|
||||||
IASTScope scope,
|
|
||||||
char[] spec, int startingOffset, int startingLine, char[] fn) ;
|
|
||||||
|
|
||||||
public IASTClassSpecifier createClassSpecifier(
|
|
||||||
IASTScope scope,
|
|
||||||
ITokenDuple name,
|
|
||||||
ASTClassKind kind,
|
|
||||||
ClassNameType type,
|
|
||||||
ASTAccessVisibility access,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn) throws ASTSemanticException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param astClassSpec
|
|
||||||
* @param isVirtual
|
|
||||||
* @param visibility
|
|
||||||
* @param string
|
|
||||||
*/
|
|
||||||
public void addBaseSpecifier(
|
|
||||||
IASTClassSpecifier astClassSpec,
|
|
||||||
boolean isVirtual,
|
|
||||||
ASTAccessVisibility visibility,
|
|
||||||
ITokenDuple parentClassName) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(
|
|
||||||
IASTScope scope,
|
|
||||||
ASTClassKind elaboratedClassKind,
|
|
||||||
ITokenDuple typeName,
|
|
||||||
int startingOffset, int startingLine, int endOffset, int endingLine, boolean isForewardDecl, boolean isFriend) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTEnumerationSpecifier createEnumerationSpecifier(
|
|
||||||
IASTScope scope,
|
|
||||||
char[] name,
|
|
||||||
int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTEnumerator addEnumerator(
|
|
||||||
IASTEnumerationSpecifier enumeration,
|
|
||||||
char[] string,
|
|
||||||
int startingOffset,
|
|
||||||
int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endLine, IASTExpression initialValue, char[] fn)throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTExpression createExpression(
|
|
||||||
IASTScope scope,
|
|
||||||
IASTExpression.Kind kind,
|
|
||||||
IASTExpression lhs,
|
|
||||||
IASTExpression rhs,
|
|
||||||
IASTExpression thirdExpression,
|
|
||||||
IASTTypeId typeId,
|
|
||||||
ITokenDuple idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor, ITokenDuple extra) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions);
|
|
||||||
|
|
||||||
public IASTInitializerClause createInitializerClause(
|
|
||||||
IASTScope scope,
|
|
||||||
IASTInitializerClause.Kind kind,
|
|
||||||
IASTExpression assignmentExpression, List initializerClauses, List designators) ;
|
|
||||||
|
|
||||||
public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param exp
|
|
||||||
*/
|
|
||||||
public IASTArrayModifier createArrayModifier(IASTExpression exp);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param duple
|
|
||||||
* @param expressionList
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
|
|
||||||
public IASTConstructorMemberInitializer createConstructorMemberInitializer(
|
|
||||||
IASTScope scope,
|
|
||||||
ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(
|
|
||||||
IASTScope scope,
|
|
||||||
IASTSimpleTypeSpecifier.Type kind,
|
|
||||||
ITokenDuple typeName,
|
|
||||||
boolean isShort,
|
|
||||||
boolean isLong,
|
|
||||||
boolean isSigned,
|
|
||||||
boolean isUnsigned,
|
|
||||||
boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map map ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTFunction createFunction(
|
|
||||||
IASTScope scope,
|
|
||||||
ITokenDuple name,
|
|
||||||
List parameters,
|
|
||||||
IASTAbstractDeclaration returnType,
|
|
||||||
IASTExceptionSpecification exception,
|
|
||||||
boolean isInline,
|
|
||||||
boolean isFriend,
|
|
||||||
boolean isStatic,
|
|
||||||
int startOffset,
|
|
||||||
int startLine,
|
|
||||||
int nameOffset,
|
|
||||||
int nameEndOffset,
|
|
||||||
int nameLine,
|
|
||||||
IASTTemplate ownerTemplate,
|
|
||||||
boolean isConst,
|
|
||||||
boolean isVolatile,
|
|
||||||
boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
|
|
||||||
public IASTAbstractDeclaration createAbstractDeclaration(
|
|
||||||
boolean isConst,
|
|
||||||
boolean isVolatile,
|
|
||||||
IASTTypeSpecifier typeSpecifier,
|
|
||||||
List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator);
|
|
||||||
|
|
||||||
public IASTMethod createMethod(
|
|
||||||
IASTScope scope,
|
|
||||||
ITokenDuple name,
|
|
||||||
List parameters,
|
|
||||||
IASTAbstractDeclaration returnType,
|
|
||||||
IASTExceptionSpecification exception,
|
|
||||||
boolean isInline,
|
|
||||||
boolean isFriend,
|
|
||||||
boolean isStatic,
|
|
||||||
int startOffset,
|
|
||||||
int startLine,
|
|
||||||
int nameOffset,
|
|
||||||
int nameEndOffset,
|
|
||||||
int nameLine,
|
|
||||||
IASTTemplate ownerTemplate,
|
|
||||||
boolean isConst,
|
|
||||||
boolean isVolatile,
|
|
||||||
boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTVariable createVariable(IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression,
|
|
||||||
IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, char[] fn ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTField createField( IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility, char[] fn) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms );
|
|
||||||
|
|
||||||
public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, char[] parameterName, IASTInitializerClause initializerClause, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn ) ;
|
|
||||||
|
|
||||||
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset, int startingLine, char[] fn ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, char[] identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset, int startingLine, char[] fn);
|
|
||||||
|
|
||||||
public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset, int startingLine, char[] fn);
|
|
||||||
|
|
||||||
public IASTTypedefDeclaration createTypedef( IASTScope scope, char[] name, IASTAbstractDeclaration mapping, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn ) throws ASTSemanticException;
|
|
||||||
|
|
||||||
public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int startingLine, int endingOffset, int endingLine, boolean isFriend, char[] fn );
|
|
||||||
|
|
||||||
public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) ;
|
|
||||||
|
|
||||||
static final char[] DOUBLE_COLON = new char[] { ':', ':' };
|
|
||||||
static final char[] TELTA = new char[] { '~' };
|
|
||||||
/**
|
|
||||||
* @param scope
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IASTCodeScope createNewCodeBlock(IASTScope scope);
|
|
||||||
|
|
||||||
public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort,
|
|
||||||
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods, char[] completeSignature ) throws ASTSemanticException;
|
|
||||||
/**
|
|
||||||
* @param astClassSpecifier
|
|
||||||
*/
|
|
||||||
public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier);
|
|
||||||
|
|
||||||
public IASTNode lookupSymbolInContext( IASTScope scope, ITokenDuple duple, IASTNode reference ) throws ASTNotImplementedException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param log
|
|
||||||
*/
|
|
||||||
public void setLogger(IParserLogService log);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param scope
|
|
||||||
* @param duple
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IASTScope getDeclaratorScope(IASTScope scope, ITokenDuple duple);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param scope TODO
|
|
||||||
* @param expression
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public IASTNode expressionToMostPreciseASTNode(IASTScope scope, IASTExpression expression);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param node
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean validateIndirectMemberOperation(IASTNode node);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param node
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean validateDirectMemberOperation(IASTNode node);
|
|
||||||
|
|
||||||
public void constructExpressions( boolean flag );
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2002, 2006 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
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.ast;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author jcamelon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface IASTField extends IASTVariable, IASTMember {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue