diff options
Diffstat (limited to 'core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests')
37 files changed, 0 insertions, 22729 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java deleted file mode 100644 index 33c2447760c..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Properties; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public abstract class AutomatedFramework extends TestCase { - - public AutomatedFramework() { - super(); - } - - public AutomatedFramework(String name) { - super(name); - } - - protected abstract AutomatedFramework newTest( String name ); - protected abstract void loadProperties() throws Exception; - public abstract void doFile() throws Throwable; - - private void fillSuite( TestSuite suite, File path ){ - File files[] = null; - if( path.isFile() ){ - files = new File[ 1 ]; - files[0] = path; - } - else - files = path.listFiles(); - - File file = null; - String filePath = null; - int i = 0; - try{ - file = files[ i++ ]; - while( file != null ) - { - if( file.isDirectory() ) - fillSuite( suite, file ); - else if( file.isFile() && nameFilter.accept( file.getParentFile(), file.getName() ) ){ - try{ - filePath = file.getCanonicalPath(); - } catch ( Exception e ){ - continue; - } - - if( filePath.endsWith(".cpp") || filePath.endsWith(".hpp") || //$NON-NLS-1$ //$NON-NLS-2$ - filePath.endsWith(".cc") || filePath.endsWith(".CC") || //$NON-NLS-1$ //$NON-NLS-2$ - filePath.endsWith(".C") || //$NON-NLS-1$ - filePath.endsWith(".hxx") || filePath.endsWith(".hh") ) //$NON-NLS-1$ //$NON-NLS-2$ - { - AutomatedTest.natures.put( filePath, "cpp" ); //$NON-NLS-1$ - } else if( filePath.endsWith(".c") ){ //$NON-NLS-1$ - AutomatedTest.natures.put( filePath, "c" ); //$NON-NLS-1$ - } else { - AutomatedTest.natures.put( filePath, AutomatedTest.defaultNature ); - } - - AutomatedTest.fileList.add( file ); - suite.addTest( newTest( file.getName().replace(',', '_') ) ); - } - file = files[ i++ ]; - } - } catch( ArrayIndexOutOfBoundsException e ){ - //done - } - } - - public void reportFailed() { - fail( "Unable to open " + outputFile + "for output of results." ); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void propertiesFailed() { - fail( "Unable to load properties file." ); //$NON-NLS-1$ - } - - protected void runTest() throws Throwable { - String name = getName(); - - if( name.equals("propertiesFailed") ) //$NON-NLS-1$ - propertiesFailed(); - else if ( name.equals("reportFailed") ) //$NON-NLS-1$ - reportFailed(); - else - doFile(); - } - - public Test createSuite() { - TestSuite suite = new TestSuite(); - - try{ - loadProperties(); - } catch( Exception e ){ - suite.addTest( newTest( "propertiesFailed") ); //$NON-NLS-1$ - } - - if( outputFile != null && !outputFile.equals("") ){ //$NON-NLS-1$ - try{ - - File output = new File( outputFile ); - - if( output.exists() ){ - output.delete(); - } - - output.createNewFile(); - - report = new FileOutputStream( output ); - - } catch( Exception e ) { - suite.addTest( newTest( "reportFailed" ) ); //$NON-NLS-1$ - } - } - - Set keys = testSources.keySet(); - Iterator iter = keys.iterator(); - int size = keys.size(); - String item = null; - for( int i = size; i > 0; i-- ) - { - item = (String) iter.next(); - File file = new File( item ); - if( file.exists() ){ - defaultNature = (String) testSources.get( item ); - fillSuite( suite, file ); - } - } - - return suite; - } - - protected static ISourceElementRequestor nullCallback = new NullSourceElementRequestor(); - protected static Properties properties = new Properties(); - protected static String defaultNature; - protected static String outputFile = null; - protected static HashMap testSources = new HashMap(); - protected static HashMap natures = new HashMap(); - protected static LinkedList fileList = new LinkedList(); - private static FilenameFilter nameFilter = new Filter(); - protected static FileOutputStream report = null; - - static private class Filter implements FilenameFilter - { - public boolean accept(File dir, String name) { - if( name.endsWith(".cpp") || //$NON-NLS-1$ - name.endsWith(".c") || //$NON-NLS-1$ - name.endsWith(".cc") || //$NON-NLS-1$ - name.endsWith(".CC") || //$NON-NLS-1$ - name.endsWith(".C") || //$NON-NLS-1$ - name.endsWith(".h") || //$NON-NLS-1$ - name.endsWith(".hh") || //$NON-NLS-1$ - name.endsWith(".hpp") || //$NON-NLS-1$ - name.endsWith(".hxx")) //$NON-NLS-1$ - { - return true; - } - else - return false; - } - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java deleted file mode 100644 index a91ca6e2242..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM 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.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 = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").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$ - } - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java deleted file mode 100644 index e96c29b30a0..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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]); - } - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java deleted file mode 100644 index 771ea51f723..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests; - -import junit.framework.TestCase; - -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.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.ScannerException; -import org.eclipse.cdt.core.parser.ScannerInfo; - -/** - * @author jcamelon - * - */ -public class BaseScannerTest extends TestCase { - - protected IScanner scanner; - - public BaseScannerTest( 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= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$ - } - - protected void initializeScanner(String input) throws ParserFactoryError - { - initializeScanner( input, ParserMode.COMPLETE_PARSE ); - } - - - - 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) - { - } - catch (ScannerException se) - { - throw se; - } - return scanner.getCount(); - } - public void validateIdentifier(String expectedImage) throws ScannerException - { - try { - IToken t= scanner.nextToken(); - assertEquals( t.getType(), IToken.tIDENTIFIER ); - assertEquals(t.getImage(), expectedImage ); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateInteger(String expectedImage) throws ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - validateString( expectedImage, false ); - } - - public void validateString(String expectedImage, boolean lString ) throws ScannerException - { - try { - IToken t= scanner.nextToken(); - if( lString ) - assertTrue(t.getType() == IToken.tLSTRING); - else - assertTrue(t.getType() == IToken.tSTRING); - assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateToken(int tokenType) throws ScannerException - { - try { - IToken t= scanner.nextToken(); - assertTrue(t.getType() == tokenType); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateBalance(int expected) - { - assertTrue(scanner.getDepth() == expected); - } - - public void validateBalance() - { - assertTrue(scanner.getDepth() == 0); - } - - public void validateEOF() throws ScannerException - { - try { - assertNull(scanner.nextToken()); - } catch (EndOfFileException e) { - } - } - - - - public void validateDefinition(String name, String value) - { - String definition= null; - definition= scanner.getDefinition(name).getExpansionSignature(); - assertNotNull(definition); - assertTrue(definition.trim().equals(value)); - } - - public void validateDefinition(String name, int value) - { - String definition= null; - definition= scanner.getDefinition(name).getExpansionSignature(); - assertNotNull(definition); - int intValue= (Integer.valueOf(definition)).intValue(); - assertEquals(value, intValue); - } - - public void validateAsUndefined(String name) - { - assertNull(scanner.getDefinition(name)); - } - - 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(); - assertTrue(t.getType() == IToken.tLCHAR ); - assertEquals( t.getImage(), string ); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java deleted file mode 100644 index 2a1881ab5ba..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003,2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.EmptyStackException; - -import junit.framework.TestCase; - -import org.eclipse.cdt.internal.core.parser.scanner.BranchTracker; - -/** - * @author jcamelon - */ -public class BranchTrackerTest extends TestCase { - - public BranchTrackerTest( String ignoreMe ) - { - super( ignoreMe ); - } - - public static void assertFalse( boolean input ) - { - assertTrue( input == false ); - } - - public void testIgnore() - { - - BranchTracker bt = new BranchTracker(); - try - { - /* - * #if 0 - * # if 1 - * # elif 1 - * # else - * # endif - * #else - * #endif - */ - - assertFalse( bt.poundIf( false ) ); - assertFalse( bt.poundIf( true ) ); - assertFalse( bt.poundElif( true ) ); - assertFalse( bt.poundElse() ); - assertFalse( bt.poundEndif() ); - assertTrue( bt.poundElse() ); - assertTrue( bt.poundEndif() ); - - /* - * #if 0 - * # if 1 - * # elif 1 - * # else - * # endif - * #else - * # if 0 - * # elif 1 - * # elif 0 - * # elif 1 - * # else - * # endif - * #endif - */ - - bt = new BranchTracker(); - assertFalse( bt.poundIf( false ) ); - assertFalse( bt.poundIf( true )); - assertFalse( bt.poundElif( true ) ); - assertFalse( bt.poundElse() ); - assertFalse( bt.poundEndif() ); - assertTrue( bt.poundElse() ); - assertFalse( bt.poundIf( false ) ); - assertTrue( bt.poundElif( true ) ); - assertFalse( bt.poundElif( false ) ); - assertFalse( bt.poundElif( true ) ); - assertFalse( bt.poundElse() ); - assertTrue( bt.poundEndif() ); - assertTrue( bt.poundEndif() ); - assertEquals( 0, bt.getDepth() ); - - /* - * #if 0 - * # if 1 - * # elif 0 - * # elif 1 - * # else - * # endif - * #elif 0 - * # if 0 - * # elif 0 - * # elif 1 - * # else - * # endif - * #elif 1 - * # if 0 - * # elif 0 - * # elif 0 - * # else - * # endif - * #else - * # if 1 - * # elif 0 - * # elif 1 - * # else - * # endif - * #endif - */ - - assertFalse(bt.poundIf(false)); - assertFalse(bt.poundIf(true)); - assertFalse(bt.poundElif(false)); - assertFalse(bt.poundElif(true)); - assertFalse(bt.poundElse()); - assertFalse( bt.poundEndif() ); - assertFalse(bt.poundElif(false)); - assertFalse(bt.poundIf(false)); - assertFalse(bt.poundElif(false)); - assertFalse(bt.poundElif(true)); - assertFalse(bt.poundElse()); - assertFalse( bt.poundEndif()); - assertTrue(bt.poundElif(true)); - assertFalse(bt.poundIf(false)); - assertFalse(bt.poundElif(false)); - assertFalse(bt.poundElif(false)); - assertTrue(bt.poundElse()); - assertTrue( bt.poundEndif() ); - assertFalse(bt.poundElse()); - assertFalse(bt.poundIf(true)); - assertFalse(bt.poundElif(false)); - assertFalse(bt.poundElif(true)); - assertFalse(bt.poundElse()); - assertFalse( bt.poundEndif() ); - assertTrue( bt.poundEndif() ); - assertEquals(0, bt.getDepth()); - } catch (EmptyStackException se) { - fail("Unexpected Scanner exception thrown"); //$NON-NLS-1$ - } - } - - public void testSimpleBranches() - { - try - { - /* - * code sequence is - * #if 1 - * #else - * #endif - */ - BranchTracker bt = new BranchTracker(); - assertTrue( bt.poundIf( true ) ); - assertFalse( bt.poundElse() ); - assertTrue( bt.poundEndif() ); - - /* - * code sequence is - * #if 1 - * # if 0 - * # elif 0 - * # else - * # endif - * #else - * #endif - */ - bt = new BranchTracker(); - assertTrue( bt.poundIf( true )); - assertFalse( bt.poundIf( false )); - assertFalse( bt.poundElif( false )); - assertTrue( bt.poundElse()); - assertTrue( bt.poundEndif() ); - assertFalse( bt.poundElse() ); - assertTrue( bt.poundEndif() ); - - /* - * #if 1 - * #elsif 1 - * #elsif 0 - * #else - * #endif - */ - - bt = new BranchTracker(); - assertTrue( bt.poundIf( true ) ); - assertFalse( bt.poundElif( true )); - assertFalse( bt.poundElif( false )); - assertFalse( bt.poundElse()); - assertTrue( bt.poundEndif() ); - - - } - catch( EmptyStackException se ) - { - fail( "Exception" ); //$NON-NLS-1$ - } - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java deleted file mode 100644 index c617d3375f3..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import junit.framework.TestCase; - -import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap; -import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayPool; -import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils; - -/** - * @author Doug Schaefer - */ -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() { - CharArrayObjectMap map = new CharArrayObjectMap(4); - char[] key1 = "key1".toCharArray(); - Object value1 = new Integer(43); - map.put(key1, value1); - - char[] key2 = "key1".toCharArray(); - Object value2 = map.get(key2); - assertEquals(value1, value2); - - for (int i = 0; i < 5; ++i) { - map.put(("ikey" + i).toCharArray(), new Integer(i)); - } - - Object ivalue1 = map.get("ikey1".toCharArray()); - assertEquals(ivalue1, new Integer(1)); - - Object ivalue4 = map.get("ikey4".toCharArray()); - assertEquals(ivalue4, new Integer(4)); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java deleted file mode 100644 index 58ad016501c..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java +++ /dev/null @@ -1,1106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 Rational Software Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - initial 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.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @author hamer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ - - public CompleteParseASTExpressionTest(String a) - { - super(a); - } - // Kind PRIMARY_EMPTY : void - public void testPrimaryEmpty() throws Exception - { - Iterator i = parse ("int f(char); \r\n int f(void); \r\n int x = f();").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences(1, createTaskList( new Task( f2 ) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f()" ); //$NON-NLS-1$ - } - // Kind PRIMARY_INTEGER_LITERAL : int - public void testPrimaryIntegerLiteral() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1, 2 + 3)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_CHAR_LITERAL : char - public void testPrimaryCharLiteral() throws Exception - { - Iterator i = parse ("int f(char, int); \n int f(char); \n int x = f('c');").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f('c')" ); //$NON-NLS-1$ - } - // Kind PRIMARY_FLOAT_LITERAL : float - public void testPrimaryFloatLiteral() throws Exception - { - Iterator i = parse ("int f(char); \n int f(float); \n int x = f(1.13);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1.13)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_STRING_LITERAL : char* - public void testPrimaryStringLiteral() throws Exception - { - Iterator i = parse ("int f(char); \n int f(char*); \n int x = f(\"str\");").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(\"str\")" ); //$NON-NLS-1$ - } - // Kind PRIMARY_BOOLEAN_LITERAL : bool - public void testPrimaryBooleanLiteral() throws Exception - { - Iterator i = parse ("int f(bool); \n int f(float); \n int x = f(true);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(true)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_THIS : type of inner most enclosing structure scope - public void testPrimaryThis() throws Exception - { - Iterator i = parse ("class A{ int m(); }; A a; \n int f(void); \n int f(A * a); \n int A::m(){ int x = f(this); }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = getDeclarations(cl); - IASTMethod method = (IASTMethod)members.next(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTMethod m = (IASTMethod) i.next(); - Iterator r = callback.getReferences().iterator(); - assertAllReferences( 4, createTaskList( new Task( cl, 3 ), new Task( f2 ))); - - Iterator body = getDeclarations( m ); - IASTVariable x = (IASTVariable) body.next(); - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(this)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_BRACKETED_EXPRESSION : LHS - public void testPrimaryBracketedExpression() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, (2+3));").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1, (2 + 3))" ); //$NON-NLS-1$ - } - // Kind ID_EXPRESSION : type of the ID - public void testIdExpression() throws Exception - { - Iterator i = parse ("class A{}a; \n int f(A a); \n int f(void); \n int x = f(a);").getDeclarations(); //$NON-NLS-1$ - - IASTVariable a = (IASTVariable) i.next(); - IASTClassSpecifier cl = (IASTClassSpecifier)a.getAbstractDeclaration().getTypeSpecifier(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - - assertAllReferences( 3, createTaskList( new Task( cl ), new Task( f1 ),new Task( a ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(a)" ); //$NON-NLS-1$ - } - // Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID - public void testIdExpressionToPointer() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int f(void); \n int x = f(pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( f1 ), new Task( a ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_SUBSCRIPT - public void testPostfixSubscript() throws Exception - { - Iterator i = parse ("int pa[10]; \n int f(int ia){} \n int f(void); \n int x = f(pa[1]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptA() throws Exception - { - Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptB() throws Exception - { - Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptWithReferences() throws Exception - { - Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( pa ), new Task( f1 ))); - } - - // Kind POSTFIX_FUNCTIONCALL : return type of called function - public void testPostfixFunctioncallBug42822() throws Exception - { - Iterator i = parse( "int foo( float b ); int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction bar = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( bar ), new Task( foo, 2 ))); - - i = getDeclarations( test ); - IASTVariable x = (IASTVariable) i.next(); - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "bar(foo(3.0), foo(5.0))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_SIMPLETYPE_* : simple type - public void testPostfixSimpletypesBug42823() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );"); //$NON-NLS-1$ - buffer.append( "void test( void ) { int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo ))); - - i = getDeclarations( test ); - IASTVariable someInt = (IASTVariable) i.next(); - IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3))" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_TYPENAME_IDENTIFIER - public void testPostfixTypenameIdentifier() throws Exception{ - Iterator i = parse( "class A {}; \n int foo(); int foo( A a ); \n int x = foo( typename A() );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( cl, 2 ), new Task( f2) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename A())" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_TYPENAME_TEMPLATEID - public void testPostfixTypeNameTemplateId() throws Exception{ - Iterator i = parse( " template<class T> class A {}; int foo( A<int> a ); \n int x = foo( typename template A< int >() );").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTFunction f = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( f ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename template A<int>())" ); //$NON-NLS-1$ - } - - public void testPostfixTypeNameTemplateId_2() throws Exception{ - Iterator i = parse( "namespace NS{ template<class T> class A {}; } int foo( NS::A<int> a ); \n int x = foo( typename NS::template A< int >() );").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition NS = (IASTNamespaceDefinition) i.next(); - IASTFunction f = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - - i = getDeclarations( NS ); - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - - assertAllReferences( 5, createTaskList( new Task( NS, 2 ), new Task( A, 2 ), new Task( f ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename NS::template A<int>())" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container - public void testPostfixDotExpression() throws Exception{ - Iterator i = parse( "class A {int m;}; \n A a; \n int foo(char); int foo( int ); \n int x = foo( a.m );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator members = getDeclarations(cl); - IASTField m = (IASTField)members.next(); - assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a.m)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container - public void testPostfixArrowExpression() throws Exception{ - Iterator i = parse( "class A {int m;}; \n A * a; \n int foo(char); int foo( int ); \n int x = foo( a->m );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator members = getDeclarations(cl); - IASTField m = (IASTField)members.next(); - assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a->m)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DOT_TEMPL_IDEXPRESS - // Kind POSTFIX_ARROW_TEMPL_IDEXP - - // Kind POSTFIX_DOT_DESTRUCTOR - // Kind POSTFIX_ARROW_DESTRUCTOR - - // Kind POSTFIX_INCREMENT : LHS - public void testPostfixIncrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(x++)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DECREMENT : LHS - public void testPostfixDecrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x-- ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(x--)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DYNAMIC_CAST - public void testPostfixDynamicCast() throws Exception{ - Iterator i = parse( "class A {}; class B : public A{}; \n A *a; \n int foo(); int foo( B* ); \n int x = foo( dynamic_cast<B*>(a) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 6, createTaskList( new Task( cla, 2 ), new Task( clb, 2), new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(dynamic_cast<B*>(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_REINTERPRET_CAST - public void testPostfixReinterpretCast() throws Exception{ - Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast<double *>(a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(reinterpret_cast<double *>(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_STATIC_CAST - public void testPostfixStaticCast() throws Exception{ - Iterator i = parse( "int a; \n int foo(); int foo( char ); \n int x = foo( static_cast<char>(a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(static_cast<char>(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_CONST_CAST - public void testPostfixConstCast() throws Exception{ - Iterator i = parse( "const int a; \n int foo(); int foo( int * ); \n int x = foo( const_cast<int *>(&a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(const_cast<int *>(&a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_EXPRESSION : LHS - public void testPostfixTypeIdExpression() throws Exception{ - Iterator i = parse( "int foo(char); int foo( int ); \n int x = foo( typeid(5) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(5))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_EXPRESSION : type of the ID - public void testPostfixTypeIdExpression2() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(a) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_TYPEID : type of the ID - public void testPostfixTypeIdTypeId() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(A) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(A))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_TYPEID : type of the ID - public void testPostfixTypeIdTypeId2() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(const A) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(const A))" ); //$NON-NLS-1$ - } - // Kind UNARY_INCREMENT : LHS - public void testUnaryIncrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( ++x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(++x)" ); //$NON-NLS-1$ - } - // Kind UNARY_DECREMENT : LHS - public void testUnaryDecrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( --x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(--x)" ); //$NON-NLS-1$ - } - // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer - public void testUnaryStarCastExpression() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int f(void); \n int x = f(*pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(*pa)" ); //$NON-NLS-1$ - } - // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference - public void testUnaryAmpersandCastExpression() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int f(void); \n int x = f(&pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(&pa)" ); //$NON-NLS-1$ - } - // Kind UNARY_PLUS_CASTEXPRESSION : LHS - public void testUnaryPlusCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = foo( +5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(+5)" ); //$NON-NLS-1$ - } - // Kind UNARY_MINUS_CASTEXPRESSION : LHS - public void testUnaryMinusCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = foo( -5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(-5)" ); //$NON-NLS-1$ - } - // Kind UNARY_NOT_CASTEXPRESSION : LHS - public void testUnaryNotCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); bool b=true; int x = foo( !b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( b ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(!b)" ); //$NON-NLS-1$ - } - // Kind UNARY_TILDE_CASTEXPRESSION : LHS - public void testTildeNotCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( ~x );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(~x)" ); //$NON-NLS-1$ - } - // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int - public void testUnarySizeofUnaryExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(5) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(sizeof (5))" ); //$NON-NLS-1$ - } - // Kind UNARY_SIZEOF_TYPEID : unsigned int - public void testUnarySizeofTypeId() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(x) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(sizeof (x))" ); //$NON-NLS-1$ - } - // Kind NEW_NEWTYPEID - // Kind NEW_TYPEID - public void testNewTypeId() throws Exception { - Iterator i = parse( "class A{}; void foo(); int foo( A * a ); int x = foo( new A() );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(new A())" ); //$NON-NLS-1$ - } - - // Kind DELETE_CASTEXPRESSION - // Kind DELETE_VECTORCASTEXPRESSION - - // Kind CASTEXPRESSION - public void testCastExpression() throws Exception{ - Iterator i = parse( "class A {}; class B : public A{}; \n B *b; \n int foo(); int foo( A* ); \n int x = foo( (A*)b );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable b = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo((A*)b)" ); //$NON-NLS-1$ - } - - // Kind PM_DOTSTAR - // failed - - // Kind PM_ARROWSTAR - // failed - - // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions - public void testMultiplicativeMultiply() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( a * b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a * b)" ); //$NON-NLS-1$ - } - // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions - public void testMultiplicativeDivide() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b / a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b / a)" ); //$NON-NLS-1$ - } - // Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions - public void testMultiplicativeModulus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b % a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b % a)" ); //$NON-NLS-1$ - } - // Kind ADDITIVE_PLUS : usual arithmetic conversions - public void testAdditivePlus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b + a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b + a)" ); //$NON-NLS-1$ - } - // Kind ADDITIVE_MINUS : usual arithmetic conversions - public void testAdditiveMinus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b - a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b - a)" ); //$NON-NLS-1$ - } - // Kind SHIFT_LEFT : LHS - public void testShiftLeft() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a << 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a << 5)" ); //$NON-NLS-1$ - } - // Kind SHIFT_RIGHT : LHS - public void testShiftRight() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >> 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a >> 5)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_LESSTHAN : bool - public void testRelationalLessThan() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b < 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b < 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_GREATERTHAN : bool - public void testRelationalGreaterThan() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b > 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b > 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_LESSTHANEQUALTO : bool - public void testRelationalLessThanOrEqual() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b <= 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b <= 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_GREATERTHANEQUALTO : bool - public void testRelationalGreaterThanOrEqual() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b >= 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b >= 3)" ); //$NON-NLS-1$ - } - // Kind EQUALITY_EQUALS : bool - public void testEqualityEquals() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b == 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b == 3)" ); //$NON-NLS-1$ - } - // Kind EQUALITY_NOTEQUALS : bool - public void testEqualityNotEquals() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b != 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b != 3)" ); //$NON-NLS-1$ - } - // Kind ANDEXPRESSION : usual arithmetic conversions - public void testAndExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a & b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a & b)" ); //$NON-NLS-1$ - } - // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions - public void testExclusiveOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a ^ b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a ^ b)" ); //$NON-NLS-1$ - } - // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions - public void testInclusiveOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a | b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a | b)" ); //$NON-NLS-1$ - } - // Kind LOGICALANDEXPRESSION : bool - public void testLogicalAndExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a && b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a && b)" ); //$NON-NLS-1$ - } - // Kind LOGICALOREXPRESSION : bool - public void testLogicalOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a || b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a || b)" ); //$NON-NLS-1$ - } - // Kind CONDITIONALEXPRESSION : conditional Expression Conversions - public void testConditionalExpression() throws Exception { - Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 4, createTaskList( new Task( a ), new Task(b), new Task( c ), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a > 5 ? b : c)" ); //$NON-NLS-1$ - } - // Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions - public void testConditionalExpressionWithReferencesA() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A*); A *a ; B *b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ - } - public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 8, - createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ - } - // Kind THROWEXPRESSION - - // Kind ASSIGNMENTEXPRESSION_NORMAL : LHS - public void testAssignmentExpressionNormal() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a = 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a = 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_PLUS : LHS - public void testAssignmentExpressionPlus() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a += 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a += 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MINUS : LHS - public void testAssignmentExpressionMinus() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a -= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a -= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MULT : LHS - public void testAssignmentExpressionMulti() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a *= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a *= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_DIV : LHS - public void testAssignmentExpressionDiv() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a /= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a /= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MOD : LHS - public void testAssignmentExpressionMod() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a %= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a %= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS - public void testAssignmentExpressionLShift() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >>= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a >>= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS - public void testAssignmentExpressionRShift() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a <<= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a <<= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_AND : LHS - public void testAssignmentExpressionAnd() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a &= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a &= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_OR : LHS - public void testAssignmentExpressionOr() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a |= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a |= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_XOR : LHS - public void testAssignmentExpressionXOr() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a ^= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a ^= 5)" ); //$NON-NLS-1$ - } - // Kind EXPRESSIONLIST : list of LHS, RHS - // Already tested with each test trying to find a reference to function. - - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java deleted file mode 100644 index 0aed7bbe757..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * 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.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.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 callback; - - protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError - { - callback = new CompilationUnitCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(), - ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null - ); - if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - - return callback.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() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java deleted file mode 100644 index 0569a844195..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java +++ /dev/null @@ -1,1047 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - /* - * Created on Mar 30, 2004 - */ -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.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.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.IASTParameterDeclaration; -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.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; - -/** - * @author aniefer - */ -public class CompleteParseASTTemplateTest extends CompleteParseBaseTest { - /** - * @param name - */ - public CompleteParseASTTemplateTest(String name) { - super(name); - } - - public void testTemplateClassDeclaration() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > class A { T t; }; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i = getDeclarations( template ); - - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( classA.getName(), "A" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - - i = getDeclarations( classA ); - - IASTField t = (IASTField) i.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - - IASTSimpleTypeSpecifier specifier = (IASTSimpleTypeSpecifier) t.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( specifier.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( specifier.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - } - - public void testTemplateFunction() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > void f( T t ){} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i = getDeclarations( template ); - IASTFunction f = (IASTFunction) i.next(); - assertEquals( f.getName(), "f" ); //$NON-NLS-1$ - - params = f.getParameters(); - IASTParameterDeclaration t = (IASTParameterDeclaration) params.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) t.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - } - - public void testTemplateFunctionDefinition() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template <class T> void f( T t );" ); //$NON-NLS-1$ - writer.write( "template <class U> void f( U u ) { }" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - - Iterator tempDecls = getDeclarations( template ); - IASTFunction f = (IASTFunction) tempDecls.next(); - assertEquals( f.getName(), "f" ); //$NON-NLS-1$ - assertFalse( f.hasFunctionBody() ); - assertFalse( tempDecls.hasNext() ); - - params = f.getParameters(); - IASTParameterDeclaration t = (IASTParameterDeclaration) params.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) t.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - - params = template2.getTemplateParameters(); - - IASTTemplateParameter U = (IASTTemplateParameter) params.next(); - assertEquals( U.getIdentifier(), "U" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - - tempDecls = getDeclarations( template2 ); - IASTFunction f2 = (IASTFunction) tempDecls.next(); - assertEquals( f2.getName(), "f" ); //$NON-NLS-1$ - assertTrue( f2.previouslyDeclared() ); - - params = f2.getParameters(); - IASTParameterDeclaration u = (IASTParameterDeclaration) params.next(); - assertEquals( u.getName(), "u" ); //$NON-NLS-1$ - typeSpec = (IASTSimpleTypeSpecifier) u.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "U" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), U ); //TODO uncomment when bug 54029 is fixed - - assertFalse( i.hasNext() ); - } - - public void testClassMemberTemplate() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "namespace N { " ); //$NON-NLS-1$ - writer.write( " class A { " ); //$NON-NLS-1$ - writer.write( " template < class T > T f();" ); //$NON-NLS-1$ - writer.write( " }; " ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - writer.write( "template <class U> U N::A::f() {} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTNamespaceDefinition N = (IASTNamespaceDefinition) i.next(); - - Iterator i2 = getDeclarations( N ); - - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i2.next()).getTypeSpecifier(); - assertFalse( i2.hasNext() ); - - i2 = getDeclarations( A ); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i2.next(); - Iterator params = template.getTemplateParameters(); - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertFalse( params.hasNext() ); - assertFalse( i2.hasNext() ); - - i2 = getDeclarations( template ); - - IASTMethod f = (IASTMethod) i2.next(); - assertEquals( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).getTypename(), "T" ); //$NON-NLS-1$ - assertFalse( i2.hasNext() ); - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - params = template.getTemplateParameters(); - IASTTemplateParameter U = (IASTTemplateParameter) params.next(); - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i2 = getDeclarations( template2 ); - - IASTMethod f2 = (IASTMethod) i2.next(); - assertEquals( ((IASTSimpleTypeSpecifier)f2.getReturnType().getTypeSpecifier()).getTypename(), "U" ); //$NON-NLS-1$ - assertQualifiedName( f2.getFullyQualifiedName(), new String [] { "N", "A", "f" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - assertTrue( f2.previouslyDeclared() ); - assertFalse( i2.hasNext() ); - } - - public void testOverloadedFunctionTemplates() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " template < class T > void f ( T ) {} " ); //$NON-NLS-1$ - writer.write( " template < class T > void f ( T * ) {} " ); //$NON-NLS-1$ - writer.write( " int * p;" ); //$NON-NLS-1$ - writer.write( " void main () {" ); //$NON-NLS-1$ - writer.write( " f( p );" ); //$NON-NLS-1$ - writer.write( " f( *p );" ); //$NON-NLS-1$ - writer.write( " }" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T1 = (IASTTemplateParameter) template1.getTemplateParameters().next(); - - IASTFunction f1 = (IASTFunction) template1.getOwnedDeclaration(); - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - IASTFunction f2 = (IASTFunction) template2.getOwnedDeclaration(); - IASTTemplateParameter T2 = (IASTTemplateParameter) template2.getTemplateParameters().next(); - - IASTVariable p = (IASTVariable) i.next(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 6, createTaskList( new Task( T1 ), - new Task( T2 ), - new Task( f1, 1, false, false ), - new Task( p, 2 ), - new Task( f2, 1, false, false ) ) ); - - } - - public void testOverloadedFunctionTemplates_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template< class T > struct A { }; \n"); //$NON-NLS-1$ - writer.write("template< class T > void h( const T & ); //#1 \n"); //$NON-NLS-1$ - writer.write("template< class T > void h( A<T>& ); //#2 \n"); //$NON-NLS-1$ - writer.write("void foo() { \n"); //$NON-NLS-1$ - writer.write(" A<int> z; \n"); //$NON-NLS-1$ - writer.write(" h( z ); //calls 2 \n"); //$NON-NLS-1$ - - writer.write(" const A<int> z2; \n"); //$NON-NLS-1$ - writer.write(" h( z2 ); //calls 1 because 2 is not callable. \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateh1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateh2 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier A = (IASTClassSpecifier) templateA.getOwnedDeclaration(); - IASTFunction h1 = (IASTFunction) templateh1.getOwnedDeclaration(); - IASTFunction h2 = (IASTFunction) templateh2.getOwnedDeclaration(); - - IASTTemplateParameter T1 = (IASTTemplateParameter) templateA.getTemplateParameters().next(); - IASTTemplateParameter T2 = (IASTTemplateParameter) templateh1.getTemplateParameters().next(); - IASTTemplateParameter T3 = (IASTTemplateParameter) templateh2.getTemplateParameters().next(); - - IASTFunction foo = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( foo ); - IASTVariable z = (IASTVariable) i.next(); - IASTVariable z2 = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - - assertEquals( ((IASTSimpleTypeSpecifier)z.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A ); - assertEquals( ((IASTSimpleTypeSpecifier)z2.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A ); - - assertAllReferences( 9, createTaskList( new Task( T2 ), - new Task( T3 ), - new Task( A, 3 ), - new Task( z ), - new Task( z2 ), - new Task( h1, 1, false, false ), - new Task( h2, 1, false, false ) ) ); - - - } - - public void testTemplateClassPartialSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T1, class T2, int I > class A {}; //#1\n" ); //$NON-NLS-1$ - writer.write( "template < class T, int I > class A < T, T*, I > {}; //#2\n"); //$NON-NLS-1$ - writer.write( "template < class T1, class T2, int I > class A < T1*, T2, I > {}; //#3\n"); //$NON-NLS-1$ - writer.write( "template < class T > class A < int, T*, 5 > {}; //#4\n"); //$NON-NLS-1$ - writer.write( "template < class T1, class T2, int I > class A < T1, T2*, I > {}; //#5\n"); //$NON-NLS-1$ - - writer.write( "A <int, int, 1> a1; //uses #1 \n"); //$NON-NLS-1$ - writer.write( "A <int, int*, 1> a2; //uses #2, T is int, I is 1 \n"); //$NON-NLS-1$ - writer.write( "A <int, char*, 5> a4; //uses #4, T is char \n"); //$NON-NLS-1$ - writer.write( "A <int, char*, 1> a5; //uses #5, T is int, T2 is char, I is1 \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - writer.write( " A <int*, int*, 2> amgiguous; //ambiguous, matches #3 & #5 \n"); //$NON-NLS-1$ - - try{ - //we expect this parse to fail because of the ambiguity in the last line - parse( writer.toString() ); - assertFalse( true ); - } catch ( ParserException e ){ - assertEquals( e.getMessage(), "FAILURE" ); //$NON-NLS-1$ - } - - IASTTemplateDeclaration template1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec3 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec4 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec5 = (IASTTemplateDeclaration) i.next(); - - IASTVariable a1 = (IASTVariable) i.next(); - IASTVariable a2 = (IASTVariable) i.next(); - IASTVariable a4 = (IASTVariable) i.next(); - IASTVariable a5 = (IASTVariable) i.next(); - - assertFalse( i.hasNext() ); - - IASTClassSpecifier A1 = (IASTClassSpecifier)template1.getOwnedDeclaration(); - IASTClassSpecifier A2 = (IASTClassSpecifier)spec2.getOwnedDeclaration(); - IASTClassSpecifier A3 = (IASTClassSpecifier)spec3.getOwnedDeclaration(); - IASTClassSpecifier A4 = (IASTClassSpecifier)spec4.getOwnedDeclaration(); - IASTClassSpecifier A5 = (IASTClassSpecifier)spec5.getOwnedDeclaration(); - - assertEquals( ((IASTSimpleTypeSpecifier)a1.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A1 ); - assertEquals( ((IASTSimpleTypeSpecifier)a2.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A2 ); - assertEquals( ((IASTSimpleTypeSpecifier)a4.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A4 ); - assertEquals( ((IASTSimpleTypeSpecifier)a5.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A5 ); - - } - - public void testTemplateInstanceAsBaseClause() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template< class T > class A { T t; }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A< int > {}; \n" ); //$NON-NLS-1$ - writer.write( "void f( int ); \n" ); //$NON-NLS-1$ - - writer.write( "void main(){ \n" ); //$NON-NLS-1$ - writer.write( " B b; \n" ); //$NON-NLS-1$ - writer.write( " f( b.t ); \n" ); //if this function call is good, it implies that b.t is type int //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier B = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - i = getDeclarations( A ); - IASTField t = (IASTField) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( main ); - - IASTVariable b = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 6, createTaskList( new Task( T ), - new Task( A ), - new Task( B ), - new Task( b ), - new Task( t ), - new Task( f ) ) ); - } - - public void testTemplateParameterAsBaseClause() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > class A : public T {}; \n" ); //$NON-NLS-1$ - writer.write( "class B { int i; }; \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( " A<B> a; \n" ); //$NON-NLS-1$ - writer.write( " a.i; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) iter.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier B = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - IASTFunction main = (IASTFunction) iter.next(); - assertFalse( iter.hasNext() ); - - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - - iter = getDeclarations( B ); - IASTVariable i = (IASTVariable) iter.next(); - - iter = getDeclarations( main ); - IASTVariable a = (IASTVariable) iter.next(); - - assertAllReferences( 5, createTaskList( new Task( T ), new Task( A ), new Task( B ), new Task( a ), new Task( i ) ) ); - } - - public void testTypedefedTemplate() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > class _A{ int x; }; \n" ); //$NON-NLS-1$ - writer.write( "typedef _A < char > A; \n" ); //$NON-NLS-1$ - writer.write( "void foo() { \n" ); //$NON-NLS-1$ - writer.write( " A a; \n" ); //$NON-NLS-1$ - writer.write( " a.x; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration _A = (IASTTemplateDeclaration) i.next(); - IASTTypedefDeclaration A = (IASTTypedefDeclaration) i.next(); - IASTFunction foo = (IASTFunction) i.next(); - - IASTClassSpecifier classA = (IASTClassSpecifier) _A.getOwnedDeclaration(); - IASTVariable x = (IASTVariable) getDeclarations( classA ).next(); - IASTVariable a = (IASTVariable) getDeclarations( foo ).next(); - - assertAllReferences( 4, createTaskList( new Task( classA ), new Task( A ), new Task( a ), new Task( x ) ) ); - } - - public void testTypedefedTemplate_2() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > struct A { T x; }; \n" ); //$NON-NLS-1$ - writer.write( "template < class U > struct B { \n" ); //$NON-NLS-1$ - writer.write( " typedef A< U > AU; \n" ); //$NON-NLS-1$ - writer.write( " void f( U ); \n" ); //$NON-NLS-1$ - writer.write( " void f( char ); \n" ); //$NON-NLS-1$ - writer.write( " void g(){ \n" ); //$NON-NLS-1$ - writer.write( " AU au; \n" ); //$NON-NLS-1$ - writer.write( " f( au.x ); \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f2( int ); \n" ); //$NON-NLS-1$ - writer.write( "void f2( char ); \n" ); //$NON-NLS-1$ - writer.write( "void h(){ \n" ); //$NON-NLS-1$ - writer.write( " B< int >::AU b; \n" ); //$NON-NLS-1$ - writer.write( " f2( b.x ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration tA = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) tA.getTemplateParameters().next(); - IASTClassSpecifier A = (IASTClassSpecifier) tA.getOwnedDeclaration(); - IASTField x = (IASTField) getDeclarations( A ).next(); - IASTTemplateDeclaration tB = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier B = (IASTClassSpecifier) tB.getOwnedDeclaration(); - IASTTemplateParameter U = (IASTTemplateParameter) tB.getTemplateParameters().next(); - IASTFunction f21 = (IASTFunction) i.next(); - IASTFunction f22 = (IASTFunction) i.next(); - IASTFunction h = (IASTFunction) i.next(); - - i = getDeclarations( B ); - IASTTypedefDeclaration AU = (IASTTypedefDeclaration) i.next(); - IASTMethod f11 = (IASTMethod) i.next(); - IASTMethod f12 = (IASTMethod) i.next(); - IASTMethod g = (IASTMethod) i.next(); - - IASTVariable au = (IASTVariable) getDeclarations( g ).next(); - IASTVariable b = (IASTVariable) getDeclarations( h ).next(); - - assertAllReferences( 13, createTaskList( new Task( A ), - new Task( T ), - new Task( U, 2 ), - new Task( AU, 2 ), - new Task( au ), - new Task( x, 2 ), - new Task( f11, 1, false, false ), - new Task( B ), - new Task( b ), - new Task( f21, 1, false, false ) ) ); - } - - public void testInstantiatingDeferredInstances() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > struct A { A < T > next; }; \n" ); //$NON-NLS-1$ - writer.write( "A< int > a; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTField next = (IASTField) getDeclarations( A ).next(); - IASTVariable a = (IASTVariable) i.next(); - - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( T ) ) ); - } - - public void testTemplateArgumentDeduction() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template< class T > struct B {}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T > struct D : public B < T > {}; \n" ); //$NON-NLS-1$ - writer.write( "struct D2 : public B< int > {}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T > T f( B<T> & ) {} \n" ); //$NON-NLS-1$ - writer.write( "void test( int ); \n" ); //$NON-NLS-1$ - writer.write( "void test( char ); \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( " D<int> d; \n" ); //$NON-NLS-1$ - writer.write( " D2 d2; \n" ); //$NON-NLS-1$ - writer.write( " test( f( d ) ); \n" ); //$NON-NLS-1$ - writer.write( " test( f( d2 ) ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateB = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateD = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier D2 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTemplateDeclaration templateF = (IASTTemplateDeclaration) i.next(); - IASTFunction test1 = (IASTFunction) i.next(); - IASTFunction test2 = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - - assertFalse( i.hasNext() ); - assertReferenceTask( new Task( test1, 2, false, false ) ); - } - public void testClassTemplateStaticMemberDefinition() throws Exception { - Writer writer = new StringWriter(); - writer.write( "template< class T > class A{ \n" ); //$NON-NLS-1$ - writer.write( " typedef T * PT; \n" ); //$NON-NLS-1$ - writer.write( " static T * member; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T> A<T>::PT A<T>::member = null; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T1 = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T2 = (IASTTemplateParameter) template2.getTemplateParameters().next(); - - IASTField member = (IASTField) getDeclarations( template2 ).next(); - assertEquals( member.getName(), "member" ); //$NON-NLS-1$ - - assertReferenceTask( new Task( T1, 2, false, false ) ); - assertReferenceTask( new Task( T2, 2, false, false ) ); - } - - public void testTemplateTemplateParameter() throws Exception{ - Writer writer = new StringWriter(); - writer.write( " template< class T > class A { "); //$NON-NLS-1$ - writer.write( " int x; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " template < class T > class A < T * > { "); //$NON-NLS-1$ - writer.write( " long x; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " template< template< class U > class V > class C{ "); //$NON-NLS-1$ - writer.write( " V< int > y; "); //$NON-NLS-1$ - writer.write( " V< int * > z; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " void f( int ); "); //$NON-NLS-1$ - writer.write( " void f( long ); "); //$NON-NLS-1$ - writer.write( " void main() { "); //$NON-NLS-1$ - writer.write( " C< A > c; "); //$NON-NLS-1$ - writer.write( " f( c.y.x ); "); //$NON-NLS-1$ - writer.write( " f( c.z.x ); "); //$NON-NLS-1$ - writer.write( " } "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateA2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateC = (IASTTemplateDeclaration) i.next(); - - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - IASTVariable c = (IASTVariable) getDeclarations( main ).next(); - - IASTSimpleTypeSpecifier spec = (IASTSimpleTypeSpecifier) c.getAbstractDeclaration().getTypeSpecifier(); - IASTClassSpecifier C = (IASTClassSpecifier) spec.getTypeSpecifier(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 1, false, false ) ); - } - - public void testBug56834() throws Exception{ - Iterator i = parse( "template < class T, class U = T > class A;" ).getDeclarations(); //$NON-NLS-1$ - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - assertFalse( i.hasNext() ); - - i = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) i.next(); - IASTTemplateParameter U = (IASTTemplateParameter) i.next(); - } - - public void testDefaultTemplateParameters() throws Exception { - Iterator i = parse( "template < class T = int > class A{}; A<> a;" ).getDeclarations(); //$NON-NLS-1$ - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTVariable a = (IASTVariable) i.next(); - } - - public void testBug56834WithInstantiation() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template< class T, class U = T > class A {};" ); //$NON-NLS-1$ - writer.write( "A< char > a;" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTVariable a = (IASTVariable) i.next(); - } - - public void testDefaultTemplateParameterWithDeferedInstance() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > class A; \n" ); //$NON-NLS-1$ - writer.write( "template < class U, class V = A< U > > class B; \n" ); //$NON-NLS-1$ - writer.write( "B< int > b;" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateB = (IASTTemplateDeclaration) i.next(); - IASTVariable b = (IASTVariable) i.next(); - } - - public void testExplicitInstantiation() throws Exception{ - - Writer writer = new StringWriter(); - writer.write( "template < class T > class A { }; " ); //$NON-NLS-1$ - writer.write( "template class A< int >; " ); //$NON-NLS-1$ - writer.write( "A< int > a; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTTemplateInstantiation instance = (IASTTemplateInstantiation) i.next(); - IASTVariable var = (IASTVariable) i.next(); - - assertAllReferences( 2, createTaskList( new Task( A, 2 ) ) ); - } - - public void testTemplateParametersInExpressions() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Tp > power( _Tp, unsigned int ); \n" ); //$NON-NLS-1$ - writer.write( "template < typename _Tp > _Tp helper( _Tp __x, int _n ) \n" ); //$NON-NLS-1$ - writer.write( "{ " ); //$NON-NLS-1$ - writer.write( " return n < 0 ? _Tp( 1 ) / power( __x, -__n ) \n" ); //$NON-NLS-1$ - writer.write( " : power( __x, __n ); \n" ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - parse( writer.toString () ); - } - - public void testBug44338() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < bool T > class A { "); //$NON-NLS-1$ - writer.write( " void foo( bool b = T ); "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "typedef A< 1 < 2 > A_TRUE; "); //$NON-NLS-1$ - writer.write( "typedef A< ( 1 > 2 ) > A_FALSE; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTypedefDeclaration a_true = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration a_false = (IASTTypedefDeclaration) i.next(); - } - - public void testBug44338_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < int i > class X {}; "); //$NON-NLS-1$ - writer.write( "template < class T > class Y {}; "); //$NON-NLS-1$ - writer.write( "Y< X < 1 > > y1; "); //$NON-NLS-1$ - writer.write( "Y< X < 6 >> 1 > > y2; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateX = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateY = (IASTTemplateDeclaration) i.next(); - IASTVariable y1 = (IASTVariable) i.next(); - IASTVariable y2 = (IASTVariable) i.next(); - } - - public void testBug4338_3() throws Exception - { - try{ - //this is expected to fail the parse - parse( "template < int i > class X {}; X< 1 > 2 > x; " ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - } - - public void testBug57754() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class A{ "); //$NON-NLS-1$ - writer.write(" typedef int _type; "); //$NON-NLS-1$ - writer.write(" void f( _type, T ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template < class T > void A< T >::f( _type, T ) {} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cls = (IASTClassSpecifier) template.getOwnedDeclaration(); - - i = getDeclarations( cls ); - IASTTypedefDeclaration _type = (IASTTypedefDeclaration) i.next(); - - assertReferenceTask( new Task( _type, 2 ) ); - } - - public void testContructorsAndExplicitSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class A { "); //$NON-NLS-1$ - writer.write(" A(); "); //$NON-NLS-1$ - writer.write(" A( int ); "); //$NON-NLS-1$ - writer.write(" ~A(); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template <> A< char >::~A(); "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateSpecialization spec = (IASTTemplateSpecialization) i.next(); - } - - public void testTemplateMemberTemplateDefinition() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template< typename _Tp > "); //$NON-NLS-1$ - writer.write( "class list "); //$NON-NLS-1$ - writer.write( "{ "); //$NON-NLS-1$ - writer.write( " template<typename _S> void merge(list&, _S); "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - - writer.write( "template < typename _Tp > "); //$NON-NLS-1$ - writer.write( "template < typename _S > "); //$NON-NLS-1$ - writer.write( "void list<_Tp>::merge(list<_Tp>& __x, _S __comp) "); //$NON-NLS-1$ - writer.write( "{} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration temp2 = (IASTTemplateDeclaration) i.next(); - } - - public void test_14_7_3__5_ExplicitSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template< class T > struct A { "); //$NON-NLS-1$ - writer.write(" void f( T ) {} "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template <> struct A< int >{ "); //$NON-NLS-1$ - writer.write(" void f( int ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("void A< int >::f( int ){ } "); //$NON-NLS-1$ - - writer.write("void main(){ "); //$NON-NLS-1$ - writer.write(" A<int> a; "); //$NON-NLS-1$ - writer.write(" a.f( 1 ); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTTemplateSpecialization spec = (IASTTemplateSpecialization) i.next(); - IASTMethod f = (IASTMethod) i.next(); - IASTFunction main = (IASTFunction) i.next(); - - IASTClassSpecifier ASpec = (IASTClassSpecifier) spec.getOwnedDeclaration(); - - i = getDeclarations( main ); - IASTVariable a = (IASTVariable) i.next(); - - assertAllReferences( 5, createTaskList( new Task( T ), new Task( ASpec, 2 ), new Task( a ), new Task( f ) ) ); - } - public void test_14_7_3__11_ExplicitSpecializationArgumentDeduction() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class Array { }; "); //$NON-NLS-1$ - writer.write("template < class T > void sort( Array< T > & ); "); //$NON-NLS-1$ - writer.write("template<> void sort( Array< int > & ){} "); //$NON-NLS-1$ - writer.write("void f(){ "); //$NON-NLS-1$ - writer.write(" Array<int> a1; "); //$NON-NLS-1$ - writer.write(" Array<char> a2; "); //$NON-NLS-1$ - writer.write(" sort( a1 ); "); //$NON-NLS-1$ - writer.write(" sort( a2 ); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateArray = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateSort = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration sortSpec = (IASTTemplateDeclaration) i.next(); - IASTFunction f = (IASTFunction) i.next(); - - IASTFunction sort1 = (IASTFunction) templateSort.getOwnedDeclaration(); - IASTFunction sort2 = (IASTFunction) sortSpec.getOwnedDeclaration(); - - assertReferenceTask( new Task( sort1, 1, false, false ) ); - assertReferenceTask( new Task( sort2, 1, false, false ) ); - } - - public void test_14_8_1__2_ExplicitArgumentSpecification() throws Exception{ - Writer writer = new StringWriter(); - writer.write("void f( int ){} //#1 \n"); //$NON-NLS-1$ - writer.write("template < class T > void f( T ){} //#2 \n"); //$NON-NLS-1$ - writer.write("int main(){ \n"); //$NON-NLS-1$ - writer.write(" f( 1 ); //calls #1 \n"); //$NON-NLS-1$ - writer.write(" f<int>( 1 ); //calls #2 \n"); //$NON-NLS-1$ - writer.write(" f<> ( 1 ); //calls #2 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction f1 = (IASTFunction) i.next(); - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTFunction f2 = (IASTFunction) template.getOwnedDeclaration(); - IASTFunction main = (IASTFunction) i.next(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 2, false, false ) ); - } - - public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template< class T > void f( T ); "); //$NON-NLS-1$ - writer.write("template< class T > void f( T * ); "); //$NON-NLS-1$ - writer.write("template <> void f< int*>( int * );"); //$NON-NLS-1$ - writer.write("template <> void f< int >( int * );"); //$NON-NLS-1$ - writer.write("template <> void f( char ); "); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testPartialSpecializationDefinitions() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template < class T1, class T2 > class A { void f(); };"); //$NON-NLS-1$ - writer.write("template < class T > class A < T, T > { void f(); };"); //$NON-NLS-1$ - writer.write("template < class T > class A < char, T > { void f(); };"); //$NON-NLS-1$ - - writer.write("template < class U, class V > void A<U, V>::f(){} "); //$NON-NLS-1$ - writer.write("template < class W > void A < W, W >::f(){} "); //$NON-NLS-1$ - writer.write("template < class X > void A < char, X >::f(){} "); //$NON-NLS-1$ - - writer.write("void main(){ "); //$NON-NLS-1$ - writer.write(" A< int, char > a1; "); //$NON-NLS-1$ - writer.write(" a1.f(); "); //$NON-NLS-1$ - writer.write(" A< int, int > a2; "); //$NON-NLS-1$ - writer.write(" a2.f(); "); //$NON-NLS-1$ - writer.write(" A< char, int > a3; "); //$NON-NLS-1$ - writer.write(" a3.f(); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration t1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t3 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t4 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t5 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t6 = (IASTTemplateDeclaration) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - IASTMethod f1 = (IASTMethod) t4.getOwnedDeclaration(); - IASTMethod f2 = (IASTMethod) t5.getOwnedDeclaration(); - IASTMethod f3 = (IASTMethod) t6.getOwnedDeclaration(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 1, false, false ) ); - assertReferenceTask( new Task( f3, 1, false, false ) ); - } - - public void test_14_5_2__2_MemberFunctionTemplates() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template < class T > struct A { "); //$NON-NLS-1$ - writer.write(" void f( int ); "); //$NON-NLS-1$ - writer.write(" template < class T2 > void f( T2 ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - - writer.write("template <> void A<int>::f(int) {} //non-template member \n"); //$NON-NLS-1$ - writer.write("template <> template<> void A<int>::f<>( int ) {} //template member \n"); //$NON-NLS-1$ - - writer.write("int main(){ "); //$NON-NLS-1$ - writer.write(" A< int > ac; "); //$NON-NLS-1$ - writer.write(" ac.f( 1 ); //non-template \n"); //$NON-NLS-1$ - writer.write(" ac.f( 'c' ); //template \n"); //$NON-NLS-1$ - writer.write(" ac.f<>(1); //template \n"); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec2 = (IASTTemplateDeclaration) i.next(); - - IASTMethod f1 = (IASTMethod) spec1.getOwnedDeclaration(); - IASTMethod f2 = (IASTMethod) spec2.getOwnedDeclaration();; - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - //we aren't going to be completely correct about references to explicit specializations - //due to limitations in the implementation, see bug 59811 - } - - public void testBug64753() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class _T > void foo () { \n" ); //$NON-NLS-1$ - writer.write( " if( 1 ) { \n" ); //$NON-NLS-1$ - writer.write( " _T p1, p2; \n" ); //$NON-NLS-1$ - writer.write( " int n = p1 - p2; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration foo = (IASTTemplateDeclaration) i.next(); - } - - public void testBug64919() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Foo{}; "); //$NON-NLS-1$ - writer.write("class Bar{}; "); //$NON-NLS-1$ - writer.write("template <class T, class U> class A {}; "); //$NON-NLS-1$ - writer.write("template < class X > class A < X, X > : public A< X, Bar> "); //$NON-NLS-1$ - writer.write("{ typedef int TYPE; }; "); //$NON-NLS-1$ - writer.write("template < class X > class A < X, Foo > : public A< X, X > "); //$NON-NLS-1$ - writer.write("{ void f ( TYPE ); }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier Foo = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier Bar = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTemplateDeclaration T1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration T2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration T3 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier A1 = (IASTClassSpecifier) T1.getOwnedDeclaration(); - IASTClassSpecifier A2 = (IASTClassSpecifier) T2.getOwnedDeclaration(); - IASTClassSpecifier A3 = (IASTClassSpecifier) T3.getOwnedDeclaration(); - - IASTBaseSpecifier parent = (IASTBaseSpecifier) A2.getBaseClauses().next(); - assertEquals( parent.getParentClassSpecifier(), A1 ); - - parent = (IASTBaseSpecifier) A3.getBaseClauses().next(); - assertEquals( parent.getParentClassSpecifier(), A2 ); - } - - public void testBug64939() throws Exception - { - try{ - parse( "template < class T > class A : public A< T * > {}; A<int> a;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - - try{ - parse( "template < class T > class A { A<T*> f(); }; A< int > a;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - } - - public void testBug65114() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Tp, typename _Alloc > class _simple_alloc {}; \n" ); //$NON-NLS-1$ - writer.write( "template < int _inst > class __malloc_alloc {}; \n" ); //$NON-NLS-1$ - writer.write( "template < typename _Tp, int __inst> \n" ); //$NON-NLS-1$ - writer.write( "struct _Alloc_traits { \n" ); //$NON-NLS-1$ - writer.write( " typedef _simple_alloc< _Tp, __malloc_alloc<__inst> > _Alloc_type; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration simple_alloc = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration malloc_alloc = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration alloc_traits = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier alloc = (IASTClassSpecifier) alloc_traits.getOwnedDeclaration(); - i = alloc_traits.getTemplateParameters(); - IASTTemplateParameter _Tp = (IASTTemplateParameter) i.next(); - IASTTemplateParameter inst = (IASTTemplateParameter) i.next(); - - IASTClassSpecifier simple = (IASTClassSpecifier) simple_alloc.getOwnedDeclaration(); - IASTClassSpecifier malloc = (IASTClassSpecifier) malloc_alloc.getOwnedDeclaration(); - - assertAllReferences( 4, createTaskList( new Task( simple ), new Task( _Tp ), - new Task( malloc ), new Task( inst ) ) ); - } - - public void testBug655114_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Alloc > class base_allocator { int _Tp; }; \n"); //$NON-NLS-1$ - writer.write( "template < class T > class B {}; \n"); //$NON-NLS-1$ - writer.write( "template <> class B < int > {}; \n"); //$NON-NLS-1$ - writer.write( "template < typename _Alloc > class allocator; \n"); //$NON-NLS-1$ - writer.write( "template < typename _Tp > class allocator : base_allocator<_Tp>, B<_Tp> {}; \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration base = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier baseCls = (IASTClassSpecifier) base.getOwnedDeclaration(); - - IASTTemplateDeclaration B1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration B2 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier B1cls = (IASTClassSpecifier) B1.getOwnedDeclaration(); - IASTClassSpecifier B2cls = (IASTClassSpecifier) B2.getOwnedDeclaration(); - - IASTTemplateDeclaration forward = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration allocator = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier cls = (IASTClassSpecifier) allocator.getOwnedDeclaration(); - i = cls.getBaseClauses(); - IASTBaseSpecifier clause = (IASTBaseSpecifier) i.next(); - assertEquals( clause.getParentClassSpecifier(), baseCls ); - clause = (IASTBaseSpecifier) i.next(); - assertEquals( clause.getParentClassSpecifier(), B1cls ); - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java deleted file mode 100644 index f7e3d4f11da..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ /dev/null @@ -1,2082 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003,2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -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.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -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.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.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -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.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ParserException; - - -/** - * @author jcamelon - * - */ -public class CompleteParseASTTest extends CompleteParseBaseTest -{ - /** - * @param a - */ - public CompleteParseASTTest(String a) - { - super(a); - } - - public void testEmptyCompilationUnit() throws Exception - { - IASTScope compilationUnit = parse( "// no real code "); //$NON-NLS-1$ - assertNotNull( compilationUnit ); - assertFalse( compilationUnit.getDeclarations().hasNext() ); - } - - 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( getDeclarations( namespaceDefinition ).hasNext() ); - } - - 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$ - namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( getDeclarations( namespaceDefinition ).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 = getDeclarations( namespaceDefinition ); - 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$ - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier(); - assertEquals( classSpec.getName(), "A"); //$NON-NLS-1$ - assertFalse( getDeclarations( classSpec ).hasNext() ); - assertFalse( declarations.hasNext() ); - } - - public void testSimpleSubclass() throws Exception - { - Iterator declarations = parse( "class A { }; class B : public A { };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator parentClasses = classB.getBaseClauses(); - IASTBaseSpecifier baseClass = (IASTBaseSpecifier)parentClasses.next(); - assertEquals( classA, baseClass.getParentClassSpecifier() ); - assertEquals( baseClass.getParentClassName(), "A"); //$NON-NLS-1$ - assertEquals( baseClass.getAccess(), ASTAccessVisibility.PUBLIC); - assertFalse( baseClass.isVirtual() ); - } - - 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(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)getDeclarations( namespaceDefinition).next() ).getTypeSpecifier(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator baseClauses = classB.getBaseClauses(); - IASTBaseSpecifier baseClass = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( classA, baseClass.getParentClassSpecifier() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - 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$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testSimpleClassReferenceVariable() throws Exception - { - Iterator declarations = parse( "class A { }; A x;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertAllReferences( 1, createTaskList( new Task( classA ))); - } - - public void testNestedClassReferenceVariable() throws Exception - { - Iterator declarations = parse( "namespace N { class A { }; } N::A x;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)declarations.next(); - Iterator iter = getDeclarations( namespace ); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testMultipleDeclaratorsVariable() throws Exception - { - Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 3 ); - Iterator i = callback.getReferences().iterator(); - while( i.hasNext() ) - assertEquals( ((IASTReference)i.next()).getReferencedElement(), classA ); - } - - public void testSimpleField() throws Exception - { - Iterator declarations = parse( "class A { double x; };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator fields =getDeclarations(classA); - IASTField f = (IASTField)fields.next(); - assertEquals( f.getName(), "x" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - } - - public void testUsingClauses() throws Exception - { - Iterator declarations = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n using namespace A::B;\n using A::B::x;using A::B::C;using A::B::C::y;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - IASTNamespaceDefinition namespaceB = (IASTNamespaceDefinition)getDeclarations( namespaceA ).next(); - Iterator i = getDeclarations( namespaceB ); - IASTVariable variableX = (IASTVariable)i.next(); - IASTClassSpecifier classC = ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()); - IASTField fieldY = (IASTField)getDeclarations( classC ).next(); - assertQualifiedName( fieldY.getFullyQualifiedName(), new String [] { "A", "B", "C", "y" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - IASTUsingDirective directive = (IASTUsingDirective)declarations.next(); - assertEquals( directive.getNamespaceDefinition(), namespaceB ); - assertEquals( directive.getNamespaceName(), "A::B" ); //$NON-NLS-1$ - IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), variableX ); - declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), classC ); - declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), fieldY ); - assertEquals( callback.getReferences().size(), 12 ); - - } - - 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 = getDeclarations( namespaceA ); - IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)namespaceMembers.next()).getTypeSpecifier(); - 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 ); - } - - 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$ - assertEquals( callback.getReferences().size(), 0 ); - } - - public void testSimpleFunctionWithTypes() throws Exception - { - Iterator declarations = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator classDecls = getDeclarations(classA); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)classDecls.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction)declarations.next(); - assertAllReferences( 3, createTaskList( new Task( classA ,2), new Task(classB))); - } - - public void testSimpleMethod() throws Exception - { - Iterator declarations = parse( "class A { void foo(); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); - assertEquals( method.getName(), "foo" ); //$NON-NLS-1$ - } - - public void testSimpleMethodWithTypes() throws Exception - { - Iterator declarations = parse( "class U { }; class A { U foo( U areDumb ); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classU = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); - assertEquals( method.getName(), "foo" ); //$NON-NLS-1$ - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testUsingDeclarationWithFunctionsAndMethods() throws Exception - { - Iterator declarations = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ).getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - IASTFunction fooFunction = (IASTFunction)(getDeclarations(namespaceN).next()); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod methodM = (IASTMethod)(getDeclarations(classA).next()); - IASTUsingDeclaration using1 = (IASTUsingDeclaration)declarations.next(); - IASTUsingDeclaration using2 = (IASTUsingDeclaration)declarations.next(); - assertEquals( callback.getReferences().size(), 4 ); - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), namespaceN ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), fooFunction ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), classA ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), methodM ); - } - - public void testLinkageSpec() throws Exception - { - IASTLinkageSpecification linkage = (IASTLinkageSpecification)parse( "extern \"C\" { int foo(); }").getDeclarations().next(); //$NON-NLS-1$ - Iterator i = getDeclarations( linkage ); - IASTFunction f = (IASTFunction)i.next(); - assertEquals( f.getName(),"foo"); //$NON-NLS-1$ - } - - - public void testBogdansExample() throws Exception - { - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)parse( "namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} ").getDeclarations().next(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceB = (IASTNamespaceDefinition)(getDeclarations(namespaceA).next()); - Iterator subB = getDeclarations( namespaceB ); - IASTEnumerationSpecifier enumE1 = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)subB.next()).getTypeSpecifier(); - Iterator enumerators = enumE1.getEnumerators(); - IASTEnumerator enumeratorE_1 = (IASTEnumerator)enumerators.next(); - assertEquals( enumeratorE_1.getOwnerEnumerationSpecifier(), enumE1 ); - IASTVariable variableX = (IASTVariable)subB.next(); - IASTClassSpecifier classC = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)subB.next()).getTypeSpecifier(); - } - - public void testAndrewsExample() throws Exception - { - Iterator declarations = parse( "namespace N{ class A {}; } using namespace N; class B: public A{};").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)getDeclarations( namespaceN ).next()).getTypeSpecifier(); - IASTUsingDirective usingClause = (IASTUsingDirective)declarations.next(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)classB.getBaseClauses().next(); - assertEquals( baseSpec.getParentClassSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 2 ); - } - - 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$ - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testComplexTypedef() throws Exception - { - Iterator declarations = parse( "class A{ }; typedef A ** A_DOUBLEPTR;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)declarations.next(); - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 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]); - } - } - - public void testBug40842() throws Exception{ - Writer code = new StringWriter(); - - code.write("class A {} a;\n"); //$NON-NLS-1$ - Iterator i = parse(code.toString()).getDeclarations(); - IASTVariable instanceA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 0 ); - } - - public void testNestedClassname() throws Exception - { - Iterator declarations = parse( "namespace A { } \n class A::B { };").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertEquals( classB.getOwnerScope(), namespaceA ); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testForwardDeclaration() throws Exception - { - Iterator i = parse( "class forward;").getDeclarations(); //$NON-NLS-1$ - assertTrue( i.hasNext() ); - IASTAbstractTypeSpecifierDeclaration d = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)d.getTypeSpecifier(); - assertEquals( elab.getName(), "forward"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.CLASS ); - } - - public void testElaboratedType() throws Exception - { - Iterator i = parse( "class A; class A * a;").getDeclarations(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( elab.getName(), "A" ); //$NON-NLS-1$ - IASTVariable variableA = (IASTVariable)i.next(); - assertEquals( variableA.getName(), "a"); //$NON-NLS-1$ - assertEquals( variableA.getAbstractDeclaration().getTypeSpecifier(), elab ); - } - - public void testForewardDeclarationWithUsage() throws Exception - { - Iterator declarations = parse( "class A; A * anA;class A { };").getDeclarations(); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTVariable variable = (IASTVariable)declarations.next(); - IASTAbstractTypeSpecifierDeclaration classDecl = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)forewardDecl.getTypeSpecifier(); - IASTClassSpecifier clasSpec = (IASTClassSpecifier)classDecl.getTypeSpecifier(); - assertEquals( elab.getName(), clasSpec.getName() ); - String [] fqnClass = clasSpec.getFullyQualifiedName(); - String [] fqnElab = elab.getFullyQualifiedName(); - assertEquals( fqnClass.length, fqnElab.length ); - for( int i = 0; i < fqnClass.length; ++i ) - assertEquals( fqnClass[i], fqnElab[i]); - assertEquals( callback.getReferences().size(), 1 ); - assertEquals( callback.getForewardDecls().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertTrue( ref.getReferencedElement() instanceof IASTElaboratedTypeSpecifier ); - assertEquals( ref.getReferencedElement(), elab ); - } - - - public void testASM() throws Exception - { - IASTASMDefinition asm = (IASTASMDefinition)parse( "asm ( \"blah blah blah\" );" ).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( asm.getBody(), "blah blah blah"); //$NON-NLS-1$ - } - - 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 testSimpleExpression() throws Exception - { - Iterator i = parse( "int x; int y = x;").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable varY = (IASTVariable)i.next(); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testParameterExpressions() throws Exception - { - Iterator i = parse( "int x = 5; void foo( int sub = x ) { }").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTFunction funFoo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testNestedNamespaceExpression() throws Exception - { - Iterator i = parse( "namespace A { int x = 666; } int y = A::x;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)i.next(); - IASTVariable variableY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testConstructorChain() throws Exception - { - Iterator i = parse( "int x = 5;\n class A \n{ public : \n int a; \n A() : a( x ) { } };").getDeclarations(); //$NON-NLS-1$ - IASTVariable variableX = (IASTVariable)i.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator s = getDeclarations( classA ); - IASTField fieldA = (IASTField)s.next(); - IASTMethod methodA = (IASTMethod)s.next(); - assertFalse( s.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( fieldA), new Task( variableX ))); - } - - public void testArrayModExpression() throws Exception - { - Iterator i = parse( "const int x = 5; int y [ x ]; ").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable varY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - } - - - public void testPointerVariable() throws Exception - { - Iterator i = parse( "class A { }; A * anA;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable varAnA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertEquals( ref.getReferencedElement(), classA ); - } - - public void testExceptionSpecification() throws Exception - { - Iterator i = parse( "class A { }; void foo( void ) throw ( A );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertEquals( ref.getReferencedElement(), classA ); - } - - public void testNewExpressions() throws Exception - { - Iterator declarations = parse( "int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable variableA = (IASTVariable)declarations.next(); - IASTVariable variableB = (IASTVariable)declarations.next(); - IASTVariable variableC = (IASTVariable)declarations.next(); - IASTVariable variableD = (IASTVariable)declarations.next(); - IASTVariable variableP = (IASTVariable)declarations.next(); - IASTVariable variablep = (IASTVariable)declarations.next(); - assertEquals( callback.getReferences().size(), 5 ); - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableP ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableB ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD ); - } - - public void testBug41520() throws Exception - { - Iterator i = parse( "const int x = 666; const int y( x );").getDeclarations(); //$NON-NLS-1$ - IASTVariable variableX = (IASTVariable)i.next(); - IASTVariable variableY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - } - - public void testNewXReferences() throws Exception - { - Iterator declarations = parse( "const int max = 5;\n int * x = new int[max];").getDeclarations(); //$NON-NLS-1$ - IASTVariable max = (IASTVariable) declarations.next(); - IASTVariable x = (IASTVariable) declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTVariableReference maxRef = (IASTVariableReference) callback.getReferences().get(0); - assertEquals( maxRef.getReferencedElement(), max ); - } - - public void testQualifiedNameReferences() throws Exception - { - // Used to cause AST Semantic exception - Iterator i = parse( "class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)j.next()).getTypeSpecifier(); - Iterator k = getDeclarations(classB); - IASTClassSpecifier classC = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)k.next()).getTypeSpecifier(); - // Note : this used to be considered a function, not a method - IASTMethod method = (IASTMethod)i.next(); - - assertAllReferences( 3, createTaskList( new Task( classA ), new Task( classB ), new Task( classC ))); - - } - - public void testIsConstructor() throws Exception - { - Iterator i = parse( "class A{ public: A(); }; \n A::A() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)i.next(); - assertTrue (method.isConstructor()); - } - - public void testIsDestructor() throws Exception - { - Iterator i = parse( "class A{ public: ~A(); }; \n A::~A() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)i.next(); - assertTrue (method.isDestructor()); - } - - public void testBug41445() throws Exception - { - Iterator i = parse( "class A { }; namespace N { class B : public A { struct A {}; }; }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)i.next(); - Iterator sub = getDeclarations( namespaceN ); - IASTClassSpecifier classB = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)sub.next()).getTypeSpecifier(); - IASTClassSpecifier structA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)( getDeclarations( classB ).next())).getTypeSpecifier(); - } - - public void testSimpleFunctionBody() throws Exception - { - Iterator i = parse( "class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method_prototype = (IASTMethod)getDeclarations(classA).next(); - IASTVariable x = (IASTVariable) i.next(); - IASTFunction function_f = (IASTFunction) i.next(); - IASTMethod method_f = (IASTMethod)i.next(); - assertEquals( method_f.getName(), method_prototype.getName() ); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - IASTVariableReference referenceX = (IASTVariableReference) callback.getReferences().get(0); - assertEquals( referenceX.getReferencedElement(), x ); - IASTClassReference referenceA = (IASTClassReference) callback.getReferences().get(1); - assertEquals( referenceA.getReferencedElement(), classA ); - referenceX = (IASTVariableReference) callback.getReferences().get(2); - assertEquals( referenceX.getReferencedElement(), x ); - } - - - public void testSimpleForLoop() throws Exception - { - Iterator i = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) { x += i; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable five = (IASTVariable) i.next(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 5 ); - i = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) x += i; }").getDeclarations(); //$NON-NLS-1$ - five = (IASTVariable) i.next(); - f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 5 ); - - i = parse( "class A { }; void f() { for( int i = 0; i < (A*)0; ++i ) { A anA; } }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - f = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 4 ); - } - - public void testBug42541() throws Exception - { - Iterator i = parse( "union{ int v; char a; } id;" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable id = (IASTVariable)i.next(); - - IASTClassSpecifier union = (IASTClassSpecifier) id.getAbstractDeclaration().getTypeSpecifier(); - Iterator sub = getDeclarations( union ); - IASTField intV = (IASTField)sub.next(); - IASTField charA = (IASTField)sub.next(); - } - - - - public void testSimpleIfStatement() throws Exception - { - Iterator i = parse( "const bool T = true; int foo() { if( T ) { return 5; } else if( ! T ) return 20; else { return 10; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable t = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleWhileStatement() throws Exception - { - Iterator i = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable t = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - } - - public void testSimpleSwitchStatement() throws Exception - { - Iterator i = parse( "const int x = 5; const int y = 10; void foo() { switch( x ) { case 1: break; case 2: goto blah; case y: continue; default: break;} }").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleDoStatement() throws Exception - { - Iterator i = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - IASTVariable counter = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - } - - public void testThrowStatement() throws Exception - { - Iterator i = parse( "class A { }; void foo() throw ( A ) { throw A; throw; } ").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction functionF = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - for( int j = 0; j < 2; ++j ) - assertEquals( ((IASTReference)callback.getReferences().get(j) ).getReferencedElement(), classA ); - } - - public void testScoping() throws Exception - { - Iterator i = parse( "void foo() { int x = 3; if( x == 1 ) { int x = 4; } else int x = 2; }").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)i.next(); - Iterator subDeclarations = getDeclarations(f); - IASTVariable topX = (IASTVariable)subDeclarations.next(); - assertEquals( topX.getInitializerClause().getAssigmentExpression().getLiteralString(), "3"); //$NON-NLS-1$ - assertEquals( topX.getName(), "x"); //$NON-NLS-1$ - assertFalse( subDeclarations.hasNext() ); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - assertEquals( ((IASTReference)callback.getReferences().get(0)).getReferencedElement(), topX ); - - Iterator level1 = getNestedScopes( f ); - IASTCodeScope codeScope = (IASTCodeScope)level1.next(); - Iterator subSubDeclarations = getDeclarations(codeScope); - IASTVariable secondX = (IASTVariable)subSubDeclarations.next(); - assertEquals( secondX.getInitializerClause().getAssigmentExpression().getLiteralString(), "4"); //$NON-NLS-1$ - codeScope = (IASTCodeScope)level1.next(); - assertFalse( level1.hasNext() ); - subSubDeclarations = getDeclarations(codeScope); - IASTVariable thirdX = (IASTVariable)subSubDeclarations.next(); - assertEquals( thirdX.getInitializerClause().getAssigmentExpression().getLiteralString(), "2"); //$NON-NLS-1$ - - } - - public void testEnumeratorReferences() throws Exception - { - Iterator i = parse( "enum E { e1, e2, e3 }; E anE = e1;").getDeclarations(); //$NON-NLS-1$ - IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable anE = (IASTVariable)i.next(); - IASTEnumerator e1 = (IASTEnumerator)enumE.getEnumerators().next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - assertEquals( ((IASTReference)callback.getReferences().get(0)).getReferencedElement(), enumE ); - assertEquals( ((IASTReference)callback.getReferences().get(1)).getReferencedElement(), e1 ); - } - - public void testBug42840() throws Exception - { - Iterator i = parse( "void foo(); void foo() { } class SearchMe { };").getDeclarations(); //$NON-NLS-1$ - IASTFunction fooDeclaration = (IASTFunction)i.next(); - IASTFunction fooDefinition = (IASTFunction)i.next(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - assertTrue( callback.getReferences().isEmpty()); - - i = parse( "class A { void f ( A ); }; void A::f( A ){ return; }" ).getDeclarations(); //$NON-NLS-1$ - classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod fooMethodDefinition = (IASTMethod)i.next(); - assertFalse( i.hasNext() ); - Iterator subIterator = getDeclarations( classSpec ); - IASTMethod fooMethodDeclaration = (IASTMethod)subIterator.next(); - assertFalse( subIterator.hasNext()); - Iterator references = callback.getReferences().iterator(); - assertEquals( callback.getReferences().size(), 3 ); - for( int j = 0; j < 3; ++j) - assertEquals( ((IASTReference)callback.getReferences().get( j )).getReferencedElement(), classSpec ); - - } - - public void testBug42872() throws Exception - { - Iterator i = parse( "struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast<B*>(dp); }" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier structB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier structD = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo = (IASTFunction)i.next(); - IASTVariable bp = (IASTVariable)getDeclarations(foo).next(); - assertFalse( i.hasNext() ); - } - - public void testBug43503A() throws Exception { - Iterator i = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod f = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - IASTFunction main = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - Iterator k = getDeclarations(main); - assertTrue(k.hasNext()); - } - - - public void testBug42979() throws Exception - { - Writer code = new StringWriter(); - code.write( "class OperatorOverload{\n" ); //$NON-NLS-1$ - code.write( "public:\n" ); //$NON-NLS-1$ - code.write( " bool operator==( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( " { return true; }\n" ); //$NON-NLS-1$ - code.write( " bool operator!=( const class OperatorOverload& that );\n" ); //$NON-NLS-1$ - code.write( "}; \n" ); //$NON-NLS-1$ - - code.write( "bool OperatorOverload::operator!=( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( "{ return false; }\n" ); //$NON-NLS-1$ - - Iterator i = parse( code.toString() ).getDeclarations(); - IASTClassSpecifier classOp = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator subDeclarations = getDeclarations(classOp); - IASTMethod operatorEqualsDeclaration = (IASTMethod)subDeclarations.next(); - IASTMethod operatorNotEqualsDeclaration = (IASTMethod)subDeclarations.next(); - IASTMethod operatorNotEqualDefinition = (IASTMethod)i.next(); - assertEquals( operatorNotEqualDefinition.getName(), operatorNotEqualsDeclaration.getName() ); - assertFalse( i.hasNext()); - assertEquals( callback.getReferences().size(), 4 ); - for( int j =0; j < 4; ++j ) - assertFalse( classOp.getNameOffset() == ((IASTReference)callback.getReferences().get(j)).getOffset() ); - } - /** - * class A { static int x; } int A::x = 5; - */ - public void testBug43373() throws Exception - { - Iterator i = parse( "class A { static int x; }; int A::x = 5;" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTField field1 = (IASTField) j.next(); - // Note : this used to be considered a variable, not a field - IASTField field2 = (IASTField)i.next(); - assertTrue (field1.getVisiblity() == field2.getVisiblity()); - assertAllReferences( 1, createTaskList( new Task( classA ))); - } - - public void testBug39504() throws Exception - { - Iterator i = parse( "const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable varW = (IASTVariable)i.next(); - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable vary = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testBug43375() throws Exception - { - IASTVariable varX = (IASTVariable)parse( "extern int x;").getDeclarations().next(); //$NON-NLS-1$ - assertTrue( varX.isExtern() ); - } - - public void testBug43503() throws Exception - { - StringBuffer buff = new StringBuffer(); - - buff.append( "class SD_02 {"); //$NON-NLS-1$ - buff.append( " public:"); //$NON-NLS-1$ - buff.append( " void f_SD_02();"); //$NON-NLS-1$ - buff.append( " };"); //$NON-NLS-1$ - buff.append( "class SD_01 {\n"); //$NON-NLS-1$ - buff.append( " public:\n"); //$NON-NLS-1$ - buff.append( " SD_02 *next;"); // REFERENCE SD_02 //$NON-NLS-1$ - buff.append( " void f_SD_01();\n"); //$NON-NLS-1$ - buff.append( "};\n"); //$NON-NLS-1$ - buff.append( "int main(){\n"); //$NON-NLS-1$ - buff.append( " SD_01 a = new SD_01();\n"); // REFERENCE SD_01 * 2 //$NON-NLS-1$ - buff.append( " a->f_SD_01();\n"); // REFERENCE a && REFERENCE f_SD_01 //$NON-NLS-1$ - buff.append( "}\n"); //$NON-NLS-1$ - buff.append( "void SD_01::f_SD_01()\n"); // REFERENCE SD_01 //$NON-NLS-1$ - buff.append( "{\n"); //$NON-NLS-1$ - buff.append( " next->f_SD_02();\n"); // REFERENCE next && reference f_SD_02 //$NON-NLS-1$ - buff.append( "}\n"); //$NON-NLS-1$ - Iterator i = parse( buff.toString() ).getDeclarations(); - IASTClassSpecifier SD_02 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod f_SD_02 = (IASTMethod)getDeclarations( SD_02 ).next(); - IASTClassSpecifier SD_01 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField next= (IASTField)getDeclarations( SD_01 ).next(); - IASTFunction main = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)getDeclarations(main).next(); - IASTMethod f_SD_01 = (IASTMethod)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 8, createTaskList( new Task( SD_02), new Task( SD_01, 3 ), new Task( a ), new Task( f_SD_01 ), new Task( f_SD_02 ), new Task( next ) )); - } - - public void testBug43679_A () throws Exception - { - try{ // this used to throw a null pointer exception - Iterator i = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } ", false ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(A); - IASTMethod s = (IASTMethod) j.next(); - assertFalse (j.hasNext()); - IASTFunction g = (IASTFunction) i.next(); - IASTFunction t = (IASTFunction) i.next(); - assertFalse (i.hasNext()); - Iterator ref = callback.getReferences().iterator(); - assertAllReferences( 3, createTaskList( new Task(A) , new Task( s ) , new Task (g) )); - - } catch(Exception e){ - fail(); - } - } - public void testBug43679_B () throws Exception - { - try{ // this used to throw a class cast exception - Iterator i = parse( "struct Sample{int size() const; }; struct Sample; ", false ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(A); - IASTMethod s = (IASTMethod) j.next(); - assertFalse (j.hasNext()); - IASTAbstractTypeSpecifierDeclaration forwardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse (i.hasNext()); - Iterator ref = callback.getReferences().iterator(); - assertFalse (ref.hasNext()); - - } catch(Exception e){ - fail(); - } - } - - public void testBug43951() throws Exception - { - Iterator i = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}", false ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier b = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( b.getName(), "B"); //$NON-NLS-1$ - IASTMethod constructor = (IASTMethod) i.next(); - assertEquals( constructor.getName(), "B" ); //$NON-NLS-1$ - assertTrue( constructor.previouslyDeclared() ); - } - - public void testBug44342() throws Exception { - try{ - IASTScope scope = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ - Iterator i = scope.getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod f = (IASTMethod)j.next(); - IASTMethod f2 = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - IASTFunction main = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - Iterator k = getDeclarations(main); - assertTrue(k.hasNext()); - IASTVariable a = (IASTVariable)k.next(); - Iterator ref = callback.getReferences().iterator(); - assertAllReferences( 4, createTaskList( new Task(classA , 2) , new Task( a ) , new Task (f) )); - - }catch (ParserException e){ - // parsing fails for now - fail(); - } - } - - - public void testCDesignatedInitializers() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "struct Inner { int a,b,c; };"); //$NON-NLS-1$ - buffer.append( "struct A { int x; int y[]; struct Inner innerArray[]; int z []; };"); //$NON-NLS-1$ - buffer.append( "struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString(), true, ParserLanguage.C ).getDeclarations(); - IASTClassSpecifier Inner = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = getDeclarations(Inner); - IASTField a = (IASTField)members.next(); - IASTField b = (IASTField)members.next(); - IASTField c = (IASTField)members.next(); - assertFalse( members.hasNext()); - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - members = getDeclarations( A ); - IASTField x = (IASTField)members.next(); - IASTField y = (IASTField)members.next(); - IASTField innerArray = (IASTField)members.next(); - IASTField z = (IASTField)members.next(); - assertFalse( members.hasNext() ); - IASTVariable myA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 12, createTaskList( new Task( A ), - new Task( x ), - new Task( y, 2 ), - new Task( Inner ), - new Task( innerArray, 3), - new Task( a ), - new Task( b ), - new Task( c ), - new Task( z ) ) ); - } - - public void testBug39551A() throws Exception - { - IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( function.getName(), "conjf"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() ); - } - - public void testBug39551B() throws Exception - { - IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;", true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "id"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() ); - } - - public void testCBool() throws Exception - { - IASTVariable variable = (IASTVariable)parse( "_Bool x;", true, ParserLanguage.C ).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type._BOOL ); - } - - public void testCBoolAsParameter() throws Exception - { - Iterator i = parse( "void f( _Bool b ) {} " + //$NON-NLS-1$ - "_Bool g( _Bool b ) {} " + //$NON-NLS-1$ - "void main(){" + //$NON-NLS-1$ - " _Bool b; " + //$NON-NLS-1$ - " f(b);" + //$NON-NLS-1$ - " f( g( (_Bool) 1 ) );" + //$NON-NLS-1$ - "}", //$NON-NLS-1$ - true, ParserLanguage.C ).getDeclarations(); - - IASTFunction f = (IASTFunction) i.next(); - IASTFunction g = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - IASTVariable b = (IASTVariable) getDeclarations( main ).next(); - - assertAllReferences( 4, createTaskList( new Task( f, 2 ), new Task( b ), new Task( g ) ) ); - } - - public void testBug44510() throws Exception - { - Iterator i = parse( "int initialize(); " + //$NON-NLS-1$ - "int initialize( char ){} " + //$NON-NLS-1$ - "int initialize(){ return 1; } " + //$NON-NLS-1$ - "void main(){ int i = initialize(); }" ).getDeclarations(); //$NON-NLS-1$ - - IASTFunction function1 = (IASTFunction) i.next(); - assertEquals( function1.previouslyDeclared(), false ); - - IASTFunction function2 = (IASTFunction) i.next(); - assertEquals( function2.previouslyDeclared(), false ); - - IASTFunction function3 = (IASTFunction) i.next(); - assertEquals( function3.previouslyDeclared(), true ); - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 1, createTaskList( new Task( function3 ) ) ); - } - - public void testBug44925() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class MyClass { };"); //$NON-NLS-1$ - buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$ - buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$ - buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - - IASTClassSpecifier MyClass = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable myObj1 = (IASTVariable) i.next(); - IASTEnumerationSpecifier MyEnum = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable myObj2 = (IASTVariable) i.next(); - - assertFalse( i.hasNext() ); - - assertAllReferences( 2, createTaskList( new Task( MyClass ), new Task( MyEnum ) ) ); - } - - public void testBug44838() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField myX = (IASTField)getDeclarations( classA ).next(); - IASTMethod constructor = (IASTMethod)i.next(); - IASTParameterDeclaration parmX = (IASTParameterDeclaration)constructor.getParameters().next(); - assertTrue( constructor.isConstructor()); - assertFalse(i.hasNext()); - } - - public void testBug46165() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField myX = (IASTField)getDeclarations( classA ).next(); - IASTMethod constructor = (IASTMethod)i.next(); - IASTParameterDeclaration parmX = (IASTParameterDeclaration)constructor.getParameters().next(); - assertTrue( constructor.isConstructor()); - assertAllReferences( 4, createTaskList( new Task( classA ), new Task( myX, 2 ), new Task( parmX ))); - assertFalse(i.hasNext()); - } - - public void testBug47624() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "struct s { }; \n" ); //$NON-NLS-1$ - buffer.append( "void f ( int s ) { \n" ); //$NON-NLS-1$ - buffer.append( " struct s sInstance; \n" ); //$NON-NLS-1$ - buffer.append( "}\n"); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier structS = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction) i.next(); - Iterator fnIter = getDeclarations( function ); - IASTVariable sInstance = (IASTVariable) fnIter.next(); - IASTElaboratedTypeSpecifier elaborated = (IASTElaboratedTypeSpecifier) sInstance.getAbstractDeclaration().getTypeSpecifier(); - assertFalse( fnIter.hasNext() ); - - assertAllReferences( 1, createTaskList( new Task( structS ) ) ); - assertFalse( i.hasNext() ); - } - - public void testQualifiedLookup() throws Exception{ - //this is meant to test that on a->f, the lookup for f is qualified - //the namespace is necessary because of bug 47926 - StringBuffer buffer = new StringBuffer(); - buffer.append( "namespace N {" ); //$NON-NLS-1$ - buffer.append( " void f () {} \n" ); //$NON-NLS-1$ - buffer.append( " class A { }; \n" ); //$NON-NLS-1$ - buffer.append( "}" ); //$NON-NLS-1$ - buffer.append( "void main() { N::A * a = new N::A(); a->f(); } "); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) i.next(); - Iterator nsIter = getDeclarations( namespace ); - - IASTFunction f = (IASTFunction) nsIter.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)nsIter.next()).getTypeSpecifier(); - - assertFalse( nsIter.hasNext() ); - - IASTFunction main = (IASTFunction) i.next(); - - Iterator fnIter = getDeclarations( main ); - IASTVariable a = (IASTVariable) fnIter.next(); - - assertAllReferences( 5, createTaskList( new Task( namespace, 2 ), new Task( classA, 2 ), new Task( a ) ) ); - } - - public void testBug43110() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append("void x( int y, ... );\n"); //$NON-NLS-1$ - buffer.append("void y( int x... );\n"); //$NON-NLS-1$ - buffer.append("void z(...);"); //$NON-NLS-1$ - Iterator i = parse(buffer.toString() ).getDeclarations(); - while( i.hasNext() ) - assertTrue( ((IASTFunction)i.next()).takesVarArgs() ); - } - - public void testBug43110_XRef() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - assertTrue( foo.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void foo( int x ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - assertTrue( foo1.takesVarArgs() ); - assertFalse( foo2.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void foo( int x = 1) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo(); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - foo1 = (IASTFunction)i.next(); - foo2 = (IASTFunction)i.next(); - assertTrue( foo1.takesVarArgs() ); - assertFalse( foo2.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( int x ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1, 2, 'a' ); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - foo = (IASTFunction)i.next(); - assertTrue( foo.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo ) ) ); - } - - public void testErrorHandling_1() throws Exception - { - Iterator i = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ).getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - assertEquals( x.getName(), "x"); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( A.getName(), "A"); //$NON-NLS-1$ - IASTVariable anotherA = (IASTVariable)i.next(); - assertEquals( anotherA.getName(), "anotherA"); //$NON-NLS-1$ - IASTVariable b = (IASTVariable)i.next(); - assertEquals( b.getName(), "b"); //$NON-NLS-1$ - assertFalse(i.hasNext()); // should be true - } - - public void testBug44340() throws Exception { - // inline function with reference to variables declared after them - IASTScope scope = parse ("class A{ int getX() {return x[1];} int x[10];};", false ); //$NON-NLS-1$ - Iterator i = scope.getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod g = (IASTMethod)j.next(); - IASTField x = (IASTField)j.next(); - assertFalse(j.hasNext()); - assertAllReferences( 1, createTaskList( new Task( x ))); - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction h1 = (IASTFunction) i.next(); - assertEquals( h1.getName(), "h"); //$NON-NLS-1$ - Iterator parms = h1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - - IASTFunction h2 = (IASTFunction) i.next(); - assertEquals( h2.getName(), "h"); //$NON-NLS-1$ - parms = h2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "unsigned char" ); //$NON-NLS-1$ - - IASTFunction h3 = (IASTFunction) i.next(); - assertEquals( h3.getName(), "h"); //$NON-NLS-1$ - parms = h3.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "signed char" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug47636() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void f( char [] ); \n" ); //$NON-NLS-1$ - writer.write( "void f( char * ){} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction fDec = (IASTFunction) i.next(); - assertEquals( fDec.getName(), "f"); //$NON-NLS-1$ - - - IASTFunction fDef = (IASTFunction) i.next(); - assertEquals( fDef.getName(), "f"); //$NON-NLS-1$ - - assertTrue( fDef.previouslyDeclared() ); - - assertFalse( i.hasNext() ); - } - - public void testBug45697() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " int f( bool ); \n"); //$NON-NLS-1$ - writer.write( " int f( char ){ } "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction f1 = (IASTFunction) i.next(); - assertEquals( f1.getName(), "f"); //$NON-NLS-1$ - Iterator parms = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "bool" ); //$NON-NLS-1$ - - IASTFunction f2 = (IASTFunction) i.next(); - assertEquals( f2.getName(), "f"); //$NON-NLS-1$ - parms = f2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - assertFalse( f2.previouslyDeclared() ); - assertFalse( i.hasNext() ); - } - - public void testBug54639() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef enum _A { } A, *pA; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)i.next(); - assertEquals( typedef.getName(), "A" ); //$NON-NLS-1$ - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) typedef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( enumSpec.getName(), "_A" ); //$NON-NLS-1$ - - IASTTypedefDeclaration typedef2 = (IASTTypedefDeclaration)i.next(); - assertEquals( typedef2.getName(), "pA" ); //$NON-NLS-1$ - assertEquals( typedef2.getAbstractDeclarator().getPointerOperators().next(), ASTPointerOperator.POINTER ); - enumSpec = (IASTEnumerationSpecifier) typedef2.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( enumSpec.getName(), "_A" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug55163() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo() { \n"); //$NON-NLS-1$ - writer.write( " int i, n; \n"); //$NON-NLS-1$ - writer.write( " double di; \n"); //$NON-NLS-1$ - writer.write( " for( i = n - 1, di = (double)( i + i ); i > 0; i-- ){ } \n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTFunction foo = (IASTFunction) iter.next(); - assertFalse( iter.hasNext() ); - iter = getDeclarations( foo ); - IASTVariable i = (IASTVariable)iter.next(); - IASTVariable n = (IASTVariable)iter.next(); - IASTVariable di = (IASTVariable)iter.next(); - - assertAllReferences( 7, createTaskList( new Task( n ), new Task( i, 5 ), new Task( di ) ) ); - - } - public void testBug55673() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "struct Example { int i; int ( * pfi ) ( int ); }; "); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier example = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - assertFalse( iter.hasNext() ); - - iter = getDeclarations( example ); - - IASTField i = (IASTField) iter.next(); - IASTField pfi = (IASTField) iter.next(); - - assertFalse( iter.hasNext() ); - } - - public void testBug54531() throws Exception - { - Iterator i = parse( "typedef enum _A {} A, *pA;" ).getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration theEnum = (IASTTypedefDeclaration) i.next(); - assertEquals( theEnum.getName(), "A"); //$NON-NLS-1$ - IASTTypedefDeclaration thePointer = (IASTTypedefDeclaration) i.next(); - assertEquals( thePointer.getName(), "pA" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug56516() throws Exception - { - Iterator i = parse( "typedef struct blah sb;").getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration sb = (IASTTypedefDeclaration) i.next(); - assertEquals( sb.getName(), "sb"); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - IASTElaboratedTypeSpecifier elab = ((IASTElaboratedTypeSpecifier)sb.getAbstractDeclarator().getTypeSpecifier()); - assertEquals( elab.getName(), "blah"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - } - - public void testBug53786() throws Exception - { - Iterator i = parse( "struct Example { struct Data * data; };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier Example = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - assertEquals( Example.getName(), "Example"); //$NON-NLS-1$ - assertEquals( Example.getClassKind(), ASTClassKind.STRUCT ); - Iterator j = getDeclarations( Example ); - IASTField data = (IASTField) j.next(); - assertFalse( j.hasNext() ); - assertEquals( data.getName(), "data" ); //$NON-NLS-1$ - } - - public void testBug54029() throws Exception - { - Iterator i = parse( "typedef int T; T i;" ).getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration) i.next(); - assertEquals( typedef.getName(), "T"); //$NON-NLS-1$ - assertTrue( typedef.getAbstractDeclarator().getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - IASTVariable variable = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertEquals( variable.getName(), "i"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypename(), "T" ); //$NON-NLS-1$ - assertNotNull( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier() ); - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), typedef ); - } - - public void testBug47625() throws Exception - { - Writer writer = new StringWriter(); - writer.write("struct s { int num; }; "); //$NON-NLS-1$ - writer.write("namespace ns{ "); //$NON-NLS-1$ - writer.write(" struct s { double num; };"); //$NON-NLS-1$ - writer.write(" s inner = { 3.14 };"); //$NON-NLS-1$ - writer.write(" ::s outer = { 42 };"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier outerS = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); - - i = getDeclarations( ns ); - IASTClassSpecifier innerS = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable inner = (IASTVariable) i.next(); - IASTVariable outer = (IASTVariable) i.next(); - - assertAllReferences( 2, createTaskList( new Task( outerS ), new Task( innerS ) ) ); - } - - public void testBug57754() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct X { " ); //$NON-NLS-1$ - writer.write( " typedef int T; " ); //$NON-NLS-1$ - writer.write( " void f( T ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void X::f( T ) { } " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier X = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod f = (IASTMethod) i.next(); - - assertTrue( f.previouslyDeclared() ); - - i = getDeclarations( X ); - IASTTypedefDeclaration T = (IASTTypedefDeclaration) i.next(); - - assertAllReferences( 3, createTaskList( new Task( X ), new Task( T, 2 ) ) ); - } - - public void testBug57800() throws Exception - { - Writer writer= new StringWriter(); - writer.write( "class G2 { int j; };"); //$NON-NLS-1$ - writer.write( "typedef G2 AltG2;"); //$NON-NLS-1$ - writer.write( "class AltG3 : AltG2 { int x;};"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier G2 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration AltG2 = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier AltG3 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator baseClauses = AltG3.getBaseClauses(); - IASTBaseSpecifier baseClause = (IASTBaseSpecifier) baseClauses.next(); - assertFalse( baseClauses.hasNext() ); - assertEquals( baseClause.getParentClassSpecifier(), AltG2 ); - } - - public void testBug46246() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct A { "); //$NON-NLS-1$ - writer.write( " struct B { int ab; } b; "); //$NON-NLS-1$ - writer.write( " int a; "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "struct A a1; "); //$NON-NLS-1$ - writer.write( "struct B b1; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString(), true, ParserLanguage.C ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a1 = (IASTVariable) i.next(); - IASTVariable b1 = (IASTVariable) i.next(); - i = getDeclarations( A ); - IASTField b = (IASTField) i.next(); - IASTField a = (IASTField) i.next(); - IASTClassSpecifier B = (IASTClassSpecifier) b.getAbstractDeclaration().getTypeSpecifier(); - - assertAllReferences( 2, createTaskList( new Task( A ), new Task( B ) ) ); - } - - public void testBug45235() throws Exception - { - Iterator i = parse( "class A { friend class B; friend void f(); }; " ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = getDeclarations( A ); - - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTFunction f = (IASTFunction) i.next(); - - assertTrue( forewardDecl.isFriendDeclaration() ); - assertTrue( f.isFriend() ); - } - - public void testBug57791() throws Exception - { - Writer writer = new StringWriter(); - writer.write(" void f() { "); //$NON-NLS-1$ - writer.write(" struct astruct astruct; "); //$NON-NLS-1$ - writer.write(" astruct.foo++; "); //$NON-NLS-1$ - writer.write(" }"); //$NON-NLS-1$ - - parse( writer.toString(), true, ParserLanguage.C ); - } - - public void testBug44249() throws Exception - { - - Iterator i = parse( "class SD_01 { public:\n void SD_01::f_SD_01();};" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier SD_01 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - i = getDeclarations( SD_01 ); - IASTMethod f_SD_01 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - assertEquals( f_SD_01.getName(), "f_SD_01"); //$NON-NLS-1$ - assertAllReferences( 1, createTaskList( new Task( SD_01 ))); - } - - 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 testBug59149() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ friend class B; friend class B; };" ); //$NON-NLS-1$ - writer.write( "class B{ };" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - } - 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 testBug59302() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class A { class N{}; }; "); //$NON-NLS-1$ - writer.write("class B { friend class A::N; }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = getDeclarations( A ); - IASTClassSpecifier N = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - assertFalse( A.getFriends().hasNext() ); - assertEquals( B.getFriends().next(), N ); - } - - - 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 testULong() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifndef ASMINCLUDE\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned short ushort;\n"); //$NON-NLS-1$ - writer.write( "typedef volatile unsigned long semaphore;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long ulong;\n"); //$NON-NLS-1$ - writer.write( "#ifndef _NO_LONGLONG\n"); //$NON-NLS-1$ - writer.write( "typedef long long longlong;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long long ulonglong;\n"); //$NON-NLS-1$ - writer.write( "#endif /* _NO_LONGLONG */\n"); //$NON-NLS-1$ - writer.write( "#endif /* ASMINCLUDE */\n"); //$NON-NLS-1$ - writer.write( "typedef struct section_type_ {\n"); //$NON-NLS-1$ - writer.write( "ulong source;\n"); //$NON-NLS-1$ - writer.write( "ulong dest;\n"); //$NON-NLS-1$ - writer.write( "ulong bytes;\n"); //$NON-NLS-1$ - writer.write( "} section_type;\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTTypedefDeclaration ushort = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration semaphore = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration ulong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration longlong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration ulonglong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration section_type = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier section_type_ = (IASTClassSpecifier) section_type.getAbstractDeclarator().getTypeSpecifier(); - Iterator fields = getDeclarations(section_type_); - IASTField source = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)source.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - IASTField dest = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)dest.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - IASTField bytes = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)bytes.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - - assertFalse( i.hasNext() ); - - } - - public void testBug47926() throws Exception - { - Iterator i = parse( "void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - i = getDeclarations( main ); - IASTVariable a = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( a ))); - } - - public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "class num_put { " ); //$NON-NLS-1$ - writer.write( " typedef _OutIter iter_type; " ); //$NON-NLS-1$ - writer.write( " template< typename _ValueT > " ); //$NON-NLS-1$ - writer.write( " iter_type _M_convert_float( iter_type ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "template < typename _ValueT > " ); //$NON-NLS-1$ - writer.write( "_OutIter num_put<_OutIter>::_M_convert_float( _OutIter ) { } " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier num_put = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTTemplateDeclaration defn = (IASTTemplateDeclaration) i.next(); - IASTMethod convert = (IASTMethod) defn.getOwnedDeclaration(); - - assertEquals( convert.getOwnerClassSpecifier(), num_put ); - } - - public void testGloballyQualifiedUsingDeclaration() throws Exception - { - Iterator declarations = parse( "int iii; namespace N { using ::iii; }" ).getDeclarations(); //$NON-NLS-1$ - - IASTVariable iii = (IASTVariable) declarations.next(); - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - - IASTUsingDeclaration using = (IASTUsingDeclaration)(getDeclarations(namespaceN).next()); - - assertEquals( callback.getReferences().size(), 1 ); - - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), iii ); - } - - public void test57513_new() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( int ); }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( " A * a2 = new(1)A(); \n" ); //$NON-NLS-1$ - writer.write( " A * a3 = new A( 1 ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( A ); - IASTMethod constructor1 = (IASTMethod) i.next(); - IASTMethod constructor2 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( constructor1, 2, false, false ) ); - assertReferenceTask( new Task( constructor2, 1, false, false ) ); - assertReferenceTask( new Task( A, 3, false, false ) ); - } - - public void test57513_NoConstructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( A, 2, false, false ) ); - } - - public void test57513_ctorinit() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( A * ); }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A { B(); }; \n" ); //$NON-NLS-1$ - writer.write( "B::B():A( new A ){} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTMethod constructorB = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( A ); - IASTMethod constructor1 = (IASTMethod) i.next(); - IASTMethod constructor2 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( constructor1, 1, false, false ) ); - assertReferenceTask( new Task( constructor2, 1, false, false ) ); - assertReferenceTask( new Task( A, 2, false, false ) ); - } - - public void test575513_qualified() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace Foo{ " ); //$NON-NLS-1$ - writer.write( " class Bar{ public : Bar(); }; " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - writer.write( "void main(){ " ); //$NON-NLS-1$ - writer.write( " Foo::Bar * bar = new Foo::Bar(); " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) i.next(); - IASTFunction main = (IASTFunction) i.next(); - i = getDeclarations( namespace ); - IASTClassSpecifier Bar = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - i = getDeclarations( Bar ); - IASTMethod constructor = (IASTMethod) i.next(); - - assertAllReferences( 4, createTaskList( new Task(namespace, 2 ), new Task( Bar, 1 ), new Task( constructor, 1 ) ) ); - } - - public void testBug60944() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int OurInt;\n"); //$NON-NLS-1$ - writer.write( "class A { int x; };\n"); //$NON-NLS-1$ - writer.write( "typedef A AnotherA;\n"); //$NON-NLS-1$ - writer.write( "typedef AnotherA SecondA;\n"); //$NON-NLS-1$ - writer.write( "typedef OurInt AnotherInt;\n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTTypedefDeclaration OurInt = (IASTTypedefDeclaration) i.next(); - assertTrue( OurInt.getFinalTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)OurInt.getFinalTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration AnotherA = (IASTTypedefDeclaration) i.next(); - assertEquals( AnotherA.getFinalTypeSpecifier(), A ); - IASTTypedefDeclaration SecondA = (IASTTypedefDeclaration) i.next(); - assertEquals( SecondA.getFinalTypeSpecifier(), A ); - IASTTypedefDeclaration AnotherInt = (IASTTypedefDeclaration) i.next(); - assertTrue( AnotherInt.getFinalTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)AnotherInt.getFinalTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - - assertFalse( i.hasNext() ); - } - - public void testDestructorReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC {\n"); //$NON-NLS-1$ - writer.write( " public:\n"); //$NON-NLS-1$ - writer.write( " ~ABC(){ }\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC * abc = new ABC();\n"); //$NON-NLS-1$ - writer.write( "abc->~ABC();\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - Iterator declarations = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier ABC = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTFunction main = (IASTFunction) declarations.next(); - assertFalse( declarations.hasNext() ); - Iterator members = getDeclarations(ABC); - IASTFunction destructor = (IASTFunction) members.next(); - assertFalse( members.hasNext() ); - Iterator localVariables = getDeclarations( main ); - IASTVariable variable = (IASTVariable) localVariables.next(); - assertFalse( localVariables.hasNext() ); - assertAllReferences( 4, createTaskList( new Task( ABC, 2 ), new Task( variable ), new Task( destructor ))); - } - - public void testBug39676_tough() throws Exception - { - parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, ParserLanguage.C ); //$NON-NLS-1$ - } - - public void testBug60939() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - Writer writer = new StringWriter(); - writer.write( "namespace ABC { class DEF { }; }\n"); //$NON-NLS-1$ - if( i == 0 ) - writer.write( "using namespace ABC;\n"); //$NON-NLS-1$ - else - writer.write( "using ABC::DEF;\n"); //$NON-NLS-1$ - writer.write( "class GHI : public DEF { };"); //$NON-NLS-1$ - Iterator d = parse( writer.toString() ).getDeclarations(); - IASTNamespaceDefinition ABC = (IASTNamespaceDefinition) d.next(); - if( i == 0 ) - assertTrue( d.next() instanceof IASTUsingDirective ); - else - assertTrue( d.next() instanceof IASTUsingDeclaration ); - IASTClassSpecifier GHI = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)d.next()).getTypeSpecifier(); - Iterator baseClauses = GHI.getBaseClauses(); - IASTBaseSpecifier baseClause = (IASTBaseSpecifier) baseClauses.next(); - IASTClassSpecifier DEF = (IASTClassSpecifier) baseClause.getParentClassSpecifier(); - String [] theTruth = new String[2]; - theTruth[0] = "ABC"; //$NON-NLS-1$ - theTruth[1] = "DEF"; //$NON-NLS-1$ - qualifiedNamesEquals( DEF.getFullyQualifiedName(), theTruth ); - } - - - } - - public void testBug64010() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " #define ONE else if (0) { } \n"); //$NON-NLS-1$ - writer.write( " #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); //$NON-NLS-1$ - writer.write( " #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); //$NON-NLS-1$ - writer.write( " #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); //$NON-NLS-1$ - writer.write("void foo() "); //$NON-NLS-1$ - writer.write("{ "); //$NON-NLS-1$ - writer.write(" if (0) { } "); //$NON-NLS-1$ - writer.write(" /* 11,000 else if's. */ "); //$NON-NLS-1$ - writer.write(" THOU THOU THOU THOU THOU THOU THOU THOU THOU THOU THOU "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator d = parse( writer.toString() ).getDeclarations(); - - IASTFunction f = (IASTFunction) d.next(); - } - - public void testBug64271() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = blah;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug47752() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class BBC\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "int x;\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "void func( BBC bar )\n"); //$NON-NLS-1$ - writer.write( "try\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "catch ( BBC error )\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( " //... error handling code ...\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - parse( writer.toString() ); - assertEquals( callback.getReferences().size(), 2 ); - } - public void testBug61972() throws Exception - { - parse( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false ); //$NON-NLS-1$ - } - - public void testBug65569() throws Exception - { - parse( "class Sample;\nstruct Sample { /* ... */ };" ); //$NON-NLS-1$ - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write("for (;;) { \\\n"); //$NON-NLS-1$ - writer.write("/* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write("up the parser. */ }\n"); //$NON-NLS-1$ - writer.write(" void abc() {\n"); //$NON-NLS-1$ - writer.write("BODY\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ - } - - public void testBug67680() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived : public Base, Base<int>, foo {}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString(), false ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier base = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTClassSpecifier derived = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - //only Base<int> is a valid parent, Base and foo are not expected to show up in the iterator. - i = derived.getBaseClauses(); - IASTBaseSpecifier parent = (IASTBaseSpecifier) i.next(); - assertFalse( i.hasNext() ); - - assertEquals( parent.getParentClassSpecifier(), base ); - } - - public void testTypeIDSignature() throws Exception - { - IASTVariable v = (IASTVariable) parse( "int * v = (int*)0;").getDeclarations().next();//$NON-NLS-1$ - IASTTypeId typeId = v.getInitializerClause().getAssigmentExpression().getTypeId(); - assertEquals( typeId.getFullSignature(), "int *"); //$NON-NLS-1$ - } - - public void testUnaryAmperCast() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "void f( char * ); \r\n "); //$NON-NLS-1$ - writer.write( "void f( char ); \n "); //$NON-NLS-1$ - writer.write( "void main() { \n "); //$NON-NLS-1$ - writer.write( " char * t = new char [ 5 ]; \n "); //$NON-NLS-1$ - writer.write( " f( &t[1] ); \n "); //$NON-NLS-1$ - writer.write( "} \n "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - IASTVariable t = (IASTVariable) getDeclarations( main ).next(); - - assertAllReferences( 2, createTaskList( new Task( f1, 1, false, false), new Task( t ) ) ); - } - - public void testBug68235() throws Exception{ - Writer writer = new StringWriter(); - writer.write( " struct xTag { int x; }; "); //$NON-NLS-1$ - writer.write( " typedef xTag xType; "); //$NON-NLS-1$ - writer.write( " typedef struct yTag { int x; } yType; "); //$NON-NLS-1$ - writer.write( " class C1 { xType x; yType y; }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier xTag = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration xType = (IASTTypedefDeclaration) i.next(); - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) xType.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( typeSpec.getTypeSpecifier(), xTag ); - - IASTTypedefDeclaration yType = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier yTag = (IASTClassSpecifier) yType.getAbstractDeclarator().getTypeSpecifier(); - - IASTClassSpecifier C1 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - i = getDeclarations( C1 ); - - IASTField x = (IASTField) i.next(); - IASTField y = (IASTField) i.next(); - assertFalse( i.hasNext() ); - - IASTSimpleTypeSpecifier simple = (IASTSimpleTypeSpecifier) x.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( simple.getTypeSpecifier(), xType ); - simple = (IASTSimpleTypeSpecifier) y.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( simple.getTypeSpecifier(), yType ); - } - - public void testBug60407() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct ZZZ { int x, y, z; };\r\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$ - parse( writer.toString() ); - } - - public void testBug68623() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A(); \n" ); //$NON-NLS-1$ - writer.write( " class sub{}; \n" ); //$NON-NLS-1$ - writer.write( " sub * x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "A::A() : x( (sub *) 0 ) {} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - - writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A() : x (0) {} \n" ); //$NON-NLS-1$ - writer.write( " int x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = A.getDeclarations(); - IASTMethod constructor = (IASTMethod) i.next(); - IASTField x = (IASTField) i.next(); - - assertAllReferences( 1, createTaskList( new Task( x ) ) ); - } - - public void testBug69798() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "enum Flags { FLAG1, FLAG2 }; \n" ); //$NON-NLS-1$ - writer.write( "int f() { int a, b; b = ( a ? FLAG1 : 0 ) | FLAG2; } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug69662() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A { operator float * (); }; \n" ); - writer.write( "A::operator float * () { } \n" ); - - parse( writer.toString() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java deleted file mode 100644 index f2f52a2f8f4..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java +++ /dev/null @@ -1,1023 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.Stack; - -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.ISourceElementCallbackDelegate; -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.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.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -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.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTReference; -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.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -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.parser.ast.IReferenceManager; -import org.eclipse.cdt.internal.core.parser.CompleteParser; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache; -import org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTTypedefReference; - -/** - * @author jcamelon - * - */ -public class CompleteParseBaseTest extends TestCase -{ - /** - * - */ - public CompleteParseBaseTest() - { - super(); - // TODO Auto-generated constructor stub - } - /** - * @param name - */ - public CompleteParseBaseTest(String name) - { - super(name); - // TODO Auto-generated constructor stub - } - public static class Scope implements IASTScope - { - private List decls = new ArrayList(); - private final IASTScope scope; - public Scope( IASTScope scope ) - { - this.scope = scope; - } - - public void addDeclaration( IASTDeclaration d ) - { - decls.add(d); - } - - public Iterator getDeclarations() - { - return decls.iterator(); - } - - /** - * @return - */ - public IASTScope getScope() - { - - return scope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#getFileIndex() - */ - public int getFileIndex() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#setFileIndex(int) - */ - public void setFileIndex(int index) { - // TODO Auto-generated method stub - - } - - } - - public static class CodeScope extends Scope implements IASTCodeScope - { - private List nestedScopes = new ArrayList(); - /** - * @param scope - */ - public CodeScope(IASTCodeScope scope) - { - super(scope); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope() - */ - public IASTCodeScope getOwnerCodeScope() - { - return ((IASTCodeScope)getScope()).getOwnerCodeScope(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor, IReferenceManager manager) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor, IReferenceManager manager) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor, IReferenceManager manager) - { - } - - public void addNewScope( IASTCodeScope s ) - { - nestedScopes.add( s ); - } - - public Iterator getCodeBlocks() - { - return nestedScopes.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getContainingFunction() - */ - public IASTFunction getContainingFunction() { - // TODO Auto-generated method stub - return null; - } - } - - public static class FullParseCallback implements ISourceElementRequestor - { - private List references = new ArrayList(); - private List forewardDecls = new ArrayList(); - private Stack inclusions = new Stack(); - private Scope compilationUnit; - - public FullParseCallback() - { -// System.out.println( "NEW"); -// System.out.println(); - } - - public void finalize() - { -// System.out.println( ); - } - - public IASTScope getCompilationUnit() - { - return compilationUnit; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) - { - getCurrentScope().addDeclaration( variable ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) - { - getCurrentScope().addDeclaration(function); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) - { - getCurrentScope().addDeclaration(usageDirective); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration) - */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) - { - getCurrentScope().addDeclaration(usageDeclaration); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) - */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) - { - getCurrentScope().addDeclaration(asmDefinition); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration) - */ - public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) - { - getCurrentScope().addDeclaration(typedef); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) - */ - public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) - { - getCurrentScope().addDeclaration( abstractDeclaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) - { - pushCodeScope( function ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void exitFunctionBody(IASTFunction function) - { - popScope(); - getCurrentScope().addDeclaration(function); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit cu) - { - pushScope( cu ); - this.compilationUnit = getCurrentScope(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) - { - pushInclusion( inclusion ); - } - - /** - * @param inclusion - */ - private void pushInclusion(IASTInclusion inclusion) - { - inclusions.push( inclusion ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - pushScope( namespaceDefinition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#entesrClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) - { - pushScope( classSpecification ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - pushScope( linkageSpec ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) - { - pushScope( declaration ); - } - - /* (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#enterTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) - { - pushScope( instantiation ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) - { - getCurrentScope().addDeclaration( method ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) - { - pushCodeScope(method); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void exitMethodBody(IASTMethod method) - { - popScope(); - getCurrentScope().addDeclaration(method); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) - { - getCurrentScope().addDeclaration(field); - - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) - { - popScope(); - getCurrentScope().addDeclaration( declaration ); - } - - /* (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) - { - popScope(); - getCurrentScope().addDeclaration( instantiation ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - popScope(); - getCurrentScope().addDeclaration(linkageSpec); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) - { - popScope(); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - popScope(); - getCurrentScope().addDeclaration(namespaceDefinition); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void exitInclusion(IASTInclusion inclusion) - { - popInclusion(); - } - - /** - * - */ - private void popInclusion() - { - inclusions.pop(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit cu ) - { - } - - - - private Stack scopes = new Stack(); - protected Scope getCurrentScope() - { - return (Scope)scopes.peek(); - } - - protected CodeScope getCurrentCodeScope() - { - if( scopes.peek() instanceof CodeScope ) - return (CodeScope)scopes.peek(); - return null; - } - - protected Scope popScope() - { - Scope s = (Scope)scopes.pop(); - h.put( s.getScope(), s ); - return s; - } - - protected void pushScope( IASTScope scope ) - { - scopes.push( new Scope( scope )); - } - - Hashtable h = new Hashtable(); - - public Scope lookup( IASTScope s) - { - return (Scope)h.get(s); - } - - public CodeScope lookup( IASTCodeScope s ) - { - return (CodeScope)h.get(s); - } - - - List problems = new ArrayList(); - - public Iterator getProblems() { - return problems.iterator(); - } - /* (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 true; - } - - /* (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#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference) - */ - public void acceptClassReference(IASTClassReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference) - */ - public void acceptTypedefReference(IASTTypedefReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference) - */ - public void acceptNamespaceReference(IASTNamespaceReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumerationReference(IASTEnumerationReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference) - */ - public void acceptVariableReference(IASTVariableReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference) - */ - public void acceptFunctionReference(IASTFunctionReference reference) - { - processReference(reference); - } - - protected void processReference(IASTReference reference) - { - ISourceElementCallbackDelegate referencedElement = reference.getReferencedElement(); - IASTReference r = null; - if (referencedElement instanceof IASTTypedefDeclaration) - r = new ASTTypedefReference(reference.getOffset(), - (IASTTypedefDeclaration) referencedElement); - if (referencedElement instanceof IASTEnumerationSpecifier) - r = new ReferenceCache.ASTEnumerationReference(reference.getOffset(), - (IASTEnumerationSpecifier) referencedElement); - if (referencedElement instanceof IASTTemplateParameter) - r = new ReferenceCache.ASTTemplateParameterReference(reference.getOffset(), - (IASTTemplateParameter) referencedElement); - if (referencedElement instanceof IASTParameterDeclaration) - r = new ReferenceCache.ASTParameterReference(reference.getOffset(), - (IASTParameterDeclaration) referencedElement); - if (referencedElement instanceof IASTTypeSpecifier) - r = new ReferenceCache.ASTClassReference(reference.getOffset(), - (IASTTypeSpecifier) referencedElement); - if (referencedElement instanceof IASTNamespaceDefinition) - r = new ReferenceCache.ASTNamespaceReference(reference.getOffset(), - (IASTNamespaceDefinition) referencedElement); - if (referencedElement instanceof IASTFunction) - r = new ReferenceCache.ASTFunctionReference(reference.getOffset(), - (IASTFunction) referencedElement); - if (referencedElement instanceof IASTMethod) - r = new ReferenceCache.ASTMethodReference(reference.getOffset(), (IASTMethod) referencedElement); - if (referencedElement instanceof IASTField) - r = new ReferenceCache.ASTFieldReference(reference.getOffset(), (IASTField) referencedElement); - if (referencedElement instanceof IASTVariable) - r = new ReferenceCache.ASTVariableReference(reference.getOffset(), - (IASTVariable) referencedElement); - if (referencedElement instanceof IASTEnumerator) - r = new ReferenceCache.ASTEnumeratorReference(reference.getOffset(), - (IASTEnumerator) referencedElement); - if( r != null ) - references.add( r ); -// System.out.println( "Callback received Reference to " + reference.getName() + " @ offset " + reference.getOffset() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference) - */ - public void acceptFieldReference(IASTFieldReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference) - */ - public void acceptMethodReference(IASTMethodReference reference) - { - processReference( reference ); - - } - - public List getReferences() - { - return references; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) - */ - public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) - { - forewardDecls.add( elaboratedType ); - } - /** - * @return - */ - public List getForewardDecls() - { - return forewardDecls; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void enterCodeBlock(IASTCodeScope scope) { - pushCodeScope( scope ); - } - - /** - * @param scope - */ - protected void pushCodeScope(IASTCodeScope scope) - { - scopes.push( new CodeScope( scope ) ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void exitCodeBlock(IASTCodeScope scope) { - popScope(); - if( getCurrentCodeScope() != null ) - getCurrentCodeScope().addNewScope(scope); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumeratorReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumeratorReference(IASTEnumeratorReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference) - */ - public void acceptParameterReference(IASTParameterReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) - */ - public CodeReader createReader(String finalPath, Iterator workingCopies) { - return ParserUtil.createReader(finalPath,workingCopies); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTemplateParameterReference(org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference) - */ - public void acceptTemplateParameterReference(IASTTemplateParameterReference reference) { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#parserTimeout() - */ - public boolean parserTimeout() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFriendDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void acceptFriendDeclaration(IASTDeclaration declaration) { - getCurrentScope().addDeclaration( declaration ); - } - } - - protected Iterator getNestedScopes( IASTCodeScope scope ) - { - CodeScope s = callback.lookup( scope ); - if( s != null ) - return s.getCodeBlocks(); - return null; - - } - protected Iterator getDeclarations(IASTScope scope) - { - Scope s = callback.lookup( scope ); - if( s != null ) - return s.getDeclarations(); - return null; - } - protected FullParseCallback callback; - - protected IASTScope parse( String code ) throws ParserException, ParserFactoryError - { - return parse( code, true, ParserLanguage.CPP ); - } - - protected IASTScope parse( String code, boolean throwOnError ) throws ParserException, ParserFactoryError - { - return parse( code, throwOnError, ParserLanguage.CPP ); - } - - protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError - { - callback = new FullParseCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null - ); - boolean parseResult = parser.parse(); - if( ! parseResult && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - if( parseResult ) - assertTrue( ((CompleteParser)parser).validateCaches()); - return callback.getCompilationUnit(); - } - - protected void assertReferences( - ISourceElementCallbackDelegate element, - int expectedDistinctReferenceCount, - boolean allowDuplicates, boolean allowNameMatching ) - { - Set matches = new HashSet(); - Iterator allReferences = callback.getReferences().iterator(); - while( allReferences.hasNext() ) - { - IASTReference r = (IASTReference)allReferences.next(); - if( r.getReferencedElement() == element ) - { - assertEquals( r.getName(), ((IASTOffsetableNamedElement)element).getName() ); - if( ! matches.add( r ) && ! allowDuplicates ) - fail( "Duplicate reference found for ISourceElementCallbackDelegate: " + element + " @ offset " + r.getOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - } - else - { - if( r.getReferencedElement() instanceof IASTQualifiedNameElement && - element instanceof IASTQualifiedNameElement && - allowNameMatching ) - { - if( qualifiedNamesEquals( - ((IASTQualifiedNameElement)r.getReferencedElement()).getFullyQualifiedName(), - ((IASTQualifiedNameElement)element).getFullyQualifiedName() - ) - ) - { - - if( ! matches.add( r ) && ! allowDuplicates ) - fail( "Duplicate reference found for ISourceElementCallbackDelegate: " + element + " @ offset " + r.getOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - } - - } - } - } - - assertEquals( expectedDistinctReferenceCount, matches.size() ); - } - - protected static class Task - { - private final boolean allowNameMatching; - private final boolean unique; - private final int count; - private final ISourceElementCallbackDelegate element; - - - public Task( ISourceElementCallbackDelegate element, int referenceCount, boolean distinct, boolean matchNames ){ - this.element = element; - this.count = referenceCount; - this.unique = distinct; - this.allowNameMatching = matchNames; - } - - public Task( ISourceElementCallbackDelegate element, int referenceCount, boolean distinct ) - { - this( element, referenceCount, distinct, true ); - } - - public Task( ISourceElementCallbackDelegate element, int referenceCount ) - { - this( element, referenceCount, true ); - } - - public Task( ISourceElementCallbackDelegate element ) - { - this( element, 1, false ); - } - - /** - * @return - */ - public int getCount() - { - return count; - } - - /** - * @return - */ - public ISourceElementCallbackDelegate getElement() - { - return element; - } - - /** - * @return - */ - public boolean isUnique() - { - return unique; - } - - public boolean allowNameMatching(){ - return allowNameMatching; - } - - } - - protected void assertReferenceTask( Task task ) - { - assertReferences( task.getElement(), task.getCount(), task.isUnique(), task.allowNameMatching() ); - } - - protected void assertAllReferences( int count, List tasks ) - { - assertEquals( callback.getReferences().size(), count ); - if( tasks == null ) return; - Iterator i = tasks.iterator(); - while( i.hasNext() ) - { - assertReferenceTask( (Task)i.next() ); - } - } - - protected List createTaskList( Task t1 ) - { - List result = new ArrayList(); - result.add( t1 ); - return result; - } - - protected List createTaskList( Task t1, Task t2 ) - { - List result = createTaskList(t1); - result.add( t2 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3 ) - { - List result = createTaskList(t1, t2); - result.add( t3 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3, Task t4 ) - { - List result = createTaskList(t1, t2, t3); - result.add( t4 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3, Task t4, Task t5 ) - { - List result = createTaskList(t1, t2, t3, t4); - result.add( t5 ); - return result; - } - /** - * @param task - * @param task2 - * @param task3 - * @param task4 - * @param task5 - * @param task6 - * @return - */ - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6) - { - List result = createTaskList( task, task2, task3, task4, task5 ); - result.add( task6 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7) - { - List result = createTaskList( task, task2, task3, task4, task5, task6 ); - result.add( task7 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7 ); - result.add( task8 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8, Task task9 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7, task8 ); - result.add( task9 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8, Task task9, Task task10 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7, task8, task9 ); - result.add( task10 ); - return result; - } - - public boolean qualifiedNamesEquals( String [] fromAST, String [] theTruth) - { - if( fromAST == null || theTruth == null ) return false; - if( fromAST.length != theTruth.length ) return false; - for( int i = 0; i < fromAST.length; ++i ) - { - if( !( fromAST[i].equals( theTruth[i] ) ) ) - return false; - } - return true; - } - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) - { - assertTrue( qualifiedNamesEquals( fromAST, theTruth )); - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java deleted file mode 100644 index 9836c51b4ce..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002-2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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 ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java deleted file mode 100644 index bce211a9b1d..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002-2004 IBM Canada and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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() ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java deleted file mode 100644 index 23aafc7c32d..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java +++ /dev/null @@ -1,1218 +0,0 @@ -/* - * Created on Dec 8, 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.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.internal.core.parser.token.KeywordSets; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to Window - - * Preferences - Java - Code Generation - Code and Comments - */ -public class CompletionParseTest extends CompletionParseBaseTest { - - - public CompletionParseTest(String name) { - super(name); - } - - public void testBaseCase_SimpleDeclaration() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class ABC " ); //$NON-NLS-1$ - writer.write( "{int x;}; " ); //$NON-NLS-1$ - writer.write( "AB\n\n" ); //$NON-NLS-1$ - - IASTCompletionNode node = null; - Iterator keywords = null; - - node = parse( writer.toString(), 21); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), "A"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 12); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertTrue( node.getCompletionScope() instanceof IASTClassSpecifier ); - assertEquals( node.getCompletionPrefix(), "i"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.FIELD_TYPE ); - keywords = node.getKeywords(); - assertTrue( keywords.hasNext() ); - assertEquals( (String) keywords.next(), "inline"); //$NON-NLS-1$ - assertEquals( (String) keywords.next(), "int"); //$NON-NLS-1$ - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 22); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), "AB"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 6); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), ""); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.CLASS_REFERENCE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - } - - public void testCompletionLookup_Unqualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aVar; " ); //$NON-NLS-1$ - writer.write( "void foo( ) { " ); //$NON-NLS-1$ - writer.write( " int anotherVar; " ); //$NON-NLS-1$ - writer.write( " a " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - String code = writer.toString(); - - for( int i = 0; i < 2; ++i ) - { - int index = ( i == 0 ? code.indexOf( " a " ) + 2 : code.indexOf( " a ") + 1 ); //$NON-NLS-1$ //$NON-NLS-2$ - - IASTCompletionNode node = parse( code, index ); - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertNotNull( prefix ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( prefix, i == 0 ? "a" :"" ); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.ALL; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTVariable anotherVar = (IASTVariable) iter.next(); - - IASTVariable aVar = (IASTVariable) iter.next(); - - if( i != 0 ) - { - IASTFunction foo = (IASTFunction) iter.next(); - assertEquals( foo.getName(), "foo"); //$NON-NLS-1$ - } - - assertFalse( iter.hasNext() ); - assertEquals( anotherVar.getName(), "anotherVar" ); //$NON-NLS-1$ - assertEquals( aVar.getName(), "aVar" ); //$NON-NLS-1$ - } - } - - public void testCompletionLookup_Qualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aVar; " ); //$NON-NLS-1$ - writer.write( "struct D{ " ); //$NON-NLS-1$ - writer.write( " int aField; " ); //$NON-NLS-1$ - writer.write( " void aMethod(); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " D d; " ); //$NON-NLS-1$ - writer.write( " d.a " ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "d.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertNotNull( prefix ); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.ALL; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTField aField = (IASTField) iter.next(); - IASTMethod aMethod = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( aMethod.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( aField.getName(), "aField" ); //$NON-NLS-1$ - } - - public void testMemberCompletion_Arrow() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B * b = new B();" ); //$NON-NLS-1$ - writer.write( " b-> \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b->" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - assertNotNull(node); - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE); - assertTrue(node.getCompletionScope() instanceof IASTFunction ); - assertEquals( ((IASTFunction)node.getCompletionScope()).getName(), "foo" ); //$NON-NLS-1$ - assertTrue(node.getCompletionContext() instanceof IASTVariable ); - assertEquals( ((IASTVariable)node.getCompletionContext()).getName(), "b" ); //$NON-NLS-1$ - } - - public void testMemberCompletion_Dot() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B b;" ); //$NON-NLS-1$ - writer.write( " b. \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b." ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - assertNotNull(node); - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE); - assertTrue(node.getCompletionScope() instanceof IASTFunction ); - assertEquals( ((IASTFunction)node.getCompletionScope()).getName(), "foo" ); //$NON-NLS-1$ - assertTrue(node.getCompletionContext() instanceof IASTVariable ); - assertEquals( ((IASTVariable)node.getCompletionContext()).getName(), "b" ); //$NON-NLS-1$ - } - - - public void testCompletionLookup_Pointer() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B * b = new B();" ); //$NON-NLS-1$ - writer.write( " b->a \n" ); //$NON-NLS-1$ - - for( int i = 0; i < 2; ++i ) - { - String code = writer.toString(); - - int index; - - index = (i == 0 )? (code.indexOf( "b->a" )+4) :(code.indexOf( "b->") + 3); //$NON-NLS-1$ //$NON-NLS-2$ - - IASTCompletionNode node = parse( code, index); - - assertNotNull( node ); - String prefix = node.getCompletionPrefix(); - - assertEquals( prefix, ( i == 0 ) ? "a" :""); //$NON-NLS-1$ //$NON-NLS-2$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.METHODS; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - IASTMethod method = (IASTMethod) iter.next(); - IASTMethod baseMethod = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( baseMethod.getName(), "aPublicBaseMethod" ); //$NON-NLS-1$ - } - } - - public void testCompletionLookup_FriendClass_1() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateMethod();" ); //$NON-NLS-1$ - writer.write( " friend class C;" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "class C {" ); //$NON-NLS-1$ - writer.write( " void foo();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "void C::foo(){" ); //$NON-NLS-1$ - writer.write( " A a;" ); //$NON-NLS-1$ - writer.write( " a.a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "a.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - assertTrue( iter.hasNext() ); - - IASTMethod method = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aPrivateMethod" ); //$NON-NLS-1$ - } - - public void testCompletionLookup_FriendClass_2() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class C {" ); //$NON-NLS-1$ - writer.write( " void foo();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateMethod();" ); //$NON-NLS-1$ - writer.write( " friend class C;" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "void C::foo(){" ); //$NON-NLS-1$ - writer.write( " A a;" ); //$NON-NLS-1$ - writer.write( " a.a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "a.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - assertTrue( iter.hasNext() ); - - IASTMethod method = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aPrivateMethod" ); //$NON-NLS-1$ - } - - - public void testCompletionLookup_ParametersAsLocalVariables() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "int foo( int aParameter ){" ); //$NON-NLS-1$ - writer.write( " int aLocal;" ); //$NON-NLS-1$ - writer.write( " if( aLocal != 0 ){" ); //$NON-NLS-1$ - writer.write( " int aBlockLocal;" ); //$NON-NLS-1$ - writer.write( " a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( " a " ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTCodeScope ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull( node.getCompletionContext() ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.LOCAL_VARIABLES }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTVariable aBlockLocal = (IASTVariable) iter.next(); - IASTVariable aLocal = (IASTVariable) iter.next(); - IASTParameterDeclaration aParameter = (IASTParameterDeclaration) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( aBlockLocal.getName(), "aBlockLocal" ); //$NON-NLS-1$ - assertEquals( aLocal.getName(), "aLocal" ); //$NON-NLS-1$ - assertEquals( aParameter.getName(), "aParameter" ); //$NON-NLS-1$ - } - - public void testCompletionLookup_LookupKindTHIS() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "int aGlobalVar;" ); //$NON-NLS-1$ - writer.write( "namespace NS { " ); //$NON-NLS-1$ - writer.write( " int aNamespaceFunction(){}" ); //$NON-NLS-1$ - writer.write( " class Base { " ); //$NON-NLS-1$ - writer.write( " protected: int aBaseField;" ); //$NON-NLS-1$ - writer.write( " };" ); //$NON-NLS-1$ - writer.write( " class Derived : public Base {" ); //$NON-NLS-1$ - writer.write( " int aMethod();" ); //$NON-NLS-1$ - writer.write( " };" ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - writer.write( "int NS::Derived::aMethod(){"); //$NON-NLS-1$ - writer.write( " int aLocal;" ); //$NON-NLS-1$ - writer.write( " a "); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( " a " ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - - assertNotNull( node ); - - assertEquals( node.getCompletionPrefix(), "a" ); //$NON-NLS-1$ - assertTrue( node.getCompletionScope() instanceof IASTMethod ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 2 ); - - Iterator iter = result.getNodes(); - IASTMethod method = (IASTMethod) iter.next(); - IASTField field = (IASTField) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( field.getName(), "aBaseField" ); //$NON-NLS-1$ - - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS, IASTNode.LookupKind.METHODS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - iter = result.getNodes(); - method = (IASTMethod) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - } - - public void testCompletionInConstructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class SimpleTest{"); //$NON-NLS-1$ - writer.write(" public:"); //$NON-NLS-1$ - writer.write("SimpleTest();"); //$NON-NLS-1$ - writer.write("~SimpleTest();"); //$NON-NLS-1$ - writer.write("int a, b, c, aa, bb, cc, abc;"); //$NON-NLS-1$ - writer.write("};"); //$NON-NLS-1$ - writer.write("SimpleTest::~SimpleTest()"); //$NON-NLS-1$ - writer.write("{}"); //$NON-NLS-1$ - writer.write("SimpleTest::SimpleTest()"); //$NON-NLS-1$ - writer.write("{"); //$NON-NLS-1$ - writer.write("/**/a"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTCompletionNode node = parse( writer.toString(), writer.toString().indexOf("/**/a") + 5 ); //$NON-NLS-1$ - assertNotNull(node); - assertEquals(node.getCompletionPrefix(), "a"); //$NON-NLS-1$ - assertTrue(node.getCompletionScope() instanceof IASTMethod); - IASTMethod inquestion = (IASTMethod)node.getCompletionScope(); - assertEquals( inquestion.getName(), "SimpleTest"); //$NON-NLS-1$ - assertTrue(inquestion.isConstructor()); - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull(node.getCompletionContext()); - LookupKind[] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - - ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$ - assertEquals(result.getResultsSize(), 3 ); - } - - public void testCompletionInDestructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class SimpleTest{"); //$NON-NLS-1$ - writer.write(" public:"); //$NON-NLS-1$ - writer.write("SimpleTest();"); //$NON-NLS-1$ - writer.write("~SimpleTest();"); //$NON-NLS-1$ - writer.write("int a, b, c, aa, bb, cc, abc;"); //$NON-NLS-1$ - writer.write("};"); //$NON-NLS-1$ - writer.write("SimpleTest::SimpleTest()"); //$NON-NLS-1$ - writer.write("{}"); //$NON-NLS-1$ - writer.write("SimpleTest::~SimpleTest()"); //$NON-NLS-1$ - writer.write("{"); //$NON-NLS-1$ - writer.write("/**/a"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTCompletionNode node = parse( writer.toString(), writer.toString().indexOf("/**/a") + 5 ); //$NON-NLS-1$ - assertNotNull(node); - assertEquals(node.getCompletionPrefix(), "a"); //$NON-NLS-1$ - assertTrue(node.getCompletionScope() instanceof IASTMethod); - IASTMethod inquestion = (IASTMethod)node.getCompletionScope(); - assertEquals( inquestion.getName(), "~SimpleTest"); //$NON-NLS-1$ - assertTrue(inquestion.isDestructor()); - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull(node.getCompletionContext()); - LookupKind[] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - - ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$ - assertEquals(result.getResultsSize(), 3 ); - } - - public void testBug48307_FriendFunction_1() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{ public : void foo(); }; " ); //$NON-NLS-1$ - writer.write( "class B{ "); //$NON-NLS-1$ - writer.write( " private : int aPrivate;" ); //$NON-NLS-1$ - writer.write( " friend void A::foo(); "); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void A::foo(){" ); //$NON-NLS-1$ - writer.write( " B b;"); //$NON-NLS-1$ - writer.write( " b.aP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b.aP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index + 4 ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - IASTField field = (IASTField) result.getNodes().next(); - assertEquals( field.getName(), "aPrivate" ); //$NON-NLS-1$ - } - - public void testBug48307_FriendFunction_2() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "void global();" ); //$NON-NLS-1$ - writer.write( "class B{ "); //$NON-NLS-1$ - writer.write( " private : int aPrivate;" ); //$NON-NLS-1$ - writer.write( " friend void global(); "); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void global(){" ); //$NON-NLS-1$ - writer.write( " B b;"); //$NON-NLS-1$ - writer.write( " b.aP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b.aP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index + 4 ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - IASTField field = (IASTField) result.getNodes().next(); - assertEquals( field.getName(), "aPrivate" ); //$NON-NLS-1$ - } - - public void testBug51260() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( " class A { public: void a(); }; " ); //$NON-NLS-1$ - writer.write( " class B : public virtual A { public: void b(); };" ); //$NON-NLS-1$ - writer.write( " class C : public virtual A { public: void c(); };" ); //$NON-NLS-1$ - writer.write( " class D : public B, C { public: void d(); };" ); //$NON-NLS-1$ - - writer.write( " void A::a(){} "); //$NON-NLS-1$ - writer.write( " void B::b(){} "); //$NON-NLS-1$ - writer.write( " void C::c(){} "); //$NON-NLS-1$ - writer.write( " void D::d(){ SP }" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.THIS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 4 ); - - Iterator iter = result.getNodes(); - IASTMethod d = (IASTMethod) iter.next(); - IASTMethod b = (IASTMethod) iter.next(); - IASTMethod a = (IASTMethod) iter.next(); - IASTMethod c = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( a.getName(), "a" ); //$NON-NLS-1$ - assertEquals( b.getName(), "b" ); //$NON-NLS-1$ - assertEquals( c.getName(), "c" ); //$NON-NLS-1$ - assertEquals( d.getName(), "d" ); //$NON-NLS-1$ - - } - - public void testBug52948() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "typedef int Int; "); //$NON-NLS-1$ - writer.write( "InSP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.TYPEDEFS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - - Iterator iter = result.getNodes(); - IASTTypedefDeclaration typeDef = (IASTTypedefDeclaration) iter.next(); - - assertEquals( typeDef.getName(), "Int" ); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - - - public void testCompletionInFunctionBodyFullyQualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aInteger = 5;\n"); //$NON-NLS-1$ - writer.write( "namespace NMS { \n"); //$NON-NLS-1$ - writer.write( " int foo() { \n"); //$NON-NLS-1$ - writer.write( "::A "); //$NON-NLS-1$ - writer.write( "}\n}\n"); //$NON-NLS-1$ - String code = writer.toString(); - - for( int i = 0; i < 2; ++i ) - { - String stringToCompleteAfter = ( i == 0 ) ? "::" : "::A"; //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() ); - - validateCompletionNode(node, ( i == 0 ? "" : "A"), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, getCompilationUnit(), false ); //$NON-NLS-1$ //$NON-NLS-2$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - Set results = new HashSet(); - results.add( "aInteger"); //$NON-NLS-1$ - if( i == 0 ) - results.add( "NMS"); //$NON-NLS-1$ - validateLookupResult(result, results ); - } - } - - public void testCompletionInFunctionBodyQualifiedName() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "namespace ABC {\n"); //$NON-NLS-1$ - writer.write( " struct DEF { int x; }; \n" ); //$NON-NLS-1$ - writer.write( " struct GHI { float y;};\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC::D }\n"); //$NON-NLS-1$ - String code = writer.toString(); - - for( int j = 0; j< 2; ++j ) - { - String stringToCompleteAfter = (j == 0 ) ? "::" : "::D"; //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() ); - - IASTNamespaceDefinition namespaceDefinition = null; - Iterator i = callback.getCompilationUnit().getDeclarations(); - while( i.hasNext() ) - { - IASTDeclaration d = (IASTDeclaration) i.next(); - if( d instanceof IASTNamespaceDefinition ) - if( ((IASTNamespaceDefinition)d).getName().equals( "ABC") ) //$NON-NLS-1$ - { - namespaceDefinition = (IASTNamespaceDefinition) d; - break; - } - } - assertNotNull( namespaceDefinition ); - validateCompletionNode( node, - ( j == 0 ) ? "" : "D", //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, namespaceDefinition, false ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - Set results = new HashSet(); - results.add( "DEF"); //$NON-NLS-1$ - if( j == 0 ) - results.add( "GHI"); //$NON-NLS-1$ - validateLookupResult(result, results ); - } - - } - - public void testCompletionWithTemplateInstanceAsParent() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "template < class T > class A { public : int a_member; }; "); //$NON-NLS-1$ - writer.write( "template < class T > class B : public A< T > { public : int b_member; }; "); //$NON-NLS-1$ - writer.write( "void f() { "); //$NON-NLS-1$ - writer.write( " B< int > b; "); //$NON-NLS-1$ - writer.write( " b.SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( "", //$NON-NLS-1$ - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - Iterator i = result.getNodes(); - - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - assertFalse( i.hasNext() ); - } - - public void testBug58178() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define GL_T 0x2001\n"); //$NON-NLS-1$ - writer.write( "#define GL_TRUE 0x1\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned char GLboolean;\n"); //$NON-NLS-1$ - writer.write( "static GLboolean should_rotate = GL_T"); //$NON-NLS-1$ - String code = writer.toString(); - final String where = "= GL_T"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( where ) + where.length() ); - assertEquals( node.getCompletionPrefix(), "GL_T"); //$NON-NLS-1$ - } - - public void testBug52253() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class CMyClass {public:\n void doorBell(){ return; }};"); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {CMyClass mc; mc.do }"); //$NON-NLS-1$ - String code = writer.toString(); - final String where = "mc.do"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( where) + where.length() ); - assertEquals( node.getCompletionPrefix(), "do"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.MEMBER_REFERENCE ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - Iterator i = result.getNodes(); - IASTMethod doorBell = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - assertEquals( doorBell.getName(), "doorBell"); //$NON-NLS-1$ - - } - - public void testBug58492() throws Exception - { - Writer writer = new StringWriter(); - writer.write("struct Cube { "); //$NON-NLS-1$ - writer.write(" int nLen; "); //$NON-NLS-1$ - writer.write(" int nWidth; "); //$NON-NLS-1$ - writer.write(" int nHeight; "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("int volume( struct Cube * pCube ) { "); //$NON-NLS-1$ - writer.write(" pCube->SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf("SP"), ParserLanguage.C ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] {IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 3 ); - Iterator i = result.getNodes(); - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - } - - public void testCompletionOnExpression() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC { public: void voidMethod(); };\n"); //$NON-NLS-1$ - writer.write( "ABC * someFunction(void) { return new ABC(); }\n"); //$NON-NLS-1$ - writer.write( "void testFunction( void ) { someFunction()->V }\n" ); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "V"); //$NON-NLS-1$ - if( i == 1 ) ++index; - IASTCompletionNode node = parse( code, index ); - assertEquals( node.getCompletionPrefix(), (i == 0 )? "": "V"); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals( node.getCompletionKind(), CompletionKind.MEMBER_REFERENCE ); - assertTrue( node.getCompletionContext() instanceof IASTExpression ); - } - - } - - public void testCompletionInTypeDef() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "struct A { int name; }; \n" ); //$NON-NLS-1$ - writer.write( "typedef struct A * PA; \n" ); //$NON-NLS-1$ - writer.write( "int main() { \n" ); //$NON-NLS-1$ - writer.write( " PA a; \n" ); //$NON-NLS-1$ - writer.write( " a->SP \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - - Iterator iter = result.getNodes(); - IASTField name = (IASTField) iter.next(); - - assertEquals( name.getName(), "name" ); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - - public void testBug59134() throws Exception - { - String code = "int main(){ siz }"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf(" siz") ); //$NON-NLS-1$ - assertNotNull( node ); - Iterator keywords = node.getKeywords(); - boolean passed = false; - while( keywords.hasNext() ) - { - String keyword = (String) keywords.next(); - if( keyword.equals( "sizeof")) //$NON-NLS-1$ - passed = true; - } - assertTrue( passed ); - - } - - public void testBug59893() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct A { \n" ); //$NON-NLS-1$ - writer.write( " void f1() const volatile; \n" ); //$NON-NLS-1$ - writer.write( " void f2() const; \n" ); //$NON-NLS-1$ - writer.write( " void f3() volatile; \n" ); //$NON-NLS-1$ - writer.write( " void f4(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void main( const A& a1 ) \n" ); //$NON-NLS-1$ - writer.write( "{ \n" ); //$NON-NLS-1$ - writer.write( " const volatile A * a2; \n" ); //$NON-NLS-1$ - writer.write( " const A * a3; \n" ); //$NON-NLS-1$ - writer.write( " volatile A * a4; \n" ); //$NON-NLS-1$ - writer.write( " A * a5; \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - - IASTCompletionNode node = parse( code + "a1. ", code.length() + 3 ); //$NON-NLS-1$ - - assertNotNull( node ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a2-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - - node = parse( code + "a3-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a4-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a5-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 4 ); - } - - public void testBug59893_Expression() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct A { \n" ); //$NON-NLS-1$ - writer.write( " void f2() const; \n" ); //$NON-NLS-1$ - writer.write( " void f4(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "const A * foo(){} \n" ); //$NON-NLS-1$ - writer.write( "void main( ) \n" ); //$NON-NLS-1$ - writer.write( "{ \n" ); //$NON-NLS-1$ - writer.write( " foo()->SP \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - } - - public void testParameterListFunctionReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int foo( int firstParam, int secondParam );\n"); //$NON-NLS-1$ - writer.write( "void main() { \n"); //$NON-NLS-1$ - writer.write( " int abc;\n"); //$NON-NLS-1$ - writer.write( " int x;\n" ); //$NON-NLS-1$ - writer.write( " foo( x,a"); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "x,a") + 2; //$NON-NLS-1$ - if( i == 1 ) index++; - IASTCompletionNode node = parse( code, index ); - validateCompletionNode(node, (( i == 0 ) ? "" : "a" ), CompletionKind.FUNCTION_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$ - assertNotNull( node.getFunctionParameters() ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES }, - node.getCompletionContext(), null ); - assertNotNull(result); - assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 ); - } - } - - public void testParameterListConstructorReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A { \n"); //$NON-NLS-1$ - writer.write( "public:\n"); //$NON-NLS-1$ - writer.write( " A( int first, int second );\n"); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "void main() { \n"); //$NON-NLS-1$ - writer.write( " int four, x;"); //$NON-NLS-1$ - writer.write( " A * a = new A( x,f "); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "x,f") + 2; //$NON-NLS-1$ - if( i == 1 ) index++; - IASTCompletionNode node = parse( code, index ); - validateCompletionNode(node, (( i == 0 ) ? "" : "f" ), CompletionKind.CONSTRUCTOR_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$ - assertNotNull( node.getFunctionParameters() ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES }, - node.getCompletionContext(), null ); - assertNotNull(result); - assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 ); - } - } - - public void testConstructors() throws Exception - { - String code = "class Foo{ public: Foo(); }; Foo::SP "; //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - IASTMethod constructor = (IASTMethod) result.getNodes().next(); - assertEquals( constructor.getName(), "Foo" ); //$NON-NLS-1$ - } - - public void testBug50807() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo();" ); //$NON-NLS-1$ - writer.write( "void foo( int );" ); //$NON-NLS-1$ - writer.write( "void foo( int, char );" ); //$NON-NLS-1$ - writer.write( "void foo( int, int, int );" ); //$NON-NLS-1$ - writer.write( "void bar(){ " ); //$NON-NLS-1$ - - String code = writer.toString() + "foo( SP"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$ - ILookupResult result = node.getCompletionScope().lookup( node.getFunctionName(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 4 ); - - code = writer.toString() + "foo( 1, SP"; //$NON-NLS-1$ - node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$ - result = node.getCompletionScope().lookup( node.getFunctionName(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, - node.getCompletionContext(), node.getFunctionParameters() ); - - assertEquals( result.getResultsSize(), 2 ); - } - - public void testBug60298() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC { public: ABC(); int myInt(); };\n"); //$NON-NLS-1$ - writer.write( "int ABC::" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "::") + 2 ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE ); - - } - - public void testBug62344() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " namespace Foo{ class bar{}; } "); //$NON-NLS-1$ - writer.write( " void main() { "); //$NON-NLS-1$ - writer.write( " Foo::bar * foobar = new Foo::SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.NEW_TYPE_REFERENCE ); - } - - public void testBug62339() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct Cube { int nLength; int nWidth; int nHeight; };\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) { struct Cube * pCube;\n" ); //$NON-NLS-1$ - writer.write( " pCube = (str" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "(str") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - boolean foundStruct = false; - Iterator i = node.getKeywords(); - while( i.hasNext() ) - if( ((String) i.next()).equals( "struct")) //$NON-NLS-1$ - foundStruct = true; - assertTrue( foundStruct ); - } - - public void testBug62721() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int f() {\n" ); //$NON-NLS-1$ - writer.write( "short blah;\n" ); //$NON-NLS-1$ - writer.write( "int x = sizeof(bl" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "of(bl") + 3); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull( node.getCompletionContext() ); - IASTNode.LookupKind [] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES; - IASTNode.ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kinds, null, null ); - assertEquals( result.getResultsSize(), 1 ); - IASTNode blah = (IASTNode) result.getNodes().next(); - assertTrue( blah instanceof IASTVariable ); - assertEquals( ((IASTVariable)blah).getName(), "blah" ); //$NON-NLS-1$ - } - - public void testBug62725() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int f() {\n" ); //$NON-NLS-1$ - writer.write( " int biSizeImage = 5;\n" ); //$NON-NLS-1$ - writer.write( "for (int i = 0; i < bi " ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "< bi") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionPrefix(), "bi"); //$NON-NLS-1$\ - assertNull( node.getCompletionContext() ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - } - - public void testBug62728() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct Temp { char * t; };" ); //$NON-NLS-1$ - writer.write( "int f(Temp * t) {\n" ); //$NON-NLS-1$ - writer.write( "t->t[5] = t-> "); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "= t->") + 5 ); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$ - assertNotNull( node.getCompletionContext() ); - } - - public void testBug64271() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = bl\n"); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "= bl") + 4); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertEquals( node.getCompletionPrefix(), "bl"); //$NON-NLS-1$ - assertNull( node.getCompletionContext() ); - assertFalse( node.getKeywords().hasNext() ); - - LookupKind[] kind = new LookupKind[1]; - kind[0] = LookupKind.ENUMERATORS; - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kind, null, null ); - assertNotNull( result ); - assertEquals( result.getResultsSize(), 3 ); - } - - public void testBug52988() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - ParserLanguage language = ( i == 0 ) ? ParserLanguage.C : ParserLanguage.CPP; - String code = "void foo() { "; //$NON-NLS-1$ - Set kset = KeywordSets.getKeywords( KeywordSetKey.STATEMENT, language ); - - validateAllKeywordsAndPrefixes( code, kset, language ); - } - } - - /** - * @param startingCode - * @param keywordsToTry - * @param language - * @throws Exception - */ - private void validateAllKeywordsAndPrefixes(String startingCode, Set keywordsToTry, ParserLanguage language) throws Exception { - Iterator keywordIterator = keywordsToTry.iterator(); - while( keywordIterator.hasNext() ) - { - String keyword = (String) keywordIterator.next(); - for( int i = 0; i < keyword.length(); ++i ) - { - String substring = keyword.subSequence( 0, i ).toString(); - String totalCode = (startingCode + substring); - IASTCompletionNode node = parse( totalCode, totalCode.length() - 1, language ); - assertNotNull( node ); - assertTrue( "Failure on keyword=" + keyword + " prefix=" + substring, setContainsKeyword( node.getKeywords(), keyword )); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - } - - /** - * @param keywords - * @param keyword - * @return - */ - private boolean setContainsKeyword(Iterator keywords, String keyword) { - while( keywords.hasNext() ) - { - if( keywords.next().equals( keyword )) return true; - } - return false; - } - - public void testBug66543() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct packet { int a; int b; };\n" ); //$NON-NLS-1$ - writer.write( "struct packet buffer[5];\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " buffer[2]." ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "[2].") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - assertNotNull( node.getCompletionContext() ); - IASTNode.LookupKind [] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kinds, node.getCompletionContext(), node.getFunctionParameters() ); - assertNotNull( result ); - assertEquals( result.getResultsSize(), 2 ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java deleted file mode 100644 index 39fe4b34223..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.eclipse.cdt.core.parser.tests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.CodeReader; -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.ParserLanguage; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.internal.core.parser.IExpressionParser; -import org.eclipse.cdt.internal.core.parser.InternalParserUtil; - -public class ExprEvalTest extends TestCase { - - public static Test suite() { - return new TestSuite(ExprEvalTest.class); - } - - public ExprEvalTest(String name) { - super(name); - } - - public void runTest(String code, int expectedValue) throws Exception { - - final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor(); - IExpressionParser parser = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService(), null ), ParserLanguage.CPP, null ); - IASTExpression expression = parser.expression(null,null, null); - assertEquals(expectedValue, expression.evaluateExpression()); - } - - public void testInteger() throws Exception { - runTest("5;", 5); //$NON-NLS-1$ - runTest( "33;", 33 ); //$NON-NLS-1$ - } - - public void testNot() throws Exception - { - runTest( "!1;", 0 ); //$NON-NLS-1$ - runTest( "!0;", 1 ); //$NON-NLS-1$ - runTest( "!4;", 0 ); //$NON-NLS-1$ - runTest( "!!4;", 1 ); //$NON-NLS-1$ - } - - public void testMultiplicational() throws Exception - { - runTest( "3 * 4;", 12 ); //$NON-NLS-1$ - runTest( "55 * 2;", 110 ); //$NON-NLS-1$ - runTest( "4 / 3;", 1 ); //$NON-NLS-1$ - runTest( "100/4;", 25 ); //$NON-NLS-1$ - runTest( "8 % 2;", 0 ); //$NON-NLS-1$ - runTest( "8 % 3;", 2 ); //$NON-NLS-1$ - } - - public void testAdditive() throws Exception - { - runTest( "4 + 4;", 8 ); //$NON-NLS-1$ - runTest( "4 - 4;", 0 ); //$NON-NLS-1$ - } - - public void testLogicalAnd() throws Exception - { - runTest( "4 && 5;", 1 ); //$NON-NLS-1$ - runTest( "0 && 5;", 0 ); //$NON-NLS-1$ - runTest( "5 && 0;", 0 ); //$NON-NLS-1$ - runTest( "0 && 0;", 0 ); //$NON-NLS-1$ - } - - public void testLogicalOr() throws Exception - { - runTest( "4 || 5;", 1 ); //$NON-NLS-1$ - runTest( "0 || 5;", 1 ); //$NON-NLS-1$ - runTest( "5 || 0;", 1 ); //$NON-NLS-1$ - runTest( "0 || 0;", 0 ); //$NON-NLS-1$ - } - - public void testRelational() throws Exception { - runTest("1 < 2;", 1); //$NON-NLS-1$ - runTest("2 < 1;", 0); //$NON-NLS-1$ - runTest("2 == 1 + 1;", 1); //$NON-NLS-1$ - runTest("2 != 1 + 1;", 0); //$NON-NLS-1$ - } - - public void testBracketed() throws Exception { - runTest("2 * (3 + 4);", 14); //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java deleted file mode 100644 index 306e5f0f3fb..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java +++ /dev/null @@ -1,206 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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 ); -// } - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java deleted file mode 100644 index 645077607a0..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM 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.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 = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").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; -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java deleted file mode 100644 index a1b0f570802..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java +++ /dev/null @@ -1,2632 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISpecializedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author aniefer - */ - -public class ParserSymbolTableTemplateTests extends TestCase { - - public ParserSymbolTable table = null; - public TypeInfoProvider provider = null; - - public ParserSymbolTableTemplateTests( String arg ) - { - super( arg ); - } - - public ParserSymbolTable newTable(){ - return newTable( ParserLanguage.CPP ); - } - - public ParserSymbolTable newTable( ParserLanguage language ){ - table = new ParserSymbolTable( language, ParserMode.COMPLETE_PARSE ); - provider = table.getTypeInfoProvider(); - return table; - } - - /** - * - * @throws Exception - * - * template < class T > class A : public T {}; - * - * class B - * { - * int i; - * } - * - * A<B> a; - * a.i; //finds B::i; - */ - public void testTemplateParameterAsParent() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol param = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - A.addParent( param ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$ - B.addSymbol( i ); - table.getCompilationUnit().addSymbol( B ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ); - ArrayList args = new ArrayList(); - args.add( type ); - - IContainerSymbol instance = (IContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertEquals( instance.getInstantiatedSymbol(), A ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( instance ); - - table.getCompilationUnit().addSymbol( a ); - - ISymbol look = table.getCompilationUnit().lookup( "a" ); //$NON-NLS-1$ - - assertEquals( look, a ); - - ISymbol symbol = a.getTypeSymbol(); - assertEquals( symbol, instance ); - - look = instance.lookup( "i" ); //$NON-NLS-1$ - assertEquals( look, i ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * template < class T > class A { T t; } - * class B : public A< int > { } - * - * B b; - * b.t; //finds A::t, will be type int - */ - public void testTemplateInstanceAsParent() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ISymbol t = table.newSymbol( "t", ITypeInfo.t_type ); //$NON-NLS-1$ - ISymbol look = template.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, param ); - t.setTypeSymbol( param ); - A.addSymbol( t ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0 , null ); - ArrayList args = new ArrayList(); - args.add( type ); - - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - - B.addParent( look ); - - ISymbol b = table.newSymbol( "b", ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( B ); - table.getCompilationUnit().addSymbol( b ); - - look = table.getCompilationUnit().lookup( "b" ); //$NON-NLS-1$ - assertEquals( look, b ); - - look = ((IDerivableContainerSymbol) b.getTypeSymbol()).lookup( "t" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), t ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * The scope of a template-parameter extends from its point of declaration - * until the end of its template. In particular, a template parameter can be used - * in the declaration of a subsequent template-parameter and its default arguments. - * @throws Exception - * - * template< class T, class U = T > class X - * { - * T t; - * U u; - * }; - * - * X< char > x; - * x.t; - * x.u; - */ - public void testTemplateParameterDefaults() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - - ISymbol paramT = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ISymbol look = template.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, paramT ); - ISymbol paramU = table.newSymbol( "U" ); //$NON-NLS-1$ - paramU.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter, 0, null, null, - TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ) ) ); - template.addTemplateParameter( paramU ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - look = X.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, paramT ); - ISymbol t = table.newSymbol( "t", ITypeInfo.t_type ); //$NON-NLS-1$ - t.setTypeSymbol( look ); - X.addSymbol( t ); - - look = X.lookup( "U" ); //$NON-NLS-1$ - assertEquals( look, paramU ); - ISymbol u = table.newSymbol( "u", ITypeInfo.t_type ); //$NON-NLS-1$ - u.setTypeSymbol( look ); - X.addSymbol( u ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - ArrayList args = new ArrayList(); - args.add( type ); - IDerivableContainerSymbol lookX = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( lookX.isTemplateInstance() ); - assertEquals( lookX.getInstantiatedSymbol(), X ); - - - look = lookX.lookup( "t" ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), t ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - - look = lookX.lookup( "u" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), u ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * template < class T > class A { - * T t; - * }; - * class B {}; - * void f( char c ) {} - * void f( A<B> b ) { ... } - * void f( int i ) {} - * - * A<B> a; - * f( a ); //calls f( A<B> ) - * - */ - public void testTemplateParameterAsFunctionArgument() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol paramT = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ISymbol t = table.newSymbol( "t", ITypeInfo.t_type ); //$NON-NLS-1$ - t.setTypeSymbol( paramT ); - A.addSymbol( t ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - ArrayList args = new ArrayList(); - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ); - args.add( arg ); - - IDerivableContainerSymbol lookA = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( lookA.isTemplateInstance() ); - assertEquals( lookA.getInstantiatedSymbol(), A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_char, 0, null, false ); - table.getCompilationUnit().addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( lookA, 0, null, false ); - table.getCompilationUnit().addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - table.getCompilationUnit().addSymbol( f3 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ) ); - IDerivableContainerSymbol lookA2 = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertEquals( lookA2, lookA ); - - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( lookA ); - table.getCompilationUnit().addSymbol( a ); - - ArrayList params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * class T { }; - * int i; - * - * template< class T, T i > void f( T t ) - * { - * T t1 = i; //template parameters T & i - * } - */ - public void test_14_1__3_ParameterLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol T = table.newDerivableContainerSymbol( "T", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( T ); - - ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( i ); - - ITemplateSymbol template = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - - ISymbol paramT = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - ISymbol parami = table.newSymbol( "i", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - parami.getTypeInfo().setTemplateParameterType( ITypeInfo.t_type ); - - ISymbol look = factory.lookup( "T" ); //$NON-NLS-1$ - - assertEquals( look, paramT ); - parami.setTypeSymbol( look ); - template.addTemplateParameter( parami ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - ISymbol fParam = table.newSymbol( "t", ITypeInfo.t_type ); //$NON-NLS-1$ - fParam.setTypeSymbol( paramT ); - f.addParameter( fParam ); - - factory.addSymbol( f ); - - look = f.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, paramT ); - - look = f.lookup( "i" ); //$NON-NLS-1$ - assertEquals( look, parami ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A non-type template parameter of type "array of T" or "function returning T" is adjusted to - * be of type "pointer to T" or "pointer to function returning T" respectively - * - * template < int *a > struct R {}; - * template < int b[5] > struct S {}; - * - * int *p; - * R<p> w; //ok - * S<p> x; //ok due to parameter adjustment - * int v[5]; - * R<v> y; //ok due to implicit argument conversion - * S<v> z; //ok due to adjustment and conversion - * @throws Exception - */ - public void test_14_1__8_ParameterAdjustment() throws Exception{ - newTable(); - - ITemplateSymbol templateR = table.newTemplateSymbol( "R" ); //$NON-NLS-1$ - - ISymbol paramA = table.newSymbol( "a", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - paramA.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - paramA.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - templateR.addTemplateParameter( paramA ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateR ); - - IDerivableContainerSymbol R = table.newDerivableContainerSymbol( "R", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( R ); - - ITemplateSymbol templateS = table.newTemplateSymbol( "S" ); //$NON-NLS-1$ - - ISymbol paramB = table.newSymbol( "b", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - paramB.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - paramB.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - templateS.addTemplateParameter( paramB ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateS ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( S ); - - ISymbol look = table.getCompilationUnit().lookup( "S" ); //$NON-NLS-1$ - assertEquals( look, templateS ); - - Iterator iter = templateS.getParameterList().iterator(); - ISymbol param = (ISymbol) iter.next(); - assertFalse( iter.hasNext() ); - iter = param.getTypeInfo().getPtrOperators().iterator(); - ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( ptr.getType(), ITypeInfo.PtrOp.t_pointer ); - - ISymbol p = table.newSymbol( "p", ITypeInfo.t_int ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - table.getCompilationUnit().addSymbol( p ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - look = table.getCompilationUnit().lookupTemplateId( "R", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), R ); - - look = table.getCompilationUnit().lookupTemplateId( "S", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), S ); - - ISymbol v = table.newSymbol( "v", ITypeInfo.t_int ); //$NON-NLS-1$ - v.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - table.getCompilationUnit().addSymbol( v ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, v ) ); - - look = table.getCompilationUnit().lookupTemplateId( "R", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), R ); - - look = table.getCompilationUnit().lookupTemplateId( "S", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), S ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * When default template-arguments are used, a template-argument list can be empty. In that - * case, the empty <> brackets shall still be used as the template-argument list - * - * template< class T = char > class String; - * String <> * p; //ok, T = char - * - * @throws Exception - */ - public void test_14_3__4_ParameterDefaults() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "String" ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "T" ); //$NON-NLS-1$ - param.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter, 0, null, null, - TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) )); - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "String", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( string ); - - List args = new ArrayList(); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "String", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), string ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A local type, a type with no linkage, an unnamed type or a type compounded from - * any of these type shall not be used as a template-argument for a template-parameter - * - * template <class T> class X { }; - * void f(){ - * struct S { }; - * - * X<S> x; //error - * X<S*> y; //error - * } - * @throws Exception - */ - public void test_14_3_1__2_TypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - factory.addSymbol( table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ) ); //$NON-NLS-1$ - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( f ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S", ITypeInfo.t_struct ); //$NON-NLS-1$ - f.addSymbol( S ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, S ) ); - try{ - f.lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, S, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - try{ - f.lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A String literal is not an acceptable template-argument for a non-type, non-template parameter - * because a string literal is an object with internal linkage - * - * template< class T, char* p> class X {}; - * - * X< int, "Studebaker" > x1; //error - * - * char p [] = "Vivisectionist"; - * X< int, p > x2; //ok - * - * @throws Exception - */ - public void test_14_3_2__2_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ISymbol param2 = table.newSymbol( "p", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - param2.getTypeInfo().setTemplateParameterType( ITypeInfo.t_char ); - param2.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - template.addTemplateParameter( param2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - provider.beginTypeConstruction(); - provider.setType( ITypeInfo.t_char ); - provider.setDefaultObj( "Studebaker" ); //$NON-NLS-1$ - ITypeInfo info = provider.completeConstruction(); - info.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - args.add( info ); //$NON-NLS-1$ - - try{ - table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - ISymbol p = table.newSymbol( "p", ITypeInfo.t_char ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - table.getCompilationUnit().addSymbol( p ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), X ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * names or addresses of non-static class members are not acceptable non-type template arguments - * - * template < int * p > class X {}; - * - * struct S - * { - * int m; - * static int s; - * int * t; - * } s; - * - * X<&s.m> x1; //error, address of non-static member - * X<s.t> x2; //error, name of non-static member - * X<&S::s> x3; //ok, address of static member - * - * @throws Exception - */ - public void test_14_3_2__3_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "p", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - param.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S", ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( S ); - - ISymbol m = table.newSymbol( "m", ITypeInfo.t_int ); //$NON-NLS-1$ - S.addSymbol( m ); - ISymbol s = table.newSymbol( "s", ITypeInfo.t_int ); //$NON-NLS-1$ - s.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - S.addSymbol( s ); - ISymbol t = table.newSymbol( "t", ITypeInfo.t_int ); //$NON-NLS-1$ - t.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - S.addSymbol( t ); - - List args = new ArrayList(); - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, m ); - arg.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - args.add( arg ); - - try - { - table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, t ) ); - - try - { - table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, s ); - arg.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - args.add( arg ); - - assertNotNull( table.getCompilationUnit().lookupTemplateId( "X", args ) ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Tempories, unnamed lvalues, and named lvalues that do not have external linkage are - * not acceptable template-arguments when the corresponding template-parameter has - * reference type - * - * template< const int & I > struct B {}; - * - * B<1> b1; //error, temporary would be required - * int c = 1; - * B<c> b2; //ok - * @throws Exception - */ - public void test_14_3_2__4_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "B" ); //$NON-NLS-1$ - - ISymbol I = table.newSymbol( "I", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - I.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - I.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ) ); - template.addTemplateParameter( I ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( B ); - - List args = new ArrayList( ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1" ) ); //$NON-NLS-1$ - - try{ - table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - ISymbol c = table.newSymbol( "c", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( c ); - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), B ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > class A { - * int x; - * }; - * - * template < class T > class A < T * > { - * long x; - * }; - * - * template< template< class U > class V > class C{ - * V< int > y; - * V< int * > z; - * } - * - * C< A > c; //V<int> uses primary template, so C.y.x is type int - * //V<int*> uses partial specialization, so C.z.x is type long - * - * @throws Exception - */ - public void test_14_3_3__2_PartialSpecialization_TemplateTemplateParameter() throws Exception{ - //TODO - newTable(); - - ITemplateSymbol templateA = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( templateA ); - - templateA.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - templateA.addSymbol( A1 ); - - ISymbol x1 = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - A1.addSymbol( x1 ); - - ISpecializedSymbol specialization = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - templateA.addSpecialization( specialization ); - - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specialization.addTemplateParameter( T ); - specialization.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - specialization.addSymbol( A2 ); - - ISymbol x2 = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - x2.getTypeInfo().setBit( true, ITypeInfo.isLong ); - A2.addSymbol( x2 ); - - ITemplateSymbol templateC = table.newTemplateSymbol( "C" ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( templateC ); - - ITemplateSymbol templateV = table.newTemplateSymbol( "V" ); //$NON-NLS-1$ - templateV.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter ) ); - templateV.getTypeInfo().setTemplateParameterType( ITypeInfo.t_template ); - ISymbol U = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateV.addTemplateParameter( U ); - - templateC.addTemplateParameter( templateV ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C", ITypeInfo.t_class ); //$NON-NLS-1$ - templateC.addSymbol( C ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol look = templateC.lookupTemplateId( "V", args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - - ISymbol y = table.newSymbol( "y", ITypeInfo.t_type ); //$NON-NLS-1$ - y.setTypeSymbol( look ); - - C.addSymbol( y ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - look = templateC.lookupTemplateId( "V", args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - - ISymbol z = table.newSymbol( "z", ITypeInfo.t_type ); //$NON-NLS-1$ - z.setTypeSymbol( look ); - C.addSymbol( z ); - - look = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( look, templateA ); - - args.clear(); - args.add ( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ) ); - look = table.getCompilationUnit().lookupTemplateId( "C", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), C ); - - IDerivableContainerSymbol lookC = (IDerivableContainerSymbol)look; - look = lookC.lookup( "y" ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_type ); - ISymbol symbol = look.getTypeSymbol(); - assertTrue( symbol instanceof IContainerSymbol ); - assertTrue( symbol.isTemplateInstance() ); - assertEquals( symbol.getInstantiatedSymbol(), A1 ); - - look = ((IContainerSymbol) symbol).lookup( "x" ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( look.getTypeInfo().checkBit( ITypeInfo.isLong ), false ); - - look = lookC.lookup( "z" ); //$NON-NLS-1$ - assertEquals( look.getType(), ITypeInfo.t_type ); - symbol = look.getTypeSymbol(); - assertTrue( symbol instanceof IContainerSymbol ); - assertTrue( symbol.isTemplateInstance() ); - assertEquals( symbol.getInstantiatedSymbol(), A2 ); - look = ((IContainerSymbol)symbol).lookup( "x" ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( look.getTypeInfo().checkBit( ITypeInfo.isLong ), true ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T1, class T2 > struct A { - * T1 f1(); - * void f2(); - * }; - * - * template<class U, class V> U A< U, V >::f1() {} //ok - * - * template<class X, class Y> void A< Y, X >::f2() {} //error - * - * - * @throws Exception - */ - public void test_14_5_1__3_MemberFunctions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - ISymbol primaryT1 = table.newSymbol( "T1", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol primaryT2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( primaryT1 ); - template.addTemplateParameter( primaryT2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - factory.addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f1", ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol look = A.lookup( "T1" ); //$NON-NLS-1$ - assertEquals( look, primaryT1 ); - - f1.setIsForwardDeclaration( true ); - f1.setReturnType( look ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f2", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setIsForwardDeclaration( true ); - - A.addSymbol( f1 ); - A.addSymbol( f2 ); - - ITemplateSymbol temp = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - ISymbol U = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - temp.addTemplateParameter( V ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ISymbol returnType = factory.lookup( "U" ); //$NON-NLS-1$ - assertEquals( returnType, U ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, V ) ); - - look = factory.lookupTemplateIdForDefinition( "A", args ); //$NON-NLS-1$ - assertEquals( look, A ); - factory.pushTemplateId( look, args ); - - IParameterizedSymbol lookF = factory.lookupMethodForDefinition( "f1", new ArrayList() ); //$NON-NLS-1$ - assertEquals( lookF, f1 ); - assertTrue( lookF.isForwardDeclaration() ); - - IParameterizedSymbol defnd = table.newParameterizedSymbol( "f1", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setForwardSymbol( defnd ); - defnd.setReturnType( returnType ); - factory.addSymbol( defnd ); - - //Test that the adding was all good by doing a lookup - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - IDerivableContainerSymbol lookA = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( lookA.isTemplateInstance() ); - assertEquals( lookA.getInstantiatedSymbol(), A ); - - List params = new ArrayList(); - look = lookA.qualifiedFunctionLookup( "f1", params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), defnd ); - assertTrue( ((IParameterizedSymbol)look).getReturnType().isType( ITypeInfo.t_int ) ); - - params.clear(); - args.clear(); - - temp = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - ISymbol X = table.newSymbol( "X", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol Y = table.newSymbol( "Y", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( X ); - temp.addTemplateParameter( Y ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, Y ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, X ) ); - - try{ - look = factory.lookupTemplateIdForDefinition( "A", args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplate ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template<class T> struct A{ - * class B; - * }; - * template< class U > class A<U>::B { U i; }; - * A<int>::B b; - * - * @throws Exception - */ - public void test_14_5_1_2_MemberClass() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol primaryT = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( primaryT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - B.setIsForwardDeclaration( true ); - A.addSymbol( B ); - - ISymbol U = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ITemplateSymbol temp = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - - IContainerSymbol lookA = factory.lookupTemplateIdForDefinition( "A", args ); //$NON-NLS-1$ - assertEquals( lookA, A ); - factory.pushTemplateId( lookA, args ); - - ISymbol look = lookA.lookupMemberForDefinition( "B" ); //$NON-NLS-1$ - assertEquals( look, B ); - - IDerivableContainerSymbol newB = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - look.setForwardSymbol( newB ); - - factory.addSymbol( newB ); - - ISymbol i = table.newSymbol( "i", ITypeInfo.t_type ); //$NON-NLS-1$ - look = newB.lookup( "U" ); //$NON-NLS-1$ - assertEquals( look, U ); - i.setTypeSymbol( U ); - newB.addSymbol( i ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - - assertTrue( look instanceof IDerivableContainerSymbol ); - lookA = (IDerivableContainerSymbol) look; - look = lookA.qualifiedLookup( "B" ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newB ); - - look = ((IDerivableContainerSymbol) look).lookup( "i" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), i ); - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T> class X{ - * static T s; - * }; - * - * template<class U> U X<U>::s = 0; - * - * @throws Exception - */ - public void test_14_5_1_3_StaticDataMember() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - ISymbol look = X.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, T ); - - ISymbol s = table.newSymbol( "s", ITypeInfo.t_type ); //$NON-NLS-1$ - s.setTypeSymbol( look ); - s.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - s.setIsForwardDeclaration( true ); - X.addSymbol( s ); - - ITemplateSymbol temp = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - ISymbol paramU = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( paramU ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, paramU ) ); - - look = factory.lookupTemplateIdForDefinition( "X", args ); //$NON-NLS-1$ - assertEquals( look, X ); - factory.pushTemplateId( X, args ); - - look = ((IContainerSymbol)look).lookupMemberForDefinition("s" ); //$NON-NLS-1$ - assertEquals( look, s ); - assertTrue( look.isForwardDeclaration() ); - - ISymbol newS = table.newSymbol( "s", ITypeInfo.t_type ); //$NON-NLS-1$ - newS.setTypeSymbol( paramU ); - - look.setForwardSymbol( newS ); - - factory.addSymbol( newS ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), X ); - - look = ((IContainerSymbol)look).qualifiedLookup( "s" ); //$NON-NLS-1$ - - assertTrue( look.isType( ITypeInfo.t_float ) ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newS ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > class string{ - * template< class T2 > T2 compare( const T2 & ); - * }; - * - * template< class U > template< class V > V string<U>::compare( const V & ) { - * U u; - * } - * @throws Exception - */ - public void test_14_5_2__1_MemberTemplates() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "string" ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "string", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( string ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "compare" ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template2.addTemplateParameter( T2 ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( string ); - factory.pushTemplate( template2 ); - - IParameterizedSymbol compare = table.newParameterizedSymbol( "compare", ITypeInfo.t_function ); //$NON-NLS-1$ - compare.setIsForwardDeclaration( true ); - compare.addParameter( T2, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ); - ISymbol returnType = table.newSymbol( "", ITypeInfo.t_type ); //$NON-NLS-1$ - returnType.setTypeSymbol( T2 ); - compare.setReturnType( returnType ); - factory.addSymbol( compare ); - - ITemplateSymbol temp = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - ISymbol U = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ITemplateSymbol temp2 = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp2.addTemplateParameter( V ); - - factory.pushTemplate( temp2 ); - - ISymbol lookV = factory.lookup( "V" ); //$NON-NLS-1$ - assertEquals( lookV, V ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - - ISymbol look = factory.lookupTemplateIdForDefinition( "string", args ); //$NON-NLS-1$ - assertEquals( look, string ); - factory.pushTemplateId( look, args ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, lookV, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ) ); - - look = ((IContainerSymbol)look).lookupMethodForDefinition( "compare", args ); //$NON-NLS-1$ - assertEquals( look, compare ); - - IParameterizedSymbol compareDef = table.newParameterizedSymbol( "compare", ITypeInfo.t_function ); //$NON-NLS-1$ - compareDef.addParameter( lookV, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ); - ISymbol defReturn = table.newSymbol( "", ITypeInfo.t_type ); //$NON-NLS-1$ - defReturn.setTypeSymbol( lookV ); - compareDef.setReturnType( defReturn ); - compare.setForwardSymbol( compareDef ); - factory.addSymbol( compareDef ); - - look = compareDef.lookup( "U" ); //$NON-NLS-1$ - assertEquals( look, U ); - - ISymbol u = table.newSymbol( "u", ITypeInfo.t_type ); //$NON-NLS-1$ - u.setTypeSymbol( look ); - - compareDef.addSymbol( u ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "string", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), string ); - - look = ((IDerivableContainerSymbol)look).lookupTemplateId( "compare", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertTrue( look.getInstantiatedSymbol().isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol().getInstantiatedSymbol(), compareDef ); - - assertTrue( ((IParameterizedSymbol)look).getReturnType().isType( ITypeInfo.t_int ) ); - - look = ((IContainerSymbol)look).lookup( "u" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertTrue( look.getInstantiatedSymbol().isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol().getInstantiatedSymbol(), u ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A member function template shall not be virtual - * - * template< class T > struct A { - * template < class C > virtual void g( C ); //error - * virtual void f(); //ok - * }; - * @throws Exception - */ - public void test_14_5_2__3_VirtualMemberFunctionTemplate() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ITemplateSymbol memberTemplate = table.newTemplateSymbol( "g" ); //$NON-NLS-1$ - ISymbol C = table.newSymbol( "C", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - memberTemplate.addTemplateParameter( C ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( A ); - factory.pushTemplate( memberTemplate ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( C, 0, null, false ); - g.getTypeInfo().setBit( true, ITypeInfo.isVirtual ); - - try{ - factory.addSymbol( memberTemplate ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplate ); - } - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.getTypeInfo().setBit( true, ITypeInfo.isVirtual ); - - A.addSymbol( f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Partial specialization declarations are not found by name lookup, Rather, when the primary - * template name is used, any previously declared partial template specializations of the - * primary template are also considered. - * One consequence is that a using-declaration which refers to a class template does not restrict - * the set of partial specializations which may be found through the using-declaration. - * - * namespace N{ - * template< class T1, class T2 > class A {}; - * } - * - * using N::A; - * - * namespace N{ - * template< class T> class A < T, T * > {}; - * } - * - * A< int, int * > a; //uses partial specialization - * - * @throws Exception - */ - public void test_14_5_4__7_PartialSpecializationLookup() throws Exception{ - //TODO - newTable(); - - IContainerSymbol N = table.newContainerSymbol( "N", ITypeInfo.t_namespace ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( N ); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - - template.addTemplateParameter( table.newSymbol( "T1", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T2", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - template.addSymbol( A1 ); - - N.addSymbol( template ); - - table.getCompilationUnit().addUsingDeclaration( "A", N ); //$NON-NLS-1$ - - ISpecializedSymbol spec = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec.addTemplateParameter( T ); - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - spec.addSymbol( A2 ); - template.addSpecialization( spec ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * template < class T1, class T2, int I > class A {} //#1 - * template < class T, int I > class A < T, T*, I > {} //#2 - * template < class T1, class T2, int I > class A < T1*, T2, I > {} //#3 - * template < class T > class A < int, T*, 5 > {} //#4 - * template < class T1, class T2, int I > class A < T1, T2*, I > {} //#5 - * - * A <int, int, 1> a1; //uses #1 - * A <int, int*, 1> a2; //uses #2, T is int, I is 1 - * A <int, char*, 5> a3; //uses #4, T is char - * A <int, char*, 1> a4; //uses #5, T is int, T2 is char, I is1 - * A <int*, int*, 2> a5; //ambiguous, matches #3 & #5. - * - * @throws Exception - */ - public void test_14_5_4_1__2_MatchingTemplateSpecializations() throws Exception{ - //TODO - newTable(); - - IDerivableContainerSymbol cls1 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls2 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls3 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls4 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls5 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - ITemplateSymbol template1 = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol T1p1 = table.newSymbol( "T1", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T1p2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T1p3 = table.newSymbol( "I", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T1p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template1.addTemplateParameter( T1p1 ); - template1.addTemplateParameter( T1p2 ); - template1.addTemplateParameter( T1p3 ); - template1.addSymbol( cls1 ); - table.getCompilationUnit().addSymbol( template1 ); - - ISpecializedSymbol template2 = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - ISymbol T2p1 = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T2p2 = table.newSymbol( "I", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T2p2.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template2.addTemplateParameter( T2p1 ); - template2.addTemplateParameter( T2p2 ); - - ITypeInfo T2a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p1 ); - ITypeInfo T2a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T2a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p2 ); - - template2.addArgument( T2a1 ); - template2.addArgument( T2a2 ); - template2.addArgument( T2a3 ); - template2.addSymbol( cls2 ); - template1.addSpecialization( template2 ); - - ISpecializedSymbol template3 = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - ISymbol T3p1 = table.newSymbol( "T1", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T3p2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T3p3 = table.newSymbol( "I", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T3p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template3.addTemplateParameter( T3p1 ); - template3.addTemplateParameter( T3p2 ); - template3.addTemplateParameter( T3p3 ); - - ITypeInfo T3a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T3a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p2 ); - ITypeInfo T3a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p3 ); - - template3.addArgument( T3a1 ); - template3.addArgument( T3a2 ); - template3.addArgument( T3a3 ); - template3.addSymbol( cls3 ); - template1.addSpecialization( template3 ); - - ISpecializedSymbol template4 = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - ISymbol T4p1 = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template4.addTemplateParameter( T4p1 ); - - ITypeInfo T4a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - ITypeInfo T4a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T4p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T4a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "5" ); //$NON-NLS-1$ - - template4.addArgument( T4a1 ); - template4.addArgument( T4a2 ); - template4.addArgument( T4a3 ); - template4.addSymbol( cls4 ); - template1.addSpecialization( template4 ); - - ISpecializedSymbol template5 = table.newSpecializedSymbol( "A" ); //$NON-NLS-1$ - ISymbol T5p1 = table.newSymbol( "T1", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T5p2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T5p3 = table.newSymbol( "I", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T5p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template5.addTemplateParameter( T5p1 ); - template5.addTemplateParameter( T5p2 ); - template5.addTemplateParameter( T5p3 ); - - ITypeInfo T5a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p1 ); - ITypeInfo T5a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p2, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T5a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p3 ); - - template5.addArgument( T5a1 ); - template5.addArgument( T5a2 ); - template5.addArgument( T5a3 ); - template5.addSymbol( cls5 ); - template1.addSpecialization( template5 ); - - ITemplateSymbol a = (ITemplateSymbol) table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( a, template1 ); - - ArrayList args = new ArrayList(); - - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1" ) ); //$NON-NLS-1$ - - IContainerSymbol a1 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a1.isTemplateInstance() ); - assertEquals( a1.getInstantiatedSymbol(), cls1 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1" ) ); //$NON-NLS-1$ - - IContainerSymbol a2 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a2.isTemplateInstance() ); - assertEquals( a2.getInstantiatedSymbol(), cls2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "5" ) ); //$NON-NLS-1$ - IContainerSymbol a3 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a3.isTemplateInstance() ); - assertEquals( a3.getInstantiatedSymbol(), cls4 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1" ) ); //$NON-NLS-1$ - IContainerSymbol a4 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a4.isTemplateInstance() ); - assertEquals( a4.getInstantiatedSymbol(), cls5 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "2" ) ); //$NON-NLS-1$ - - try{ - a.instantiate( args ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > void f( T ); //#1 - * template< class T > void f( T* ); //#2 - * template< class T > void f( const T* ); //#3 - * - * const int *p; - * f( p ); //calls f( const T * ) , 3 is more specialized than 1 or 2 - * - * @throws Exception - * - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_1() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( T, 0, null, false ); - factory.addSymbol( f1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - factory.addSymbol( f2 ); - - ITemplateSymbol template3 = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - template3.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template3 ); - - T = template3.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( T, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - factory.addSymbol( f3 ); - - ISymbol p = table.newSymbol( "p", ITypeInfo.t_int ); //$NON-NLS-1$ - p.getTypeInfo().setBit( true, ITypeInfo.isConst ); - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - table.getCompilationUnit().addSymbol( p ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > void g( T ); //#1 - * template< class T > void g( T& ); //#2 - - * float x; - * g( x ); //ambiguous 1 or 2 - * - * @throws Exception - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_2() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "g" ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g1.addParameter( T, 0, null, false ); - factory.addSymbol( g1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "g" ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g2.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - factory.addSymbol( g2 ); - - ISymbol x = table.newSymbol( "x", ITypeInfo.t_float ); //$NON-NLS-1$ - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, x ) ); - try{ - table.getCompilationUnit().unqualifiedFunctionLookup( "g", params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > struct A { }; - * - * template< class T > void h( const T & ); //#1 - * template< class T > void h( A<T>& ); //#2 - * - * A<int> z; - * h( z ); //calls 2 - * - * const A<int> z2; - * h( z2 ); //calls 1 because 2 is not callable. - * @throws Exception - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_3() throws Exception{ - newTable(); - - ITemplateSymbol templateA = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - templateA.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateA ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ITemplateSymbol template1 = table.newTemplateSymbol( "h" ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T" ); //$NON-NLS-1$ - IParameterizedSymbol h1 = table.newParameterizedSymbol( "h", ITypeInfo.t_function ); //$NON-NLS-1$ - h1.addParameter( T, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ),false ); - factory.addSymbol( h1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "h" ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T" ); //$NON-NLS-1$ - - IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", ITypeInfo.t_function ); //$NON-NLS-1$ - List argList = new ArrayList(); - argList.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - h2.addParameter( templateA.instantiate( argList ), 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - factory.addSymbol( h2 ); - - ISymbol z = table.newSymbol( "z", ITypeInfo.t_type ); //$NON-NLS-1$ - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - z.setTypeSymbol( look ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, z ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "h", params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), h2 ); - - ISymbol z2 = table.newSymbol( "z2", ITypeInfo.t_type ); //$NON-NLS-1$ - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - z2.setTypeSymbol( look ); - z2.getTypeInfo().setBit( true, ITypeInfo.isConst ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, z2 ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "h", params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), h1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Within the scope of a class template, when the name of the template is neither qualified - * nor followed by <, it is equivalent to the name of the template followed by the template-parameters - * enclosed in <>. - * - * template < class T > class X { - * X* p; //meaning X< T > - * }; - * - * @throws Exception - */ - public void test_14_6_1__1_TemplateName() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - ISymbol look = X.lookup( "X" ); //$NON-NLS-1$ - - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) look; - assertEquals( deferred.getTemplate(), template ); - - Iterator iter = deferred.getArguments().iterator(); - ITypeInfo type = (ITypeInfo) iter.next(); - assertTrue( type.isType( ITypeInfo.t_type ) ); - assertEquals( type.getTypeSymbol(), T ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Within the scope of a class template specialization or partial specialization, when the name of the - * template is neither qualified nor followed by <, it is equivalent to the name of the template - * followed by the template-arguments enclosed in <> - * - * template< class T > class Y; - * - * template<> class Y< int > { - * Y* p; //meaning Y<int> - * } - * @throws Exception - */ - public void test_14_6_1__2_SpecializationName() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "Y" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - IDerivableContainerSymbol Y1 = table.newDerivableContainerSymbol( "Y", ITypeInfo.t_class ); //$NON-NLS-1$ - template.addSymbol( Y1 ); - - table.getCompilationUnit().addSymbol( template ); - - ISpecializedSymbol spec = table.newSpecializedSymbol( "Y" ); //$NON-NLS-1$ - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - template.addSpecialization( spec ); - - IDerivableContainerSymbol Y2 = table.newDerivableContainerSymbol( "Y", ITypeInfo.t_class ); //$NON-NLS-1$ - spec.addSymbol( Y2 ); - - ISymbol look = Y2.lookup( "Y" ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), Y2 ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A template-parameter shall not be redeclared within its scope. A template-parameter shall - * not have the same name as the template name. - * - * template< class T, int i > class Y { - * int T; //error - * void f(){ - * char T; //error - * } - * }; - * - * template <class X> class X {}; //error - * - * @throws Exception - */ - public void test_14_6_1__4_ParameterRedeclaration() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "Y" ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ISymbol i = table.newSymbol( "i", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - i.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - template.addTemplateParameter( i ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol Y = table.newDerivableContainerSymbol( "Y", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( Y ); - - ISymbol T = table.newSymbol( "T", ITypeInfo.t_int ); //$NON-NLS-1$ - try{ - Y.addSymbol( T ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_RedeclaredTemplateParam ); - } - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - Y.addSymbol( f ); - - try{ - f.addSymbol( table.newSymbol( "T", ITypeInfo.t_char ) ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_RedeclaredTemplateParam ); - } - - ITemplateSymbol template2 = table.newTemplateSymbol( "X" ); //$NON-NLS-1$ - try{ - template2.addTemplateParameter( table.newSymbol( "X", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateParameter ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * A member of an explicitly specialized class shall be explicitly defined in the same - * manner as members of normal classes - * - * template< class T > struct A { - * void f( T ) {} - * }; - * - * template <> struct A< int >{ - * void f( int ); - * } - * - * void A< int >::f( int ){ } - * - * @throws Exception - */ - public void test_14_7_3__5_ExplicitSpecialization() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( T, 0, null, false ); - - A.addSymbol( f ); - - ITemplateSymbol temp = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ArrayList args = new ArrayList(); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - ITemplateSymbol templateSpec = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - factory.pushTemplate( templateSpec ); - - IDerivableContainerSymbol ASpec = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - factory.addTemplateId( ASpec, args ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - f2.setIsForwardDeclaration( true ); - ASpec.addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - - IDerivableContainerSymbol look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), ASpec ); - - ISymbol flook = look.lookupMethodForDefinition( "f", args ); //$NON-NLS-1$ - assertTrue( flook.isTemplateInstance() ); - assertEquals( flook.getInstantiatedSymbol(), f2 ); - flook.setForwardSymbol( f3 ); - - look.addSymbol( f3 ); - - look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - flook = look.qualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ - - assertEquals( flook, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template < class T > class Array { }; - * template < class T > void sort( Array< T > & ); - * - * template<> void sort( Array< int > & ){} //T deduced as int - * - * @throws Exception - */ - public void test_14_7_3__11_ExplicitSpecializationArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol templateArray = table.newTemplateSymbol( "Array" ); //$NON-NLS-1$ - templateArray.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateArray ); - - IDerivableContainerSymbol array = table.newDerivableContainerSymbol( "Array", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( array ); - - ITemplateSymbol templateSort = table.newTemplateSymbol( "sort" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateSort.addTemplateParameter( T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateSort ); - - IParameterizedSymbol sort = table.newParameterizedSymbol( "sort", ITypeInfo.t_function ); //$NON-NLS-1$ - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - - ISymbol arrayLook = factory.lookupTemplateId( "Array", args ); //$NON-NLS-1$ - sort.addParameter( arrayLook, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - factory.addSymbol( sort ); - - ITemplateSymbol temp = table.newTemplateSymbol( "" ); //$NON-NLS-1$ - factory = table.newTemplateFactory(); - - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - IParameterizedSymbol newSort = table.newParameterizedSymbol( "sort", ITypeInfo.t_function ); //$NON-NLS-1$ - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - arrayLook = table.getCompilationUnit().lookupTemplateId( "Array", args ); //$NON-NLS-1$ - assertTrue( arrayLook.isTemplateInstance() ); - assertEquals( arrayLook.getInstantiatedSymbol(), array ); - newSort.addParameter( arrayLook, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - factory.addSymbol( newSort ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( arrayLook ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "sort", args ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newSort ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * It is possible for a specialization with a given function signature to be instantiated from more - * than one function-template. In such cases, explicit specification of the template arguments must be used - * to uniquely identify the function template specialization being specialized - * - * template< class T > void f( T ); - * template< class T > void f( T * ); - * - * template <> void f<int *>( int * ); - * template <> void f< int >( int * ); - * template <> void f( char ); - * - * @throws Exception - */ - public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - ISymbol T1 = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template1.addTemplateParameter( T1 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( T1, 0, null, false ); - - factory.addSymbol( f1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template2.addTemplateParameter( T2 ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( T2, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - factory.addSymbol( f2 ); - - factory = table.newTemplateFactory(); - ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - factory.addTemplateId( f3, args ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f4 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f4.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - factory.addTemplateId( f4, args ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f5 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f5.addParameter( ITypeInfo.t_char, 0, null, false ); - factory.addSymbol( f5 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f5 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * template < class T > void f( T x, T y ) { } - * struct A {}; - * struct B : A {}; - * - * A a; - * B b; - * - * f( a, b ); //error, T could be A or B - * f( b, a ); //error, T could be A or B - * f( a, a ); //ok, T is A - * f( b, b ); //ok, T is B - * @throws Exception - */ - public void test_14_8_2_4__5_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol lookT = template.lookup( "T" ); //$NON-NLS-1$ - assertEquals( lookT, T ); - - ISymbol paramX = table.newSymbol( "x", ITypeInfo.t_type ); //$NON-NLS-1$ - paramX.setTypeSymbol( lookT ); - - ISymbol paramY = table.newSymbol( "y", ITypeInfo.t_type ); //$NON-NLS-1$ - paramY.setTypeSymbol( lookT ); - - f.addParameter( paramX ); - f.addParameter( paramY ); - - factory.addSymbol( f ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_struct ); //$NON-NLS-1$ - B.addParent( A ); - table.getCompilationUnit().addSymbol( B ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( A ); - - ISymbol b = table.newSymbol( "b", ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( B ); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - List argList = new ArrayList(); - ITypeInfo aParam = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - ITypeInfo bParam = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - - argList.add( aParam ); - argList.add( bParam ); - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - argList.clear(); - argList.add( bParam ); - argList.add( aParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - argList.clear(); - argList.add( aParam ); - argList.add( aParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - argList.clear(); - argList.add( bParam ); - argList.add( bParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance()); - assertEquals( look.getInstantiatedSymbol(), f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T, class U > void f( T (*)( T, U, U ) ); - * int g1( int, float, float ); - * char g2( int, float, float ); - * int g3( int, char, float ); - * - * f( g1 ); //OK, T is int and U is float - * f( g2 ); //error, T could be char or int - * f( g3 ); //error, U could be char or float - * - * @throws Exception - */ - public void test_14_8_2_4__6_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - - template.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "U", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol paramFunction = table.newParameterizedSymbol( "", ITypeInfo.t_function ); //$NON-NLS-1$ - paramFunction.setIsTemplateMember( true ); - - ISymbol T = template.lookup( "T" ); //$NON-NLS-1$ - ISymbol U = template.lookup( "U" ); //$NON-NLS-1$ - - paramFunction.setReturnType( T ); - paramFunction.addParameter( T, 0, null, false ); - paramFunction.addParameter( U, 0, null, false ); - paramFunction.addParameter( U, 0, null, false ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( paramFunction, 0, null, false ); - - factory.addSymbol( f ); - - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g1", ITypeInfo.t_function ); //$NON-NLS-1$ - g1.setReturnType( table.newSymbol( "", ITypeInfo.t_int ) ); //$NON-NLS-1$ - g1.addParameter( ITypeInfo.t_int, 0, null, false ); - g1.addParameter( ITypeInfo.t_float, 0, null, false ); - g1.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g1 ); - - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g2", ITypeInfo.t_function ); //$NON-NLS-1$ - g2.setReturnType( table.newSymbol( "", ITypeInfo.t_char ) ); //$NON-NLS-1$ - g2.addParameter( ITypeInfo.t_int, 0, null, false ); - g2.addParameter( ITypeInfo.t_float, 0, null, false ); - g2.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g2); - - IParameterizedSymbol g3 = table.newParameterizedSymbol( "g3", ITypeInfo.t_function ); //$NON-NLS-1$ - g3.setReturnType( table.newSymbol( "", ITypeInfo.t_int ) ); //$NON-NLS-1$ - g3.addParameter( ITypeInfo.t_int, 0, null, false ); - g3.addParameter( ITypeInfo.t_char, 0, null, false ); - g3.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g3); - - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, g1 ); - List argList = new ArrayList(); - argList.add( arg ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - arg.setTypeSymbol( g2 ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - arg.setTypeSymbol( g3 ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * template< class T > void f( const T * ){} - * - * int *p; - * - * f( p ); //f ( const int * ) - * - * @throws Exception - */ - public void test_14_8_2_4__7_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, true, false ), false ); - factory.addSymbol( f ); - - ISymbol p = table.newSymbol( "p", ITypeInfo.t_int ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - - assertEquals( look.getInstantiatedSymbol(), f ); - - IParameterizedSymbol fn = (IParameterizedSymbol) look; - Iterator iter = fn.getParameterList().iterator(); - ISymbol param = (ISymbol) iter.next(); - assertTrue( param.isType( ITypeInfo.t_int ) ); - - assertFalse( iter.hasNext() ); - - iter = param.getTypeInfo().getPtrOperators().iterator(); - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) iter.next(); - assertTrue( op.isConst() ); - assertEquals( op.getType(), ITypeInfo.PtrOp.t_pointer ); - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > struct B {}; - * - * template< class T > struct D : public B< T > {}; - * - * struct D2 : public B< int > {}; - * - * template< class T > void f( B<T> & ) {} - * - * D<int> d; - * D2 d2; - * - * f( d ); //f( B<int> & ) - * f( d2 ); //f( B<int> & ) - * @throws Exception - */ - public void test_14_8_2_4__8_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol templateB = table.newTemplateSymbol( "B" ); //$NON-NLS-1$ - templateB.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateB ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( B ); - - ITemplateSymbol templateD = table.newTemplateSymbol( "D" ); //$NON-NLS-1$ - templateD.addTemplateParameter( table.newSymbol( "T", ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateD ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D", ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( D ); - - ISymbol T = templateD.lookup( "T" ); //$NON-NLS-1$ - List args = new ArrayList (); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ - assertTrue( look instanceof IDeferredTemplateInstance ); - assertEquals( ((IDeferredTemplateInstance)look).getTemplate(), templateB ); - - D.addParent( look ); - - IDerivableContainerSymbol D2 = table.newDerivableContainerSymbol( "D2", ITypeInfo.t_struct ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), B ); - - D2.addParent( look ); - - table.getCompilationUnit().addSymbol( D2 ); - - ITemplateSymbol templatef = table.newTemplateSymbol( "f" ); //$NON-NLS-1$ - T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templatef.addTemplateParameter( T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templatef ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - - look = table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ - assertTrue( look instanceof IDeferredTemplateInstance ); - assertEquals( ((IDeferredTemplateInstance)look).getTemplate(), templateB ); - - ISymbol param = table.newSymbol( "", ITypeInfo.t_type ); //$NON-NLS-1$ - param.setTypeSymbol( look ); - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ) ); - f.addParameter( param ); - - factory.addSymbol( f ); - - ISymbol d = table.newSymbol( "d", ITypeInfo.t_type ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().lookupTemplateId( "D", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), D ); - - d.setTypeSymbol( look ); - table.getCompilationUnit().addSymbol( d ); - - ISymbol d2 = table.newSymbol( "d2", ITypeInfo.t_type ); //$NON-NLS-1$ - d2.setTypeSymbol( D2 ); - table.getCompilationUnit().addSymbol( d2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, d ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, d2 ) ); - ISymbol look2 = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ - assertTrue( look2 != null ); - assertTrue( look2.isTemplateInstance() ); - assertEquals( look2.getInstantiatedSymbol(), f ); - - //both are the template function instantiated with int, should be the same instance. - assertEquals( look, look2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - - - /** - * template < class T1, class T2 > class A { void f(); }; //#1 - * - * template < class T > class A < T, T > { void f(); }; //#2 - * template < class T > class A < char, T > { void f(); }; //#3 - * - * template < class U, class V > void A<U, V>::f(){ - * int c; - * } - * - * template < class W > void A < W, W >::f(){ - * char c; - * } - * - * template < class X > void A< char, X >::f(){ - * float c; - * } - * - * A< int, char > a1; //#1 - * a1.f(); //#1 - * - * A< int, int > a2; //#2 - * a2.f(); //#2 - * - * A< char, int > a3; //#3 - * a3.f(); //#3 - * - * @throws Exception - */ - public void testPartialSpecializationDefinitions() throws Exception{ - newTable(); - - //template < class T1, class T2 > class A { void f(); }; - ITemplateSymbol template = table.newTemplateSymbol( "A" ); //$NON-NLS-1$ - ISymbol T1 = table.newSymbol( "T1", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T2", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T1 ); - template.addTemplateParameter( T2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setIsForwardDeclaration( true ); - A1.addSymbol( f1 ); - - //template < class T > class A < T, T > { void f(); }; - ITemplateSymbol spec1 = table.newTemplateSymbol(""); //$NON-NLS-1$ - ISymbol spec1_T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec1.addTemplateParameter( spec1_T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec1 ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec1_T ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec1_T ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addTemplateId( A2, args ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setIsForwardDeclaration( true ); - A2.addSymbol( f2 ); - - //template < class T > class A < char, T > { void f(); }; - ITemplateSymbol spec2 = table.newTemplateSymbol(""); //$NON-NLS-1$ - ISymbol spec2_T = table.newSymbol( "T", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec2.addTemplateParameter( spec2_T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec2_T ) ); - - IDerivableContainerSymbol A3 = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addTemplateId( A3, args ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.setIsForwardDeclaration( true ); - A3.addSymbol( f3 ); - - //template < class U, class V > void A<U, V>::f(){ int c; } - ITemplateSymbol templateDef = table.newTemplateSymbol(""); //$NON-NLS-1$ - ISymbol U = table.newSymbol( "U", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateDef.addTemplateParameter( U ); - templateDef.addTemplateParameter( V ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, V ) ); - - ISymbol symbol = factory.lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertEquals( ((IDeferredTemplateInstance)symbol).getTemplate(), template ); - factory.pushTemplateId( symbol, args ); - - ISymbol look = factory.lookupMethodForDefinition( "f", new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f1 ); - IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setForwardSymbol( f1Def ); - factory.addSymbol( f1Def ); - - ISymbol c1 = table.newSymbol( "c", ITypeInfo.t_int ); //$NON-NLS-1$ - f1Def.addSymbol( c1 ); - - //template < class W > void A < W, W >::f(){ char c; } - ITemplateSymbol specDef1 = table.newTemplateSymbol(""); //$NON-NLS-1$ - ISymbol W = table.newSymbol( "W", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specDef1.addTemplateParameter( W ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( specDef1 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, W ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, W ) ); - - symbol = factory.lookupTemplateId( "A", args ); //$NON-NLS-1$ - factory.pushTemplateId( symbol, args ); - - look = factory.lookupMethodForDefinition( "f", new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f2 ); - IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setForwardSymbol( f2Def ); - factory.addSymbol( f2Def ); - - ISymbol c2 = table.newSymbol( "c", ITypeInfo.t_char ); //$NON-NLS-1$ - f2Def.addSymbol( c2 ); - - //template < class X > void < char, X >::f(){ float c; } - ITemplateSymbol specDef2 = table.newTemplateSymbol(""); //$NON-NLS-1$ - ISymbol X = table.newSymbol( "X", ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specDef2.addTemplateParameter( X ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( specDef1 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, X ) ); - - symbol = factory.lookupTemplateId( "A", args ); //$NON-NLS-1$ - factory.pushTemplateId( symbol, args ); - - look = factory.lookupMethodForDefinition( "f", new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f3 ); - IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.setForwardSymbol( f3Def ); - factory.addSymbol( f3Def ); - - ISymbol c3 = table.newSymbol( "c", ITypeInfo.t_float ); //$NON-NLS-1$ - f3Def.addSymbol( c3 ); - - //A< int, char > a1; - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A1 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f1Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c1 ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - - //A< int, int > a2; - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A2 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f2Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c2 ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - - //A< char, int > a3; - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A", args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A3 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f3Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c" ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c3 ); - assertTrue( look.isType( ITypeInfo.t_float ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } -}
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java deleted file mode 100644 index 462518b8974..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ /dev/null @@ -1,3517 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * 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.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTClassSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTCompilationUnit; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTField; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDeclarationSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; -import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap; - - - - -/** - * @author aniefer - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class ParserSymbolTableTest extends TestCase { - - public ParserSymbolTable table = null; - public TypeInfoProvider provider = null; - - public ParserSymbolTableTest( String arg ) - { - super( arg ); - } - - public ParserSymbolTable newTable(){ - return newTable( ParserLanguage.CPP, ParserMode.COMPLETE_PARSE ); - } - - public ParserSymbolTable newTable( ParserLanguage language, ParserMode mode ){ - table = new ParserSymbolTable( language, mode ); - provider = table.getTypeInfoProvider(); - return table; - } - /** - * testSimpleAdd. - * Add a declaration to the table and confirm it is there. - * - * @throws Exception - */ - public void testSimpleAdd() throws Exception{ - newTable(); //create the symbol table - - ISymbol x = table.newSymbol( "x" ); //$NON-NLS-1$ - x.setTypeInfo( TypeInfoProvider.newTypeInfo() ); - IContainerSymbol compUnit = table.getCompilationUnit(); - compUnit.addSymbol( x ); - - ObjectMap declarations = compUnit.getContainedSymbols(); - assertEquals( 1, declarations.size() ); - - ISymbol contained = (ISymbol) declarations.getAt( 0 ); - - assertEquals( declarations.size(), 1 ); - assertEquals( x, contained ); - assertEquals( contained.getName(), "x" ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testSimpleLookup - * Add a declaration to the table, then look it up. - * @throws Exception - */ - public void testSimpleLookup() throws Exception{ - newTable(); //new symbol table - - ISymbol x = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( x ); - - ISymbol look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ - - assertEquals( x, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testLookupNonExistant() throws Exception{ - newTable(); - - ISymbol look = table.getCompilationUnit().lookup("boo"); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testSimpleSetGetObject() throws Exception{ - newTable(); - - IContainerSymbol x = table.newContainerSymbol( "x", ITypeInfo.t_namespace ); //$NON-NLS-1$ - - ISymbolASTExtension extension = new StandardSymbolExtension(x,null); - - x.setASTExtension( extension ); - - table.getCompilationUnit().addSymbol( x ); - - ISymbol look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ - - assertEquals( look.getASTExtension(), extension ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testHide - * test that a declaration in a scope hides declarations in containing - * scopes - * @throws Exception - */ - public void testHide() throws Exception{ - newTable(); - - ISymbol firstX = table.newSymbol("x"); //$NON-NLS-1$ - firstX.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - table.getCompilationUnit().addSymbol( firstX ); - - IDerivableContainerSymbol firstClass = table.newDerivableContainerSymbol("class"); //$NON-NLS-1$ - firstClass.setType( ITypeInfo.t_class ); - table.getCompilationUnit().addSymbol( firstClass ); - - ISymbol look = firstClass.lookup( "x" ); //$NON-NLS-1$ - assertEquals( look, firstX ); - - ISymbol secondX = table.newSymbol("x"); //$NON-NLS-1$ - firstClass.addSymbol( secondX ); - - look = firstClass.lookup( "x" ); //$NON-NLS-1$ - assertEquals( look, secondX ); - - look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ - assertEquals( look, firstX ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testContainingScopeLookup - * test lookup of something declared in the containing scope - * @throws Exception - */ - public void testContainingScopeLookup() throws Exception{ - newTable(); - - ISymbol x = table.newSymbol("x"); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( x ); - - IDerivableContainerSymbol decl = table.newDerivableContainerSymbol("class"); //$NON-NLS-1$ - decl.setType( ITypeInfo.t_class ); - table.getCompilationUnit().addSymbol( decl ); - - ISymbol look = decl.lookup( "x" ); //$NON-NLS-1$ - - assertEquals( x, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testParentLookup - * test lookup of a variable declaration in the parent - * - * @throws Exception - */ - public void testParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol parent = table.newDerivableContainerSymbol("parent"); //$NON-NLS-1$ - parent.setType( ITypeInfo.t_class ); - - IDerivableContainerSymbol class1 = table.newDerivableContainerSymbol("class"); //$NON-NLS-1$ - class1.setType( ITypeInfo.t_class ); - class1.addParent( parent ); - - ISymbol decl = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - parent.addSymbol( decl ); - - table.getCompilationUnit().addSymbol( parent ); - table.getCompilationUnit().addSymbol( class1 ); - - ISymbol look = class1.lookup( "x" ); //$NON-NLS-1$ - assertEquals( look, decl ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testAmbiguousParentLookup - * calls testParentLookup - * - * tests that if a variable is declared in two parents that the lookup - * returns an ambiguous result. - * - * @throws Exception - */ - public void testAmbiguousParentLookup() throws Exception{ - testParentLookup(); - - IDerivableContainerSymbol parent2 = table.newDerivableContainerSymbol("parent2"); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( parent2 ); - - IDerivableContainerSymbol class1 = (IDerivableContainerSymbol) table.getCompilationUnit().lookup( "class" ); //$NON-NLS-1$ - class1.addParent( parent2 ); - - ISymbol decl = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - parent2.addSymbol( decl ); - - try{ - class1.lookup( "x" ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * test for circular inheritance - */ - public void testCircularParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a"); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a ); - - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("b"); //$NON-NLS-1$ - b.addParent( a ); - table.getCompilationUnit().addSymbol( b ); - - a.addParent( b ); - - try{ - a.lookup("foo"); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e) { - assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * testVirtualParentLookup - * - * @throws Exception - * tests lookup of name in virtual baseclass C - * - * C - * / \ - * A B - * \ / - * class - */ - public void testVirtualParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol decl = table.newDerivableContainerSymbol("class"); //$NON-NLS-1$ - IDerivableContainerSymbol c = table.newDerivableContainerSymbol("C"); //$NON-NLS-1$ - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("A"); //$NON-NLS-1$ - a.addParent( c, true, ASTAccessVisibility.PUBLIC, 3, null ); - - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("B"); //$NON-NLS-1$ - b.addParent( c, true, ASTAccessVisibility.PUBLIC, 6, null ); - - decl.addParent( a ); - decl.addParent( b ); - - IContainerSymbol compUnit = table.getCompilationUnit(); - compUnit.addSymbol( c ); - - ISymbol x = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - c.addSymbol( x ); - - compUnit.addSymbol( decl ); - compUnit.addSymbol( a ); - compUnit.addSymbol( b ); - - ISymbol look = decl.lookup( "x" ); //$NON-NLS-1$ - - assertEquals( look, x ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testAmbiguousVirtualParentLookup - * @throws Exception - * - * tests lookup of name in base class C in the following hierarchy - * C C - * / \ | - * A B D - * \ / / - * class - */ - public void testAmbiguousVirtualParentLookup() throws Exception{ - testVirtualParentLookup(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol cls = (IDerivableContainerSymbol) compUnit.lookup("class"); //$NON-NLS-1$ - IDerivableContainerSymbol c = (IDerivableContainerSymbol) compUnit.lookup("C"); //$NON-NLS-1$ - IDerivableContainerSymbol d = table.newDerivableContainerSymbol("D"); //$NON-NLS-1$ - - d.addParent( c ); - cls.addParent( d ); - - compUnit.addSymbol( d ); - - try{ - cls.lookup( "x" ); //$NON-NLS-1$ - assertTrue( false ); - } - catch( ParserSymbolTableException e){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testStaticEnumParentLookup - * - * @throws Exception - * - * D D - * | | - * B C - * \ / - * A - * - * Things defined in D are not ambiguous if they are static or an enum - */ - public void testStaticEnumParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a" ); //$NON-NLS-1$ - IDerivableContainerSymbol b = table.newDerivableContainerSymbol( "b" ); //$NON-NLS-1$ - IDerivableContainerSymbol c = table.newDerivableContainerSymbol( "c" ); //$NON-NLS-1$ - IDerivableContainerSymbol d = table.newDerivableContainerSymbol( "d" ); //$NON-NLS-1$ - - IContainerSymbol compUnit = table.getCompilationUnit(); - - compUnit.addSymbol( a ); - compUnit.addSymbol( b ); - compUnit.addSymbol( c ); - compUnit.addSymbol( d ); - - IContainerSymbol enum = table.newContainerSymbol( "enum", ITypeInfo.t_enumeration ); //$NON-NLS-1$ - - ISymbol enumerator = table.newSymbol( "enumerator", ITypeInfo.t_enumerator ); //$NON-NLS-1$ - - ISymbol stat = table.newSymbol( "static", ITypeInfo.t_int ); //$NON-NLS-1$ - stat.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - - ISymbol x = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - - d.addSymbol( enum ); - d.addSymbol( stat ); - d.addSymbol( x ); - - enum.addSymbol( enumerator ); - - a.addParent( b ); - a.addParent( c ); - b.addParent( d ); - c.addParent( d ); - - try{ - a.lookup( "enumerator" ); //$NON-NLS-1$ - assertTrue( true ); - } - catch ( ParserSymbolTableException e){ - assertTrue( false ); - } - - try{ - a.lookup( "static" ); //$NON-NLS-1$ - assertTrue( true ); - } - catch ( ParserSymbolTableException e){ - assertTrue( false ); - } - - try{ - a.lookup( "x" ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testElaboratedLookup - * @throws Exception - * test lookup of hidden names using elaborated type spec - */ - public void testElaboratedLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "class" ); //$NON-NLS-1$ - cls.setType( ITypeInfo.t_class ); - - IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("struct"); //$NON-NLS-1$ - struct.setType( ITypeInfo.t_struct ); - - IContainerSymbol union = table.newContainerSymbol("union"); //$NON-NLS-1$ - union.setType( ITypeInfo.t_union ); - - IDerivableContainerSymbol hideCls = table.newDerivableContainerSymbol( "class" ); //$NON-NLS-1$ - hideCls.setType( ITypeInfo.t_int ); - IDerivableContainerSymbol hideStruct = table.newDerivableContainerSymbol("struct"); //$NON-NLS-1$ - hideStruct.setType( ITypeInfo.t_int ); - IContainerSymbol hideUnion = table.newContainerSymbol("union"); //$NON-NLS-1$ - hideUnion.setType( ITypeInfo.t_int ); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a"); //$NON-NLS-1$ - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("b"); //$NON-NLS-1$ - - a.addSymbol(hideCls); - a.addSymbol(hideStruct); - a.addSymbol(hideUnion); - - a.addParent( b ); - - b.addSymbol(cls); - b.addSymbol(struct); - b.addSymbol(union); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - ISymbol look = a.elaboratedLookup( ITypeInfo.t_class, "class" ); //$NON-NLS-1$ - assertEquals( look, cls ); - look = a.elaboratedLookup( ITypeInfo.t_struct, "struct" ); //$NON-NLS-1$ - assertEquals( look, struct ); - look = a.elaboratedLookup( ITypeInfo.t_union, "union" ); //$NON-NLS-1$ - assertEquals( look, union ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testDeclarationType - * @throws Exception - * test the use of ParserSymbolTable.Declaration type in the scenario - * A a; - * a.member <=...>; - * where A was previously declared - */ - public void testDeclarationType() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - //pre-condition - IContainerSymbol A = table.newContainerSymbol("A"); //$NON-NLS-1$ - compUnit.addSymbol(A); - - ISymbol member = table.newSymbol("member"); //$NON-NLS-1$ - A.addSymbol(member); - - //at time of "A a;" - ISymbol look = compUnit.lookup("A"); //$NON-NLS-1$ - assertEquals( look, A ); - ISymbol a = table.newSymbol("a"); //$NON-NLS-1$ - a.setTypeSymbol( look ); - compUnit.addSymbol( a ); - - //later "a.member" - look = compUnit.lookup("a"); //$NON-NLS-1$ - assertEquals( look, a ); - IContainerSymbol type = (IContainerSymbol) look.getTypeSymbol(); - assertEquals( type, A ); - - look = type.lookup("member"); //$NON-NLS-1$ - assertEquals( look, member ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * struct stat { - * //... - * } - * int stat( struct stat* ); - * void f() - * { - * struct stat *ps; - * stat(ps); - * } - */ - public void testFunctionHidesClass() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("stat"); //$NON-NLS-1$ - struct.setType( ITypeInfo.t_struct ); - compUnit.addSymbol( struct ); - - IParameterizedSymbol function = table.newParameterizedSymbol( "stat" ); //$NON-NLS-1$ - function.setType( ITypeInfo.t_function ); - compUnit.addSymbol( function ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - compUnit.addSymbol( f ); - - ISymbol look = f.elaboratedLookup( ITypeInfo.t_struct, "stat" ); //$NON-NLS-1$ - assertEquals( look, struct ); - - look = f.lookup( "stat" ); //$NON-NLS-1$ - assertEquals( look, function ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace A { - * int i; - * namespace B { - * namespace C{ - * int i; - * } - * using namespace A::B::C; - * void f1() { - * i = 5; //OK, C::i visible and hides A::i - * } - * } - * namespace D{ - * using namespace B; - * using namespace C; - * void f2(){ - * i = 5; //ambiguous, B::C and A::i - * } - * } - * void f3() { - * i = 5; //uses A::i - * } - * } - * void f4(){ - * i = 5; //no i is visible here - * } - * - */ - public void testUsingDirectives_1() throws Exception{ - newTable(); - - IContainerSymbol nsA = table.newContainerSymbol("A"); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - table.getCompilationUnit().addSymbol( nsA ); - - ISymbol nsA_i = table.newSymbol("i"); //$NON-NLS-1$ - nsA.addSymbol( nsA_i ); - - IContainerSymbol nsB = table.newContainerSymbol("B"); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsB ); - - IContainerSymbol nsC = table.newContainerSymbol("C"); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace ); - nsB.addSymbol( nsC ); - - ISymbol nsC_i = table.newSymbol("i"); //$NON-NLS-1$ - nsC.addSymbol( nsC_i ); - - ISymbol look = nsB.lookup("C"); //$NON-NLS-1$ - assertEquals( look, nsC ); - nsB.addUsingDirective( nsC ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - - nsB.addSymbol( f1 ); - - look = f1.lookup( "i" ); //$NON-NLS-1$ - assertEquals( look, nsC_i ); //C::i visible and hides A::i - - IContainerSymbol nsD = table.newContainerSymbol("D"); //$NON-NLS-1$ - nsD.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsD ); - - look = nsD.lookup("B"); //$NON-NLS-1$ - assertEquals( look, nsB ); - nsD.addUsingDirective( nsB ); - - look = nsD.lookup("C"); //$NON-NLS-1$ - assertEquals( look, nsC ); - nsD.addUsingDirective( nsC ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f2" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - nsD.addSymbol( f2 ); - - try - { - look = f2.lookup( "i" ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ) - { - //ambiguous B::C::i and A::i - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IParameterizedSymbol f3 = table.newParameterizedSymbol("f3"); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - nsA.addSymbol( f3 ); - - look = f3.lookup("i"); //$NON-NLS-1$ - assertEquals( look, nsA_i ); //uses A::i - - IParameterizedSymbol f4 = table.newParameterizedSymbol("f4"); //$NON-NLS-1$ - f4.setType( ITypeInfo.t_function ); - table.getCompilationUnit().addSymbol( f4 ); - - look = f4.lookup("i"); //$NON-NLS-1$ - assertEquals( look, null );//neither i is visible here. - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * - * @throws Exception - * - * namespace M { - * int i; - * } - * namespace N { - * int i; - * using namespace M; - * } - * - * void f() { - * using namespace N; - * i = 7; //error, both M::i and N::i are visible - * N::i = 5; //ok, i directly declared in N, using M not - * considered (since this is a qualified lookup) - * } - * - */ - public void testTransitiveUsingDirective() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsM = table.newContainerSymbol( "M" ); //$NON-NLS-1$ - nsM.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsM ); - - ISymbol nsM_i = table.newSymbol("i"); //$NON-NLS-1$ - nsM.addSymbol( nsM_i ); - - IContainerSymbol nsN = table.newContainerSymbol( "N" ); //$NON-NLS-1$ - nsN.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsN ); - - ISymbol nsN_i = table.newSymbol("i"); //$NON-NLS-1$ - nsN.addSymbol( nsN_i ); - nsN.addUsingDirective( nsM ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - compUnit.addSymbol( f ); - - f.addUsingDirective( nsN ); - - ISymbol look = null; - try - { - look = f.lookup( "i" ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ) - { - //ambiguous, both M::i and N::i are visible. - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - look = f.lookupNestedNameSpecifier("N"); //$NON-NLS-1$ - assertEquals( look, nsN ); - - look = ((IContainerSymbol) look).qualifiedLookup("i"); //ok //$NON-NLS-1$ - assertEquals( look, nsN_i ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * The same declaration found more than once is not an ambiguity - * namespace A{ - * int a; - * } - * namespace B{ - * using namespace A; - * } - * namespace C{ - * using namespace A; - * } - * - * namespace BC{ - * using namespace B; - * using namespace C; - * } - * - * void f(){ - * BC::a++; //ok - * } - */ - public void testUsing_SameDeclarationTwice() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol("A"); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - ISymbol a = table.newSymbol("a"); //$NON-NLS-1$ - nsA.addSymbol( a ); - - IContainerSymbol nsB = table.newContainerSymbol("B"); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - nsB.addUsingDirective( nsA ); - - IContainerSymbol nsC = table.newContainerSymbol("C"); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsC ); - nsC.addUsingDirective( nsA ); - - IContainerSymbol nsBC = table.newContainerSymbol("BC"); //$NON-NLS-1$ - nsBC.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsBC ); - nsBC.addUsingDirective( nsB ); - nsBC.addUsingDirective( nsC ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f.setType(ITypeInfo.t_function); - compUnit.addSymbol( f ); - - ISymbol look = f.lookupNestedNameSpecifier("BC"); //$NON-NLS-1$ - assertEquals( look, nsBC ); - look = ((IContainerSymbol)look).qualifiedLookup("a"); //$NON-NLS-1$ - assertEquals( look, a ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace B { - * int b; - * } - * namespace A { - * using namespace B; - * int a; - * } - * namespace B { - * using namespace A; - * } - * - * void f(){ - * A::a++; //ok - * A::b++; //ok - * B::a++; //ok - * B::b++; //ok - * } - */ - public void testUsing_SearchedOnce() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsB = table.newContainerSymbol( "B" ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - - ISymbol b = table.newSymbol("b"); //$NON-NLS-1$ - nsB.addSymbol( b ); - - IContainerSymbol nsA = table.newContainerSymbol( "A" ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - nsA.addUsingDirective( nsB ); - - ISymbol a = table.newSymbol("a"); //$NON-NLS-1$ - nsA.addSymbol( a ); - - nsB.addUsingDirective( nsA ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - compUnit.addSymbol(f); - - IContainerSymbol lookA = f.lookupNestedNameSpecifier("A"); //$NON-NLS-1$ - assertEquals( lookA, nsA ); - - ISymbol look = lookA.qualifiedLookup("a"); //$NON-NLS-1$ - assertEquals( look, a ); - - look = lookA.qualifiedLookup("b"); //$NON-NLS-1$ - assertEquals( look, b ); - - IContainerSymbol lookB = f.lookupNestedNameSpecifier("B"); //$NON-NLS-1$ - look = lookB.qualifiedLookup("a"); //$NON-NLS-1$ - assertEquals( look, a ); - - look = lookB.qualifiedLookup("b"); //$NON-NLS-1$ - assertEquals( look, b ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * we pass if we don't go into an infinite loop. - * TBD: we need a mechanism to detect failure of this - * test instead of just looping forever. - * - * @throws Exception - * - * namespace A{ - * } - * namespace B{ - * using namespace A; - * } - * namespace A{ - * using namespace B; - * } - * void f(){ - * using namespace A; - * using namespace B; - * i = 1; //not declared anywhere. - * } - */ - public void testUsing_SearchedOnce_2() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol( "A" ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - IContainerSymbol nsB = table.newContainerSymbol( "B" ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - nsB.addUsingDirective( nsA ); - - nsA.addUsingDirective( nsB ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - compUnit.addSymbol(f); - f.addUsingDirective(nsA); - f.addUsingDirective(nsB); - - ISymbol look = f.lookup("i"); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * During lookup of a qualified namespace member name, if the lookup finds - * more than one declaration of the member, non-type names hide class or - * enumeration names if and only if the declarations are from the same - * namespace - * @throws Exception - * - * namespace A { - * struct x { }; - * int x; - * int y; - * } - * namespace B { - * struct y { }; - * } - * - * namespace C { - * using namespace A; - * using namespace B; - * - * int i = C::x; //ok, finds A::x - * int j = C::y; //ambiguous, A::y or B::y - * } - */ - public void testNamespaceMemberHiding() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol("A"); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsA ); - - IContainerSymbol structX = table.newContainerSymbol("x"); //$NON-NLS-1$ - structX.setType( ITypeInfo.t_struct ); - nsA.addSymbol( structX ); - - ISymbol intX = table.newSymbol("x"); //$NON-NLS-1$ - intX.setType( ITypeInfo.t_int ); - nsA.addSymbol( intX ); - - ISymbol intY = table.newSymbol("y"); //$NON-NLS-1$ - intY.setType( ITypeInfo.t_int ); - nsA.addSymbol( intY ); - - IContainerSymbol nsB = table.newContainerSymbol("B"); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsB ); - IContainerSymbol structY = table.newContainerSymbol("y"); //$NON-NLS-1$ - structY.setType( ITypeInfo.t_struct ); - nsB.addSymbol( structY ); - - IContainerSymbol nsC = table.newContainerSymbol("C"); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace); - compUnit.addSymbol( nsC ); - - ISymbol look = nsC.lookup("A"); //$NON-NLS-1$ - assertEquals( look, nsA ); - nsC.addUsingDirective( nsA ); - - look = nsC.lookup("B"); //$NON-NLS-1$ - assertEquals( look, nsB ); - nsC.addUsingDirective( nsB ); - - //lookup C::x - look = nsC.lookupNestedNameSpecifier("C"); //$NON-NLS-1$ - assertEquals( look, nsC ); - look = ((IContainerSymbol)look).qualifiedLookup( "x" ); //$NON-NLS-1$ - assertEquals( look, intX ); - - //lookup C::y - look = nsC.lookupNestedNameSpecifier("C"); //$NON-NLS-1$ - assertEquals( look, nsC ); - - try{ - look = ((IContainerSymbol)look).qualifiedLookup( "y" ); //$NON-NLS-1$ - assertTrue(false); - } catch ( ParserSymbolTableException e ) { - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * In a definition for a namespace member in which the declarator-id is a - * qualified-id, given that the qualified-id for the namespace member has - * the form "nested-name-specifier unqualified-id", the unqualified-id shall - * name a member of the namespace designated by the nested-name-specifier. - * - * namespace A{ - * namespace B{ - * void f1(int); - * } - * using namespace B; - * } - * void A::f1(int) { ... } //ill-formed, f1 is not a member of A - */ - public void testLookupMemberForDefinition() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol( "A" ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - IContainerSymbol nsB = table.newContainerSymbol( "B" ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsB ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f1"); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - nsB.addSymbol( f1 ); - - nsA.addUsingDirective( nsB ); - - IContainerSymbol lookA = compUnit.lookupNestedNameSpecifier( "A" ); //$NON-NLS-1$ - assertEquals( nsA, lookA ); - - ISymbol look = lookA.lookupMemberForDefinition( "f1" ); //$NON-NLS-1$ - assertEquals( look, null ); - - //but notice if you wanted to do A::f1 as a function call, it is ok - look = lookA.qualifiedLookup( "f1" ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testUsingDeclaration - * @throws Exception - * 7.3.3-4 A using-declaration used as a member-declaration shall refer to a - * member of a base-class of the class being defined, shall refer to a - * member of an anonymous union that is a member of a base class of the - * class being defined or shall refer to an enumerator for an enumeration - * type that is a member of a base class of the class being defined - * - * struct B { - * void f( char ); - * enum E { e }; - * union { int x; }; - * }; - * class C { - * int g(); - * } - * struct D : B { - * using B::f; //ok, B is a base class of D - * using B::e; //ok, e is an enumerator in base class B - * using B::x; //ok, x is an union member of base class B - * using C::g; //error, C isn't a base class of D - * } - */ - public void testUsingDeclaration() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B"); //$NON-NLS-1$ - B.setType( ITypeInfo.t_struct ); - compUnit.addSymbol( B ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - B.addSymbol( f ); - - IContainerSymbol E = table.newContainerSymbol( "E" ); //$NON-NLS-1$ - E.setType( ITypeInfo.t_enumeration ); - B.addSymbol( E ); - - ISymbol e = table.newSymbol( "e" ); //$NON-NLS-1$ - e.setType( ITypeInfo.t_enumerator ); - E.addSymbol( e ); - - /** - * TBD: Anonymous unions are not yet implemented - */ - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol( C ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g" ); //$NON-NLS-1$ - g.setType( ITypeInfo.t_function ); - C.addSymbol( g ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D" ); //$NON-NLS-1$ - D.setType( ITypeInfo.t_struct ); - ISymbol look = compUnit.lookup( "B" ); //$NON-NLS-1$ - assertEquals( look, B ); - D.addParent( B ); - - compUnit.addSymbol( D ); - - IContainerSymbol lookB = D.lookupNestedNameSpecifier("B"); //$NON-NLS-1$ - assertEquals( lookB, B ); - - D.addUsingDeclaration( "f", lookB ); //$NON-NLS-1$ - D.addUsingDeclaration( "e", lookB ); //$NON-NLS-1$ - - //TBD anonymous union - //D.addUsingDeclaration( "x", lookB ); - - look = D.lookupNestedNameSpecifier("C"); //$NON-NLS-1$ - assertEquals( look, C ); - - try{ - D.addUsingDeclaration( "g", C ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException exception ){ - assertTrue( true ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testUsingDeclaration_2 - * @throws Exception - * 7.3.3-9 The entity declared by a using-declaration shall be known in the - * context using it according to its definition at the point of the using- - * declaration. Definitions added to the namespace after the using- - * declaration are not considered when a use of the name is made. - * - * namespace A { - * void f(int); - * } - * using A::f; - * - * namespace A { - * void f(char); - * } - * void foo(){ - * f('a'); //calls f( int ) - * } - * void bar(){ - * using A::f; - * f('a'); //calls f( char ); - * } - */ - public void testUsingDeclaration_2() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol A = table.newContainerSymbol( "A", ITypeInfo.t_namespace ); //$NON-NLS-1$ - compUnit.addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - A.addSymbol( f1 ); - - ISymbol look = compUnit.lookupNestedNameSpecifier("A"); //$NON-NLS-1$ - assertEquals( look, A ); - - IUsingDeclarationSymbol using = compUnit.addUsingDeclaration( "f", A ); //$NON-NLS-1$ - assertEquals( using.getReferencedSymbols().size(), 1 ); - - assertEquals( using.getReferencedSymbols().get(0), f1 ); - - IParameterizedSymbol usingF = (IParameterizedSymbol)using.getDeclaredSymbols().get(0); - - look = compUnit.lookup("A"); //$NON-NLS-1$ - assertEquals( look, A ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_char, 0, null, false ); - - A.addSymbol( f2 ); - - IParameterizedSymbol foo = table.newParameterizedSymbol("foo"); //$NON-NLS-1$ - foo.setType( ITypeInfo.t_function ); - compUnit.addSymbol( foo ); - - ArrayList paramList = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - paramList.add( param ); - - look = foo.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, usingF ); - assertTrue( usingF.hasSameParameters( f1 ) ); - - IParameterizedSymbol bar = table.newParameterizedSymbol( "bar" ); //$NON-NLS-1$ - bar.setType( ITypeInfo.t_function ); - bar.addParameter( ITypeInfo.t_char, 0, null, false ); - compUnit.addSymbol( bar ); - - look = bar.lookupNestedNameSpecifier( "A" ); //$NON-NLS-1$ - assertEquals( look, A ); - - using = bar.addUsingDeclaration( "f", A ); //$NON-NLS-1$ - - List list = using.getReferencedSymbols(); - assertTrue( list.contains( f1 ) ); - assertTrue( list.contains( f2 ) ); - assertEquals( list.size(), 2 ); - - int index = list.indexOf( f2 ); - list = using.getDeclaredSymbols(); - - look = bar.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertTrue( look != null ); - assertEquals( look, list.get( index ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testThisPointer - * @throws Exception - * In the body of a nonstatic member function... the type of this of a class - * X is X*. If the member function is declared const, the type of this is - * const X*, if the member function is declared volatile, the type of this - * is volatile X*.... - */ - public void testThisPointer() throws Exception{ - newTable(); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "class", ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol fn = table.newParameterizedSymbol("function", ITypeInfo.t_function ); //$NON-NLS-1$ - fn.setType( ITypeInfo.t_function ); - fn.getTypeInfo().setBit( true, ITypeInfo.isConst ); - - table.getCompilationUnit().addSymbol( cls ); - cls.addSymbol( fn ); - - ISymbol look = fn.lookup("this"); //$NON-NLS-1$ - assertTrue( look != null ); - - assertEquals( look.getType(), ITypeInfo.t_type ); - assertEquals( look.getTypeSymbol(), cls ); - assertTrue( look.getTypeInfo().checkBit( ITypeInfo.isConst ) ); - assertEquals( ((ITypeInfo.PtrOp)look.getPtrOperators().iterator().next()).getType(), ITypeInfo.PtrOp.t_pointer ); - - assertEquals( look.getContainingSymbol(), fn ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testEnumerator - * @throws Exception - * Following the closing brace of an enum-specifier, each enumerator has the - * type of its enumeration. - * The enum-name and each enumerator declared by an enum-specifier is - * declared in the scope that immediately contains the enum-specifier - */ - public void testEnumerator() throws Exception{ - newTable(); - - IContainerSymbol cls = table.newContainerSymbol("class"); //$NON-NLS-1$ - cls.setType( ITypeInfo.t_class ); - - IContainerSymbol enumeration = table.newContainerSymbol("enumeration"); //$NON-NLS-1$ - enumeration.setType( ITypeInfo.t_enumeration ); - - table.getCompilationUnit().addSymbol( cls ); - cls.addSymbol( enumeration ); - - ISymbol enumerator = table.newSymbol( "enumerator" ); //$NON-NLS-1$ - enumerator.setType( ITypeInfo.t_enumerator ); - enumeration.addSymbol( enumerator ); - - ISymbol look = cls.lookup( "enumerator" ); //$NON-NLS-1$ - assertEquals( look, enumerator ); - assertEquals( look.getContainingSymbol(), cls ); - assertEquals( look.getTypeSymbol(), enumeration ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace NS{ - * class T {}; - * void f( T ); - * } - * NS::T parm; - * int main(){ - * f( parm ); //ok, calls NS::f - * } - */ - public void testArgumentDependentLookup() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol NS = table.newContainerSymbol("NS"); //$NON-NLS-1$ - NS.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS ); - - IDerivableContainerSymbol T = table.newDerivableContainerSymbol("T"); //$NON-NLS-1$ - T.setType( ITypeInfo.t_class ); - - NS.addSymbol( T ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - f.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - - ISymbol look = NS.lookup( "T" ); //$NON-NLS-1$ - assertEquals( look, T ); - f.addParameter( look, 0, null, false ); - - NS.addSymbol( f ); - - look = compUnit.lookupNestedNameSpecifier( "NS" ); //$NON-NLS-1$ - assertEquals( look, NS ); - look = NS.qualifiedLookup( "T" ); //$NON-NLS-1$ - assertEquals( look, T ); - - ISymbol param = table.newSymbol("parm"); //$NON-NLS-1$ - param.setType( ITypeInfo.t_type ); - param.setTypeSymbol( look ); - compUnit.addSymbol( param ); - - IParameterizedSymbol main = table.newParameterizedSymbol("main"); //$NON-NLS-1$ - main.setType( ITypeInfo.t_function ); - main.setReturnType( table.newSymbol( "", ITypeInfo.t_int ) ); //$NON-NLS-1$ - compUnit.addSymbol( main ); - - ArrayList paramList = new ArrayList(); - look = main.lookup( "parm" ); //$NON-NLS-1$ - assertEquals( look, param ); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ); - paramList.add( p ); - - look = main.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testArgumentDependentLookup_2 - * @throws Exception - * in the following, NS2 is an associated namespace of class B which is an - * associated namespace of class A, so we should find f in NS2, we should - * not find f in NS1 because usings are ignored for associated scopes. - * - * - * namespace NS1{ - * void f( void * ){}; - * } - * namespace NS2{ - * using namespace NS1; - * class B {}; - * void f( void * ){}; - * } - * - * class A : public NS2::B {}; - * - * A a; - * f( &a ); - * - */ - public void testArgumentDependentLookup_2() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol NS1 = table.newContainerSymbol( "NS1" ); //$NON-NLS-1$ - NS1.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_void, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - NS1.addSymbol( f1 ); - - IContainerSymbol NS2 = table.newContainerSymbol( "NS2" ); //$NON-NLS-1$ - NS2.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS2 ); - - ISymbol look = NS2.lookup( "NS1" ); //$NON-NLS-1$ - assertEquals( look, NS1 ); - NS2.addUsingDirective( NS1 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - NS2.addSymbol( B ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_void, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - NS2.addSymbol( f2 ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - look = compUnit.lookupNestedNameSpecifier( "NS2" ); //$NON-NLS-1$ - assertEquals( look, NS2 ); - - look = NS2.qualifiedLookup( "B" ); //$NON-NLS-1$ - assertEquals( look, B ); - A.addParent( B ); - - compUnit.addSymbol( A ); - - look = compUnit.lookup( "A" ); //$NON-NLS-1$ - assertEquals( look, A ); - ISymbol a = table.newSymbol( "a" ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( look ); - compUnit.addSymbol( a ); - - ArrayList paramList = new ArrayList(); - look = compUnit.lookup( "a" ); //$NON-NLS-1$ - assertEquals( look, a ); - ITypeInfo param = TypeInfoProvider.newTypeInfo( look.getType(), 0, look, null, false ); - //new PtrOp( PtrOp.t_reference ) - param.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - paramList.add( param ); - - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testFunctionOverloading - * @throws Exception - * Note that this test has been contrived to not strain the resolution as - * that aspect is not yet complete. - * - * class C - * { - * void foo( int i ); - * void foo( int i, char c ); - * void foo( int i, char c, C * ptr ); - * } - * - * C * c = new C; - * c->foo( 1 ); - * c->foo( 1, 'a' ); - * c->foo( 1, 'a', c ); - * - */ - - public void testFunctionOverloading() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol(C); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("foo"); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - C.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("foo"); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - f2.addParameter( ITypeInfo.t_char, 0, null, false ); - C.addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol("foo"); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - f3.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - f3.addParameter( ITypeInfo.t_char, 0, null, false ); - f3.addParameter( C, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - C.addSymbol( f3 ); - - ISymbol look = compUnit.lookup("C"); //$NON-NLS-1$ - assertEquals( look, C ); - - ISymbol c = table.newSymbol("c"); //$NON-NLS-1$ - c.setType( ITypeInfo.t_type ); - c.setTypeSymbol( look ); - c.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - compUnit.addSymbol( c ); - - look = compUnit.lookup( "c" ); //$NON-NLS-1$ - assertEquals( look, c ); - assertEquals( look.getTypeSymbol(), C ); - - ArrayList paramList = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - - paramList.add( p1 ); - look = C.memberFunctionLookup( "foo", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.add( p2 ); - look = C.memberFunctionLookup( "foo", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - paramList.add( p3 ); - look = C.memberFunctionLookup( "foo", paramList ); //$NON-NLS-1$ - assertEquals( look, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * test basic function resolution - * - * void f( int i ); - * void f( char c = 'c' ); - * - * f( 1 ); //calls f( int ); - * f( 'b' ); //calls f( char ); - * f(); //calls f( char ); - */ - public void testFunctionResolution() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("f"); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( ITypeInfo.t_char, 0, null, true ); - compUnit.addSymbol( f2 ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - paramList.add( p1 ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.clear(); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - paramList.add( p2 ); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - paramList.clear(); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_bool, 0, null ); - paramList.add( p3 ); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - look = compUnit.unqualifiedFunctionLookup( "f", null ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A { }; - * class B : public A {}; - * class C : public B {}; - * - * void f ( A * ); - * void f ( B * ); - * - * A* a = new A(); - * C* c = new C(); - * - * f( a ); //calls f( A * ); - * f( c ); //calls f( B * ); - */ - public void testFunctionResolution_PointersAndBaseClasses() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - B.addParent( A ); - compUnit.addSymbol( B ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - C.addParent( B ); - compUnit.addSymbol( C ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f2 ); - - ISymbol a = table.newSymbol( "a" ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( A ); - a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - - ISymbol c = table.newSymbol( "c" ); //$NON-NLS-1$ - c.setType( ITypeInfo.t_type ); - c.setTypeSymbol( C ); - c.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p1 ); - ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.clear(); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - paramList.add( p2 ); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A {}; - * typedef A * B; - * - * void f( A * ); - * void f( A ); - * - * A a; - * B b; - * A [] array; - * - * f( a ); //calls f( A ); - * f( &a ); //calls f( A * ); - * f( b ); //calls f( A * ); - * f( *b ); //calls f( A ); - * f( array ); //calls f( A * ); - */ - public void testFunctionResolution_TypedefsAndPointers() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - ISymbol B = table.newSymbol( "B" ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_type ); - B.setTypeSymbol( A ); - B.getTypeInfo().setBit( true, ITypeInfo.isTypedef ); - B.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - compUnit.addSymbol( B ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( A, 0, null, false ); - compUnit.addSymbol( f2 ); - - ISymbol a = table.newSymbol( "a" ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( A ); - compUnit.addSymbol( a ); - - ISymbol b = table.newSymbol( "b" ); //$NON-NLS-1$ - b.setType( ITypeInfo.t_type ); - b.setTypeSymbol( B ); - compUnit.addSymbol( b ); - - ISymbol array = table.newSymbol( "array" ); //$NON-NLS-1$ - array.setType( ITypeInfo.t_type ); - array.setTypeSymbol( A ); - array.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array, false, false ) ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - p.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - p.setTypeSymbol( b ); - p.getPtrOperators().clear(); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - p = p.getFinalType( null ); - p.applyOperatorExpression( ITypeInfo.OperatorExpression.indirection ); - paramList.clear(); - paramList.add( p ); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - p.setTypeSymbol( array ); - p.getPtrOperators().clear(); - look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A {}; - * - * class B - * { - * B( A a ){ }; - * }; - * - * void f( B b ){}; - * - * A a; - * f( a ); - */ - public void testUserDefinedConversionSequences() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - compUnit.addSymbol( B ); - - IParameterizedSymbol constructor = table.newParameterizedSymbol("B"); //$NON-NLS-1$ - constructor.setType( ITypeInfo.t_constructor ); - constructor.addParameter( A, 0, null, false ); - B.addConstructor( constructor ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - f.addParameter( B, 0, null, false ); - compUnit.addSymbol( f ); - - ISymbol a = table.newSymbol( "a" ); //$NON-NLS-1$ - a.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type ) ); - a.setTypeSymbol( A ); - compUnit.addSymbol( a ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * void f( const int *, short ); - * void f( int *, int ); - * - * int i; - * short s; - * - * void main() { - * f( &i, s ); //ambiguous because &i->int* is better than &i->const int * - * //but s-> short is better than s->int - * f( &i, 1L ); //calls f(int *, int) because &i->int* is better than &i->const int * - * //and 1L->short and 1L->int are indistinguishable - * f( &i, 'c' ); //calls f( int*, int) because &i->int * is better than &i->const int * - * //and c->int is better than c->short - * f( (const int *)&i, 1L ); //calls f(const int *, short ) because const &i->int* is better than &i->int * - * //and 1L->short and 1L->int are indistinguishable - * } - */ - public void testOverloadRanking() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isShort, null, false ); - - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - compUnit.addSymbol( f2 ); - - ISymbol i = table.newSymbol( "i" ); //$NON-NLS-1$ - i.setType( ITypeInfo.t_int ); - compUnit.addSymbol( i ); - - ISymbol s = table.newSymbol( "s" ); //$NON-NLS-1$ - s.setType( ITypeInfo.t_int ); - s.getTypeInfo().setBit( true, ITypeInfo.isShort ); - compUnit.addSymbol( s ); - - IParameterizedSymbol main = table.newParameterizedSymbol( "main" ); //$NON-NLS-1$ - main.setType( ITypeInfo.t_function ); - compUnit.addSymbol( main ); - - ArrayList params = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, i ); - p1.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, s ); - params.add( p1 ); - params.add( p2 ); - - ISymbol look = null; - - try{ - look = main.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - params.clear(); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLong, null ); - params.add( p1 ); - params.add( p3 ); - look = main.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - params.clear(); - ITypeInfo p4 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - params.add( p1 ); - params.add( p4 ); - look = main.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - params.clear(); - p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isConst, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - - params.add( p1 ); - params.add( p3 ); - look = main.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class B; - * class A { A( B& ); }; - * class B { operator A(); }; - * - * void f(A){} - * - * B b; - * f( b ); //ambiguous because b->A via constructor or conversion - * - * class C { C( B& ); }; - * - * void f(C){} - * - * f( b ); //ambiguous because b->C via constructor and b->a via constructor/conversion - * - * void f(B){} - * - * f( b ); //calls f(B) - */ - - public void testUserDefinedConversionByOperator() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - - compUnit.addSymbol( B ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IParameterizedSymbol constructA = table.newParameterizedSymbol( "A" ); //$NON-NLS-1$ - constructA.setType( ITypeInfo.t_constructor ); - constructA.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - A.addConstructor( constructA ); - - IParameterizedSymbol operator = table.newParameterizedSymbol( "operator A" ); //$NON-NLS-1$ - operator.setType( ITypeInfo.t_function ); - B.addSymbol( operator ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, null, false ); - compUnit.addSymbol( f1 ); - - ISymbol b = table.newSymbol( "b" ); //$NON-NLS-1$ - b.setType( ITypeInfo.t_type ); - b.setTypeSymbol( B ); - - ArrayList params = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - params.add( p1 ); - - ISymbol look = null; - - try{ - look = compUnit.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol("C"); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol( C ); - - IParameterizedSymbol constructC = table.newParameterizedSymbol("C"); //$NON-NLS-1$ - constructC.setType( ITypeInfo.t_constructor ); - constructC.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - C.addConstructor( constructC ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( C, 0, null, false ); - compUnit.addSymbol( f2 ); - - try{ - look = compUnit.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f" ); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - f3.addParameter( B, 0, null, false ); - compUnit.addSymbol( f3 ); - - look = compUnit.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - -// public void testMarkRollback() throws Exception{ -// newTable(); -// -// IDerivableContainerSymbol A = table.newDerivableContainerSymbol("A"); -// A.setType( TypeInfo.t_class ); -// table.getCompilationUnit().addSymbol( A ); -// -// Mark mark = table.setMark(); -// -// ISymbol f = table.newSymbol("f"); -// A.addSymbol( f ); -// -// ISymbol look = A.lookup("f"); -// assertEquals( look, f ); -// -// assertTrue( table.rollBack( mark ) ); -// -// look = A.lookup("f"); -// assertEquals( look, null ); -// -// IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B"); -// B.setType( TypeInfo.t_class ); -// -// mark = table.setMark(); -// table.getCompilationUnit().addSymbol( B ); -// Mark mark2 = table.setMark(); -// A.addParent( B ); -// Mark mark3 = table.setMark(); -// -// IParameterizedSymbol C = table.newParameterizedSymbol("C"); -// C.addParameter( TypeInfo.t_class, 0, null, false ); -// -// assertEquals( C.getParameterList().size(), 1 ); -// table.rollBack( mark3 ); -// assertEquals( C.getParameterList().size(), 0 ); -// assertEquals( A.getParents().size(), 1 ); -// table.rollBack( mark2 ); -// assertEquals( A.getParents().size(), 0 ); -// -// assertFalse( table.commit( mark2 ) ); -// assertFalse( table.rollBack( mark2 ) ); -// -// B.setType( TypeInfo.t_namespace ); -// -// mark = table.setMark(); -// C.addUsingDirective( B ); -// assertEquals( C.getUsingDirectives().size(), 1 ); -// table.rollBack( mark ); -// assertEquals( C.getUsingDirectives().size(), 0 ); -// } - - /** - * class A; - * - * A * a; - * - * class A {}; - * - * @throws Exception - */ - public void testForwardClassDeclaration() throws Exception{ - newTable(); - - ISymbol forwardSymbol = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - forwardSymbol.setIsForwardDeclaration( true ); - - table.getCompilationUnit().addSymbol( forwardSymbol ); - - /*...*/ - - ISymbol lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - ISymbol otherLookup = table.getCompilationUnit().elaboratedLookup( ITypeInfo.t_class, "A" ); //$NON-NLS-1$ - - assertEquals( lookup, otherLookup ); - assertEquals( lookup, forwardSymbol ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( forwardSymbol ); - a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a ); - - /*...*/ - - lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - assertTrue( lookup.isForwardDeclaration() ); - lookup.setForwardSymbol( classA ); - - table.getCompilationUnit().addSymbol( classA ); - - lookup = table.getCompilationUnit().lookup( "a" ); //$NON-NLS-1$ - assertEquals( lookup, a ); - assertEquals( a.getTypeSymbol(), classA ); - - lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - - lookup = table.getCompilationUnit().elaboratedLookup( ITypeInfo.t_class, "A" ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A; - * - * class B { - * static void f( A * ); - * static void f( int ); - * }; - * - * A* a1; - * - * class A {}; - * - * void B::f( A * ) {} - * void B::f( int ) {} - * - * A* a2; - * - * B::f( a1 ); - * B::f( a2 ); - * - * @throws Exception - */ - public void testForwardDeclarationUsedAsFunctionParam() throws Exception{ - newTable(); - - ISymbol forwardSymbol = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - forwardSymbol.setIsForwardDeclaration( true ); - table.getCompilationUnit().addSymbol( forwardSymbol ); - - /*...*/ - - IDerivableContainerSymbol classB = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol fn1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - ISymbol lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( lookup, forwardSymbol ); - fn1.addParameter( lookup, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - fn1.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - classB.addSymbol( fn1 ); - - IParameterizedSymbol fn2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - fn2.addParameter( ITypeInfo.t_int, 0, null, false ); - fn2.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - classB.addSymbol( fn2 ); - - table.getCompilationUnit().addSymbol( classB ); - - /*...*/ - - ISymbol a1 = table.newSymbol( "a1", ITypeInfo.t_type ); //$NON-NLS-1$ - lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( lookup, forwardSymbol ); - a1.setTypeSymbol( lookup ); - a1.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a1 ); - - /*...*/ - - lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - assertTrue( lookup.isForwardDeclaration() ); - lookup.setForwardSymbol( classA ); - table.getCompilationUnit().addSymbol( classA ); - - /*..*/ - ISymbol a2 = table.newSymbol( "a2", ITypeInfo.t_type ); //$NON-NLS-1$ - lookup = table.getCompilationUnit().lookup( "A" ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - a2.setTypeSymbol( lookup ); - a2.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a2 ); - - /*..*/ - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a1 ); - paramList.add( p1 ); - ISymbol look = classB.memberFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, fn1 ); - - paramList.clear(); - p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a2 ); - paramList.add( p1 ); - look = classB.memberFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, fn1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testConstructors() throws Exception{ - newTable(); - - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol constructor1 = table.newParameterizedSymbol( "A", ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor1.addParameter( classA, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - IParameterizedSymbol constructor2 = table.newParameterizedSymbol( "A", ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor2.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol constructor3 = table.newParameterizedSymbol( "A", ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor3.addParameter( ITypeInfo.t_char, 0, null, false ); - - classA.addConstructor( constructor1 ); - classA.addConstructor( constructor2 ); - classA.addConstructor( constructor3 ); - - assertEquals( classA.getConstructors().size(), 3 ); - - IParameterizedSymbol cloned = (IParameterizedSymbol) constructor2.clone(); - try{ - classA.addConstructor( cloned ); - } catch ( ParserSymbolTableException e ) { - assertEquals( e.reason, ParserSymbolTableException.r_InvalidOverload ); - } - - ArrayList paramList = new ArrayList(); - paramList.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol lookup = classA.lookupConstructor( paramList ); - - assertEquals( lookup, constructor2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace A - * { - * int x; - * } - * namespace B = A; - * - * ++B::x; - */ - public void testNamespaceAlias() throws Exception{ - newTable(); - - IContainerSymbol NSA = table.newContainerSymbol( "A", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - ISymbol x = table.newSymbol( "x", ITypeInfo.t_int ); //$NON-NLS-1$ - NSA.addSymbol( x ); - - IContainerSymbol NSB = table.newContainerSymbol( "B", ITypeInfo.t_namespace ); //$NON-NLS-1$ - NSB.setForwardSymbol( NSA ); //alias B to A - - table.getCompilationUnit().addSymbol( NSB ); - - ISymbol lookup = table.getCompilationUnit().lookup( "B" ); //$NON-NLS-1$ - assertEquals( lookup, NSB ); - - lookup = NSB.lookup( "x" ); //$NON-NLS-1$ - assertEquals( lookup, x ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * namespace A - * { - * void f( ); - * } - * namespace B = A; - * - * B::f(); - * - * using namespace B; - * f(); - */ - public void testUsingNamespaceAlias() throws Exception{ - newTable(); - - IContainerSymbol NSA = table.newContainerSymbol( "A", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - - NSA.addSymbol( f ); - - IContainerSymbol NSB = table.newContainerSymbol( "B", ITypeInfo.t_namespace ); //$NON-NLS-1$ - NSB.setForwardSymbol( NSA ); - table.getCompilationUnit().addSymbol( NSB ); - - //look for function that has no parameters - ArrayList paramList = new ArrayList(); - ISymbol look = NSB.qualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - - table.getCompilationUnit().addUsingDirective( NSB ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * The general rule is that when you set a TypeInfo's type to be t_type, you - * should set the type symbol to be something. This is to test that the function - * resolution can handle a bad typeInfo that has a null symbol without throwing a NPE - */ - public void testBadParameterInfo() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.setReturnType( table.newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a ); - - f.addParameter( a, 0, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - ArrayList paramList = new ArrayList (); - - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, null ); - - paramList.add( param ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - - assertEquals( look, null ); - - ISymbol intermediate = table.newSymbol( "", ITypeInfo.t_type ); //$NON-NLS-1$ - - param.setTypeSymbol( intermediate ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ - - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * A ( C ) {}; - * } a; - * class B : public A {} b; - * class C { - * C ( A ) {}; - * } c; - * - * isTrue ? &a : &b; //expect type = 2nd operand ( A ) - * isTrue ? &a : &c; //expect null, neither converts - * isTrue ? a : c; //expect exception, both convert - * - * @throws Exception - */ - public void testGetConditionalOperand_bug43106() throws Exception{ - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - - clsB.addParent( clsA ); - - table.getCompilationUnit().addSymbol( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( clsA ); - - ISymbol b = table.newSymbol( "b", ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - ITypeInfo secondOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - secondOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - ITypeInfo thirdOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - thirdOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - - ITypeInfo returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, secondOp ); - - IDerivableContainerSymbol clsC = table.newDerivableContainerSymbol( "C", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( clsC ); - ISymbol c = table.newSymbol( "c", ITypeInfo.t_type ); //$NON-NLS-1$ - c.setTypeSymbol( clsC ); - table.getCompilationUnit().addSymbol( c ); - - ITypeInfo anotherOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - anotherOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - - returned = table.getConditionalOperand( secondOp, anotherOp ); - assertEquals( returned, null ); - - IParameterizedSymbol constructorA = table.newParameterizedSymbol( "A", ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructorA.addParameter( clsC, 0, null, false ); - clsA.addConstructor( constructorA ); - - IParameterizedSymbol constructorC = table.newParameterizedSymbol( "C", ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructorC.addParameter( clsA, 0, null, false ); - clsC.addConstructor( constructorC ); - - secondOp.getPtrOperators().clear(); - anotherOp.getPtrOperators().clear(); - try{ - - returned = table.getConditionalOperand( secondOp, anotherOp ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - //good - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * class A {}; - * class B : public A {} b; - * class C : private A {} c; - * int f ( A & ); - * - * int i = f ( b ); //calls f( A & ); - * - * int f ( B & ); - * i = f( b ); //now calls f( B& ); - * - * i = f( c ); //exception, A is not an accessible base class - */ - public void testDerivedReference() throws Exception{ - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsC = table.newDerivableContainerSymbol( "C", ITypeInfo.t_class ); //$NON-NLS-1$ - - clsB.addParent( clsA ); - clsC.addParent( clsA, false, ASTAccessVisibility.PRIVATE, 0, null ); - - ISymbol b = table.newSymbol("b", ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - - ISymbol c = table.newSymbol("c", ITypeInfo.t_type ); //$NON-NLS-1$ - c.setTypeSymbol( clsC ); - - table.getCompilationUnit().addSymbol( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - table.getCompilationUnit().addSymbol( clsC ); - table.getCompilationUnit().addSymbol( b ); - table.getCompilationUnit().addSymbol( c ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( clsA, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - table.getCompilationUnit().addSymbol( f1 ); - - ArrayList parameters = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - parameters.add( param ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( clsB, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - table.getCompilationUnit().addSymbol( f2 ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - parameters.clear(); - param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - parameters.add( param ); - try{ - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - //good - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A { - * private : - * A ( const A & ) {} - * } a; - * - * class B : public A { - * } b; - * - * 1 > 2 ? a : b; //fails, b can't be converted to a without the A( const A & ) copy constructor - * ----------------------- - * class A { - * A ( const A & ) {} - * } a; - * class B : public A {} b; - * - * 1 > 2 ? a : b; //succeeds, b can be converted to a using copy constructor - * - */ - public void testAddCopyConstructor() throws Exception { - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( clsA ); - - ISymbol a = table.newSymbol( "a", ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( clsA ); - table.getCompilationUnit().addSymbol( a ); - - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - clsB.addParent( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - - ISymbol b = table.newSymbol( "b", ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - table.getCompilationUnit().addSymbol( b ); - - ITypeInfo secondOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a, null, false ); - ITypeInfo thirdOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b, null, false ); - - ITypeInfo returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, null ); - - clsA.addCopyConstructor(); - clsB.addCopyConstructor(); - - returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, secondOp ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testbug43834() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( f ); - - ArrayList parameters = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_void, 0, null ); - parameters.add( param ); - - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ - assertEquals( look, f ); - - f.addParameter( ITypeInfo.t_void, 0, null, false ); - - parameters.clear(); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * namespace A{ - * void f(); - * } - * namespace B{ - * int f; - * } - * namespace C{ - * using namespace A; - * using namespace B; - * using f; //ambiguous, int f or void f()? - * } - */ - public void testBug43503_AmbiguousUsing() throws Exception{ - newTable(); - IContainerSymbol NSA = table.newContainerSymbol( "A", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - NSA.addSymbol( f1 ); - - IContainerSymbol NSB = table.newContainerSymbol( "B", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSB ); - - ISymbol f2 = table.newSymbol( "f", ITypeInfo.t_int ); //$NON-NLS-1$ - NSB.addSymbol( f2 ); - - IContainerSymbol NSC = table.newContainerSymbol( "C", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSC ); - NSC.addUsingDirective( NSA ); - NSC.addUsingDirective( NSB ); - - try{ - NSC.addUsingDeclaration( "f" ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( void ); - * void f( int ); - * - * void * pF = &f; //lookup without function parameters, should be ambiguous - * @throws Exception - */ - public void testBug43503_UnableToResolveFunction() throws Exception{ - newTable(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - - table.getCompilationUnit().addSymbol( f1 ); - table.getCompilationUnit().addSymbol( f2 ); - - try{ - table.getCompilationUnit().lookup( "f" ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_UnableToResolveFunction ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int initialize(); - * int initialize(){ - * return 3; - * } - * - * int i = initialize(); - * - * @throws Exception - */ - public void testBug44510() throws Exception{ - newTable(); - - IParameterizedSymbol init1 = table.newParameterizedSymbol( "initialize", ITypeInfo.t_function ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( init1 ); - - IParameterizedSymbol init2 = table.newParameterizedSymbol( "initialize", ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, init1 ); - - init1.setIsForwardDeclaration( true ); - init1.setForwardSymbol( init2 ); - - table.getCompilationUnit().addSymbol( init2 ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new ArrayList() ); //$NON-NLS-1$ - - assertEquals( look, init2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * void f( int ) {} - * void f( ) {} - * }; - * class B : public A { - * void f( char ) { } - * } b; - * - * b.f( 1 ); //calls B::f - * b.f(); //error - * @throws Exception - */ - public void testBug46882() throws Exception{ - newTable(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - A.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( f2 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A ); - - table.getCompilationUnit().addSymbol( B ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_char, 0, null, false ); - B.addSymbol( f3 ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f3 ); - - params.clear(); - look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aVar; - * void foo( ) { - * int anotherVar; - * a(CTRL+SPACE) - * } - */ - public void testPrefixLookup_Unqualified() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aVar = table.newSymbol( "aVar", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aVar ); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( foo ); - - ISymbol anotherVar = table.newSymbol( "anotherVar", ITypeInfo.t_int ); //$NON-NLS-1$ - foo.addSymbol( anotherVar ); - - List results = foo.prefixLookup( null, "a", false, null ); //$NON-NLS-1$ - assertTrue( results != null ); - assertEquals( results.size(), 2 ); - - assertTrue( results.contains( aVar ) ); - assertTrue( results.contains( anotherVar ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aVar; //not a member of D, not reported - * - * class D{ - * int aField; - * void aMethod(); - * }; - * - * D d; - * d.a(CTRL+SPACE) - */ - public void testPrefixLookup_Qualified() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aVar = table.newSymbol( "aVar", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aVar ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( D ); - - ISymbol aField = table.newSymbol( "aField", ITypeInfo.t_int ); //$NON-NLS-1$ - IParameterizedSymbol aMethod = table.newParameterizedSymbol( "aMethod", ITypeInfo.t_function ); //$NON-NLS-1$ - - D.addSymbol( aField ); - D.addSymbol( aMethod ); - - List results = D.prefixLookup( null, "a", true, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 2 ); - - assertTrue( !results.contains( aVar ) ); - assertTrue( results.contains( aField ) ); - assertTrue( results.contains( aMethod ) ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * int aVar - * int anotherVar; //hidden, not reported - * void af (); //hidden, not reported - * }; - * - * class B : public A { - * int anotherVar; - * void af( char ); - * } b; - * - * b.a(CTRL+SPACE) - * @throws Exception - */ - public void testPrefixLookup_Inheritance() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - ISymbol aVar = table.newSymbol( "aVar", ITypeInfo.t_int ); //$NON-NLS-1$ - ISymbol anotherVar1 = table.newSymbol( "anotherVar", ITypeInfo.t_int ); //$NON-NLS-1$ - A.addSymbol( aVar ); - A.addSymbol( anotherVar1 ); - - IParameterizedSymbol af1 = table.newParameterizedSymbol( "af", ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( af1 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A ); - - table.getCompilationUnit().addSymbol( B ); - - ISymbol anotherVar2 = table.newSymbol( "anotherVar", ITypeInfo.t_int ); //$NON-NLS-1$ - B.addSymbol( anotherVar2 ); - - IParameterizedSymbol af2 = table.newParameterizedSymbol( "af", ITypeInfo.t_function ); //$NON-NLS-1$ - af2.addParameter( ITypeInfo.t_char, 0, null, false ); - B.addSymbol( af2 ); - - - List results = B.prefixLookup( null, "a", true, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 3 ); - assertTrue( ! results.contains( anotherVar1 ) ); - assertTrue( ! results.contains( af1 ) ); - assertTrue( results.contains( aVar ) ); - assertTrue( results.contains( anotherVar2 ) ); - assertTrue( results.contains( af2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aa; - * namespace { - * namespace U { - * int a; - * } - * namespace V{ - * int a; - * } - * namespace W{ - * int a; - * } - * - * void f(){ - * using namespace U; - * using namespace V; - * using namespace W; - * a(CTRL+SPACE) - * } - * } - * - * @throws Exception - */ - public void testPrefixLookup_Ambiguities() throws Exception{ - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aa = table.newSymbol( "aa", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aa ); - - IContainerSymbol ns = table.newContainerSymbol( "", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( ns ); - - IContainerSymbol U = table.newContainerSymbol( "U", ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( U ); - ISymbol a1 = table.newSymbol( "a", ITypeInfo.t_int ); //$NON-NLS-1$ - U.addSymbol( a1 ); - - IContainerSymbol V = table.newContainerSymbol( "V", ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( V ); - ISymbol a2 = table.newSymbol( "a", ITypeInfo.t_int ); //$NON-NLS-1$ - V.addSymbol( a2 ); - - IContainerSymbol W = table.newContainerSymbol( "W", ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( W ); - ISymbol a3 = table.newSymbol( "a", ITypeInfo.t_int ); //$NON-NLS-1$ - W.addSymbol( a3 ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - ns.addSymbol( f ); - - f.addUsingDirective( U ); - f.addUsingDirective( V ); - f.addUsingDirective( W ); - - List results = f.prefixLookup( null, "a", false, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aa ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int i; - * class A { - * void g(){ - * A a; - * a.i++; //fail qualified lookup, no i in A - * i++; //success unqualified lookup - * } - * }; - * - * @throws Exception - */ - public void testQualifiedUnqualifiedLookup() throws Exception{ - newTable(); - - ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( i ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( g ); - - assertEquals( null, A.qualifiedLookup( "i" ) ); //$NON-NLS-1$ - assertEquals( i, g.lookup( "i" ) ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class D { }; - * class A { - * public: static int i; - * private: static int j; - * friend class D; - * }; - * class B : private A {}; - * class C : public B, public A {}; - * - * - * @throws Exception - */ - public void testVisibilityDetermination() throws Exception{ - newTable(); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( D ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$ - ISymbol j = table.newSymbol( "j", ITypeInfo.t_int ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( A ); - - ISymbol friend = A.lookupForFriendship( "D" ); //$NON-NLS-1$ - assertEquals( friend, D ); - A.addFriend( friend ); - - A.addSymbol( i ); - A.addSymbol( j ); - - IASTCompilationUnit compUnit = new ASTCompilationUnit(table.getCompilationUnit() ); - ISymbolASTExtension cuExtension = new StandardSymbolExtension( table.getCompilationUnit(), (ASTSymbol) compUnit ); - table.getCompilationUnit().setASTExtension( cuExtension ); - - IASTClassSpecifier clsSpec = new ASTClassSpecifier( A, ASTClassKind.CLASS, ClassNameType.IDENTIFIER, ASTAccessVisibility.PUBLIC, 0, 0, 0, 0, 0, new ArrayList( ) ); - ISymbolASTExtension clsExtension = new StandardSymbolExtension( A, (ASTSymbol) clsSpec ); - A.setASTExtension( clsExtension ); - - IASTField field = new ASTField(i, null, null, null, 0, 0, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PUBLIC ); - ISymbolASTExtension extension = new StandardSymbolExtension( i, (ASTSymbol) field ); - i.setASTExtension( extension ); - - field = new ASTField(i, null, null, null, 0, 0, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PRIVATE ); - extension = new StandardSymbolExtension( j, (ASTSymbol) field ); - j.setASTExtension( extension ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A, false, ASTAccessVisibility.PRIVATE, 0, null ); - table.getCompilationUnit().addSymbol( B ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C", ITypeInfo.t_class ); //$NON-NLS-1$ - C.addParent( B ); - C.addParent( A ); - table.getCompilationUnit().addSymbol( C ); - - assertTrue( table.getCompilationUnit().isVisible( i, A ) ); - assertFalse( table.getCompilationUnit().isVisible( i, B ) ); - assertTrue( table.getCompilationUnit().isVisible(i, C ) ); - assertTrue( D.isVisible( j, A ) ); - assertFalse( D.isVisible( j, B ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * struct a1{}; - * void aFoo() {} - * int aa; - * class A2{ - * struct a3 {}; - * int a3; - * void aF(); - * void f() { - * int aLocal; - * A(CTRL+SPACE) - * }; - * }; - * @throws Exception - */ - public void testPrefixFiltering() throws Exception{ - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - IDerivableContainerSymbol a1 = table.newDerivableContainerSymbol( "a1", ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a1 ); - - IParameterizedSymbol aFoo = table.newParameterizedSymbol( "aFoo", ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aFoo ); - - ISymbol aa = table.newSymbol( "aa", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aa ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A2", ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A2 ); - - IDerivableContainerSymbol a3 = table.newDerivableContainerSymbol( "a3", ITypeInfo.t_struct ); //$NON-NLS-1$ - A2.addSymbol( a3 ); - - ISymbol a3_int = table.newSymbol( "a3", ITypeInfo.t_int ); //$NON-NLS-1$ - A2.addSymbol( a3_int ); - - IParameterizedSymbol aF = table.newParameterizedSymbol( "aF", ITypeInfo.t_function ); //$NON-NLS-1$ - A2.addSymbol( aF ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - A2.addSymbol( f ); - - ISymbol aLocal = table.newSymbol( "aLocal", ITypeInfo.t_int ); //$NON-NLS-1$ - f.addSymbol( aLocal ); - - List results = f.prefixLookup( new TypeFilter( LookupKind.STRUCTURES ), "A", false, null ); //$NON-NLS-1$ - - assertEquals( results.size(), 3 ); - - assertTrue( results.contains( a1 ) ); - assertTrue( results.contains( A2 ) ); - assertTrue( results.contains( a3 ) ); - - results = f.prefixLookup( null, "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 7 ); - assertTrue( results.contains( aF ) ); - assertTrue( results.contains( A2 ) ); - assertTrue( results.contains( a3_int ) ); - assertTrue( results.contains( a1 ) ); - assertTrue( results.contains( aFoo ) ); - assertTrue( results.contains( aa ) ); - assertTrue( results.contains( aLocal ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.FUNCTIONS ), "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aFoo ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.METHODS ), "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aF ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.LOCAL_VARIABLES ), "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aLocal ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.VARIABLES ), "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aa ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a", false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( a3_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( ... ){ } - * - * foo( 1 ); - * - * @throws Exception - */ - public void testBug43110_Ellipses() throws Exception{ - newTable(); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - foo.setHasVariableArgs( true ); - - table.getCompilationUnit().addSymbol( foo ); - - List params = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - params.add( p1 ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ - - assertEquals( foo, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( ... ) {}; //#1 - * void foo( int i ) {}; //#2 - * - * foo( 1 ); // calls foo #2 - * @throws Exception - */ - public void testBug43110_EllipsesRanking() throws Exception{ - newTable(); - - IParameterizedSymbol foo1 = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - foo1.setHasVariableArgs( true ); - - table.getCompilationUnit().addSymbol( foo1 ); - - IParameterizedSymbol foo2 = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - foo2.addParameter( ITypeInfo.t_int, 0, null, false ); - table.getCompilationUnit().addSymbol( foo2 ); - - List params = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - params.add( p1 ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ - - assertEquals( foo2, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( int i = 0 ) {}; //#1 - * void foo( ... ) {}; //#2 - * - * foo(); //calls #1 - * @throws Exception - */ - public void testBug43110_ElipsesRanking_2() throws Exception{ - newTable(); - - IParameterizedSymbol foo1 = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - foo1.addParameter( ITypeInfo.t_int, 0, null, true ); - table.getCompilationUnit().addSymbol( foo1 ); - - IParameterizedSymbol foo2 = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - foo2.setHasVariableArgs( true ); - table.getCompilationUnit().addSymbol( foo2 ); - - List params = new ArrayList(); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ - - assertEquals( foo1, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int global; - * class A { - * A(); - * int var; - * void foo(); - * }; - * - */ - public void testIterator_1() throws Exception{ - newTable(); - - ISymbol global = table.newSymbol( "global", ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( global ); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( cls ); - - IParameterizedSymbol constructor = table.newParameterizedSymbol( "A", ITypeInfo.t_constructor ); //$NON-NLS-1$ - cls.addConstructor( constructor ); - - ISymbol var = table.newSymbol( "var", ITypeInfo.t_int ); //$NON-NLS-1$ - cls.addSymbol( var ); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - cls.addSymbol( foo ); - - - Iterator iter = table.getCompilationUnit().getContentsIterator(); - assertEquals( iter.next(), global ); - IContainerSymbol symbol = (IContainerSymbol) iter.next(); - assertEquals( symbol, cls ); - assertFalse( iter.hasNext() ); - - iter = symbol.getContentsIterator(); - assertEquals( iter.next(), constructor ); - assertEquals( iter.next(), var ); - assertEquals( iter.next(), foo ); - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int foo(); - * namespace A{ - * int bar(); - * int bar( int ); - * }; - * class B{ - * void func(){ - * using namespace A; - * } - * }; - * @throws Exception - */ - public void testIterator_2() throws Exception{ - newTable(); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( foo ); - - IContainerSymbol nsA = table.newContainerSymbol( "A", ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( nsA ); - - IParameterizedSymbol bar1 = table.newParameterizedSymbol( "bar", ITypeInfo.t_function ); //$NON-NLS-1$ - nsA.addSymbol( bar1 ); - - IParameterizedSymbol bar2 = table.newParameterizedSymbol( "bar", ITypeInfo.t_function ); //$NON-NLS-1$ - bar2.addParameter( ITypeInfo.t_int, 0, null, false ); - nsA.addSymbol( bar2 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B", ITypeInfo.t_class); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - B.addCopyConstructor(); - - IParameterizedSymbol func = table.newParameterizedSymbol( "func", ITypeInfo.t_function ); //$NON-NLS-1$ - B.addSymbol( func ); - - IUsingDirectiveSymbol using = func.addUsingDirective( nsA ); - - Iterator iter = table.getCompilationUnit().getContentsIterator(); - - assertEquals( iter.next(), foo ); - - IContainerSymbol s1 = (IContainerSymbol) iter.next(); - assertEquals( s1, nsA ); - - IContainerSymbol s2 = (IContainerSymbol) iter.next(); - assertEquals( s2, B ); - - assertFalse( iter.hasNext() ); - - iter = s1.getContentsIterator(); - assertEquals( iter.next(), bar1 ); - assertEquals( iter.next(), bar2 ); - assertFalse( iter.hasNext() ); - - iter = s2.getContentsIterator(); - - //Copy constructor!! - ISymbol copy = (ISymbol) iter.next(); - assertTrue( copy instanceof IParameterizedSymbol ); - assertEquals( copy.getName(), "B" ); //$NON-NLS-1$ - assertEquals( copy.getType(), ITypeInfo.t_constructor ); - - assertEquals( iter.next(), func ); - assertFalse( iter.hasNext() ); - - iter = func.getContentsIterator(); - //this pointer!! - ISymbol th = (ISymbol) iter.next(); - assertEquals( th.getName(), "this" ); //$NON-NLS-1$ - assertEquals( th.getTypeSymbol(), B ); - - assertEquals( iter.next(), using ); - - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( long long int ){} //#1 - * void f( long int ) {} //#2 - * - * f( 1L ); //#2 - * f( 1LL ); //#1 - * - * @throws Exception - */ - public void testLongLong() throws Exception{ - newTable(); - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isLongLong, null, false ); - table.getCompilationUnit().addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, ITypeInfo.isLong, null, false ); - table.getCompilationUnit().addSymbol( f2 ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLong, null ) ); - - IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( lookup, f2 ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLongLong, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( lookup, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( float _Complex ){} - * void g( float ) {} - * - * float _Complex c; - * float fl; - * float _Imaginary i; - * - * f( c ); - * f( fl ); - * g( c ); - * g( i ); - * @throws Exception - */ - public void testComplex() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( ITypeInfo.t_float, ITypeInfo.isComplex, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( ITypeInfo.t_float, 0, null, false ); - table.getCompilationUnit().addSymbol( g ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isComplex, null ) ); - - IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - - assertEquals( lookup, f ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, 0, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( lookup, f ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isComplex, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params ); //$NON-NLS-1$ - assertEquals( lookup, g ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isImaginary, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params ); //$NON-NLS-1$ - assertEquals( lookup, g ); - - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( lookup, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void test_Bool() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( ITypeInfo.t__Bool, 0, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( ITypeInfo.t_int, 0, null, false ); - - table.getCompilationUnit().addSymbol( g ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t__Bool, 0, null ) ); - - IParameterizedSymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params ); //$NON-NLS-1$ - assertEquals( look, g ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * typedef int Int; - * void f( int i ); - * void f( Int i ); - * - * - * @throws Exception - */ - public void testBug47636FunctionParameterComparisons_1() throws Exception{ - newTable(); - - ISymbol Int = table.newSymbol( "Int", ITypeInfo.t_type ); //$NON-NLS-1$ - Int.getTypeInfo().setBit( true, ITypeInfo.isTypedef ); - Int.setTypeSymbol( table.newSymbol( ParserSymbolTable.EMPTY_NAME, ITypeInfo.t_int ) ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( Int, 0, null, false ); - - assertTrue( f1.hasSameParameters( f2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void g( char * ); - * void g( char [] ); - */ - public void testBug47636FunctionParameterComparisons_2() throws Exception{ - newTable(); - - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g1.addParameter( ITypeInfo.t_char, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g", ITypeInfo.t_function ); //$NON-NLS-1$ - g2.addParameter( ITypeInfo.t_char, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ), false ); - - assertTrue( g1.hasSameParameters( g2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void h( int() ); - * void h( int (*) () ); - */ - public void testBug47636FunctionParameterComparisons_3() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( ParserSymbolTable.EMPTY_NAME, ITypeInfo.t_function ); - f.setReturnType( table.newSymbol( ParserSymbolTable.EMPTY_NAME, ITypeInfo.t_int ) ); - - IParameterizedSymbol h1 = table.newParameterizedSymbol( "h", ITypeInfo.t_function ); //$NON-NLS-1$ - h1.addParameter( f, 0, null, false ); - - IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", ITypeInfo.t_function ); //$NON-NLS-1$ - h2.addParameter( f, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - assertTrue( h1.hasSameParameters( h2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * f( int ); - * f( const int ); - */ - public void testBug47636FunctionParameterComparisons_4() throws Exception{ - newTable(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, ITypeInfo.isConst, null, false ); - - assertTrue( f1.hasSameParameters( f2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - -// public void testBug52111RemoveSymbol() throws Exception{ -// newTable(); -// -// IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$ -// table.getCompilationUnit().addSymbol( A ); -// -// ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$ -// A.addSymbol( i ); -// -// IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ -// A.addSymbol( f1 ); -// -// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$ -// f2.addParameter( ITypeInfo.t_int, 0, null, false ); -// -// A.addSymbol( f2 ); -// -// IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$ -// B.addParent( A ); -// -// table.getCompilationUnit().addSymbol( B ); -// -// ISymbol look = B.qualifiedLookup( "i" ); //$NON-NLS-1$ -// assertEquals( look, i ); -// -// Iterator iter = A.getContentsIterator(); -// assertEquals( iter.next(), i ); -// assertEquals( iter.next(), f1 ); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// assertTrue( A.removeSymbol( i ) ); -// -// iter = A.getContentsIterator(); -// assertEquals( iter.next(), f1 ); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedLookup( "i" ); //$NON-NLS-1$ -// assertNull( look ); -// -// List params = new ArrayList(); -// -// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ -// assertEquals( look, f1 ); -// -// assertTrue( A.removeSymbol( f1 ) ); -// iter = A.getContentsIterator(); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ -// assertNull( look ); -// -// params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); -// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ -// -// assertEquals( look, f2 ); -// assertTrue( A.removeSymbol( f2 ) ); -// -// iter = A.getContentsIterator(); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ -// assertNull( look ); -// -// assertEquals( A.getContainedSymbols().size(), 0 ); -// assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); -// } -} - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java deleted file mode 100644 index 2cd9850b0e8..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ /dev/null @@ -1,51 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.model.tests.CModelElementsTests; -import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests; - -/** - * @author jcamelon - * - * 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 static Test suite() { - TestSuite suite= new TestSuite(ParserTestSuite.class.getName()); - suite.addTestSuite(BranchTrackerTest.class); - suite.addTestSuite(ScannerTestCase.class); - suite.addTestSuite(ExprEvalTest.class); - suite.addTestSuite(QuickParseASTTests.class); - suite.addTestSuite(ParserSymbolTableTest.class); - suite.addTestSuite(ParserSymbolTableTemplateTests.class ); - suite.addTestSuite(CModelElementsTests.class); - suite.addTestSuite(StructuralCModelElementsTests.class); - suite.addTestSuite(CompletionParseTest.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 ); - return suite; - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java deleted file mode 100644 index eb46ac5e839..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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()); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java deleted file mode 100644 index b598550c78f..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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.ScannerException; -import org.eclipse.cdt.core.parser.ScannerInfo; - -/** - * @author jcamelon - * - */ -public class PreprocessorConditionalTest extends BaseScannerTest -{ - - 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() - { - 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( ScannerException se ) - { - fail( "Got #error, should not have gotten that."); //$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$ - - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java deleted file mode 100644 index 77eb6d60cde..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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$ - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java deleted file mode 100644 index 3e4f78b5d6f..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java +++ /dev/null @@ -1,2267 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.core.parser.tests; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.IMacroDescriptor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -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.IASTInitializerClause; -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.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -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.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -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 jcamelon - * - */ -public class QuickParseASTTests extends BaseASTTest -{ - public QuickParseASTTests(String a) - { - super(a); - } - /** - * Test code: int x = 5; - * Purpose: to test the simple decaration in it's simplest form. - */ - public void testIntGlobal() throws Exception - { - // Parse and get the translation Unit - IASTCompilationUnit translationUnit = parse("int x = 5;"); //$NON-NLS-1$ - Iterator i = translationUnit.getDeclarations(); - assertTrue(i.hasNext()); - IASTVariable var = (IASTVariable)i.next(); - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)var - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - assertEquals(var.getName(), "x"); //$NON-NLS-1$ - assertNull(var.getInitializerClause()); - assertFalse(i.hasNext()); - } - /** - * Test code: class A { } a; - * Purpose: tests the use of a classSpecifier in - */ - public void testEmptyClass() throws Exception - { - // Parse and get the translation unit - Writer code = new StringWriter(); - code.write("class A { } a;"); //$NON-NLS-1$ - IASTCompilationUnit translationUnit = parse(code.toString()); - Iterator i = translationUnit.getDeclarations(); - assertTrue(i.hasNext()); - IASTVariable var = (IASTVariable)i.next(); - assertEquals(var.getName(), "a"); //$NON-NLS-1$ - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTClassSpecifier); - IASTClassSpecifier classSpec = - (IASTClassSpecifier)var.getAbstractDeclaration().getTypeSpecifier(); - assertEquals(classSpec.getName(), "A"); //$NON-NLS-1$ - assertFalse(classSpec.getDeclarations().hasNext()); - assertFalse(i.hasNext()); - } - /** - * Test code: class A { public: int x; }; - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMember() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A { public: int x; };"); //$NON-NLS-1$ - IASTCompilationUnit cu = parse(code.toString()); - Iterator i = cu.getDeclarations(); - assertTrue(i.hasNext()); - IASTAbstractTypeSpecifierDeclaration declaration = - (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse(i.hasNext()); - assertTrue( - declaration.getTypeSpecifier() instanceof IASTClassSpecifier); - assertTrue( - ((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind() - == ASTClassKind.CLASS); - Iterator j = - ((IASTClassSpecifier)declaration.getTypeSpecifier()) - .getDeclarations(); - assertTrue(j.hasNext()); - IASTField field = (IASTField)j.next(); - assertFalse(j.hasNext()); - assertTrue(field.getName().equals("x")); //$NON-NLS-1$ - assertTrue( - field.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)field - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - } - public void testNamespaceDefinition() throws Exception - { - for (int i = 0; i < 2; ++i) - { - IASTCompilationUnit translationUnit; - if (i == 0) - translationUnit = parse("namespace KingJohn { int x; }"); //$NON-NLS-1$ - else - translationUnit = parse("namespace { int x; }"); //$NON-NLS-1$ - Iterator iter = translationUnit.getDeclarations(); - assertTrue(iter.hasNext()); - IASTNamespaceDefinition namespaceDefinition = - (IASTNamespaceDefinition)iter.next(); - assertFalse(iter.hasNext()); - if (i == 0) - assertTrue(namespaceDefinition.getName().equals("KingJohn")); //$NON-NLS-1$ - else - assertEquals(namespaceDefinition.getName(), ""); //$NON-NLS-1$ - Iterator j = namespaceDefinition.getDeclarations(); - assertTrue(j.hasNext()); - IASTVariable var = (IASTVariable)j.next(); - assertFalse(j.hasNext()); - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)var - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - assertEquals(var.getName(), "x"); //$NON-NLS-1$ - } - } - - public void testLinkageSpecification() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - IASTCompilationUnit compilationUnit; - if( i == 0 ) - compilationUnit = parse("extern \"C\" { int x(void); }"); //$NON-NLS-1$ - else - compilationUnit = parse("extern \"ADA\" int x(void);"); //$NON-NLS-1$ - - Iterator declarations = compilationUnit.getDeclarations(); - assertTrue( declarations.hasNext() ); - IASTLinkageSpecification linkage = (IASTLinkageSpecification)declarations.next(); - assertFalse( declarations.hasNext() ); - - if( i == 0 ) - assertEquals( "C", linkage.getLinkageString() ); //$NON-NLS-1$ - else - assertEquals( "ADA", linkage.getLinkageString() ); //$NON-NLS-1$ - - Iterator subDeclarations = linkage.getDeclarations(); - assertTrue( subDeclarations.hasNext() ); - IASTFunction function = (IASTFunction)subDeclarations.next(); - assertFalse( subDeclarations.hasNext()); - - assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( function.getName(), "x"); //$NON-NLS-1$ - - Iterator parameters = function.getParameters(); - assertTrue( parameters.hasNext() ); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - } - } - - public void testEnumSpecifier() throws Exception - { - Writer code = new StringWriter(); - code.write( "enum { yo, go = 3, away };\n"); //$NON-NLS-1$ - code.write( "enum hasAString { last = 666 };"); //$NON-NLS-1$ - IASTCompilationUnit translationUnit = parse( code.toString() ); - Iterator declarations = translationUnit.getDeclarations(); - - for( int i = 0; i < 2; ++i ) - { - assertTrue( declarations.hasNext() ); - IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTEnumerationSpecifier enumerationSpec = (IASTEnumerationSpecifier)abstractDeclaration.getTypeSpecifier(); - if( i == 0 ) - assertEquals( enumerationSpec.getName(), "" ); //$NON-NLS-1$ - else - assertEquals( enumerationSpec.getName(), "hasAString" ); //$NON-NLS-1$ - Iterator j = enumerationSpec.getEnumerators(); - - if( i == 0 ) - { - IASTEnumerator enumerator1 = (IASTEnumerator)j.next(); - assertEquals( enumerator1.getName(), "yo"); //$NON-NLS-1$ - assertNull( enumerator1.getInitialValue() ); - IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); - assertNotNull( enumerator2.getInitialValue() ); - assertEquals( enumerator2.getInitialValue().getLiteralString(), "3"); //$NON-NLS-1$ - assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( enumerator2.getName(), "go"); //$NON-NLS-1$ - IASTEnumerator enumerator3 = (IASTEnumerator)j.next(); - assertEquals( enumerator3.getName(), "away"); //$NON-NLS-1$ - assertNull( enumerator3.getInitialValue() ); - assertFalse( j.hasNext() ); - } - else - { - IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); - assertNotNull( enumerator2.getInitialValue() ); - assertEquals( enumerator2.getInitialValue().getLiteralString(), "666"); //$NON-NLS-1$ - assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( enumerator2.getName(), "last"); //$NON-NLS-1$ - assertFalse( j.hasNext() ); - } - } - } - - public void testTypedef() throws Exception - { - Iterator i = parse( "typedef const struct A * const cpStructA;").getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)i.next(); - assertFalse( i.hasNext() ); - assertTrue( typedef.getAbstractDeclarator().isConst() ); - assertTrue( typedef.getAbstractDeclarator().getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier ); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( elab.getName(), "A"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - assertTrue( typedef.getAbstractDeclarator().getPointerOperators().hasNext() ); - Iterator pIter = typedef.getAbstractDeclarator().getPointerOperators(); - ASTPointerOperator po =(ASTPointerOperator)pIter.next(); - assertEquals( po, ASTPointerOperator.CONST_POINTER ); - assertFalse( pIter.hasNext() ); - assertEquals( typedef.getName(), "cpStructA"); //$NON-NLS-1$ - - } - - public void testUsingClauses() throws Exception - { - Writer code = new StringWriter(); - - code.write("using namespace A::B::C;\n"); //$NON-NLS-1$ - code.write("using namespace C;\n"); //$NON-NLS-1$ - code.write("using B::f;\n"); //$NON-NLS-1$ - code.write("using ::f;\n"); //$NON-NLS-1$ - code.write("using typename crap::de::crap;"); //$NON-NLS-1$ - Iterator declarations = parse(code.toString()).getDeclarations(); - - IASTUsingDirective usingDirective = (IASTUsingDirective)declarations.next(); - assertEquals( usingDirective.getNamespaceName(), "A::B::C" ); //$NON-NLS-1$ - - usingDirective = (IASTUsingDirective)declarations.next(); - assertEquals( usingDirective.getNamespaceName(), "C" ); //$NON-NLS-1$ - - IASTUsingDeclaration usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "B::f" ); //$NON-NLS-1$ - - usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "::f" ); //$NON-NLS-1$ - usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "crap::de::crap" ); //$NON-NLS-1$ - assertTrue( usingDeclaration.isTypename() ); - - assertFalse( declarations.hasNext()); - } - - /** - * Test code: class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; } - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMembers() throws Exception { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - Iterator baseClauses = classSpec.getBaseClauses(); - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getParentClassName(), "B" ); //$NON-NLS-1$ - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PUBLIC ); - baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getParentClassName(), "C" ); //$NON-NLS-1$ - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PRIVATE); - baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PROTECTED ); - assertTrue( baseSpec.isVirtual() ); - assertEquals( baseSpec.getParentClassName(), "D" ); //$NON-NLS-1$ - assertFalse( baseClauses.hasNext() ); - - Iterator members = classSpec.getDeclarations(); - IASTField field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "x" ); //$NON-NLS-1$ - - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "y" ); //$NON-NLS-1$ - - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "a" ); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "b" ); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "c" ); //$NON-NLS-1$ - assertFalse( members.hasNext() ); - - } - - /** - * Test code: int myFunction( void ); - */ - public void testSimpleFunctionDeclaration() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("void myFunction( void );"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTFunction f1 = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( f1.getName(), "myFunction"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - Iterator parameters = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - - } - - /** - * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); - * @throws Exception - */ - public void testFunctionDeclarationWithParameters() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );"); //$NON-NLS-1$ - Iterator declarations = parse(code.toString()).getDeclarations(); - IASTFunction f1 = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( f1.getName(), "myFunction"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.BOOL ); - Iterator parameters = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( parm.getName(), "parm1" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY ); - - parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( parm.getName(), "parm2" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - assertNull( parm.getDefaultValue() ); - assertFalse( parameters.hasNext()); - - } - - public void testAssignmentExpressions() throws Exception - { - parse( "int x = y = z = 5;"); //$NON-NLS-1$ - } - - public void testBug39348() throws Exception - { - parse("unsigned char a[sizeof (struct sss)];"); //$NON-NLS-1$ - } - - public void testBug39501() throws Exception - { - parse("struct A { A() throw (int); };"); //$NON-NLS-1$ - } - - public void testBug39349() throws Exception - { - parse( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeLLU };" ); //$NON-NLS-1$ - } - - public void testBug39544() throws Exception { - parse("wchar_t wc = L'X';"); //$NON-NLS-1$ - } - - public void testBug36290() throws Exception { - parse("typedef void ( A:: * pMethod ) ( void ); "); //$NON-NLS-1$ - parse("typedef void (boo) ( void ); "); //$NON-NLS-1$ - parse("typedef void boo (void); "); //$NON-NLS-1$ - } - - public void testBug36769B() throws Exception { - parse("class X { operator int(); } \n"); //$NON-NLS-1$ - parse("class X { operator int*(); } \n"); //$NON-NLS-1$ - parse("class X { operator int&(); } \n"); //$NON-NLS-1$ - parse("class X { operator A(); } \n"); //$NON-NLS-1$ - parse("class X { operator A*(); } \n"); //$NON-NLS-1$ - parse("class X { operator A&(); } \n"); //$NON-NLS-1$ - - parse("X::operator int() { } \n"); //$NON-NLS-1$ - parse("X::operator int*() { } \n"); //$NON-NLS-1$ - parse("X::operator int&() { } \n"); //$NON-NLS-1$ - parse("X::operator A() { } \n"); //$NON-NLS-1$ - parse("X::operator A*() { } \n"); //$NON-NLS-1$ - parse("X::operator A&() { } \n"); //$NON-NLS-1$ - - parse("template <class A,B> class X<A,C> { operator int(); } \n"); //$NON-NLS-1$ - parse("template <class A,B> class X<A,C> { operator int*(); } \n"); //$NON-NLS-1$ - parse("template <class A,B> class X<A,C> { operator int&(); } \n"); //$NON-NLS-1$ - parse("template <class A,B> class X<A,C> { operator A(); } \n"); //$NON-NLS-1$ - parse("template <class A,B> class X<A,C> { operator A*(); } \n"); //$NON-NLS-1$ - parse("template <class A,B> class X<A,C> { operator A&(); } \n"); //$NON-NLS-1$ - - parse("template <class A,B> X<A,C>::operator int() { } \n"); //$NON-NLS-1$ - parse("template <class A,B> X<A,C>::operator int*() { } \n"); //$NON-NLS-1$ - parse("template <class A,B> X<A,C>::operator int&() { } \n"); //$NON-NLS-1$ - parse("template <class A,B> X<A,C>::operator A() { } \n"); //$NON-NLS-1$ - parse("template <class A,B> X<A,C>::operator A*() { } \n"); //$NON-NLS-1$ - parse("template <class A,B> X<A,C>::operator A&() { } \n"); //$NON-NLS-1$ - } - public void testBug36932C() throws Exception { - parse("X::X( ) : var( new int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[B][C][D] ) {}"); //$NON-NLS-1$ - } - - - public void testBugSingleton192() throws Exception { - parse("int Test::* pMember_;" ); //$NON-NLS-1$ - } - public void testBug36931() throws Exception { - parse("A::nested::nested(){}; "); //$NON-NLS-1$ - parse("int A::nested::foo() {} "); //$NON-NLS-1$ - parse("int A::nested::operator+() {} "); //$NON-NLS-1$ - parse("A::nested::operator int() {} "); //$NON-NLS-1$ - parse("static const int A::nested::i = 1; "); //$NON-NLS-1$ - - parse("template <class B,C> A<B>::nested::nested(){}; "); //$NON-NLS-1$ - parse("template <class B,C> int A::nested<B,D>::foo() {} "); //$NON-NLS-1$ - parse("template <class B,C> int A<B,C>::nested<C,B>::operator+() {} "); //$NON-NLS-1$ - parse("template <class B,C> A::nested::operator int() {} "); //$NON-NLS-1$ - } - - public void testBug37019() throws Exception { - parse("static const A a( 1, 0 );"); //$NON-NLS-1$ - } - - public void testBug36766and36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template <class _CharT, class _Alloc>\n"); //$NON-NLS-1$ - code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n"); //$NON-NLS-1$ - code.write("const allocator_type& __a): _Base(__a)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769B() throws Exception { - Writer code = new StringWriter(); - code.write("template<class _CharT>\n"); //$NON-NLS-1$ - code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n"); //$NON-NLS-1$ - code.write("(const _CharT* __leaf, size_t __n)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769C() throws Exception { - Writer code = new StringWriter(); - code.write("template <class _CharT, class _Alloc>\n"); //$NON-NLS-1$ - code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n"); //$NON-NLS-1$ - code.write( - "_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769D() throws Exception { - Writer code = new StringWriter(); - code.write("template <class _CharT, class _Alloc>\n"); //$NON-NLS-1$ - code.write("rope<_CharT, _Alloc>::~rope()\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36932A() throws Exception { - parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); //$NON-NLS-1$ - } - - public void testBug36932B() throws Exception { - parse(" p = new int; "); //$NON-NLS-1$ - parse(" p = new int(5); "); //$NON-NLS-1$ - parse(" p = new int(B); "); //$NON-NLS-1$ - parse(" p = new int(B,C); "); //$NON-NLS-1$ - parse(" p = new int[5]; "); //$NON-NLS-1$ - parse(" p = new int[5][10]; "); //$NON-NLS-1$ - parse(" p = new int[B]; "); //$NON-NLS-1$ - parse(" p = new int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new A; "); //$NON-NLS-1$ - parse(" p = new A(5); "); //$NON-NLS-1$ - parse(" p = new A(B); "); //$NON-NLS-1$ - parse(" p = new A(B,C); "); //$NON-NLS-1$ - parse(" p = new A[5]; "); //$NON-NLS-1$ - parse(" p = new A[5][10]; "); //$NON-NLS-1$ - parse(" p = new A[B]; "); //$NON-NLS-1$ - parse(" p = new A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (int); "); //$NON-NLS-1$ - parse(" p = new (int)(5); "); //$NON-NLS-1$ - parse(" p = new (int)(B); "); //$NON-NLS-1$ - parse(" p = new (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (A); "); //$NON-NLS-1$ - parse(" p = new (A)(5); "); //$NON-NLS-1$ - parse(" p = new (A)(B); "); //$NON-NLS-1$ - parse(" p = new (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (A)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) int; "); //$NON-NLS-1$ - parse(" p = new (0) int(5); "); //$NON-NLS-1$ - parse(" p = new (0) int(B); "); //$NON-NLS-1$ - parse(" p = new (0) int(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) int[5]; "); //$NON-NLS-1$ - parse(" p = new (0) int[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) int[B]; "); //$NON-NLS-1$ - parse(" p = new (0) int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) A; "); //$NON-NLS-1$ - parse(" p = new (0) A(5); "); //$NON-NLS-1$ - parse(" p = new (0) A(B); "); //$NON-NLS-1$ - parse(" p = new (0) A(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) A[5]; "); //$NON-NLS-1$ - parse(" p = new (0) A[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) A[B]; "); //$NON-NLS-1$ - parse(" p = new (0) A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) (int); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(5); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(B); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) (A); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(5); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(B); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) int; "); //$NON-NLS-1$ - parse(" p = new (P) int(5); "); //$NON-NLS-1$ - parse(" p = new (P) int(B); "); //$NON-NLS-1$ - parse(" p = new (P) int(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) int[5]; "); //$NON-NLS-1$ - parse(" p = new (P) int[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) int[B]; "); //$NON-NLS-1$ - parse(" p = new (P) int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) A; "); //$NON-NLS-1$ - parse(" p = new (P) A(5); "); //$NON-NLS-1$ - parse(" p = new (P) A(B); "); //$NON-NLS-1$ - parse(" p = new (P) A(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) A[5]; "); //$NON-NLS-1$ - parse(" p = new (P) A[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) A[B]; "); //$NON-NLS-1$ - parse(" p = new (P) A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) (int); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(5); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(B); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) (A); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(5); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(B); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[B][C][D]; "); //$NON-NLS-1$ - } - - public void testBug36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template <class A, B> cls<A, C>::operator op &() const {}\n"); //$NON-NLS-1$ - code.write("template <class A, B> cls<A, C>::cls() {}\n"); //$NON-NLS-1$ - code.write("template <class A, B> cls<A, C>::~cls() {}\n"); //$NON-NLS-1$ - - parse( code.toString()); - } - - public void testBug36714() throws Exception { - Writer code = new StringWriter(); - code.write("unsigned long a = 0UL;\n"); //$NON-NLS-1$ - code.write("unsigned long a2 = 0L; \n"); //$NON-NLS-1$ - - parse( code.toString() ); - } - - public void testBugFunctor758() throws Exception { - parse( "template <typename Fun> Functor(Fun fun) : spImpl_(new FunctorHandler<Functor, Fun>(fun)){}" ); //$NON-NLS-1$ - } - - public void testBug36932() throws Exception - { - parse( "A::A(): b( new int( 5 ) ), b( new B ), c( new int ) {}" ); //$NON-NLS-1$ - } - - public void testBug36704() throws Exception { - Writer code = new StringWriter(); - code.write( "template <class T, class U>\n" ); //$NON-NLS-1$ - code.write( "struct Length< Typelist<T, U> >\n" ); //$NON-NLS-1$ - code.write( "{\n" ); //$NON-NLS-1$ - code.write( "enum { value = 1 + Length<U>::value };\n" ); //$NON-NLS-1$ - code.write( "};\n" ); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36699() throws Exception { - Writer code = new StringWriter(); - code.write( - "template < template <class> class ThreadingModel = DEFAULT_THREADING,\n"); //$NON-NLS-1$ - code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n"); //$NON-NLS-1$ - code.write( - "std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n"); //$NON-NLS-1$ - code.write("class SmallObject : public ThreadingModel<\n"); //$NON-NLS-1$ - code.write( - "SmallObject<ThreadingModel, chunkSize, maxSmallObjectSize> >\n"); //$NON-NLS-1$ - code.write("{};\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36691() throws Exception { - Writer code = new StringWriter(); - code.write("template <class T, class H>\n"); //$NON-NLS-1$ - code.write( - "typename H::template Rebind<T>::Result& Field(H& obj)\n"); //$NON-NLS-1$ - code.write("{ return obj; }\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - - public void testBug39554() throws Exception - { - parse("_Pragma(\"foobar\")", true, true, ParserLanguage.C ); //$NON-NLS-1$ - } - - public void testBug36702() throws Exception - { - Writer code = new StringWriter(); - code.write( "void mad_decoder_init(struct mad_decoder *, void *,\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, struct mad_stream *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, struct mad_header const *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_stream const *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_frame *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_header const *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_pcm *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_stream *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_frame *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, void *, unsigned int *)\n" ); //$NON-NLS-1$ - code.write( ");\n" ); //$NON-NLS-1$ - - parse( code.toString() ); - - } - - public void testBug36852() throws Exception - { - Writer code = new StringWriter(); - code.write( "int CBT::senseToAllRect( double id_standardQuot = DOSE, double id_minToleranz =15.0,\n" ); //$NON-NLS-1$ - code.write( "double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n" ); //$NON-NLS-1$ - code.write( "unsigned int iui_maxY = HEIGHT );\n" ); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testBug36689() throws Exception { - Writer code = new StringWriter(); - code.write("template\n"); //$NON-NLS-1$ - code.write("<\n"); //$NON-NLS-1$ - code.write("class AbstractFact,\n"); //$NON-NLS-1$ - code.write( - "template <class, class> class Creator = OpNewFactoryUnit,\n"); //$NON-NLS-1$ - code.write("class TList = typename AbstractFact::ProductList\n"); //$NON-NLS-1$ - code.write(">\n"); //$NON-NLS-1$ - code.write("class ConcreteFactory\n"); //$NON-NLS-1$ - code.write(": public GenLinearHierarchy<\n"); //$NON-NLS-1$ - code.write( - "typename TL::Reverse<TList>::Result, Creator, AbstractFact>\n"); //$NON-NLS-1$ - code.write("{\n"); //$NON-NLS-1$ - code.write("public:\n"); //$NON-NLS-1$ - code.write( - "typedef typename AbstractFact::ProductList ProductList;\n"); //$NON-NLS-1$ - code.write("typedef TList ConcreteProductList;\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36707() throws Exception { - parse("enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };"); //$NON-NLS-1$ - } - - public void testBug36717() throws Exception { - parse("enum { eA = A::b };"); //$NON-NLS-1$ - } - - public void testBug36693() throws Exception { - parse("FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p){}"); //$NON-NLS-1$ - } - - public void testWeirdExpression() throws Exception - { - parse( "int x = rhs.spImpl_.get();"); //$NON-NLS-1$ - } - - public void testBug36696() throws Exception { - Writer code = new StringWriter(); - code.write( - "template <typename P1> RefCounted(const RefCounted<P1>& rhs)\n"); //$NON-NLS-1$ - code.write( - ": pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_) {}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testArrayOfPointerToFunctions() throws Exception - { - parse( "unsigned char (*main_data)[MAD_BUFFER_MDLEN];"); //$NON-NLS-1$ - } - - public void testBug36073() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A{\n" ); //$NON-NLS-1$ - writer.write( "int x;\n" ); //$NON-NLS-1$ - writer.write( "public:\n" ); //$NON-NLS-1$ - writer.write( "A(const A&);\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "A::A(const A&v) : x(v.x) { }\n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - - public void testTemplateSpecialization() throws Exception - { - Iterator declarations = parse( "template<> class stream<char> { /* ... */ };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier specifier = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateSpecialization)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); - assertFalse( declarations.hasNext()); - assertEquals( specifier.getName(), "stream<char>"); //$NON-NLS-1$ - assertFalse( specifier.getDeclarations().hasNext() ); - } - - public void testTemplateInstantiation() throws Exception - { - Iterator declarations = parse( "template class Array<char>;").getDeclarations(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier specifier = (IASTElaboratedTypeSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateInstantiation)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - assertEquals( specifier.getName(), "Array<char>"); //$NON-NLS-1$ - assertEquals( specifier.getClassKind(), ASTClassKind.CLASS ); - } - - /** - * Test code: "class A { int floor( double input ), someInt; };" - */ - public void testMultipleDeclarators() throws Exception - { - // Parse and get the translaton unit - Iterator declarations = parse("class A { int floor( double input ), someInt; };").getDeclarations(); //$NON-NLS-1$ - Iterator members = ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier()).getDeclarations(); - assertFalse( declarations.hasNext() ); - IASTMethod decl1 = (IASTMethod)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)decl1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - Iterator parameters = decl1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - assertFalse( parameters.hasNext()); - assertEquals( parm.getName(), "input"); //$NON-NLS-1$ - - IASTField decl2 = (IASTField)members.next(); - assertEquals( decl2.getName(), "someInt"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)decl2.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertFalse( members.hasNext()); - } - - public void testFunctionModifiers() throws Exception - { - Iterator declarations = parse( "class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext()); - Iterator members = classSpec.getDeclarations(); - IASTMethod method = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertTrue( method.isVirtual()); - assertEquals( method.getName(), "foo"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)method.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - Iterator parameters = method.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - assertFalse( parameters.hasNext()); - assertEquals( parm.getName(), ""); //$NON-NLS-1$ - assertTrue( method.isConst() ); - assertTrue( method.isPureVirtual() ); - assertNotNull( method.getExceptionSpec() ); - Iterator exceptions = method.getExceptionSpec().getTypeIds(); - assertEquals( (String)exceptions.next(), "yay"); //$NON-NLS-1$ - assertEquals( (String)exceptions.next(), "nay"); //$NON-NLS-1$ - assertEquals( (String)exceptions.next(), "we::dont::care"); //$NON-NLS-1$ - assertFalse( exceptions.hasNext() ); - } - - - public void testArrays() throws Exception - { - Iterator declarations = parse("int x [5][];").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( ((IASTSimpleTypeSpecifier)x.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( x.getName(), "x"); //$NON-NLS-1$ - Iterator arrayMods = x.getAbstractDeclaration().getArrayModifiers(); - IASTArrayModifier mod = (IASTArrayModifier)arrayMods.next(); - assertEquals( mod.getExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( mod.getExpression().getLiteralString(), "5" ); //$NON-NLS-1$ - mod = (IASTArrayModifier)arrayMods.next(); - assertNull( mod.getExpression()); - assertFalse( arrayMods.hasNext() ); - } - - public void testElaboratedParms() throws Exception - { - Iterator declarations = parse( "int x( struct A myA ) { /* junk */ }" ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertFalse( parms.hasNext()); - assertEquals( parm.getName(), "myA"); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getName(), "A" ); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertFalse( declarations.hasNext()); - } - - public void testMemberDeclarations() throws Exception - { - Writer code = new StringWriter(); - code.write( "class A {\n" ); //$NON-NLS-1$ - code.write( "public:\n"); //$NON-NLS-1$ - code.write( " int is0;\n" ); //$NON-NLS-1$ - code.write( "private:\n"); //$NON-NLS-1$ - code.write( " int is1;\n" ); //$NON-NLS-1$ - code.write( "protected:\n"); //$NON-NLS-1$ - code.write( " int is2;\n" ); //$NON-NLS-1$ - code.write( "};"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse(declarations.hasNext()); - Iterator members = classSpec.getDeclarations(); - for( int i = 0; i < 3; ++i ) - { - IASTField field = (IASTField)members.next(); - assertEquals( field.getName(), "is"+ new Integer( i ).toString()); //$NON-NLS-1$ - ASTAccessVisibility visibility = null; - switch( i ) - { - case 0: - visibility = ASTAccessVisibility.PUBLIC; - break; - - case 1: - visibility = ASTAccessVisibility.PRIVATE; - break; - - default: - visibility = ASTAccessVisibility.PROTECTED; - break; - } - assertEquals( field.getVisiblity(), visibility ); - } - assertFalse( members.hasNext()); - } - - public void testPointerOperators() throws Exception - { - Iterator declarations = parse("int * x = 0, & y, * const * volatile * z;").getDeclarations(); //$NON-NLS-1$ - for( int i = 0; i < 3; ++i ) - { - IASTVariable v = (IASTVariable)declarations.next(); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT ); - Iterator pointerOperators = v.getAbstractDeclaration().getPointerOperators(); - ASTPointerOperator pointerOp = (ASTPointerOperator)pointerOperators.next(); - - switch( i ) - { - case 0: - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext()); - break; - case 1: - assertEquals( v.getName(), "y"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.REFERENCE); - assertFalse( pointerOperators.hasNext()); - break; - case 2: - assertEquals( v.getName(), "z"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.CONST_POINTER ); - assertEquals( pointerOperators.next(), ASTPointerOperator.VOLATILE_POINTER ); - assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext()); - break; - } - } - assertFalse( declarations.hasNext() ); - } - - public void testBug26467() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "struct foo { int fooInt; char fooChar; };\n" ); //$NON-NLS-1$ - code.write( "typedef struct foo fooStruct;\n" ); //$NON-NLS-1$ - code.write( "typedef struct { int anonInt; char anonChar; } anonStruct;\n" ); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); - assertEquals( classSpec.getName(), "foo" ); //$NON-NLS-1$ - Iterator members = classSpec.getDeclarations(); - IASTField field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "fooInt"); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( field.getName(), "fooChar"); //$NON-NLS-1$ - assertFalse( members.hasNext()); - IASTTypedefDeclaration firstTypeDef = (IASTTypedefDeclaration)declarations.next(); - assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getName(), "foo"); //$NON-NLS-1$ - assertEquals( firstTypeDef.getName(), "fooStruct"); //$NON-NLS-1$ - IASTTypedefDeclaration secondTypeDef = (IASTTypedefDeclaration)declarations.next(); - classSpec = (IASTClassSpecifier)secondTypeDef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); - assertEquals( classSpec.getName(), "" ); //$NON-NLS-1$ - members = classSpec.getDeclarations(); - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "anonInt"); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( field.getName(), "anonChar"); //$NON-NLS-1$ - assertFalse( members.hasNext()); - assertEquals( secondTypeDef.getName(), "anonStruct"); //$NON-NLS-1$ - - } - - public void testASMDefinition() throws Exception - { - Iterator declarations = parse( "asm( \"mov ep1 ds2\");" ).getDeclarations(); //$NON-NLS-1$ - IASTASMDefinition asm = (IASTASMDefinition)declarations.next(); - assertFalse( declarations.hasNext()); - assertEquals( asm.getBody(), "mov ep1 ds2"); //$NON-NLS-1$ - } - - public void testConstructorChain() throws Exception - { - Iterator declarations = parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}" ).getDeclarations(); //$NON-NLS-1$ - declarations.next(); // cannot properly do this test now with new callback structure in quickparse mode - } - - public void testBug36237() throws Exception - { - parse( "A::A():B( (char *)0 ){}" ); //$NON-NLS-1$ - } - - public void testBug36532() throws Exception - { - try - { - parse( "template<int f() {\n" ); //$NON-NLS-1$ - fail( "We should not make it this far"); //$NON-NLS-1$ - } - catch( ParserException pe ) - { - } - catch( Exception e ) - { - fail( "We should have gotten a ParserException rather than" + e); //$NON-NLS-1$ - } - } - - public void testPreprocessor() throws Exception { - - String code = "#include <stdio.h>\n#define DEF VALUE\n"; //$NON-NLS-1$ - - IASTCompilationUnit tu = parse( code.toString() ); - assertFalse( tu.getDeclarations().hasNext()); - Iterator inclusions = quickParseCallback.getInclusions(); - Iterator macros = quickParseCallback.getMacros(); - - IASTInclusion i = (IASTInclusion)inclusions.next(); - assertFalse( inclusions.hasNext()); - - assertEquals( i.getName(), "stdio.h"); //$NON-NLS-1$ - assertEquals( i.getStartingOffset(), 0 ); - assertEquals( i.getNameOffset(), code.indexOf("stdio.h") ); //$NON-NLS-1$ - assertEquals( i.getEndingOffset(), code.indexOf(">") + 1); //$NON-NLS-1$ - - - IASTMacro m = (IASTMacro)macros.next(); - assertEquals( m.getName(), "DEF" ); //$NON-NLS-1$ - assertEquals( m.getStartingOffset(), code.indexOf("#define") ); //$NON-NLS-1$ - assertEquals( m.getNameOffset(), code.indexOf("DEF") ); //$NON-NLS-1$ - assertEquals( m.getEndingOffset(), code.indexOf("VALUE") + 5); //$NON-NLS-1$ - } - - public void testTemplateDeclarationOfFunction() throws Exception - { - Iterator declarations = parse( "template<class A, typename B=C> A aTemplatedFunction( B bInstance );").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); - assertFalse( declarations.hasNext()); - Iterator templateParms = templateDeclaration.getTemplateParameters(); - IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "A"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), "B"); //$NON-NLS-1$ - assertEquals( parm.getDefaultValueIdExpression(), "C" ); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)templateDeclaration.getOwnedDeclaration(); - assertEquals( f.getName(), "aTemplatedFunction" ); //$NON-NLS-1$ - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).getTypename(), "A" ); //$NON-NLS-1$ - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parmDeclaration = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parmDeclaration.getName(), "bInstance"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getType(),IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getTypename(), "B" ); //$NON-NLS-1$ - } - - public void testTemplateDeclarationOfClass() throws Exception { - Iterator declarations = parse( "template<class T, typename Tibor = junk, class, typename, int x, float y,template <class Y> class, template<class A> class AClass> class myarray { /* ... */ };").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); - assertFalse( declarations.hasNext()); - Iterator templateParms = templateDeclaration.getTemplateParameters(); - IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "T"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), "Tibor"); //$NON-NLS-1$ - assertEquals( parm.getDefaultValueIdExpression(), "junk"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); - assertEquals( parm.getParameterDeclaration().getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); - assertEquals( parm.getParameterDeclaration().getName(), "y"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - Iterator subParms = parm.getTemplateParameters(); - parm = (IASTTemplateParameter)subParms.next(); - assertFalse( subParms.hasNext() ); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "Y" ); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); - assertEquals( parm.getIdentifier(), "AClass"); //$NON-NLS-1$ - subParms = parm.getTemplateParameters(); - parm = (IASTTemplateParameter)subParms.next(); - assertFalse( subParms.hasNext() ); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "A" ); //$NON-NLS-1$ - assertFalse( templateParms.hasNext() ); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)templateDeclaration.getOwnedDeclaration()).getTypeSpecifier(); - assertEquals( classSpec.getName(), "myarray"); //$NON-NLS-1$ - assertFalse( classSpec.getDeclarations().hasNext() ); - } - - public void testBug35906() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "void TTest::MTest() {}\n" ); //$NON-NLS-1$ - code.write( "struct TTest::STest *TTest::FTest (int i) {}\n" ); //$NON-NLS-1$ - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTFunction f = (IASTFunction)declarations.next(); - assertEquals( f.getName(), "TTest::MTest"); //$NON-NLS-1$ - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.VOID ); - f = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext()); - assertEquals( f.getName(), "TTest::FTest"); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getName(), "TTest::STest"); //$NON-NLS-1$ - Iterator pointerOperators = f.getReturnType().getPointerOperators(); - assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext() ); - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parm.getName(), "i"); //$NON-NLS-1$ - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testBug36288() throws Exception - { - Iterator declarations = parse( "int foo() {}\nlong foo2(){}" ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( f.getName(), "foo"); //$NON-NLS-1$ - f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertTrue( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).isLong() ); - assertEquals( f.getName(), "foo2"); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testBug36250() throws Exception - { - Iterator declarations = parse( "int f( int = 0 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); //$NON-NLS-1$ - } - - public void testBug36240() throws Exception - { - Iterator declarations = parse( "A & A::operator=( A ){}").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier(); - assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( typeSpec.getTypename(), "A"); //$NON-NLS-1$ - Iterator pointerOps = f.getReturnType().getPointerOperators(); - assertEquals( pointerOps.next(), ASTPointerOperator.REFERENCE ); - assertFalse( pointerOps.hasNext() ); - assertEquals( f.getName(), "A::operator ="); //$NON-NLS-1$ - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - typeSpec = (IASTSimpleTypeSpecifier)parm.getTypeSpecifier(); - assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( typeSpec.getTypename(), "A" ); //$NON-NLS-1$ - } - - public void testBug36254() throws Exception - { - Iterator declarations = parse( "unsigned i;\nvoid f( unsigned p1 = 0 );").getDeclarations(); //$NON-NLS-1$ - IASTVariable v = (IASTVariable)declarations.next(); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT); - assertTrue( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).isUnsigned() ); - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType(f, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "p1"); //$NON-NLS-1$ - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertTrue( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).isUnsigned() ); - assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext()); - } - - public void testBug36432() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define CMD_GET \"g\"\n" ); //$NON-NLS-1$ - code.write( "#define CMD_ACTION \"a\"\n" ); //$NON-NLS-1$ - code.write( "#define CMD_QUIT \"q\"\n" ); //$NON-NLS-1$ - code.write( "static const memevent_cmd_func memevent_cmd_funcs[sizeof memevent_cmds - 1] = {\n"); //$NON-NLS-1$ - code.write( "memevent_get,\n"); //$NON-NLS-1$ - code.write( "memevent_action,\n"); //$NON-NLS-1$ - code.write( "memevent_quit,\n"); //$NON-NLS-1$ - code.write( "};\n"); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testBug36594() throws Exception - { - parse( "const int n = sizeof(A) / sizeof(B);"); //$NON-NLS-1$ - } - - public void testBug36794() throws Exception - { - parse( "template<> class allocator<void> {};"); //$NON-NLS-1$ - Iterator i = quickParseCallback.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36799() throws Exception - { - parse( "static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));"); //$NON-NLS-1$ - } - - - public void testBug36764() throws Exception - { - parse( "struct{ int x : 4; int y : 8; };" ); //$NON-NLS-1$ - } - - public void testOrder() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define __SGI_STL_INTERNAL_ALGOBASE_H\n" ); //$NON-NLS-1$ - code.write( "#include <string.h>\n" ); //$NON-NLS-1$ - code.write( "template <class _Tp>\n" ); //$NON-NLS-1$ - code.write( "inline void swap(_Tp& __a, _Tp& __b) {\n" ); //$NON-NLS-1$ - code.write( "__STL_REQUIRES(_Tp, _Assignable);\n" ); //$NON-NLS-1$ - code.write( "_Tp __tmp = __a;\n" ); //$NON-NLS-1$ - code.write( "__a = __b;\n" ); //$NON-NLS-1$ - code.write( "__b = __tmp;\n" ); //$NON-NLS-1$ - code.write( "}\n" ); //$NON-NLS-1$ - - parse( code.toString() ); - Iterator i = quickParseCallback.iterateOffsetableElements(); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTMacro ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTInclusion ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTDeclaration ); - assertFalse( i.hasNext() ); - } - - public void testBug36771() throws Exception { - Writer code = new StringWriter(); - code.write("#include /**/ \"foo.h\"\n"); //$NON-NLS-1$ - - parse( code.toString() ); - - Iterator includes = quickParseCallback.getInclusions(); - - IASTInclusion include = (IASTInclusion)includes.next(); - assertTrue( include.getName().equals("foo.h") ); //$NON-NLS-1$ - assertFalse( includes.hasNext() ); - } - - - public void testBug36811() throws Exception - { - Writer code = new StringWriter(); - code.write( "using namespace std;\n" ); //$NON-NLS-1$ - code.write( "class Test {};" ); //$NON-NLS-1$ - parse( code.toString() ); - Iterator i = quickParseCallback.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36708() throws Exception { - Iterator declarations = parse("enum { isPointer = PointerTraits<T>::result };").getDeclarations(); //$NON-NLS-1$ - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - Iterator enumerators = enumSpec.getEnumerators(); - IASTEnumerator enumerator = (IASTEnumerator)enumerators.next(); - assertFalse( enumerators.hasNext() ); - assertEquals( enumerator.getName(), "isPointer"); //$NON-NLS-1$ - assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); - assertEquals( enumerator.getInitialValue().getIdExpression(), "PointerTraits<T>::result"); //$NON-NLS-1$ - } - - public void testBug36690() throws Exception { - parse("Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get())){}").getDeclarations(); //$NON-NLS-1$ - } - - public void testBug36703() throws Exception { - parse("const std::type_info& Get() const;"); //$NON-NLS-1$ - } - - public void testBug36692() throws Exception { - Writer code = new StringWriter(); - code.write("template <typename T, typename Destroyer>\n"); //$NON-NLS-1$ - code.write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); //$NON-NLS-1$ - code.write("Destroyer d = Private::Deleter<T>::Delete){}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36551() throws Exception - { - Writer code = new StringWriter(); - code.write( "class TextFrame {\n" ); //$NON-NLS-1$ - code.write( "BAD_MACRO()\n"); //$NON-NLS-1$ - code.write( "};"); //$NON-NLS-1$ - parse( code.toString(), true, false ); - } - - public void testBug36247() throws Exception - { - Writer code = new StringWriter(); - code.write( "class A {\n" ); //$NON-NLS-1$ - code.write( "INLINE_DEF int f ();\n" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A g ();" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A * h ();" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A & unlock( void );"); //$NON-NLS-1$ - code.write( "};" ); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testStruct() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct mad_bitptr { unsigned char const *byte;\n" ); //$NON-NLS-1$ - writer.write( "unsigned short cache;\n unsigned short left;};" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug36559() throws Exception - { - Writer code = new StringWriter(); - code.write( "namespace myNameSpace {\n" ); //$NON-NLS-1$ - code.write( "template<typename T=short> class B {};\n" ); //$NON-NLS-1$ - code.write( "template<> class B<int> {};\n" ); //$NON-NLS-1$ - code.write( "}\n" ); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testPointersToFunctions() throws Exception - { - Writer code = new StringWriter(); - code.write( "void (*name)( void );\n"); //$NON-NLS-1$ - code.write( "static void * (* const orig_malloc_hook)(const char *file, int line, size_t size);\n"); //$NON-NLS-1$ - - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTVariable p2f = (IASTVariable)declarations.next(); - assertSimpleType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( p2f.getName(), "name" ); //$NON-NLS-1$ - Iterator parameters = p2f.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - - p2f = (IASTVariable)declarations.next(); - assertSimpleType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); - assertTrue( p2f.isStatic() ); - Iterator rtPo = p2f.getAbstractDeclaration().getPointerOperators(); - assertEquals( rtPo.next(), ASTPointerOperator.POINTER ); - assertFalse( rtPo.hasNext() ); - parameters = p2f.getAbstractDeclaration().getParameters(); - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( parm.getName(), "file" ); //$NON-NLS-1$ - assertTrue( parm.isConst() ); - assertTrue( parm.getPointerOperators().hasNext() ); - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getName(), "line" ); //$NON-NLS-1$ - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( parm.getName(), "size" ); //$NON-NLS-1$ - assertFalse( parameters.hasNext() ); - } - - public void testBug36600() throws Exception - { - IASTVariable p2f = (IASTVariable)parse( "enum mad_flow (*input_func)(void *, struct mad_stream *);").getDeclarations().next(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)p2f.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( elab.getName(), "mad_flow"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.ENUM ); - assertEquals( p2f.getName(), "input_func"); //$NON-NLS-1$ - Iterator parms = p2f.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID); - parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); - elab = (IASTElaboratedTypeSpecifier)parm.getTypeSpecifier(); - assertEquals( elab.getName(), "mad_stream"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - - - } - - public void testBug36713() throws Exception { - Writer code = new StringWriter(); - code.write("A ( * const fPtr) (void *); \n"); //$NON-NLS-1$ - code.write("A (* const fPtr2) ( A * ); \n"); //$NON-NLS-1$ - parse(code.toString()).getDeclarations(); - } - - // K&R Test hasn't been ported from DOMTests - // still need to figure out how to represent these in the AST -// public void testOldKRFunctionDeclarations() throws Exception -// { -// // Parse and get the translaton unit -// Writer code = new StringWriter(); -// code.write("bool myFunction( parm1, parm2, parm3 )\n"); -// code.write("const char* parm1;\n"); -// code.write("int (*parm2)(float);\n"); -// code.write("{}"); -// TranslationUnit translationUnit = parse(code.toString()); -// -// // Get the declaration -// List declarations = translationUnit.getDeclarations(); -// assertEquals(1, declarations.size()); -// SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); -// assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool ); -// List declarators = simpleDeclaration.getDeclarators(); -// assertEquals( 1, declarators.size() ); -// Declarator functionDeclarator = (Declarator)declarators.get( 0 ); -// assertEquals( functionDeclarator.getName().toString(), "myFunction" ); -// -// ParameterDeclarationClause pdc = functionDeclarator.getParms(); -// assertNotNull( pdc ); -// List parameterDecls = pdc.getDeclarations(); -// assertEquals( 3, parameterDecls.size() ); -// ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); -// assertNotNull( parm1.getDeclSpecifier().getName() ); -// assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() ); -// List parm1Decls = parm1.getDeclarators(); -// assertEquals( 1, parm1Decls.size() ); -// -// ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 ); -// assertNotNull( parm2.getDeclSpecifier().getName() ); -// assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); -// List parm2Decls = parm2.getDeclarators(); -// assertEquals( 1, parm2Decls.size() ); -// -// ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 ); -// assertNotNull( parm3.getDeclSpecifier().getName() ); -// assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); -// List parm3Decls = parm3.getDeclarators(); -// assertEquals( 1, parm3Decls.size() ); -// -// OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); -// assertNotNull( clause ); -// assertEquals( clause.getDeclarations().size(), 2 ); -// SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0); -// assertEquals( decl1.getDeclarators().size(), 1 ); -// assertTrue(decl1.getDeclSpecifier().isConst()); -// assertFalse(decl1.getDeclSpecifier().isVolatile()); -// assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); -// Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); -// assertEquals( declarator1.getName().toString(), "parm1" ); -// List ptrOps1 = declarator1.getPointerOperators(); -// assertNotNull( ptrOps1 ); -// assertEquals( 1, ptrOps1.size() ); -// PointerOperator po1 = (PointerOperator)ptrOps1.get(0); -// assertNotNull( po1 ); -// assertFalse( po1.isConst() ); -// assertFalse( po1.isVolatile() ); -// assertEquals( po1.getType(), PointerOperator.t_pointer ); -// -// SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1); -// assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); -// assertEquals( declaration.getDeclarators().size(), 1); -// assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); -// assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); -// assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" ); -// ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms(); -// assertEquals( clause2.getDeclarations().size(), 1 ); -// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 ); -// assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); -// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float ); -// } - - public void testPointersToMemberFunctions() throws Exception - { - IASTVariable p2m = (IASTVariable)parse("void (A::*name)(void);").getDeclarations().next(); //$NON-NLS-1$ - assertSimpleType( p2m, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( p2m.getName(), "A::* name"); //$NON-NLS-1$ - assertEquals( p2m.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER); - Iterator parameters = p2m.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - } - - public void testBug39550() throws Exception - { - parse("double x = 0x1.fp1;").getDeclarations().next(); //$NON-NLS-1$ - } - - // digraphs/trigraphs have been temporarily remove - public void testBug39552A(int x) throws Exception - { - Writer code = new StringWriter(); - - code.write("%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */\n"); //$NON-NLS-1$ - code.write("#ifndef glue\n"); //$NON-NLS-1$ - code.write("#error glue not defined!\n"); //$NON-NLS-1$ - code.write("#endif\n"); //$NON-NLS-1$ - - code.write("%:define str(x) %:x /* #define str(x) #x */\n"); //$NON-NLS-1$ - - code.write("int main (int argc, char *argv<::>) /* argv[] */\n"); //$NON-NLS-1$ - code.write("glue (<, %) /* { */\n"); //$NON-NLS-1$ - code.write(" /* di_str[] = */\n"); //$NON-NLS-1$ - code.write(" const char di_str glue(<, :)glue(:, >) = str(%:%:<::><%%>%:);\n"); //$NON-NLS-1$ - code.write(" /* Check the glue macro actually pastes, and that the spelling of\n"); //$NON-NLS-1$ - code.write(" all digraphs is preserved. */\n"); //$NON-NLS-1$ - code.write(" if (glue(strc, mp) (di_str, \"%:%:<::><%%>%:\"))\n"); //$NON-NLS-1$ - code.write(" err (\"Digraph spelling not preserved!\");\n"); //$NON-NLS-1$ - code.write(" return 0;\n"); //$NON-NLS-1$ - code.write("glue (%, >) /* } */\n"); //$NON-NLS-1$ - - parse(code.toString()); - } - - // digraphs/trigraphs have been temporarily remove - public void testBug39552B(int x) throws Exception - { - Writer code = new StringWriter(); - - code.write("??=include <stdio.h>\n"); //$NON-NLS-1$ - code.write("??=define TWELVE 1??/\n"); //$NON-NLS-1$ - code.write("2\n"); //$NON-NLS-1$ - - code.write("static const char str??(??) = \"0123456789??/n\";\n"); //$NON-NLS-1$ - - code.write("int\n"); //$NON-NLS-1$ - code.write("main(void)\n"); //$NON-NLS-1$ - code.write("??<\n"); //$NON-NLS-1$ - code.write(" unsigned char x = 5;\n"); //$NON-NLS-1$ - code.write(" if (sizeof str != TWELVE)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" /* Test ^=, the only multi-character token to come from trigraphs. */\n"); //$NON-NLS-1$ - code.write(" x ??'= 3;\n"); //$NON-NLS-1$ - code.write(" if (x != 6)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" if ((5 ??! 3) != 7)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" return 0;\n"); //$NON-NLS-1$ - code.write("??>\n"); //$NON-NLS-1$ - - parse(code.toString()); - } - - public void testBug39553() throws Exception - { - parse("#define COMP_INC \"foobar.h\" \n" + "#include COMP_INC"); //$NON-NLS-1$ //$NON-NLS-2$ - assertTrue( quickParseCallback.getInclusions().hasNext() ); - } - - public void testBug39537() throws Exception - { - parse("typedef foo<(U::id > 0)> foobar;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39546() throws Exception - { - parse("signed char c = (signed char) 0xffffffff;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testIndirectDeclarators() throws Exception - { - IASTVariable v = (IASTVariable)parse( "void (*x)( int );").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.VOID ); - assertParameterSimpleType( (IASTParameterDeclaration)v.getAbstractDeclaration().getParameters().next(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( v.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER ); - - v = (IASTVariable)parse( "const int * (* const something)( const int * const * const );").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( v.getName(), "something"); //$NON-NLS-1$ - assertEquals( v.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.CONST_POINTER); - assertTrue( v.getAbstractDeclaration().isConst() ); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( v.getAbstractDeclaration().getPointerOperators().next(), ASTPointerOperator.POINTER ); - IASTParameterDeclaration parm = (IASTParameterDeclaration)v.getAbstractDeclaration().getParameters().next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - Iterator pointerOps = parm.getPointerOperators(); - assertEquals( pointerOps.next(), ASTPointerOperator.CONST_POINTER ); - assertEquals( pointerOps.next(), ASTPointerOperator.CONST_POINTER ); - assertFalse( pointerOps.hasNext() ); - - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)parse( "typedef void (*life)(int);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( typedef.getName(), "life"); //$NON-NLS-1$ - assertSimpleType( typedef, IASTSimpleTypeSpecifier.Type.VOID ); - assertParameterSimpleType( (IASTParameterDeclaration)typedef.getAbstractDeclarator().getParameters().next(), IASTSimpleTypeSpecifier.Type.INT ); - - IASTFunction f = (IASTFunction)parse( "void (f)(void);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - - typedef = (IASTTypedefDeclaration)parse( "typedef void (life)(int);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( typedef.getName(), "life"); //$NON-NLS-1$ - - } - - public void testBug39532() throws Exception - { - parse("class N1::N2::B : public A {};"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39540() throws Exception - { - parse("class {} const null;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39530() throws Exception - { - parse( "X sPassed(-1)"); //$NON-NLS-1$ - } - - public void testBug39526() throws Exception - { - parse("UnitList unit_list (String(\"keV\"));"); //$NON-NLS-1$ - } - - public void testBug39535() throws Exception - { - parse("namespace bar = foo;"); //$NON-NLS-1$ - } - - public void testBug39504B() throws Exception - { - parse("int y = sizeof (int*);"); //$NON-NLS-1$ - } - public void testBug39505A() throws Exception - { - parse("int AD::* gp_down = static_cast<int AD::*>(gp_stat);"); //$NON-NLS-1$ - } - public void testBug39505B() throws Exception - { - parse("int* gp_down = static_cast<int*>(gp_stat);"); //$NON-NLS-1$ - } - - public void testBug42985() throws Exception - { - parse( "const int x = 4; int y = ::x;"); //$NON-NLS-1$ - } - - public void testBug40419() throws Exception - { - Writer code = new StringWriter(); - try - { - code.write( "template <class T, class U> struct SuperSubclass {\n" ); //$NON-NLS-1$ - code.write( "enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists && \n" ); //$NON-NLS-1$ - code.write( "!::Loki::Conversion<const volatile T*, const volatile void*>::sameType) }; };" ); //$NON-NLS-1$ - } catch( IOException ioe ){} - parse( code.toString() ); - } - - public void testBug39556() throws Exception - { - parse("int *restrict ip_fn (void);", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - - } - - /** - * Test code: struct Example { Example(); Example(int); ~Example();}; - * Purpose: tests a declaration in a class scope. - */ - public void testBug43371 () throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("struct Example { Example(); Example(int); ~Example();};"); //$NON-NLS-1$ - IASTCompilationUnit cu = parse(code.toString()); - Iterator i = cu.getDeclarations(); - assertTrue(i.hasNext()); - IASTAbstractTypeSpecifierDeclaration declaration = - (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse(i.hasNext()); - assertTrue( declaration.getTypeSpecifier() instanceof IASTClassSpecifier); - assertTrue(((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind()== ASTClassKind.STRUCT); - Iterator j =((IASTClassSpecifier)declaration.getTypeSpecifier()).getDeclarations(); - assertTrue(j.hasNext()); - IASTMethod m1 = (IASTMethod)j.next(); - IASTMethod m2 = (IASTMethod)j.next(); - IASTMethod m3 = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - assertTrue(m1.getVisiblity() == ASTAccessVisibility.PUBLIC); - assertTrue(m2.getVisiblity() == ASTAccessVisibility.PUBLIC); - assertTrue(m3.getVisiblity() == ASTAccessVisibility.PUBLIC); - } - - public void testBug43644() throws Exception - { - Iterator i = parse( "void foo();{ int x; }", true, false ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)i.next(); - assertEquals( f.getName(), "foo"); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug43062() throws Exception - { - Iterator i = parse( "class X { operator short (); operator int unsigned(); operator int signed(); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classX = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator members = classX.getDeclarations(); - IASTMethod shortMethod = (IASTMethod)members.next(); - IASTMethod unsignedMethod = (IASTMethod)members.next(); - IASTMethod signedMethod = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertEquals( shortMethod.getName(), "operator short"); //$NON-NLS-1$ - assertEquals( unsignedMethod.getName(), "operator int unsigned"); //$NON-NLS-1$ - assertEquals( signedMethod.getName(), "operator int signed"); //$NON-NLS-1$ - } - - public void testBug39531() throws Exception - { - parse("class AString { operator char const *() const; };"); //$NON-NLS-1$ - } - - public void testBug40007() throws Exception - { - assertCodeFailsParse("int y = #;"); //$NON-NLS-1$ - } - - public void testBug40759() throws Exception - { - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration( "#define X SomeName \n class X {};" )).getTypeSpecifier(); //$NON-NLS-1$ - assertEquals( classSpec.getNameOffset() + 1, classSpec.getNameEndOffset() ); - assertEquals( classSpec.getName(), "SomeName"); //$NON-NLS-1$ - } - - public void testBug44633() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template <typename T> class A {};\n" ); //$NON-NLS-1$ - writer.write( "class B { template <typename T> friend class A;\n" ); //$NON-NLS-1$ - writer.write( "void method();\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - - assertTrue( i.next() instanceof IASTTemplateDeclaration ); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = classB.getDeclarations(); - assertTrue (members.next() instanceof IASTTemplateDeclaration ); - assertTrue( members.next() instanceof IASTMethod ); - assertFalse( i.hasNext() ); - } - - public void testBug39525() throws Exception - { - parse("C &(C::*DD)(const C &x) = &C::operator=;"); //$NON-NLS-1$ - } - - public void testBug41935() throws Exception - { - Iterator i = parse( "namespace A { int x; } namespace B = A;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( i.next() instanceof IASTNamespaceDefinition ); - IASTNamespaceAlias a = (IASTNamespaceAlias)i.next(); - assertEquals( a.getName(), "B" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug39528() throws Exception - { - Writer code = new StringWriter(); - try - { - code.write("struct B: public A {\n"); //$NON-NLS-1$ - code.write(" A a;\n"); //$NON-NLS-1$ - code.write(" B() try : A(1), a(2)\n"); //$NON-NLS-1$ - code.write(" { throw 1; }\n"); //$NON-NLS-1$ - code.write(" catch (...)\n"); //$NON-NLS-1$ - code.write(" { if (c != 3) r |= 1; }\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - } - catch (IOException ioe) - { - } - IASTClassSpecifier structB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString())).getTypeSpecifier(); - Iterator members = structB.getDeclarations(); - assertTrue( members.next() instanceof IASTField); - IASTMethod b = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertTrue( b.hasFunctionTryBlock() ); - } - - public void testBug39538() throws Exception - { - parse("template C::operator int<float> ();"); //$NON-NLS-1$ - } - - public void testBug39536() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template<class E>\n" ); //$NON-NLS-1$ - writer.write( "class X {\n" ); //$NON-NLS-1$ - writer.write( "X<E>(); // This fails \n" ); //$NON-NLS-1$ - writer.write( "inline X<E>(int); // This also fails \n" ); //$NON-NLS-1$ - writer.write( "inline ~X<E>(); // This works fine \n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - IASTTemplateDeclaration template = (IASTTemplateDeclaration)assertSoleDeclaration( writer.toString() ); - IASTClassSpecifier X = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)template.getOwnedDeclaration()).getTypeSpecifier(); - Iterator members = X.getDeclarations(); - for( int i = 0; i < 3; ++i ) - assertTrue( members.next() instanceof IASTMethod ); - assertFalse( members.hasNext() ); - } - - public void testBug39536A() throws Exception - { - IASTTemplateDeclaration template = (IASTTemplateDeclaration)parse("template<class E> class X { X<E>(); };").getDeclarations().next(); //$NON-NLS-1$ - IASTClassSpecifier classX = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)template.getOwnedDeclaration()).getTypeSpecifier(); - IASTDeclaration d = (IASTDeclaration)classX.getDeclarations().next(); - assertTrue( d instanceof IASTMethod); - } - public void testBug39536B() throws Exception - { - parse("template<class E> class X { inline X<E>(int); };"); //$NON-NLS-1$ - } - - public void testBug39542() throws Exception - { - parse("void f(int a, struct {int b[a];} c) {}"); //$NON-NLS-1$ - } - - //Here starts C99-specific section - public void testBug39549() throws Exception - { - parse("struct X x = { .b = 40, .z = { sizeof(X), 42 }, .t[3] = 2, .t.f[3].x = A * B };", true, true, ParserLanguage.C); //$NON-NLS-1$ - // with trailing commas - parse("struct X x = { .b = 40, .z = { sizeof(X), 42,}, .t[3] = 2, .t.f[3].x = A * B ,};", true, true, ParserLanguage.C); //$NON-NLS-1$ - } - - public void testBug39551A() throws Exception - { - IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( function.getName(), "conjf"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() ); - } - - public void testBug39551B() throws Exception - { - IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "id"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() ); - } - - public void testCBool() throws Exception - { - IASTVariable variable = (IASTVariable)assertSoleDeclaration( "_Bool x;", ParserLanguage.C ); //$NON-NLS-1$ - assertSimpleType( variable, IASTSimpleTypeSpecifier.Type._BOOL ); - } - - public void testBug39678() throws Exception - { - IASTVariable variable = (IASTVariable) assertSoleDeclaration("char *s = L\"a\" \"b\";"); //$NON-NLS-1$ - } - - public void testBug43110() throws Exception - { - IASTFunction function = (IASTFunction) assertSoleDeclaration( "void x( int y, ... );"); //$NON-NLS-1$ - assertTrue( function.takesVarArgs() ); - function = (IASTFunction) assertSoleDeclaration( "void x( int y... );"); //$NON-NLS-1$ - assertTrue( function.takesVarArgs() ); - } - - public void testBug44370() throws Exception - { - parse( "#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); //$NON-NLS-1$ - Iterator macros = quickParseCallback.getMacros(); - assertNotNull(macros); - assertTrue( macros.hasNext()); - IASTMacro swap = (IASTMacro) macros.next(); - assertFalse( macros.hasNext() ); - assertEquals( swap.getName(), "SWAP"); //$NON-NLS-1$ - assertEquals( swap.getMacroType(), IMacroDescriptor.MacroType.FUNCTION_LIKE ); - String [] params = swap.getParameters(); - assertEquals( params.length, 2 ); - assertEquals( params[0], "x"); //$NON-NLS-1$ - assertEquals( params[1], "y"); //$NON-NLS-1$ - String completeSignature = swap.getCompleteSignature().trim(); - assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ - assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ - IToken [] tokens = swap.getTokenizedExpansion(); - validateToken( tokens[0], IToken.tLBRACE); - validateIdentifier( tokens[1], "x"); //$NON-NLS-1$ - validateToken( tokens[2], IToken.tBITORASSIGN ); - validateIdentifier( tokens[3], "y"); //$NON-NLS-1$ - validateToken( tokens[4], IToken.tSEMI ); - validateIdentifier( tokens[5], "y"); //$NON-NLS-1$ - validateToken( tokens[6], IToken.tBITORASSIGN ); - validateIdentifier( tokens[7], "x"); //$NON-NLS-1$ - validateToken( tokens[8], IToken.tSEMI ); - validateIdentifier( tokens[9], "x"); //$NON-NLS-1$ - validateToken( tokens[10], IToken.tBITORASSIGN ); - validateIdentifier( tokens[11], "y"); //$NON-NLS-1$ - validateToken( tokens[12], IToken.tSEMI ); - validateToken( tokens[13], IToken.tRBRACE ); - } - /** - * @param token - * @param string - */ - private void validateIdentifier(IToken token, String identifierName ) { - validateToken( token, IToken.tIDENTIFIER); - assertEquals( token.getImage(), identifierName ); - } - /** - * @param token - * @param i - */ - private void validateToken(IToken token, int signal) { - assertEquals( token.getType(), signal ); - } - - public void testBug47752() throws Exception - { - parse("void func( cFoo bar ) try { } catch ( const char * error ){ }" ); //$NON-NLS-1$ - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTFunction h1 = (IASTFunction) i.next(); - assertEquals( h1.getName(), "h"); //$NON-NLS-1$ - Iterator parms = h1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - IASTFunction h2 = (IASTFunction) i.next(); - assertEquals( h2.getName(), "h"); //$NON-NLS-1$ - parms = h2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "unsigned char" ); //$NON-NLS-1$ - - IASTFunction h3 = (IASTFunction) i.next(); - assertEquals( h3.getName(), "h"); //$NON-NLS-1$ - parms = h3.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "signed char" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug44336() throws Exception - { - Iterator i = parse( "class A {}; typedef typename A foo;" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( classA.getClassKind(), ASTClassKind.CLASS ); - assertEquals( classA.getName(), "A"); //$NON-NLS-1$ - IASTTypedefDeclaration typedefDeclaration = (IASTTypedefDeclaration) i.next(); - assertFalse( i.hasNext() ); - } - - public void testBug39705() throws Exception - { - parse("#ident \"@(#)filename.c 1.3 90/02/12\""); //$NON-NLS-1$ - } - - 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 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 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 testBug45235() throws Exception - { - Iterator i = parse( "class A { friend class B; friend void f(); }; " ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = A.getDeclarations(); - - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTFunction f = (IASTFunction) i.next(); - - assertTrue( forewardDecl.isFriendDeclaration() ); - assertTrue( f.isFriend() ); - } - - 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 testBug59179() throws Exception - { - Iterator i = parse( "class __decl main{ int main; };", true, false ).getDeclarations(); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug57652() throws Exception - { - parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, true, ParserLanguage.C ).getDeclarations(); //$NON-NLS-1$ - } - - - public void testBug60142() throws Exception - { - IASTVariable var = (IASTVariable) assertSoleDeclaration( "unsigned long var;"); //$NON-NLS-1$ - assertEquals( var.getName(), "var"); //$NON-NLS-1$ - IASTSimpleTypeSpecifier specifier = ((IASTSimpleTypeSpecifier)var.getAbstractDeclaration().getTypeSpecifier()); - assertEquals( specifier.getTypename(), "unsigned long" ); //$NON-NLS-1$ - assertTrue( specifier.isLong() ); - assertTrue( specifier.isUnsigned() ); - assertEquals( specifier.getType(), IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testBug61431() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - ParserLanguage language = ( i == 0 ) ? ParserLanguage.C : ParserLanguage.CPP; - Iterator iter = parse( "int k[][] = { {0, {1}, {2,3}};", true, false, language ).getDeclarations(); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - } - - public void testBadIdentifier() throws Exception - { - parse( "class 0302 { private: int stinks; };", true, false ); //$NON-NLS-1$ - } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ - } - - public void testBug68116() throws Exception - { - StringBuffer buffer = new StringBuffer( "char dummy[] = \"0123456789" ); //$NON-NLS-1$ - for( int i = 0; i < 5000; ++i ) - buffer.append( "0123456789"); //$NON-NLS-1$ - buffer.append( "\";"); //$NON-NLS-1$ - parse( buffer.toString() ); - } - -}
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java deleted file mode 100644 index 677547eeb4f..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002-2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -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$ - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java deleted file mode 100644 index e0691bfb813..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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; -import org.eclipse.cdt.core.parser.ScannerException; - -/** - * @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) { - try { - IToken t = scanner.nextToken(); - - if (stream != null) - stream.println(t.getImage()); - - if (t == null) - break; - ++count; - } catch (ScannerException e) { - } - } - } catch (EndOfFileException e2) { - } - long totalTime = System.currentTimeMillis() - startTime; - System.out.println( "Resulting scan took " + totalTime + " millisecs " + - count + " tokens"); - return totalTime; - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java deleted file mode 100644 index daf11736594..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java +++ /dev/null @@ -1,1751 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003,2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.IGCCToken; -import org.eclipse.cdt.core.parser.IMacroDescriptor; -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.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerException; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.internal.core.parser.scanner.Scanner; - -/** - * @author jcamelon - */ -public class ScannerTestCase extends BaseScannerTest -{ - public class TableRow - { - private int[] values; - private int length; - - public TableRow(int[] v) - { - length= v.length; - values= new int[length]; - System.arraycopy(v, 0, values, 0, length); - } - - public String toString() - { - StringBuffer s= new StringBuffer(); - for (int i= 0; i < length; ++i) - { - s.append("var").append(i).append("=").append(values[i]).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - return s.toString(); - } - - public String symbolName(int index) - { - return "DEFINITION" + index; //$NON-NLS-1$ - } - - public int symbolValue(int index) - { - return new Long(Math.round(Math.pow(index, index))).intValue(); - } - - public String generateCode() - { - if (length < 2) - { - return "Array must have at least 2 elements"; //$NON-NLS-1$ - } - int numberOfElsifs= length - 1; - StringBuffer buffer= new StringBuffer(); - buffer.append("#if ").append(values[0]).append("\n#\tdefine "); //$NON-NLS-1$ //$NON-NLS-2$ - buffer.append(symbolName(0)).append(" ").append(symbolValue(0)); //$NON-NLS-1$ - for (int i= 0; i < numberOfElsifs; ++i) - buffer - .append("\n#elif ") //$NON-NLS-1$ - .append(values[1 + i]) - .append("\n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(i + 1)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(i + 1)); - buffer - .append("\n#else \n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(length)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(length)) - .append("\n#endif"); //$NON-NLS-1$ - return buffer.toString(); - } - - public int selectWinner() - { - for (int i= 0; i < values.length; ++i) - { - if (values[i] != 0) - { - return i; - } - } - return length; - } - /** - * Returns the length. - * @return int - */ - public int getLength() - { - return length; - } - - } - - public class TruthTable - { - private int numberOfVariables; - private int numberOfRows; - public TableRow[] rows; - - public TruthTable(int n) - { - numberOfVariables= n; - numberOfRows= new Long(Math.round(Math.pow(2, n))).intValue(); - - rows= new TableRow[numberOfRows]; - for (int i= 0; i < numberOfRows; ++i) - { - String Z= Integer.toBinaryString(i); - - int[] input= new int[numberOfVariables]; - for (int j= 0; j < numberOfVariables; ++j) - { - int padding= numberOfVariables - Z.length(); - int k= 0; - for (; k < padding; ++k) - { - input[k]= 0; - } - for (int l= 0; l < Z.length(); ++l) - { - char c= Z.charAt(l); - int value= Character.digit(c, 10); - input[k++]= value; - } - } - rows[i]= new TableRow(input); - } - } - /** - * Returns the numberOfRows. - * @return int - */ - public int getNumberOfRows() - { - return numberOfRows; - } - - } - - public final static int SIZEOF_TRUTHTABLE = 10; - - - public void testWeirdStrings() throws Exception - { - try - { - initializeScanner( "Living Life L\"LONG\""); //$NON-NLS-1$ - validateIdentifier( "Living" ); //$NON-NLS-1$ - validateIdentifier( "Life" ); //$NON-NLS-1$ - validateString("LONG", true); //$NON-NLS-1$ - validateEOF(); - } - catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - - } - - - public void testNumerics()throws Exception - { - try - { - initializeScanner("3.0 0.9 .5 3. 4E5 2.01E-03 ..."); //$NON-NLS-1$ - validateFloatingPointLiteral( "3.0"); //$NON-NLS-1$ - validateFloatingPointLiteral( "0.9"); //$NON-NLS-1$ - validateFloatingPointLiteral( ".5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "3."); //$NON-NLS-1$ - validateFloatingPointLiteral( "4E5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "2.01E-03" ); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateEOF(); - } - catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - - } - - - /** - * Constructor for ScannerTestCase. - * @param name - */ - public ScannerTestCase(String name) - { - super(name); - } - - public void testPreprocessorDefines()throws Exception - { - try - { - initializeScanner("#define SIMPLE_NUMERIC 5\nint x = SIMPLE_NUMERIC"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n\nconst char * myVariable = SIMPLE_STRING;"); //$NON-NLS-1$ - validateToken(IToken.t_const); - validateDefinition("SIMPLE_STRING", "\"This is a simple string.\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_char); - validateToken(IToken.tSTAR); - validateIdentifier("myVariable"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateString("This is a simple string."); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int tryAFOOL = FOOL + FOOL;"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("tryAFOOL"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int FOOLer = FOOL;"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("FOOLer"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - // the case we were failing against in ctype.h - // this is a definition, not a macro! - initializeScanner("#define _ALPHA (0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("_ALPHA", "(0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ //$NON-NLS-2$ - - // test for comments after the macro - initializeScanner("#define NO_COMMENT// ignore me"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define NO_COMMENT/* ignore me*/"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 // i think"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 /* i think */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTILINE 3 /* comment \n that goes more than one line */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTILINE", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTICOMMENT X /* comment1 */ + Y /* comment 2 */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTICOMMENT", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - for (int i= 0; i < 7; ++i) - { - switch (i) - { - case 0 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n"); //$NON-NLS-1$ - break; - case 4 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - break; - case 5 : - initializeScanner("#define FLAKE\n\nFLAKE"); //$NON-NLS-1$ - break; - case 6 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\\\n Continue please."); //$NON-NLS-1$ - break; - } - validateEOF(); - - switch (i) - { - case 0 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - break; - case 1 : - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2 : - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "\"This is a simple string.\""); //$NON-NLS-1$ - break; - case 4 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - break; - case 5 : - validateDefinition("FLAKE", ""); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 6 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string. Continue please."); //$NON-NLS-1$ - } - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - - public void testConcatenation() - { - try - { - initializeScanner("#define F1 3\n#define F2 F1##F1\nint x=F2;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("F1", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "F2", "F1##F1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("33"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define PREFIX RT_\n#define RUN PREFIX##Run"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( "PREFIX", "RT_" ); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "RUN", "PREFIX##Run" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner( "#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name\n DECLARE_HANDLE( joe )" ); //$NON-NLS-1$ - validateToken( IToken.t_struct ); - validateIdentifier( "joe__"); //$NON-NLS-1$ - validateToken( IToken.tLBRACE); - validateToken( IToken.t_int ); - validateIdentifier( "unused"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateToken( IToken.tSEMI ); - validateToken( IToken.t_typedef ); - validateToken( IToken.t_struct ); - validateIdentifier( "joe__" ); //$NON-NLS-1$ - validateToken( IToken.tSTAR ); - validateIdentifier( "joe"); //$NON-NLS-1$ - validateEOF(); - } - catch( Exception e ) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testSimpleIfdef() - { - try - { - - initializeScanner("#define SYMBOL 5\n#ifdef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("counter"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define SYMBOL 5\n#ifndef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("DEFINED", "100"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("100"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - scanner.addDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("101"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner( "/* NB: This is #if 0'd out */"); //$NON-NLS-1$ - validateEOF(); - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testMultipleLines() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define COMPLEX_MACRO 33 \\\n"); //$NON-NLS-1$ - code.write( " + 44\n\nCOMPLEX_MACRO"); //$NON-NLS-1$ - initializeScanner( code.toString() ); - validateInteger( "33" ); //$NON-NLS-1$ - validateToken( IToken.tPLUS ); - validateInteger( "44" ); //$NON-NLS-1$ - } - - public void testSlightlyComplexIfdefStructure() - { - try - { - initializeScanner("#ifndef BASE\n#define BASE 10\n#endif\n#ifndef BASE\n#error BASE is defined\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateAsUndefined("TWO"); //$NON-NLS-1$ - validateAsUndefined("THREE"); //$NON-NLS-1$ - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("THREE"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - scanner.addDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "ONE + TWO"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("FOO", "4"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - scanner.addDefinition("FOO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("FOO", "6"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testIfs() - { - try - { - initializeScanner("#if 0\n#error NEVER\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - initializeScanner("#define X 5\n#define Y 7\n#if (X < Y)\n#define Z X + Y\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#if T < 20\n#define Z T + 1\n#endif"); //$NON-NLS-1$ - scanner.addDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "T + 1"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ( 10 / 5 ) != 2\n#error 10/5 seems to not equal 2 anymore\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#ifndef FIVE \n#define FIVE 5\n#endif \n#ifndef TEN\n#define TEN 2 * FIVE\n#endif\n#if TEN != 10\n#define MISTAKE 1\n#error Five does not equal 10\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ((( FOUR / TWO ) * THREE )< FIVE )\n#error 6 is not less than 5 \n#endif\n#if ( ( FIVE * ONE ) != (( (FOUR) + ONE ) * ONE ) )\n#error 5 should equal 5\n#endif \n"); //$NON-NLS-1$ - - scanner.addDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateEOF(); - validateBalance(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - TruthTable table= new TruthTable(SIZEOF_TRUTHTABLE); - int numberOfRows= table.getNumberOfRows(); - TableRow[] rows= table.rows; - - for (int i= 0; i < numberOfRows; ++i) - { - TableRow row= rows[i]; - String code= row.generateCode(); - if (verbose) - System.out.println("\n\nRow " + i + " has code\n" + code); //$NON-NLS-1$ //$NON-NLS-2$ - initializeScanner(code); - validateEOF(); - validateBalance(); - validateAllDefinitions(row); - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$ - scanner.nextToken(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - assertEquals( se.getProblem().getID(), IProblem.PREPROCESSOR_POUND_ERROR); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testBug67834() throws Exception { - initializeScanner( - "#if ! BAR\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - initializeScanner( - "#if ! (BAR)\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - public void testPreprocessorMacros() - { - try - { - initializeScanner("#define GO(x) x+1\nint y(5);\ny = GO(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - IMacroDescriptor descriptor= - scanner.getDefinition("GO"); //$NON-NLS-1$ - String [] parms= descriptor.getParameters(); - assertNotNull(parms); - assertTrue(parms.length == 1); - String parm1= parms[0]; - assertTrue(parm1.equals("x")); //$NON-NLS-1$ - IToken [] expansion= descriptor.getTokenizedExpansion(); - assertNotNull(parms); - assertTrue(expansion.length == 3); - assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER); - assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$ - assertTrue((expansion[1]).getType() == IToken.tPLUS); - assertTrue((expansion[2]).getType() == IToken.tINTEGER); - assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$ - - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner( - "#define ONE 1\n" //$NON-NLS-1$ - + "#define SUM(a,b,c,d,e,f,g) ( a + b + c + d + e + f + g )\n" //$NON-NLS-1$ - + "int daSum = SUM(ONE,3,5,7,9,11,13);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("daSum"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("3"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("9"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("11"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("13"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$ - String [] params= macro.getParameters(); - assertNotNull(params); - assertTrue(params.length == 7); - - IToken [] tokens= macro.getTokenizedExpansion(); - assertNotNull(tokens); - assertTrue(tokens.length == 15); - - initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("My name is %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("Bogdan"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define INCR( x ) ++x\nint y(2);\nINCR(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateToken(IToken.tINCR); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define CHECK_AND_SET( x, y, z ) if( x ) { \\\n y = z; \\\n }\n\nCHECK_AND_SET( 1, balance, 5000 );\nCHECK_AND_SET( confused(), you, dumb );"); //$NON-NLS-1$ - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("balance"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5000"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateIdentifier("confused"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("you"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("dumb"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define ON 7\n#if defined(ON)\nint itsOn = ON;\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateBalance(1); - validateIdentifier("itsOn"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#if defined( NOTHING ) \nint x = NOTHING;\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - - - - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testQuickScan() throws ParserFactoryError - { - try - { - initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif", ParserMode.QUICK_PARSE ); //$NON-NLS-1$ - validateToken( IToken.t_int ); - validateIdentifier( "found" ); //$NON-NLS-1$ - validateToken( IToken.tASSIGN ); - validateInteger( "1"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - - try - { - initializeScanner( "#if 0\n int error = 666;\n#endif" ); //$NON-NLS-1$ - validateEOF(); - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - - } - - - public void testOtherPreprocessorCommands() throws ParserFactoryError - { - try - { - initializeScanner("#\n#\t\n#define MAX_SIZE 1024\n#\n# "); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MAX_SIZE", "1024"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - for (int i= 0; i < 4; ++i) - { - switch (i) - { - case 0 : - initializeScanner("# ape"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# #"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# 32"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("# defines"); //$NON-NLS-1$ - break; - } - - try - { - validateEOF(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - } - - public void validateAllDefinitions(TableRow row) - { - int winner= row.selectWinner(); - int rowLength= row.getLength(); - for (int i= 0; i <= rowLength; ++i) - { - if (i == winner) - validateDefinition(row.symbolName(i), row.symbolValue(i)); - else - validateAsUndefined(row.symbolName(i)); - } - } - - public void testBug36287() throws Exception - { - initializeScanner( "X::X( const X & rtg_arg ) : U( rtg_arg ) , Z( rtg_arg.Z ) , er( rtg_arg.er ){}" ); //$NON-NLS-1$ - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tCOLONCOLON); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_const ); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tAMPER ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOLON ); - validateIdentifier( "U"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - - initializeScanner( "foo.*bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tDOTSTAR ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "foo...bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug35892() throws ParserFactoryError - { - try - { - initializeScanner( "'c'" ); //$NON-NLS-1$ - validateChar( 'c' ); - validateEOF(); - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - } - - public void testBug36045() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( '"' ); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( '"'); - - buffer.append( '"'); - buffer.append( '\\'); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( "\n\n"); //$NON-NLS-1$ - initializeScanner( buffer.toString()); - validateString( "\\\"\\\\"); //$NON-NLS-1$ - } - - public void testConditionalWithBraces() throws ParserFactoryError - { - try - { - for( int i = 0; i < 4; ++i ) - { - initializeScanner( "int foobar(int a) { if(a == 0) {\n#ifdef THIS\n} else {}\n#elif THAT\n} else {}\n#endif\nreturn 0;}" ); //$NON-NLS-1$ - switch( i ) - { - case 0: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 1: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2: - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3: - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - - validateToken( IToken.t_int ); - validateIdentifier( "foobar"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_if ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tEQUAL ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - - if( i <= 1 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - if( i == 2 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - validateToken( IToken.t_return ); - validateInteger( "0"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - } - } catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - } - - public void testNestedRecursiveDefines() throws Exception - { - initializeScanner( "#define C B A\n#define B C C\n#define A B\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "C C"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "B A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("A"); //$NON-NLS-1$ - validateIdentifier("B"); //$NON-NLS-1$ - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36316() throws Exception - { - initializeScanner( "#define A B->A\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B->A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.tARROW); - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36434() throws Exception - { - initializeScanner( "#define X(Y)"); //$NON-NLS-1$ - validateEOF(); - IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$ - assertNotNull( macro ); - assertEquals( macro.getParameters().length, 1 ); - assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$ - assertEquals( macro.getTokenizedExpansion().length, 0 ); - } - - public void testBug36047() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "# define MAD_VERSION_STRINGIZE(str) #str\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_MINOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_PATCH) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_EXTRA)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MAJOR 2\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MINOR 1\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_PATCH 3\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_EXTRA boo\n" ); //$NON-NLS-1$ - writer.write( "MAD_VERSION\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateString( "2.1.3.boo" ); //$NON-NLS-1$ - - validateEOF(); - } - - public void testBug36475() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( " \"A\" \"B\" \"C\" " ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateString( "ABC" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36509() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$ - writer.write(" x ## s, x ## t) \n"); //$NON-NLS-1$ - writer.write("debug(1, 2);"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - //printf("x1=%d, x2= %s", x1, x2); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateString("x1= %d, x2= %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x1"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testBug36695() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("\'\\4\' \'\\n\'"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateChar( "\\4" ); //$NON-NLS-1$ - validateChar( "\\n" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36521() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("fputs(str(strncmp(\"abc\\0d\", \"abc\", \'\\4\')\n"); //$NON-NLS-1$ - writer.write(" == 0), s);\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier("fputs"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("s"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - } - - public void testBug36770() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n"); //$NON-NLS-1$ - writer.write( "# define foo 1\n"); //$NON-NLS-1$ - writer.write( "#else\n"); //$NON-NLS-1$ - writer.write( "# define foo 2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "foo\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateInteger( "2" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36816() throws Exception - { - initializeScanner( "#include \"foo.h" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch ( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE ); - } - - initializeScanner( "#include <foo.h" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch ( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE); - } - initializeScanner( "#define FOO(A" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN ); - } - initializeScanner( "#define FOO(A \\ B" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN); - } - - } - - public void testBug36255() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#if defined ( A ) \n" ); //$NON-NLS-1$ - writer.write( " #if defined ( B ) && ( B != 0 ) \n" ); //$NON-NLS-1$ - writer.write( " boo\n" ); //$NON-NLS-1$ - writer.write( " #endif /*B*/\n" ); //$NON-NLS-1$ - writer.write( "#endif /*A*/" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug37011() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "#define A \"//\""); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateEOF(); - validateDefinition("A", "\"//\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testOtherPreprocessorDefines() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "#define A a//boo\n" ); //$NON-NLS-1$ - writer.write( "#define B a /*boo*/ a\n" ); //$NON-NLS-1$ - writer.write( "#define C a \" //boo \"\n" ); //$NON-NLS-1$ - writer.write( "#define D a \\\"//boo\n" ); //$NON-NLS-1$ - writer.write( "#define E a \\n \"\\\"\"\n" ); //$NON-NLS-1$ - writer.write( "#define F a\\\n b\n" ); //$NON-NLS-1$ - writer.write( "#define G a '\"'//boo\n" ); //$NON-NLS-1$ - writer.write( "#define H a '\\'//b'\"/*bo\\o*/\" b\n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateEOF(); - - validateDefinition("A", "a"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "a a"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "a \" //boo \""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("D", "a \\\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("E", "a \\n \"\\\"\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("F", "a b"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("G", "a '\"'"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("H", "a '\\'//b'\"/*bo\\o*/\" b"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug38065() throws Exception - { - initializeScanner( "Foo\\\nBar" ); //$NON-NLS-1$ - - validateIdentifier("FooBar"); //$NON-NLS-1$ - validateEOF(); - - } - - public void testBug36701A() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("str( @ \\n )\n"); //$NON-NLS-1$ - - initializeScanner(writer.toString()); - validateString("@ \\\\n"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36701B() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("str( @ /*ff*/ \\n hh \"aa\" )\n"); //$NON-NLS-1$ - - initializeScanner(writer.toString()); - validateString("@ \\\\n hh \\\"aa\\\""); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug44305() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define WCHAR_MAX 0 \n"); //$NON-NLS-1$ - writer.write( "#if WCHAR_MAX <= 0xff\n" ); //$NON-NLS-1$ - writer.write( "bool\n"); //$NON-NLS-1$ - writer.write( "#endif"); //$NON-NLS-1$ - initializeScanner( writer.toString()); - validateToken( IToken.t_bool ); - validateEOF(); - } - - public void testBug45287() throws Exception - { - initializeScanner( "'abcdefg' L'hijklmnop'"); //$NON-NLS-1$ - validateChar( "abcdefg" ); //$NON-NLS-1$ - validateWideChar( "hijklmnop"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug45476() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n"); //$NON-NLS-1$ - buffer.append( "#if defined X\n"); //$NON-NLS-1$ - buffer.append( "#define Y 10\n"); //$NON-NLS-1$ - buffer.append( "#endif"); //$NON-NLS-1$ - initializeScanner( buffer.toString() ); - validateEOF(); - validateDefinition( "Y", "10"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug45477() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define D\n" ); //$NON-NLS-1$ - buffer.append( "#define D\n" ); //$NON-NLS-1$ - buffer.append( "#define sum(x,y) x+y\n" ); //$NON-NLS-1$ - buffer.append( "#define E 3\n" ); //$NON-NLS-1$ - buffer.append( "#define E 3\n" ); //$NON-NLS-1$ - buffer.append( "#define sum(x,y) x+y\n"); //$NON-NLS-1$ - buffer.append( "#if defined(D)\n" ); //$NON-NLS-1$ - buffer.append( "printf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - buffer.append( "#if defined(sum)\n" ); //$NON-NLS-1$ - buffer.append( "scanf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - buffer.append( "#if defined(E)\n" ); //$NON-NLS-1$ - buffer.append( "sprintf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString() ); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateIdentifier( "scanf"); //$NON-NLS-1$ - validateIdentifier( "sprintf" ); //$NON-NLS-1$ - validateEOF(); - - for( int i = 0; i < 5; ++i) - { - - buffer = new StringBuffer(); - - buffer.append( "#define D blah\n" ); //$NON-NLS-1$ - - switch( i ) - { - case 0: - buffer.append( "#define D\n"); //$NON-NLS-1$ - break; - case 1: - buffer.append( "#define D( x ) echo\n"); //$NON-NLS-1$ - break; - case 2: - buffer.append( "#define D ACDC\n"); //$NON-NLS-1$ - break; - case 3: - buffer.append( "#define D defined( D )\n"); //$NON-NLS-1$ - break; - case 4: - buffer.append( "#define D blahh\n"); //$NON-NLS-1$ - break; - - } - - initializeScanner( buffer.toString() ); - try - { - validateEOF(); - fail( "Should not reach here"); //$NON-NLS-1$ - } - catch( ScannerException se ) - { - assertTrue( se.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN); - } - } - - buffer = new StringBuffer(); - buffer.append( "#define X 5\n"); //$NON-NLS-1$ - buffer.append( "#define Y 7\n"); //$NON-NLS-1$ - buffer.append( "#define SUMXY X _+ Y"); //$NON-NLS-1$ - buffer.append( "#define SUMXY X + Y"); //$NON-NLS-1$ - initializeScanner(buffer.toString()); - validateEOF(); - } - - - protected static class Callback extends NullSourceElementRequestor implements ISourceElementRequestor - { - public List inclusions = new ArrayList(); - public List problems = new ArrayList(); - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) - { - inclusions.add( inclusion.getName() ); - } - - public boolean acceptProblem( IProblem p ) - { - problems.add( p ); - return super.acceptProblem(p); - } - /** - * @param mode - */ - public Callback(ParserMode mode) - { - super( mode ); - } - - } - - public void testBug45551() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define stdio someNonExistantIncludeFile\n" ); //$NON-NLS-1$ - buffer.append( "#include <stdio.h>\n" ); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( buffer.toString(), ParserMode.QUICK_PARSE, callback ); - validateEOF(); - assertEquals( callback.problems.size(), 0 ); - assertEquals( callback.inclusions.size(), 1 ); - assertEquals( callback.inclusions.get(0), "stdio.h"); //$NON-NLS-1$ - } - - public void testBug46402() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n" ); //$NON-NLS-1$ - buffer.append( "#if defined( X )\n" ); //$NON-NLS-1$ - buffer.append( "// blah\n" ); //$NON-NLS-1$ - buffer.append( "#elif Y > 5 \n" ); //$NON-NLS-1$ - buffer.append( "// coo\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE ); - validateEOF(); - } - - public void testBug50821() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "\'\n\n\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - scanner.nextToken(); - assertEquals( callback.problems.size(), 1 ); - } - - - public void test54778() throws ScannerException - { - initializeScanner("#if 1 || 0 < 3 \n printf \n #endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO > 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - - } - - public void testBug56517() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#if 0 \n"); //$NON-NLS-1$ - writer.write( "char * x = \"#boo\";\n" ); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug36770B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n" ); //$NON-NLS-1$ - writer.write( "# define foo\n" ); //$NON-NLS-1$ - writer.write( "#else\n" ); //$NON-NLS-1$ - writer.write( "# define bar\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE ); - validateEOF(); - validateDefinition( "A", 0 ); //$NON-NLS-1$ - validateDefinition( "bar", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - public void testBug47797() throws Exception - { - initializeScanner( "\"\\uABCD\" \'\\uABCD\' \\uABCD_ident \\u001A01BC_ident ident\\U01AF ident\\u01bc00AF"); //$NON-NLS-1$ - validateString( "\\uABCD"); //$NON-NLS-1$ - validateChar( "\\uABCD"); //$NON-NLS-1$ - validateIdentifier( "\\uABCD_ident"); //$NON-NLS-1$ - validateIdentifier( "\\u001A01BC_ident"); //$NON-NLS-1$ - validateIdentifier( "ident\\U01AF" ); //$NON-NLS-1$ - validateIdentifier( "ident\\u01bc00AF" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug39698() throws Exception - { - initializeScanner( "<? >?"); //$NON-NLS-1$ - validateToken( IGCCToken.tMIN ); - validateToken( IGCCToken.tMAX ); - validateEOF(); - } - - public void testBug59768() throws Exception - { - initializeScanner( "#define A A\nA"); //$NON-NLS-1$ - validateIdentifier( "A"); //$NON-NLS-1$ - validateEOF(); - IMacroDescriptor d = scanner.getDefinition( "A"); //$NON-NLS-1$ - assertTrue( d.isCircular() ); - } - - public void testBug60764() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define P a,b\n"); //$NON-NLS-1$ - writer.write( "#define M(x) M1(x)\n"); //$NON-NLS-1$ - writer.write( "#define M1(x,y) #x #y\n"); //$NON-NLS-1$ - writer.write( "M(P)\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateString( "ab"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug62042() throws Exception - { - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( "0x", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - validateEOF(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61968() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "unsigned int ui = 2172748163; //ok \n" ); //$NON-NLS-1$ - writer.write( "int big = 999999999999999;//ok \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( "caller(4); //ok\n" ); //$NON-NLS-1$ - writer.write( "caller(2172748163);//causes java.lang.NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "caller(999999999999999); //also causes NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug62378() throws Exception - { - initializeScanner( "\"\\?\\?<\""); //$NON-NLS-1$ - validateString("\\?\\?<" ); //$NON-NLS-1$ - } - - public void testBug62384() throws Exception - { - initializeScanner( "18446744073709551615LL"); //$NON-NLS-1$ - validateInteger( "18446744073709551615"); //$NON-NLS-1$ - } - - public void testBug62390() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define f(x) x\n"); //$NON-NLS-1$ - writer.write( "#if f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true1\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#if A\n"); //$NON-NLS-1$ - writer.write( "#elif f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) \"A0I70_001.h\"\n"); //$NON-NLS-1$ - writer.write( "#include f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) 1467\n"); //$NON-NLS-1$ - writer.write( "#line f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#pragma f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - } - - public void testBug62009() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#define def(x) (x#)\ndef(orange)\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - fullyTokenize(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61972() throws Exception - { - initializeScanner( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;" ); //$NON-NLS-1$ - validateIdentifier( "DEF2"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write(" { \\\n"); //$NON-NLS-1$ - writer.write(" /* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write(" up the parser. */ }\n"); //$NON-NLS-1$ - writer.write("BODY "); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - } - - public void testEndif() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifdef __X__\n" ); //$NON-NLS-1$ - writer.write( " // comment\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - assertEquals( ((Scanner)scanner).getBranchTracker().getDepth(), 0 ); - } - - public void test68229() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define COUNT 0 \n" ); //$NON-NLS-1$ - writer.write( "1 \n" ); //$NON-NLS-1$ - writer.write( "#if COUNT \n" ); //$NON-NLS-1$ - writer.write( " 2 \n" ); //$NON-NLS-1$ - writer.write( "#endif \n" ); //$NON-NLS-1$ - writer.write( "3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - IToken t1 = scanner.nextToken(); - IToken t3 = scanner.nextToken(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - assertEquals( t1.getNext(), t3 ); - validateEOF(); - - writer = new StringWriter(); - writer.write( "#define FOO( x ) x \n" ); //$NON-NLS-1$ - writer.write( "1 FOO( 2 ) 3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - t1 = scanner.nextToken(); - IToken t2 = scanner.nextToken(); - t3 = scanner.nextToken(); - validateEOF(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t2.getImage(), "2" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - - assertEquals( t1.getNext(), t2 ); - } - -// public void testBug69134() throws Exception -// { -// Writer writer = new StringWriter(); -// writer.write( "# ifdef YYDEBUG\n" ); -// writer.write( " if (yyDebug) {\n" ); -// writer.write( " (void) fprintf (yyTrace,\n" ); -// writer.write( "\" # |Position|State|Mod|Lev|Action |Terminal and Lookahead or Rule\n\");\n" ); -// writer.write( "yyNl ();\n" ); -// writer.write( "}\n" ); -// writer.write( "# endif\n" ); -// Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); -// initializeScanner(writer.toString(), ParserMode.COMPLETE_PARSE, callback ); -// fullyTokenize(); -// assertTrue( callback.problems.isEmpty() ); -// } -// -// public void testBug69161() throws Exception -// { -// Writer writer = new StringWriter(); -// writer.write( "#define MACRO(s) s\n" ); -// writer.write( "char *testQueries[] =\n"); -// writer.write( "{\n"); -// writer.write( "MACRO(\",\"), // if you change the comma to anything else there is no error\n"); -// writer.write( "MACRO(\"(\"),\n" ); -// writer.write( "MACRO(\")\")\n" ); -// writer.write( "};\n"); -// Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); -// initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); -// fullyTokenize(); -// assertTrue( callback.problems.isEmpty() ); -// } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java deleted file mode 100644 index 15456fcbd53..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002-2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation */ -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(); - assertTrue( !filename.equals( "")); //$NON-NLS-1$ - return (IASTNode) result.getOffsetableNamedElement(); - } - return null; - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java deleted file mode 100644 index 90df1be6410..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java +++ /dev/null @@ -1,369 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; - -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.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @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 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 ); - } - - 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$ - - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java deleted file mode 100644 index d73ead3d081..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java +++ /dev/null @@ -1,181 +0,0 @@ -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 ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java deleted file mode 100644 index b52cafa0c39..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ -/* - * Created on Apr 29, 2004 - */ -package org.eclipse.cdt.core.parser.tests; - -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.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -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$ - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java deleted file mode 100644 index 608c191a904..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM 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.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 = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").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.quickParse = 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 quickParse = true; - - public void run(){ - try { - ParserMode parserMode = quickParse ? 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; - } - } - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/XMLDumper.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/XMLDumper.java deleted file mode 100644 index 7a41359a5f0..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/XMLDumper.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.eclipse.cdt.core.parser.tests; - -import java.io.IOException; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.HashMap; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * This class implements a utility that will walk through an object - * and it's children and create an XML file for it. - */ -public class XMLDumper { - - public static class Test { - private String msg = "hi"; //$NON-NLS-1$ - - public String getMsg() { - return msg; - } - - public Test self = this; - } - - public static void main(String [] args) { - Test test = new Test(); - try { - XMLDumper dumper = new XMLDumper(test); - Document document = dumper.getDocument(); - StringWriter writer = new StringWriter(); - - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.transform(new DOMSource(document), new StreamResult(writer)); - - System.out.println( "STRXML = " + writer.toString() ); //Spit out DOM as a String //$NON-NLS-1$ - } catch (TransformerException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - - } - - private int id = 0; - private HashMap map = new HashMap(); - private Document document; - - public Document getDocument() { - return document; - } - - public XMLDumper(Object obj) throws ParserConfigurationException { - document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - document.appendChild(createObject(obj)); - } - - private Element createObject(Object obj) { - Class cls = obj.getClass(); - String clsName = cls.getName(); - clsName = clsName.replace('$', '.'); - - Element element = document.createElement(clsName); - map.put(obj, new Integer(id)); - element.setAttribute("id",String.valueOf(id++)); //$NON-NLS-1$ - - Field [] fields = cls.getDeclaredFields(); - for (int i = 0; i < fields.length; ++i) { - Field field = fields[i]; - int modifiers = field.getModifiers(); - - // Skip over static fields - if (Modifier.isStatic(modifiers)) - continue; - - // Skip fields that start with an underscore - if (field.getName().charAt(0) == '_') - continue; - - Object value = null; - - String fieldName = field.getName(); - if (Modifier.isPublic(modifiers)) { - try { - value = field.get(obj); - } catch (Exception e) { - value = e; - } - } else { - String methodName = "get" + //$NON-NLS-1$ - fieldName.substring(0, 1).toUpperCase() + - fieldName.substring(1); - - Method method = null; - try { - method = cls.getMethod(methodName, null); - } catch (NoSuchMethodException e) { - continue; - } - - try { - value = method.invoke(obj, null); - } catch (Exception e) { - value = e; - } - } - - Element fieldElement = document.createElement(fieldName); - element.appendChild(fieldElement); - - if (value == null) - return element; - - Class type = field.getType(); - if (String.class.isAssignableFrom(type)) - fieldElement.appendChild(document.createTextNode((String)value)); - else if (Integer.class.isAssignableFrom(type)) - fieldElement.appendChild(document.createTextNode(((Integer)value).toString())); - else if (Exception.class.isAssignableFrom(type)) - fieldElement.appendChild(document.createTextNode(value.toString())); - else { - Object v = map.get(value); - if (v != null) - fieldElement.setAttribute("refid", v.toString()); //$NON-NLS-1$ - else - fieldElement.appendChild(createObject(value)); - } - - } - - return element; - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java deleted file mode 100644 index cf2b3fd888c..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - -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.parser.CodeReader; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IParserLogService; -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.ScannerException; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.extension.ExtensionDialect; -import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.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 Scanner2 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) 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 ); - return new Scanner2( code, config, ourRequestor, ourMode, language, logService, new ParserExtensionFactory( ExtensionDialect.GCC ).createScannerExtension(), workingCopies ); - } - - 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) - { - } - catch (ScannerException se) - { - throw se; - } - return scanner.getCount(); - } - public void validateIdentifier(String expectedImage) throws ScannerException - { - try { - IToken t= scanner.nextToken(); - assertEquals( t.getType(), IToken.tIDENTIFIER ); - assertEquals(t.getImage(), expectedImage ); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateInteger(String expectedImage) throws ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - 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 ScannerException - { - validateString( expectedImage, false ); - } - - public void validateString(String expectedImage, boolean lString ) throws ScannerException - { - 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"); - } - } - - public void validateToken(int tokenType) throws ScannerException - { - 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 validateBalance() - { - assertTrue(scanner.getDepth() == 0); - } - - public void validateEOF() throws ScannerException - { - 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).expansion); - } - - public void validateDefinition(String name, int value) - { - validateDefinition(name, String.valueOf(value)); - } - - public void validateAsUndefined(String name) - { - assertNull(scanner.getDefinition(name)); - } - - 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(), string); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java deleted file mode 100644 index 17fc4b20fbc..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.scanner2; - -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.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.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerException; -import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; - -/** - * @author Doug Schaefer - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class Scanner2SpeedTest extends SpeedTest2 { - - 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 Scanner2SpeedTest().runTest(stream, 1); - } catch (Exception e) { - System.out.println(e); - } - } - - public void test() throws Exception { - runTest(10); - } - - public 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; - Scanner2 scanner = createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); - long startTime = System.currentTimeMillis(); - int count = 0; - try { - while (true) { - try { - IToken t = scanner.nextToken(); - - if (stream != null) - stream.println(t.getImage()); - - if (t == null) - break; - ++count; - } catch (ScannerException e) { - } - } - } catch (EndOfFileException e2) { - } - long totalTime = System.currentTimeMillis() - startTime; - System.out.println( "Resulting scan took " + totalTime + " millisecs " + - count + " tokens"); - return totalTime; - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java deleted file mode 100644 index a28e4b6e80b..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ /dev/null @@ -1,1686 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003,2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.IGCCToken; -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.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerException; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; - -/** - * @author jcamelon - */ -public class Scanner2Test extends BaseScanner2Test -{ - public class TableRow - { - private int[] values; - private int length; - - public TableRow(int[] v) - { - length= v.length; - values= new int[length]; - System.arraycopy(v, 0, values, 0, length); - } - - public String toString() - { - StringBuffer s= new StringBuffer(); - for (int i= 0; i < length; ++i) - { - s.append("var").append(i).append("=").append(values[i]).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - return s.toString(); - } - - public String symbolName(int index) - { - return "DEFINITION" + index; //$NON-NLS-1$ - } - - public int symbolValue(int index) - { - return new Long(Math.round(Math.pow(index, index))).intValue(); - } - - public String generateCode() - { - if (length < 2) - { - return "Array must have at least 2 elements"; //$NON-NLS-1$ - } - int numberOfElsifs= length - 1; - StringBuffer buffer= new StringBuffer(); - buffer.append("#if ").append(values[0]).append("\n#\tdefine "); //$NON-NLS-1$ //$NON-NLS-2$ - buffer.append(symbolName(0)).append(" ").append(symbolValue(0)); //$NON-NLS-1$ - for (int i= 0; i < numberOfElsifs; ++i) - buffer - .append("\n#elif ") //$NON-NLS-1$ - .append(values[1 + i]) - .append("\n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(i + 1)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(i + 1)); - buffer - .append("\n#else \n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(length)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(length)) - .append("\n#endif"); //$NON-NLS-1$ - return buffer.toString(); - } - - public int selectWinner() - { - for (int i= 0; i < values.length; ++i) - { - if (values[i] != 0) - { - return i; - } - } - return length; - } - /** - * Returns the length. - * @return int - */ - public int getLength() - { - return length; - } - - } - - public class TruthTable - { - private int numberOfVariables; - private int numberOfRows; - public TableRow[] rows; - - public TruthTable(int n) - { - numberOfVariables= n; - numberOfRows= new Long(Math.round(Math.pow(2, n))).intValue(); - - rows= new TableRow[numberOfRows]; - for (int i= 0; i < numberOfRows; ++i) - { - String Z= Integer.toBinaryString(i); - - int[] input= new int[numberOfVariables]; - for (int j= 0; j < numberOfVariables; ++j) - { - int padding= numberOfVariables - Z.length(); - int k= 0; - for (; k < padding; ++k) - { - input[k]= 0; - } - for (int l= 0; l < Z.length(); ++l) - { - char c= Z.charAt(l); - int value= Character.digit(c, 10); - input[k++]= value; - } - } - rows[i]= new TableRow(input); - } - } - /** - * Returns the numberOfRows. - * @return int - */ - public int getNumberOfRows() - { - return numberOfRows; - } - - } - - public final static int SIZEOF_TRUTHTABLE = 10; - - - public void testWeirdStrings() throws Exception - { - try - { - initializeScanner( "Living Life L\"LONG\""); //$NON-NLS-1$ - validateIdentifier( "Living" ); //$NON-NLS-1$ - validateIdentifier( "Life" ); //$NON-NLS-1$ - validateString("LONG", true); //$NON-NLS-1$ - validateEOF(); - } - catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - - } - - - public void testNumerics()throws Exception - { - try - { - initializeScanner("3.0 0.9 .5 3. 4E5 2.01E-03 ..."); //$NON-NLS-1$ - validateFloatingPointLiteral( "3.0"); //$NON-NLS-1$ - validateFloatingPointLiteral( "0.9"); //$NON-NLS-1$ - validateFloatingPointLiteral( ".5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "3."); //$NON-NLS-1$ - validateFloatingPointLiteral( "4E5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "2.01E-03" ); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateEOF(); - } - catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - - } - - - /** - * Constructor for ScannerTestCase. - * @param name - */ - public Scanner2Test(String name) - { - super(name); - } - - public void testPreprocessorDefines()throws Exception - { - initializeScanner("#define SIMPLE_NUMERIC 5\nint x = SIMPLE_NUMERIC"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n\nconst char * myVariable = SIMPLE_STRING;"); //$NON-NLS-1$ - validateToken(IToken.t_const); - validateDefinition("SIMPLE_STRING", "\"This is a simple string.\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_char); - validateToken(IToken.tSTAR); - validateIdentifier("myVariable"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateString("This is a simple string."); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int tryAFOOL = FOOL + FOOL;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("tryAFOOL"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int FOOLer = FOOL;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("FOOLer"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - // the case we were failing against in ctype.h - // this is a definition, not a macro! - initializeScanner("#define _ALPHA (0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("_ALPHA", "(0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ //$NON-NLS-2$ - - // test for comments after the macro - initializeScanner("#define NO_COMMENT// ignore me"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define NO_COMMENT/* ignore me*/"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 // i think"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 /* i think */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTILINE 3 /* comment \n that goes more than one line */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTILINE", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTICOMMENT X /* comment1 */ + Y /* comment 2 */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTICOMMENT", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "\"This is a simple string.\""); //$NON-NLS-1$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - - initializeScanner("#define FLAKE\n\nFLAKE"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("FLAKE", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\\\n Continue please."); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string. Continue please."); //$NON-NLS-1$ - } - - - public void testConcatenation() - { - try - { - initializeScanner("#define F1 3\n#define F2 F1##F1\nint x=F2;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("F1", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "F2", "F1##F1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("33"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define PREFIX RT_\n#define RUN PREFIX##Run"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( "PREFIX", "RT_" ); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "RUN", "PREFIX##Run" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner( "#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name\n DECLARE_HANDLE( joe )" ); //$NON-NLS-1$ - validateToken( IToken.t_struct ); - validateIdentifier( "joe__"); //$NON-NLS-1$ - validateToken( IToken.tLBRACE); - validateToken( IToken.t_int ); - validateIdentifier( "unused"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateToken( IToken.tSEMI ); - validateToken( IToken.t_typedef ); - validateToken( IToken.t_struct ); - validateIdentifier( "joe__" ); //$NON-NLS-1$ - validateToken( IToken.tSTAR ); - validateIdentifier( "joe"); //$NON-NLS-1$ - validateEOF(); - } - catch( Exception e ) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testSimpleIfdef() - { - try - { - - initializeScanner("#define SYMBOL 5\n#ifdef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("counter"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define SYMBOL 5\n#ifndef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("DEFINED", "100"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("100"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - scanner.addDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("101"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner( "/* NB: This is #if 0'd out */"); //$NON-NLS-1$ - validateEOF(); - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testMultipleLines() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define COMPLEX_MACRO 33 \\\n"); //$NON-NLS-1$ - code.write( " + 44\n\nCOMPLEX_MACRO"); //$NON-NLS-1$ - initializeScanner( code.toString() ); - validateInteger( "33" ); //$NON-NLS-1$ - validateToken( IToken.tPLUS ); - validateInteger( "44" ); //$NON-NLS-1$ - } - - public void testSlightlyComplexIfdefStructure() - { - try - { - initializeScanner("#ifndef BASE\n#define BASE 10\n#endif\n#ifndef BASE\n#error BASE is defined\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateAsUndefined("TWO"); //$NON-NLS-1$ - validateAsUndefined("THREE"); //$NON-NLS-1$ - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("THREE"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - scanner.addDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "ONE + TWO"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("FOO", "4"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - scanner.addDefinition("FOO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("FOO", "6"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner( - "#ifndef ONE\n" + - "# define ONE 1\n" + - "# ifndef TWO\n" + - "# define TWO ONE + ONE \n" + - "# else\n" + - "# undef TWO\n" + - "# define TWO 2 \n" + - "# endif\n" + - "#else\n" + - "# ifndef TWO\n" + - "# define TWO ONE + ONE \n" + - "# else\n" + - "# undef TWO\n" + - "# define TWO 2 \n" + - "# endif\n" + - "#endif\n"); //$NON-NLS-1$" + - - scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testIfs() - { - try - { - initializeScanner("#if 0\n#error NEVER\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - initializeScanner("#define X 5\n#define Y 7\n#if (X < Y)\n#define Z X + Y\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#if T < 20\n#define Z T + 1\n#endif"); //$NON-NLS-1$ - scanner.addDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateBalance(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "T + 1"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ( 10 / 5 ) != 2\n#error 10/5 seems to not equal 2 anymore\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner( - "#ifndef FIVE \n" + - "#define FIVE 5\n" + - "#endif \n" + - "#ifndef TEN\n" + - "#define TEN 2 * FIVE\n" + - "#endif\n" + - "#if TEN != 10\n" + - "#define MISTAKE 1\n" + - "#error Five does not equal 10\n" + - "#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ((( FOUR / TWO ) * THREE )< FIVE )\n#error 6 is not less than 5 \n#endif\n#if ( ( FIVE * ONE ) != (( (FOUR) + ONE ) * ONE ) )\n#error 5 should equal 5\n#endif \n"); //$NON-NLS-1$ - - scanner.addDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateEOF(); - validateBalance(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - TruthTable table= new TruthTable(SIZEOF_TRUTHTABLE); - int numberOfRows= table.getNumberOfRows(); - TableRow[] rows= table.rows; - - for (int i= 0; i < numberOfRows; ++i) - { - TableRow row= rows[i]; - String code= row.generateCode(); - if (verbose) - System.out.println("\n\nRow " + i + " has code\n" + code); //$NON-NLS-1$ //$NON-NLS-2$ - initializeScanner(code); - validateEOF(); - validateBalance(); - validateAllDefinitions(row); - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$ - scanner.nextToken(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - // TODO define problems - //assertEquals( se.getProblem().getID(), IProblem.PREPROCESSOR_POUND_ERROR); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testPreprocessorMacros() - { - try - { - initializeScanner("#define GO(x) x+1\nint y(5);\ny = GO(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - /* Macros don't work this way anymore - IMacroDescriptor descriptor= - scanner.getDefinition("GO"); //$NON-NLS-1$ - String [] parms= descriptor.getParameters(); - assertNotNull(parms); - assertTrue(parms.length == 1); - String parm1= parms[0]; - assertTrue(parm1.equals("x")); //$NON-NLS-1$ - IToken [] expansion= descriptor.getTokenizedExpansion(); - assertNotNull(parms); - assertTrue(expansion.length == 3); - assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER); - assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$ - assertTrue((expansion[1]).getType() == IToken.tPLUS); - assertTrue((expansion[2]).getType() == IToken.tINTEGER); - assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$ */ - - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner( - "#define ONE 1\n" //$NON-NLS-1$ - + "#define SUM(a,b,c,d,e,f,g) ( a + b + c + d + e + f + g )\n" //$NON-NLS-1$ - + "int daSum = SUM(ONE,3,5,7,9,11,13);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("daSum"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("3"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("9"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("11"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("13"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - /* - IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$ - String [] params= macro.getParameters(); - assertNotNull(params); - assertTrue(params.length == 7); - - IToken [] tokens= macro.getTokenizedExpansion(); - assertNotNull(tokens); - assertTrue(tokens.length == 15); */ - - initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("My name is %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("Bogdan"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define INCR( x ) ++x\nint y(2);\nINCR(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateToken(IToken.tINCR); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define CHECK_AND_SET( x, y, z ) if( x ) { \\\n y = z; \\\n }\n\nCHECK_AND_SET( 1, balance, 5000 );\nCHECK_AND_SET( confused(), you, dumb );"); //$NON-NLS-1$ - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("balance"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5000"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateIdentifier("confused"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("you"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("dumb"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define ON 7\n#if defined(ON)\nint itsOn = ON;\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateBalance(1); - validateIdentifier("itsOn"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#if defined( NOTHING ) \nint x = NOTHING;\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - - - - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testQuickScan() throws ParserFactoryError - { - try - { - initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif", ParserMode.QUICK_PARSE ); //$NON-NLS-1$ - validateToken( IToken.t_int ); - validateIdentifier( "found" ); //$NON-NLS-1$ - validateToken( IToken.tASSIGN ); - validateInteger( "1"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - - try - { - initializeScanner( "#if 0\n int error = 666;\n#endif" ); //$NON-NLS-1$ - validateEOF(); - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - - } - - - public void testOtherPreprocessorCommands() throws ParserFactoryError - { - try - { - initializeScanner("#\n#\t\n#define MAX_SIZE 1024\n#\n# "); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MAX_SIZE", "1024"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - for (int i= 0; i < 4; ++i) - { - switch (i) - { - case 0 : - initializeScanner("# ape"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# #"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# 32"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("# defines"); //$NON-NLS-1$ - break; - } - - try - { - validateEOF(); - // These are no longer scanner exceptions, the are simply ignored. - //fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - } - - public void validateAllDefinitions(TableRow row) - { - int winner= row.selectWinner(); - int rowLength= row.getLength(); - for (int i= 0; i <= rowLength; ++i) - { - if (i == winner) - validateDefinition(row.symbolName(i), row.symbolValue(i)); - else - validateAsUndefined(row.symbolName(i)); - } - } - - public void testBug36287() throws Exception - { - initializeScanner( "X::X( const X & rtg_arg ) : U( rtg_arg ) , Z( rtg_arg.Z ) , er( rtg_arg.er ){}" ); //$NON-NLS-1$ - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tCOLONCOLON); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_const ); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tAMPER ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOLON ); - validateIdentifier( "U"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - - initializeScanner( "foo.*bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tDOTSTAR ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "foo...bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug35892() throws ParserFactoryError - { - try - { - initializeScanner( "'c'" ); //$NON-NLS-1$ - validateChar( 'c' ); - validateEOF(); - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - } - - public void testBug36045() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( '"' ); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( '"'); - - buffer.append( '"'); - buffer.append( '\\'); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( "\n\n"); //$NON-NLS-1$ - initializeScanner( buffer.toString()); - validateString( "\\\"\\\\"); //$NON-NLS-1$ - } - - public void testConditionalWithBraces() throws ParserFactoryError - { - try - { - for( int i = 0; i < 4; ++i ) - { - initializeScanner( "int foobar(int a) { if(a == 0) {\n#ifdef THIS\n} else {}\n#elif THAT\n} else {}\n#endif\nreturn 0;}" ); //$NON-NLS-1$ - switch( i ) - { - case 0: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 1: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2: - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3: - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - - validateToken( IToken.t_int ); - validateIdentifier( "foobar"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_if ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tEQUAL ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - - if( i <= 1 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - if( i == 2 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - validateToken( IToken.t_return ); - validateInteger( "0"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - } - } catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - } - - public void testNestedRecursiveDefines() throws Exception - { - initializeScanner( "#define C B A\n#define B C C\n#define A B\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "C C"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "B A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("A"); //$NON-NLS-1$ - validateIdentifier("B"); //$NON-NLS-1$ - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36316() throws Exception - { - initializeScanner( "#define A B->A\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B->A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.tARROW); - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36434() throws Exception - { - initializeScanner( "#define X(Y)\nX(55)"); //$NON-NLS-1$ - validateEOF(); - /*IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$ - assertNotNull( macro ); - assertEquals( macro.getParameters().length, 1 ); - assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$ - assertEquals( macro.getTokenizedExpansion().length, 0 );*/ - } - - public void testBug36047() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "# define MAD_VERSION_STRINGIZE(str) #str\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_MINOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_PATCH) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_EXTRA)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MAJOR 2\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MINOR 1\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_PATCH 3\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_EXTRA boo\n" ); //$NON-NLS-1$ - writer.write( "MAD_VERSION\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateString( "2.1.3.boo" ); //$NON-NLS-1$ - - validateEOF(); - } - - public void testBug36475() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( " \"A\" \"B\" \"C\" " ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateString( "ABC" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36509() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$ - writer.write(" x ## s, x ## t) \n"); //$NON-NLS-1$ - writer.write("debug(1, 2);"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - //printf("x1=%d, x2= %s", x1, x2); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateString("x1= %d, x2= %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x1"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testBug36695() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("\'\\4\' \'\\n\'"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateChar( "\\4" ); //$NON-NLS-1$ - validateChar( "\\n" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36521() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("fputs(str(strncmp(\"abc\\0d\", \"abc\", \'\\4\')\n"); //$NON-NLS-1$ - writer.write(" == 0), s);\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier("fputs"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("s"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - } - - public void testBug36770() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n"); //$NON-NLS-1$ - writer.write( "# define foo 1\n"); //$NON-NLS-1$ - writer.write( "#else\n"); //$NON-NLS-1$ - writer.write( "# define foo 2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "foo\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateInteger( "2" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36816() throws Exception - { - initializeScanner( "#include \"foo.h" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch ( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE ); - } - - initializeScanner( "#include <foo.h" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch ( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE); - } - initializeScanner( "#define FOO(A" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN ); - } - initializeScanner( "#define FOO(A \\ B" ); //$NON-NLS-1$ - try{ - validateEOF(); - } catch( ScannerException e ){ - assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN); - } - - } - - public void testBug36255() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#if defined ( A ) \n" ); //$NON-NLS-1$ - writer.write( " #if defined ( B ) && ( B != 0 ) \n" ); //$NON-NLS-1$ - writer.write( " boo\n" ); //$NON-NLS-1$ - writer.write( " #endif /*B*/\n" ); //$NON-NLS-1$ - writer.write( "#endif /*A*/" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug37011() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "#define A \"//\""); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateEOF(); - validateDefinition("A", "\"//\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testOtherPreprocessorDefines() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "#define A a//boo\n" ); //$NON-NLS-1$ - writer.write( "#define B a /*boo*/ a\n" ); //$NON-NLS-1$ - writer.write( "#define C a \" //boo \"\n" ); //$NON-NLS-1$ - writer.write( "#define D a \\\"//boo\n" ); //$NON-NLS-1$ - writer.write( "#define E a \\n \"\\\"\"\n" ); //$NON-NLS-1$ - writer.write( "#define F a\\\n b\n" ); //$NON-NLS-1$ - writer.write( "#define G a '\"'//boo\n" ); //$NON-NLS-1$ - writer.write( "#define H a '\\'//b'\"/*bo\\o*/\" b\n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateEOF(); - - validateDefinition("A", "a"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "a a"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "a \" //boo \""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("D", "a \\\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("E", "a \\n \"\\\"\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("F", "a b"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("G", "a '\"'"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("H", "a '\\'//b'\"/*bo\\o*/\" b"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug38065() throws Exception - { - initializeScanner( "Foo\\\nBar" ); //$NON-NLS-1$ - - validateIdentifier("FooBar"); //$NON-NLS-1$ - validateEOF(); - - } - - public void testBug36701A() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("str( @ \\n )\n"); //$NON-NLS-1$ - - initializeScanner(writer.toString()); - validateString("@ \\\\n"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36701B() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("str( @ /*ff*/ \\n hh \"aa\" )\n"); //$NON-NLS-1$ - - initializeScanner(writer.toString()); - validateString("@ \\\\n hh \\\"aa\\\""); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug44305() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define WCHAR_MAX 0 \n"); //$NON-NLS-1$ - writer.write( "#if WCHAR_MAX <= 0xff\n" ); //$NON-NLS-1$ - writer.write( "bool\n"); //$NON-NLS-1$ - writer.write( "#endif"); //$NON-NLS-1$ - initializeScanner( writer.toString()); - validateToken( IToken.t_bool ); - validateEOF(); - } - - public void testBug45287() throws Exception - { - initializeScanner( "'abcdefg' L'hijklmnop'"); //$NON-NLS-1$ - validateChar( "abcdefg" ); //$NON-NLS-1$ - validateWideChar( "hijklmnop"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug45476() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n"); //$NON-NLS-1$ - buffer.append( "#if defined X\n"); //$NON-NLS-1$ - buffer.append( "#define Y 10\n"); //$NON-NLS-1$ - buffer.append( "#endif"); //$NON-NLS-1$ - initializeScanner( buffer.toString() ); - validateEOF(); - validateDefinition( "Y", "10"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug45477() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define D\n" ); //$NON-NLS-1$ - buffer.append( "#define D\n" ); //$NON-NLS-1$ - buffer.append( "#define sum(x,y) x+y\n" ); //$NON-NLS-1$ - buffer.append( "#define E 3\n" ); //$NON-NLS-1$ - buffer.append( "#define E 3\n" ); //$NON-NLS-1$ - buffer.append( "#define sum(x,y) x+y\n"); //$NON-NLS-1$ - buffer.append( "#if defined(D)\n" ); //$NON-NLS-1$ - buffer.append( "printf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - buffer.append( "#if defined(sum)\n" ); //$NON-NLS-1$ - buffer.append( "scanf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - buffer.append( "#if defined(E)\n" ); //$NON-NLS-1$ - buffer.append( "sprintf\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString() ); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateIdentifier( "scanf"); //$NON-NLS-1$ - validateIdentifier( "sprintf" ); //$NON-NLS-1$ - validateEOF(); - - for( int i = 0; i < 5; ++i) - { - - buffer = new StringBuffer(); - - buffer.append( "#define D blah\n" ); //$NON-NLS-1$ - - switch( i ) - { - case 0: - buffer.append( "#define D\n"); //$NON-NLS-1$ - break; - case 1: - buffer.append( "#define D( x ) echo\n"); //$NON-NLS-1$ - break; - case 2: - buffer.append( "#define D ACDC\n"); //$NON-NLS-1$ - break; - case 3: - buffer.append( "#define D defined( D )\n"); //$NON-NLS-1$ - break; - case 4: - buffer.append( "#define D blahh\n"); //$NON-NLS-1$ - break; - - } - - initializeScanner( buffer.toString() ); - try - { - validateEOF(); - // Preprocess overwrites are now allowed without correctness checking - //fail( "Should not reach here"); //$NON-NLS-1$ - } - catch( ScannerException se ) - { - assertTrue( se.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN); - } - } - - buffer = new StringBuffer(); - buffer.append( "#define X 5\n"); //$NON-NLS-1$ - buffer.append( "#define Y 7\n"); //$NON-NLS-1$ - buffer.append( "#define SUMXY X _+ Y"); //$NON-NLS-1$ - buffer.append( "#define SUMXY X + Y"); //$NON-NLS-1$ - initializeScanner(buffer.toString()); - validateEOF(); - } - - - protected static class Callback extends NullSourceElementRequestor implements ISourceElementRequestor - { - public List inclusions = new ArrayList(); - public List problems = new ArrayList(); - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) - { - inclusions.add( inclusion.getName() ); - } - - public boolean acceptProblem( IProblem p ) - { - problems.add( p ); - return super.acceptProblem(p); - } - /** - * @param mode - */ - public Callback(ParserMode mode) - { - super( mode ); - } - - } - - public void testBug45551() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define stdio someNonExistantIncludeFile\n" ); //$NON-NLS-1$ - buffer.append( "#include <stdio.h>\n" ); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( buffer.toString(), ParserMode.QUICK_PARSE, callback ); - validateEOF(); - assertEquals( callback.problems.size(), 0 ); - assertEquals( callback.inclusions.size(), 1 ); - assertEquals( callback.inclusions.get(0), "stdio.h"); //$NON-NLS-1$ - } - - public void testBug46402() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n" ); //$NON-NLS-1$ - buffer.append( "#if defined( X )\n" ); //$NON-NLS-1$ - buffer.append( "// blah\n" ); //$NON-NLS-1$ - buffer.append( "#elif Y > 5 \n" ); //$NON-NLS-1$ - buffer.append( "// coo\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE ); - validateEOF(); - } - - public void testBug50821() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "\'\n\n\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - scanner.nextToken(); - assertEquals( callback.problems.size(), 1 ); - } - - - public void test54778() throws ScannerException - { - initializeScanner("#if 1 || 0 < 3 \n printf \n #endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO > 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - - } - - public void testBug56517() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#if 0 \n"); //$NON-NLS-1$ - writer.write( "char * x = \"#boo\";\n" ); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug36770B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n" ); //$NON-NLS-1$ - writer.write( "# define foo\n" ); //$NON-NLS-1$ - writer.write( "#else\n" ); //$NON-NLS-1$ - writer.write( "# define bar\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE ); - validateEOF(); - validateDefinition( "A", 0 ); //$NON-NLS-1$ - validateDefinition( "bar", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - public void testBug47797() throws Exception - { - initializeScanner( "\"\\uABCD\" \'\\uABCD\' \\uABCD_ident \\u001A01BC_ident ident\\U01AF ident\\u01bc00AF"); //$NON-NLS-1$ - validateString( "\\uABCD"); //$NON-NLS-1$ - validateChar( "\\uABCD"); //$NON-NLS-1$ - validateIdentifier( "\\uABCD_ident"); //$NON-NLS-1$ - validateIdentifier( "\\u001A01BC_ident"); //$NON-NLS-1$ - validateIdentifier( "ident\\U01AF" ); //$NON-NLS-1$ - validateIdentifier( "ident\\u01bc00AF" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug39698() throws Exception - { - initializeScanner( "<? >?"); //$NON-NLS-1$ - validateToken( IGCCToken.tMIN ); - validateToken( IGCCToken.tMAX ); - validateEOF(); - } - - public void testBug59768() throws Exception - { - initializeScanner( "#define A A\nA"); //$NON-NLS-1$ - validateIdentifier( "A"); //$NON-NLS-1$ - validateEOF(); - /*IMacroDescriptor d = scanner.getDefinition( "A"); //$NON-NLS-1$ - assertTrue( d.isCircular() );*/ - } - - public void testBug60764() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define P a,b\n"); //$NON-NLS-1$ - writer.write( "#define M(x) M1(x)\n"); //$NON-NLS-1$ - writer.write( "#define M1(x,y) #x #y\n"); //$NON-NLS-1$ - writer.write( "M(P)\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateString( "ab"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug62042() throws Exception - { - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( "0x", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - validateInteger("0x"); // to me this is a valid number - validateEOF(); - //assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61968() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "unsigned int ui = 2172748163; //ok \n" ); //$NON-NLS-1$ - writer.write( "int big = 999999999999999;//ok \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( "caller(4); //ok\n" ); //$NON-NLS-1$ - writer.write( "caller(2172748163);//causes java.lang.NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "caller(999999999999999); //also causes NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug62378() throws Exception - { - initializeScanner( "\"\\?\\?<\""); //$NON-NLS-1$ - validateString("\\?\\?<" ); //$NON-NLS-1$ - } - - public void testBug62384() throws Exception - { - initializeScanner( "18446744073709551615LL"); //$NON-NLS-1$ - validateInteger( "18446744073709551615LL"); //$NON-NLS-1$ - } - - public void testBug62390() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define f(x) x\n"); //$NON-NLS-1$ - writer.write( "#if f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true1\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#if A\n"); //$NON-NLS-1$ - writer.write( "#elif f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) \"A0I70_001.h\"\n"); //$NON-NLS-1$ - writer.write( "#include f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) 1467\n"); //$NON-NLS-1$ - writer.write( "#line f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#pragma f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - } - - public void testBug62009() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#define def(x) (x#)\ndef(orange)\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - fullyTokenize(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61972() throws Exception - { - initializeScanner( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;" ); //$NON-NLS-1$ - validateIdentifier( "DEF2"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write(" { \\\n"); //$NON-NLS-1$ - writer.write(" /* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write(" up the parser. */ }\n"); //$NON-NLS-1$ - writer.write("BODY "); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - } - - public void test__attribute__() throws Exception { - initializeScanner( - "#define __cdecl __attribute__((cdecl))\n" + - "__cdecl;"); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testUndef() throws Exception { - initializeScanner( - "#define A 5\n" + - "#define B 10\n" + - "#undef A\n" + - "A B"); - validateIdentifier("A"); - validateInteger("10"); - validateEOF(); - } - - public void testWackyFunctionMacros() throws Exception { - initializeScanner( - "#define A(X) hi##X\n" + - "#define B(Y) A(Y)\n" + - "B(there)"); - validateIdentifier("hithere"); - validateEOF(); - } - - public void testSlashes() throws Exception { - initializeScanner("__q / __n"); - validateIdentifier("__q"); - validateToken(IToken.tDIV); - validateIdentifier("__n"); - validateEOF(); - } - - public void testStringify() throws Exception { - initializeScanner("#define xS(s) #s\n#define S(s) xS(s)#define X hi\nS(X)"); - validateString("hi"); - validateEOF(); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java deleted file mode 100644 index 71e56c8e9aa..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.util.Collections; -import java.util.Hashtable; -import java.util.List; -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.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.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.extension.ExtensionDialect; -import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; - -// 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 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 { - 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 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 ); - return new Scanner2( code, config, ourRequestor, ourMode, language, logService, new ParserExtensionFactory( ExtensionDialect.GCC ).createScannerExtension(), workingCopies ); - } - - 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 ); - } - -} |