diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index faa35f5ab59..3f5c1e5a224 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2003-07-21 John Camelon + Created CompleteParseASTTest and added it to ParserTestSuite. + 2003-07-18 John Camelon Updated ParserSymbolTableTests to remove dependencies on parser.ast.full classes. Updated Parser test suites for updates to ParserFactory. 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 index 819336d8c6b..1bfb7ab0d7f 100644 --- 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 @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserMode; +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; @@ -58,7 +59,23 @@ public class BaseASTTest extends TestCase protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException { - Iterator declarationIter = parse( code ).getDeclarations(); + Iterator declarationIter = null; + try + { + try + { + declarationIter = parse(code).getDeclarations(); + } + catch (ASTNotImplementedException e1) + { + // TODO Auto-generated catch block + } + } + catch (ParserException e) + { + // TODO Auto-generated catch block + } + assertNotNull( declarationIter ); assertTrue( declarationIter.hasNext() ); IASTDeclaration returnValue = (IASTDeclaration)declarationIter.next(); assertFalse( declarationIter.hasNext() ); 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 new file mode 100644 index 00000000000..d3e397b89f9 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -0,0 +1,458 @@ +/********************************************************************** + * 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.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.parser.IParser; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ParserFactory; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +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.IASTInclusion; +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.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; +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.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.NullSourceElementRequestor; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.ScannerInfo; + + +/** + * @author jcamelon + * + */ +public class CompleteParseASTTest extends TestCase +{ + public 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(); + } + } + + public class FullParseCallback extends NullSourceElementRequestor implements ISourceElementRequestor + { + + private Stack inclusions = new Stack(); + private Scope compilationUnit; + + 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) + { + + } + + /* (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) + { + pushScope( function ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) + */ + public void exitFunctionBody(IASTFunction function) + { + popScope(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) + */ + public void enterCompilationUnit(IASTCompilationUnit compilationUnit) + { + pushScope( compilationUnit ); + } + + /* (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) + { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) + */ + public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) + */ + public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) + */ + public void acceptMethodDeclaration(IASTMethod method) + { + 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) + { + pushScope(method); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) + */ + public void exitMethodBody(IASTMethod method) + { + popScope(); + } + + /* (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) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) + */ + public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) + */ + public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) + */ + public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) + { + 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 compilationUnit) + { + this.compilationUnit = popScope(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTPointerToFunction) + */ + public void acceptPointerToFunction(IASTPointerToFunction function) + { + getCurrentScope().addDeclaration(function); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTPointerToMethod) + */ + public void acceptPointerToMethod(IASTPointerToMethod method) + { + getCurrentScope().addDeclaration(method); } + + + private Stack scopes = new Stack(); + protected Scope getCurrentScope() + { + return (Scope)scopes.peek(); + } + + protected Scope popScope() + { + return (Scope)scopes.pop(); + } + + protected void pushScope( IASTScope scope ) + { + scopes.push( new Scope( scope )); + } + + } + + + protected FullParseCallback callback; + + protected IASTScope parse( String code )throws ParserException + { + callback = new FullParseCallback(); + IParser parser = ParserFactory.createParser( + ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), + ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE + ); + parser.parse(); + return callback.getCompilationUnit(); + } + + /** + * @param a + */ + public CompleteParseASTTest(String a) + { + super(a); + } + + public void testEmptyCompilationUnit() throws Exception + { + IASTScope compilationUnit = parse( "// no real code "); + assertNotNull( compilationUnit ); + assertFalse( compilationUnit.getDeclarations().hasNext() ); + } + + public void testSimpleNamespace() throws Exception + { + Iterator declarations = parse( "namespace A { }").getDeclarations(); + IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); + assertEquals( namespaceDefinition.getName(), "A" ); + assertFalse( namespaceDefinition.getDeclarations().hasNext() ); + } + + public void testMultipleNamespaceDefinitions() throws Exception + { + Iterator declarations = parse( "namespace A { } namespace A { }").getDeclarations(); + IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); + assertEquals( namespaceDefinition.getName(), "A" ); + namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); + assertEquals( namespaceDefinition.getName(), "A" ); + assertFalse( namespaceDefinition.getDeclarations().hasNext() ); + } + + public void testNestedNamespaceDefinitions() throws Exception + { + Iterator declarations = parse( "namespace A { namespace B { } }").getDeclarations(); + IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); + assertEquals( namespaceDefinition.getName(), "A" ); + assertFalse( declarations.hasNext() ); + Iterator subDeclarations = namespaceDefinition.getDeclarations(); + IASTNamespaceDefinition subDeclaration = (IASTNamespaceDefinition)subDeclarations.next(); + assertEquals( subDeclaration.getName(), "B" ); + assertFalse( subDeclarations.hasNext() ); + } + +// public void testEmptyClassDeclaration() throws Exception +// { +// Iterator declarations = parse( "class A { };").getDeclarations(); +// IASTClassSpecifier classSpec = (IASTClassSpecifier)declarations.next(); +// assertEquals( classSpec.getName(), "A"); +// assertFalse( classSpec.getDeclarations().hasNext() ); +// assertFalse( declarations.hasNext() ); +// } +} 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 index 7e16dff6dae..cb7f4662d47 100644 --- 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 @@ -18,12 +18,12 @@ import java.util.Map; import junit.framework.TestCase; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.internal.core.parser.ast.complete.SymbolExtension; +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.ISymbolASTExtension; 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.ParserSymbolTable; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark; @@ -102,20 +102,60 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( look, null ); } + protected class NullSymbolExtension implements ISymbolASTExtension + { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getPrimaryDeclaration() + */ + public ASTSymbol getPrimaryDeclaration() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() + */ + public Iterator getAllDefinitions() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) + */ + public void addDefinition(ASTSymbol definition) throws ExtensionException + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() + */ + public ISymbol getSymbol() + { + // TODO Auto-generated method stub + return null; + } + } + public void testSimpleSetGetObject() throws Exception{ newTable(); IContainerSymbol x = table.new Declaration("x"); - ISymbolASTExtension extension = new SymbolExtension( null, null ); // cheating! + ISymbolASTExtension extension = new NullSymbolExtension (); - x.setASTNode( extension ); + x.setASTExtension( extension ); table.getCompilationUnit().addSymbol( x ); ISymbol look = table.getCompilationUnit().Lookup( "x" ); - assertEquals( look.getASTNode(), extension ); + assertEquals( look.getASTExtension(), extension ); } /** 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 index f7d9ea22ed6..35ed3259ced 100644 --- 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 @@ -36,6 +36,7 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite( PreprocessorTest.class ); suite.addTestSuite( PreprocessorConditionalTest.class ); suite.addTestSuite( QuickParseASTQualifiedNameTest.class); + suite.addTestSuite( CompleteParseASTTest.class ); return suite; } 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 index 8ab4e83e789..a5c6cdce1ca 100644 --- 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 @@ -1156,16 +1156,16 @@ public class QuickParseASTTests extends BaseASTTest assertFalse( inclusions.hasNext()); assertEquals( i.getName(), "stdio.h"); - assertEquals( i.getElementStartingOffset(), 0 ); - assertEquals( i.getElementNameOffset(), 10 ); - assertEquals( i.getElementEndingOffset(), 18 ); + assertEquals( i.getStartingOffset(), 0 ); + assertEquals( i.getNameOffset(), 10 ); + assertEquals( i.getEndingOffset(), 18 ); IASTMacro m = (IASTMacro)macros.next(); assertEquals( m.getName(), "DEF" ); - assertEquals( m.getElementStartingOffset(), 19 ); - assertEquals( m.getElementNameOffset(), 27 ); - assertEquals( m.getElementEndingOffset(), 18 + 19); + assertEquals( m.getStartingOffset(), 19 ); + assertEquals( m.getNameOffset(), 27 ); + assertEquals( m.getEndingOffset(), 18 + 19); } public void testTemplateDeclarationOfFunction() throws Exception diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java index b619c4e6677..1c9009341a9 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java @@ -466,10 +466,10 @@ public class DOMBuilder implements ISourceElementRequestor Macro m = new Macro( macro.getName(), - macro.getElementNameOffset(), - macro.getElementStartingOffset(), - macro.getElementEndingOffset() - - macro.getElementStartingOffset()); + macro.getNameOffset(), + macro.getStartingOffset(), + macro.getEndingOffset() + - macro.getStartingOffset()); translationUnit.addMacro(m); } /* (non-Javadoc) @@ -488,11 +488,11 @@ public class DOMBuilder implements ISourceElementRequestor SimpleDeclaration declaration = getTypeSpecOwner( getCurrentDOMScope(), - variable.getElementStartingOffset()); + variable.getStartingOffset()); if (declaration == null) { declaration = - startSimpleDeclaration(variable.getElementStartingOffset()); + startSimpleDeclaration(variable.getStartingOffset()); declaration.getDeclSpecifier().setConst( variable.getAbstractDeclaration().isConst()); declaration.getDeclSpecifier().setExtern(variable.isExtern()); @@ -579,7 +579,7 @@ public class DOMBuilder implements ISourceElementRequestor SimpleDeclaration simpleDeclaration = getTypeSpecOwner( getCurrentDOMScope(), - function.getElementStartingOffset()); + function.getStartingOffset()); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDirective(org.eclipse.cdt.core.parser.ast.IASTUsageDirective) @@ -647,9 +647,9 @@ public class DOMBuilder implements ISourceElementRequestor Inclusion i = new Inclusion( inclusion.getName(), - inclusion.getElementNameOffset(), - inclusion.getElementStartingOffset(), - inclusion.getElementEndingOffset(), + inclusion.getNameOffset(), + inclusion.getStartingOffset(), + inclusion.getEndingOffset(), inclusion.isLocal()); translationUnit.addInclusion(i); } @@ -662,10 +662,10 @@ public class DOMBuilder implements ISourceElementRequestor new NamespaceDefinition(getCurrentDOMScope()); namespaceDef.setName(namespaceDefinition.getName()); ((IOffsetable)namespaceDef).setStartingOffset( - namespaceDefinition.getElementStartingOffset()); + namespaceDefinition.getStartingOffset()); if (!namespaceDefinition.getName().equals("")) namespaceDef.setNameOffset( - namespaceDefinition.getElementNameOffset()); + namespaceDefinition.getNameOffset()); this.domScopes.push(namespaceDef); } /* (non-Javadoc) @@ -675,7 +675,7 @@ public class DOMBuilder implements ISourceElementRequestor { SimpleDeclaration decl = startSimpleDeclaration( - classSpecification.getElementStartingOffset()); + classSpecification.getStartingOffset()); int kind = ClassKey.t_struct; int visibility = AccessSpecifier.v_public; if (classSpecification.getClassKind() == ASTClassKind.CLASS) @@ -694,10 +694,10 @@ public class DOMBuilder implements ISourceElementRequestor ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl); classSpecifier.setVisibility(visibility); classSpecifier.setStartingOffset( - classSpecification.getElementStartingOffset()); + classSpecification.getStartingOffset()); decl.setTypeSpecifier(classSpecifier); classSpecifier.setName(classSpecification.getName()); - classSpecifier.setNameOffset(classSpecification.getElementNameOffset()); + classSpecifier.setNameOffset(classSpecification.getNameOffset()); domScopes.push(classSpecifier); } protected SimpleDeclaration startSimpleDeclaration(int startingOffset) @@ -810,9 +810,9 @@ public class DOMBuilder implements ISourceElementRequestor { ClassSpecifier c = (ClassSpecifier)getCurrentDOMScope(); c.setTotalLength( - classSpecification.getElementEndingOffset() + classSpecification.getEndingOffset() + 1 - - classSpecification.getElementStartingOffset()); + - classSpecification.getStartingOffset()); domScopes.pop(); } /* (non-Javadoc) @@ -822,8 +822,8 @@ public class DOMBuilder implements ISourceElementRequestor { NamespaceDefinition definition = (NamespaceDefinition)domScopes.pop(); definition.setTotalLength( - namespaceDefinition.getElementEndingOffset() - - namespaceDefinition.getElementStartingOffset()); + namespaceDefinition.getEndingOffset() + - namespaceDefinition.getStartingOffset()); getCurrentDOMScope().addDeclaration(definition); } /* (non-Javadoc) @@ -851,16 +851,16 @@ public class DOMBuilder implements ISourceElementRequestor public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) { SimpleDeclaration decl = - startSimpleDeclaration(enumeration.getElementStartingOffset()); + startSimpleDeclaration(enumeration.getStartingOffset()); EnumerationSpecifier es = new EnumerationSpecifier(decl); - es.setStartingOffset(enumeration.getElementStartingOffset()); + es.setStartingOffset(enumeration.getStartingOffset()); es.setStartImage("enum"); decl.setTypeSpecifier(es); es.setName(enumeration.getName()); es.setTotalLength( - enumeration.getElementEndingOffset() + enumeration.getEndingOffset() + 1 - - enumeration.getElementStartingOffset()); + - enumeration.getStartingOffset()); Iterator i = enumeration.getEnumerators(); while (i.hasNext()) { @@ -869,11 +869,11 @@ public class DOMBuilder implements ISourceElementRequestor es.addEnumeratorDefinition(definition); definition.setName(enumerator.getName()); ((IOffsetable)definition).setStartingOffset( - enumerator.getElementNameOffset()); + enumerator.getNameOffset()); definition.setTotalLength( - enumerator.getElementEndingOffset() + enumerator.getEndingOffset() + 1 - - enumerator.getElementStartingOffset()); + - enumerator.getStartingOffset()); } } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 5c31ba3f328..e2e6aec45b0 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-07-21 John Camelon + Fleshed out basic declarations for FullParse AST. + Fixed Bug 40554 - Fields coming back as Vars + Fixed Bug 40555 - Methods come back as Functions + 2003-07-18 John Camelon Added ISourceElementCallbackDelegate interface for AST constructs to allow the Parser to delegate callback's to the nodes themselves. Got rid of ParserMode.STRUCTURAL_PARSE for the time being. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java index ffd1aa91156..431f0ead0d0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java @@ -20,6 +20,12 @@ public class ASTSemanticException extends Exception { private final IProblem theProblem; + public ASTSemanticException() + { + theProblem = null; + } + + /** * */ @@ -33,7 +39,7 @@ public class ASTSemanticException extends Exception /** * @return */ - public IProblem getTheProblem() + public IProblem getProblem() { return theProblem; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index 551ab284468..b7f8918f20d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -15,7 +15,6 @@ import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; /** * @author jcamelon * @@ -51,7 +50,7 @@ public interface IASTFactory IASTScope scope, String identifier, int startingOffset, - int nameOffset); + int nameOffset) throws ASTSemanticException; public IASTCompilationUnit createCompilationUnit(); public IASTLinkageSpecification createLinkageSpecification( IASTScope scope, @@ -62,9 +61,8 @@ public interface IASTFactory ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, - IASTTemplate ownerTemplateDeclaration, int startingOffset, - int nameOffset); + int nameOffset) throws ASTSemanticException; /** * @param astClassSpec * @param isVirtual @@ -216,5 +214,4 @@ public interface IASTFactory boolean isPureVirtual, ASTAccessVisibility visibility, ASTPointerOperator pointerOperator); - public ISymbolASTExtension createSymbolTableDeclarationExtension( IASTDeclaration declaration, IASTDeclaration definition ) throws ASTNotImplementedException; } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java index 8b0f2690a94..7d098aaea35 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java @@ -19,8 +19,7 @@ public interface IASTOffsetableElement { public void setStartingOffset( int o ); public void setEndingOffset( int o ); - public int getElementStartingOffset(); - public int getElementEndingOffset(); - + public int getStartingOffset(); + public int getEndingOffset(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java index ec51ae2d69b..1cc6c5c0f9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java @@ -18,6 +18,6 @@ package org.eclipse.cdt.core.parser.ast; public interface IASTOffsetableNamedElement extends IASTOffsetableElement { public String getName(); - public int getElementNameOffset(); - public void setElementNameOffset( int o ); + public int getNameOffset(); + public void setNameOffset( int o ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java index b25d9e12d41..cb05720a394 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java @@ -18,5 +18,5 @@ import java.util.Iterator; */ public interface IASTScope { - public Iterator getDeclarations(); + public Iterator getDeclarations() throws ASTNotImplementedException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java index 8fa153c6805..e4e12e647fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java @@ -16,5 +16,5 @@ package org.eclipse.cdt.core.parser.ast; */ public interface IASTScopedElement { - IASTScope getOwnerScope(); + IASTScope getOwnerScope(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java index ed2f8a75d35..bb8f1ba5a2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java @@ -17,4 +17,5 @@ package org.eclipse.cdt.core.parser.ast; public interface IASTUsingDirective extends IASTDeclaration, IASTOffsetableElement { public String getNamespaceName(); + public IASTNamespaceDefinition getNamespaceDefinition() throws ASTNotImplementedException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java index e5774d656eb..b57507109f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java @@ -55,7 +55,9 @@ public class ContextStack { } undoStack.clear(); - push( new ScannerContext().initialize(reader, filename, type, null, macroOffset, macroLength, startLine ), requestor ); + IScannerContext context = new ScannerContext().initialize(reader, filename, type, null, macroOffset, macroLength, startLine ); + context.setExtension(inclusion); + push( context, requestor ); } protected void push( IScannerContext context, ISourceElementRequestor requestor ) throws ScannerException diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index ea0a0353cc5..6f948719fcf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -312,7 +312,7 @@ public class DeclarationWrapper implements IDeclaratorOwner */ private IASTDeclaration createASTNode(Declarator declarator) { - boolean isWithinClass = (getScope() instanceof IASTClassSpecifier); + boolean isWithinClass = (getScope() instanceof IASTClassSpecifier); //TODO fix this for COMPLETE_PARSE boolean isFunction = declarator.isFunction(); boolean hasInnerDeclarator = ( declarator.getOwnedDeclarator() != null ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 4059d8fea89..db9749262e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -684,12 +684,21 @@ public class Parser implements IParser if (LT(1) == IToken.tLBRACE) { consume(); - IASTNamespaceDefinition namespaceDefinition = - astFactory.createNamespaceDefinition( - scope, - (identifier == null ? "" : identifier.getImage()), - first.getOffset(), - (identifier == null ? 0 : identifier.getOffset())); + IASTNamespaceDefinition namespaceDefinition = null; + try + { + namespaceDefinition = + astFactory.createNamespaceDefinition( + scope, + (identifier == null ? "" : identifier.getImage()), + first.getOffset(), + (identifier == null ? 0 : identifier.getOffset())); + } + catch (ASTSemanticException e) + { + // TODO Auto-generated catch block + + } namespaceDefinition.enterScope( requestor ); namepsaceDeclarationLoop : while (LT(1) != IToken.tRBRACE) { @@ -2215,17 +2224,25 @@ public class Parser implements IParser backup(mark); throw backtrack; } - IASTClassSpecifier astClassSpecifier = - astFactory - .createClassSpecifier( - sdw.getScope(), - duple == null ? "" : duple.toString(), - classKind, - nameType, - access, - null, //TODO add TemplateDeclaration here - classKey.getOffset(), - duple == null ? 0 : duple.getFirstToken().getOffset()); + IASTClassSpecifier astClassSpecifier = null; + + try + { + astClassSpecifier = + astFactory + .createClassSpecifier( + sdw.getScope(), + duple == null ? "" : duple.toString(), + classKind, + nameType, + access, + classKey.getOffset(), + duple == null ? 0 : duple.getFirstToken().getOffset()); + } + catch (ASTSemanticException e) + { + // TODO Auto-generated catch block` + } sdw.setTypeSpecifier(astClassSpecifier); // base clause if (LT(1) == IToken.tCOLON) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java index 6cee5701e1e..b7dd9d99493 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.NoSuchElementException; import org.eclipse.cdt.core.parser.IQuickParseCallback; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTMacro; @@ -63,7 +64,7 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ public class OffsetableIterator implements Iterator { - private final Iterator declarationIter; + private Iterator declarationIter; private final Iterator inclusionIter; private final Iterator macroIter; @@ -71,7 +72,14 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ public OffsetableIterator() { - declarationIter = compilationUnit.getDeclarations(); + try + { + declarationIter = compilationUnit.getDeclarations(); + } + catch (ASTNotImplementedException ne ) + { + + } inclusionIter = inclusions.iterator(); macroIter = macros.iterator(); updateInclusionIterator(); @@ -125,30 +133,30 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ // case 3: 1 is null if( currentMacro == null ) - if( currentDeclaration.getElementStartingOffset() < currentInclusion.getElementStartingOffset() ) + if( currentDeclaration.getStartingOffset() < currentInclusion.getStartingOffset() ) return updateDeclarationIterator(); else return updateInclusionIterator(); if( currentInclusion == null ) - if( currentDeclaration.getElementStartingOffset() < currentMacro.getElementStartingOffset() ) + if( currentDeclaration.getStartingOffset() < currentMacro.getStartingOffset() ) return updateDeclarationIterator(); else return updateMacroIterator(); if( currentDeclaration == null ) - if( currentInclusion.getElementStartingOffset() < currentMacro.getElementStartingOffset() ) + if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() ) return updateInclusionIterator(); else return updateMacroIterator(); // case 4: none are null - if( currentInclusion.getElementStartingOffset() < currentMacro.getElementStartingOffset() && - currentInclusion.getElementStartingOffset() < currentDeclaration.getElementStartingOffset() ) + if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() && + currentInclusion.getStartingOffset() < currentDeclaration.getStartingOffset() ) return updateInclusionIterator(); - if( currentMacro.getElementStartingOffset() < currentInclusion.getElementStartingOffset() && - currentMacro.getElementStartingOffset() < currentDeclaration.getElementStartingOffset() ) + if( currentMacro.getStartingOffset() < currentInclusion.getStartingOffset() && + currentMacro.getStartingOffset() < currentDeclaration.getStartingOffset() ) return updateMacroIterator(); // only remaining case return updateDeclarationIterator(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java index 30dc21ec0e1..bf1637cedd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser; import java.util.Iterator; +import java.util.NoSuchElementException; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; @@ -61,6 +62,8 @@ public class TokenDuple implements ITokenDuple { * @see java.util.Iterator#next() */ public Object next() { + if( ! hasNext() ) + throw new NoSuchElementException(); IToken temp = iter; iter = iter.getNext(); return temp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java index 4557f7c2830..a1696ecd40c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java @@ -55,21 +55,21 @@ public class ASTInclusion implements IASTInclusion { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() { + public int getStartingOffset() { return startingOffset; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() { + public int getEndingOffset() { return endingOffset; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementNameOffset() */ - public int getElementNameOffset() { + public int getNameOffset() { return nameOffset; } @@ -91,7 +91,7 @@ public class ASTInclusion implements IASTInclusion { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.ast.IOffsetableElementRW#setNameOffset(int) */ - public void setElementNameOffset(int o) { + public void setNameOffset(int o) { nameOffset = o; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java index ae33c259cf7..b2916108e6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java @@ -48,25 +48,25 @@ public class ASTMacro implements IASTMacro { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElementRW#setNameOffset(int) */ - public void setElementNameOffset(int o) { + public void setNameOffset(int o) { nameOffset = o; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() { + public int getStartingOffset() { return startingOffset; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() { + public int getEndingOffset() { return endingOffset; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementNameOffset() */ - public int getElementNameOffset() { + public int getNameOffset() { return nameOffset; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java similarity index 97% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java index a33d99dfeb3..2c094c78da4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java @@ -8,7 +8,7 @@ * Contributors: * IBM Rational Software - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; +package org.eclipse.cdt.internal.core.parser.ast; import java.util.Stack; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java index 76727165b67..9ed2cc25f66 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java @@ -27,7 +27,7 @@ public class BaseASTFactory { IASTMacro m = new ASTMacro( name ); m.setStartingOffset( startingOffset ); m.setEndingOffset( endingOffset ); - m.setElementNameOffset( nameOffset ); + m.setNameOffset( nameOffset ); return m; } @@ -38,7 +38,7 @@ public class BaseASTFactory { IASTInclusion inclusion = new ASTInclusion( name, fileName, local ); inclusion.setStartingOffset( startingOffset ); inclusion.setEndingOffset( endingOffset ); - inclusion.setElementNameOffset( nameOffset ); + inclusion.setNameOffset( nameOffset ); return inclusion; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/NamedOffsets.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/NamedOffsets.java index 124daeb7473..a3e78cec02e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/NamedOffsets.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/NamedOffsets.java @@ -22,7 +22,7 @@ public class NamedOffsets extends Offsets { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() { + public int getNameOffset() { return nameOffset; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/Offsets.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/Offsets.java index a42238be23c..5e11a809611 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/Offsets.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/Offsets.java @@ -28,11 +28,11 @@ public class Offsets { endingOffset = o; } - public int getElementStartingOffset() { + public int getStartingOffset() { return startingOffset; } - public int getElementEndingOffset() { + public int getEndingOffset() { return endingOffset; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java new file mode 100644 index 00000000000..1b23deb9e07 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java @@ -0,0 +1,113 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; +import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; + + +/** + * @author jcamelon + * + */ +public class ASTAbstractTypeSpecifierDeclaration + extends ASTAnonymousDeclaration + implements IASTAbstractTypeSpecifierDeclaration +{ + private final IASTTypeSpecifier typeSpec; + private final IASTTemplate ownerTemplate; + private Offsets offsets = new Offsets(); + /** + * @param ownerScope + */ + public ASTAbstractTypeSpecifierDeclaration(IContainerSymbol ownerScope, IASTTypeSpecifier typeSpecifier, IASTTemplate ownerTemplate, int startingOffset, int endingOffset ) + { + super(ownerScope); + this.typeSpec = typeSpecifier; + this.ownerTemplate = ownerTemplate; + setStartingOffset(startingOffset); + setEndingOffset(endingOffset); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + requestor.acceptAbstractTypeSpecDeclaration(this); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void enterScope(ISourceElementRequestor requestor) + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void exitScope(ISourceElementRequestor requestor) + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner#getTypeSpecifier() + */ + public IASTTypeSpecifier getTypeSpecifier() + { + return typeSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() + */ + public IASTTemplate getOwnerTemplateDeclaration() + { + return ownerTemplate; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() + */ + public int getStartingOffset() + { + return offsets.getStartingOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() + */ + public int getEndingOffset() + { + return offsets.getEndingOffset(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java new file mode 100644 index 00000000000..1f0ebacab88 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java @@ -0,0 +1,39 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; + +/** + * @author jcamelon + * + */ +public abstract class ASTAnonymousDeclaration implements IASTDeclaration +{ + private final IContainerSymbol ownerScope; + /** + * + */ + public ASTAnonymousDeclaration( IContainerSymbol ownerScope ) + { + this.ownerScope = ownerScope; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() + */ + public IASTScope getOwnerScope() + { + return (IASTScope)ownerScope.getASTExtension().getPrimaryDeclaration(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java new file mode 100644 index 00000000000..ba307b0dfd5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java @@ -0,0 +1,171 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +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.IASTScope; +import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; +import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; + +/** + * @author jcamelon + * + */ +public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier +{ + private NamedOffsets offsets = new NamedOffsets(); + private final ClassNameType classNameType; + private final ASTClassKind classKind; + private ASTAccessVisibility currentVisibility; + private final ASTQualifiedNamedElement qualifiedName; + + /** + * @param symbol + */ + public ASTClassSpecifier(ISymbol symbol, ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, int startingOffset, int nameOffset ) + { + super(symbol); + classKind = kind; + classNameType = type; + currentVisibility = access; + setStartingOffset(startingOffset); + setNameOffset(nameOffset); + qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassNameType() + */ + public ClassNameType getClassNameType() + { + return classNameType; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassKind() + */ + public ASTClassKind getClassKind() + { + return classKind; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getBaseClauses() + */ + public Iterator getBaseClauses() + { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisibilityMode() + */ + public ASTAccessVisibility getCurrentVisibilityMode() + { + return currentVisibility; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#setCurrentVisibility(org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) + */ + public void setCurrentVisibility(ASTAccessVisibility visibility) + { + currentVisibility = visibility; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() + */ + public String getName() + { + return symbol.getName(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() + */ + public int getNameOffset() + { + return offsets.getNameOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) + */ + public void setNameOffset(int o) + { + offsets.setNameOffset(o); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void enterScope(ISourceElementRequestor requestor) + { + //TODO Iterate baseClauses and callback on their references + requestor.enterClassSpecifier(this); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void exitScope(ISourceElementRequestor requestor) + { + requestor.exitClassSpecifier(this); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() + */ + public int getStartingOffset() + { + return offsets.getStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() + */ + public int getEndingOffset() + { + return offsets.getEndingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() + */ + public String[] getFullyQualifiedName() + { + return qualifiedName.getFullyQualifiedName(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() + */ + public IASTScope getOwnerScope() + { + return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java new file mode 100644 index 00000000000..6484ff7199e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java @@ -0,0 +1,53 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; + +/** + * @author jcamelon + * + */ +public class ASTCompilationUnit + extends ASTScope + implements IASTCompilationUnit +{ + /** + * @param symbol + */ + public ASTCompilationUnit(ISymbol symbol) + { + super(symbol); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void enterScope(ISourceElementRequestor requestor) + { + requestor.enterCompilationUnit( this ); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void exitScope(ISourceElementRequestor requestor) + { + requestor.exitCompilationUnit( this ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java new file mode 100644 index 00000000000..2eecb66b20a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java @@ -0,0 +1,131 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; +import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; + +/** + * @author jcamelon + * + */ +public class ASTNamespaceDefinition + extends ASTScope + implements IASTNamespaceDefinition +{ + + private NamedOffsets namedOffsets = new NamedOffsets(); + private final ASTQualifiedNamedElement qualifiedName; + + /** + * @param namespaceSymbol + * @param startingOffset + * @param nameOffset + */ + public ASTNamespaceDefinition(ISymbol namespaceSymbol, int startingOffset, int nameOffset) + { + super( namespaceSymbol ); + setStartingOffset( startingOffset ); + setNameOffset( nameOffset ); + qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), namespaceSymbol.getName() ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() + */ + public String getName() + { + return symbol.getName(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() + */ + public int getNameOffset() + { + return namedOffsets.getNameOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) + */ + public void setNameOffset(int o) + { + namedOffsets.setNameOffset( o ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + namedOffsets.setStartingOffset(o); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + namedOffsets.setEndingOffset(o); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() + */ + public int getStartingOffset() + { + return namedOffsets.getStartingOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() + */ + public int getEndingOffset() + { + return namedOffsets.getEndingOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void enterScope(ISourceElementRequestor requestor) + { + requestor.enterNamespaceDefinition( this ); + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void exitScope(ISourceElementRequestor requestor) + { + requestor.exitNamespaceDefinition( this ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() + */ + public String[] getFullyQualifiedName() + { + return qualifiedName.getFullyQualifiedName(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java new file mode 100644 index 00000000000..af353cc3cb0 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java @@ -0,0 +1,46 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; + +/** + * @author jcamelon + * + */ +public abstract class ASTScope extends ASTSymbol implements IASTScope +{ + /** + * @param symbol + */ + public ASTScope(ISymbol symbol) + { + super(symbol); + } + + public IContainerSymbol getContainerSymbol() + { + return (IContainerSymbol)symbol; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() + */ + public Iterator getDeclarations() + { + return new ScopeIterator( getContainerSymbol().getContainedSymbols() ); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java new file mode 100644 index 00000000000..6be2575ea3a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java @@ -0,0 +1,38 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; +import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; + +/** + * @author jcamelon + * + */ +public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner, IASTDeclaration +{ + + public ASTSymbol( ISymbol symbol ) + { + super(symbol); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() + */ + public IASTScope getOwnerScope() + { + return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java new file mode 100644 index 00000000000..1fd4b68fcf7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; +import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; + +/** + * @author jcamelon + * + */ +public class ASTSymbolOwner implements ISymbolOwner +{ + protected final ISymbol symbol; + /** + * + */ + public ASTSymbolOwner( ISymbol symbol ) + { + this.symbol = symbol; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() + */ + public ISymbol getSymbol() + { + return symbol; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java new file mode 100644 index 00000000000..0e06aad2b3e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java @@ -0,0 +1,114 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; +import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; + +/** + * @author jcamelon + * + */ +public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUsingDirective +{ + private final IASTNamespaceDefinition namespace; + private Offsets offsets = new Offsets(); + /** + * @param namespaceDefinition + * @param startingOffset + * @param endingOffset + */ + public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset) + { + super( ownerSymbol ); + namespace = namespaceDefinition; + setStartingOffset(startingOffset); + setEndingOffset(endingOffset); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceName() + */ + public String getNamespaceName() + { + String [] fqn = namespace.getFullyQualifiedName(); + StringBuffer buffer = new StringBuffer(); + for( int i = 0; i < fqn.length; ++i ) + { + buffer.append( fqn[ i ] ); + if( i + 1 != fqn.length ) + buffer.append( "::"); + } + return buffer.toString(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset( o ); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getStartingOffset() + { + return offsets.getStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getEndingOffset() + { + return offsets.getEndingOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void enterScope(ISourceElementRequestor requestor) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void exitScope(ISourceElementRequestor requestor) + { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceDefinition() + */ + public IASTNamespaceDefinition getNamespaceDefinition() throws ASTNotImplementedException + { + return namespace; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 86671b48018..0dfc6d86b2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -10,12 +10,13 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.ast.complete; +import java.util.Iterator; import java.util.List; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTSemanticException; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; @@ -24,7 +25,6 @@ import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; -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.IASTExceptionSpecification; @@ -58,7 +58,16 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; +import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension; +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.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; +import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension; +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.ISymbolASTExtension.ExtensionException; /** * @author jcamelon @@ -84,8 +93,62 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto int endingOffset) throws ASTSemanticException { - // TODO Auto-generated method stub - return null; + Iterator iter = duple.iterator(); + if( ! iter.hasNext() ) + throw new ASTSemanticException(); + + IToken t1 = (IToken)iter.next(); + IContainerSymbol symbol = null; + + symbol = getScopeToSearchUpon(scope, t1 ); + + while( iter.hasNext() ) + { + IToken t = (IToken)iter.next(); + if( t.getType() == IToken.tCOLONCOLON ) continue; + try + { + symbol = symbol.LookupNestedNameSpecifier( t.getImage() ); + } + catch( ParserSymbolTableException pste ) + { + throw new ASTSemanticException(); + } + } + + try { + ((ASTScope)scope).getContainerSymbol().addUsingDirective( symbol ); + } catch (ParserSymbolTableException pste) { + } + + IASTUsingDirective astUD = new ASTUsingDirective( scopeToSymbol(scope), ((IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration()), startingOffset, endingOffset ); + return astUD; + } + + + protected IContainerSymbol getScopeToSearchUpon( + IASTScope currentScope, + IToken firstToken ) + { + IContainerSymbol symbol = null; + if( firstToken.getType() == IToken.tCOLONCOLON ) + symbol = pst.getCompilationUnit(); + else + { + try + { + symbol = (IContainerSymbol)scopeToSymbol(currentScope).Lookup( firstToken.getImage() ); + } + catch( ParserSymbolTableException pste ) + { + + } + } + return symbol; + } + protected IContainerSymbol scopeToSymbol(IASTScope currentScope) + { + return ((ASTScope)currentScope).getContainerSymbol(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.core.parser.ITokenDuple, int, int) @@ -119,19 +182,99 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IASTScope scope, String identifier, int startingOffset, - int nameOffset) + int nameOffset) throws ASTSemanticException { - // TODO Auto-generated method stub - return null; + // first we look up the symbol in the PST see if it already exists + // if not we create it + // TODO : handle the anonymous case + + IContainerSymbol pstScope = scopeToSymbol(scope); + ISymbol namespaceSymbol = null; + try + { + namespaceSymbol = pstScope.Lookup( identifier ); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + + if( namespaceSymbol != null ) + { + if( namespaceSymbol.getType() != ParserSymbolTable.TypeInfo.t_namespace ) + throw new ASTSemanticException(); + } + else + { + namespaceSymbol = pst.newContainerSymbol( identifier, ParserSymbolTable.TypeInfo.t_namespace ); + try + { + pstScope.addSymbol( namespaceSymbol ); + } + catch (ParserSymbolTableException e1) + { + // not overloading, should never happen + } + } + + ASTNamespaceDefinition namespaceDef = new ASTNamespaceDefinition( namespaceSymbol, startingOffset, nameOffset ); + try + { + attachSymbolExtension( namespaceSymbol, namespaceDef ); + } + catch (ExtensionException e1) + { + // will not happen with namespaces + } + return namespaceDef; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createCompilationUnit() */ public IASTCompilationUnit createCompilationUnit() { - // TODO Auto-generated method stub - return null; + ISymbol symbol = pst.getCompilationUnit(); + ASTCompilationUnit compilationUnit = new ASTCompilationUnit( symbol ); + try + { + attachSymbolExtension(symbol, compilationUnit ); + } + catch (ExtensionException e) + { + //should not happen with CompilationUnit + } + return compilationUnit; } + + + protected void attachSymbolExtension( + ISymbol symbol, + ASTSymbol astSymbol ) throws ExtensionException + { + ISymbolASTExtension extension = symbol.getASTExtension(); + if( extension == null ) + { + if( astSymbol instanceof IASTNamespaceDefinition ) + extension = new NamespaceSymbolExtension( symbol, astSymbol ); + else if( astSymbol instanceof IASTFunction ) // TODO : other foreward declare cases + { + extension = new ForewardDeclaredSymbolExtension( symbol, astSymbol ); + } + else + { + extension = new StandardSymbolExtension( symbol, astSymbol ); + } + symbol.setASTExtension( extension ); + } + else + { + extension.addDefinition( astSymbol ); + } + + + + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, int) */ @@ -152,12 +295,41 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, - IASTTemplate ownerTemplateDeclaration, int startingOffset, - int nameOffset) + int nameOffset) throws ASTSemanticException { - // TODO Auto-generated method stub - return null; + IContainerSymbol containerSymbol = scopeToSymbol(scope); + ParserSymbolTable.TypeInfo.eType pstType = null; + + if( kind == ASTClassKind.CLASS ) + pstType = ParserSymbolTable.TypeInfo.t_class; + else if( kind == ASTClassKind.STRUCT ) + pstType = ParserSymbolTable.TypeInfo.t_struct; + else if( kind == ASTClassKind.UNION ) + pstType = ParserSymbolTable.TypeInfo.t_union; + else + throw new ASTSemanticException(); + + IDerivableContainerSymbol classSymbol = pst.newDerivableContainerSymbol( name, pstType ); + try + { + containerSymbol.addSymbol( classSymbol ); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + + ASTClassSpecifier classSpecifier = new ASTClassSpecifier( classSymbol, kind, type, access, startingOffset, nameOffset ); + try + { + attachSymbolExtension(classSymbol, classSpecifier ); + } + catch (ExtensionException e1) + { + throw new ASTSemanticException(); + } + return classSpecifier; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addBaseSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, java.lang.String) @@ -463,8 +635,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto int startingOffset, int endingOffset) { - // TODO Auto-generated method stub - return null; + return new ASTAbstractTypeSpecifierDeclaration( scopeToSymbol(scope), typeSpecifier, template, startingOffset, endingOffset); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate, org.eclipse.cdt.core.parser.ast.ASTPointerOperator) @@ -514,11 +685,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto // TODO Auto-generated method stub return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSymbolTableDeclarationExtension(org.eclipse.cdt.core.parser.ast.IASTDeclaration, org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public ISymbolASTExtension createSymbolTableDeclarationExtension(IASTDeclaration declaration, IASTDeclaration definition) throws ASTNotImplementedException - { - return new SymbolExtension( declaration, definition ); - } + + protected ParserSymbolTable pst = new ParserSymbolTable(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ScopeIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ScopeIterator.java new file mode 100644 index 00000000000..f5ab5a81571 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ScopeIterator.java @@ -0,0 +1,73 @@ +/********************************************************************** + * 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.internal.core.parser.ast.complete; + +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.internal.core.parser.pst.ISymbol; +import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; + +/** + * @author jcamelon + * + */ +public class ScopeIterator implements Iterator +{ + private final Map sourceMap; + private final Iterator keyIter; + private Iterator subIterator = null; + + public ScopeIterator( Map in ) + { + sourceMap = in; + if( sourceMap != null ) + keyIter = in.keySet().iterator(); + else + keyIter = null; + } + + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() { + if( keyIter == null ) + return false; + if( subIterator != null && subIterator.hasNext() ) + return true; + subIterator = null; + return keyIter.hasNext(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() { + if( ! hasNext() ) + throw new NoSuchElementException(); + + if( subIterator != null ) + return subIterator.next(); + + + ISymbolASTExtension symbol = ((ISymbol)sourceMap.get( keyIter.next() )).getASTExtension(); + subIterator = symbol.getAllDefinitions(); + return next(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/SymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/SymbolExtension.java deleted file mode 100644 index 8e5fa313346..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/SymbolExtension.java +++ /dev/null @@ -1,82 +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.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class SymbolExtension implements ISymbolASTExtension -{ - private ISymbol symbol; - private final IASTDeclaration declaration; - private IASTDeclaration definition; - - /** - * - */ - public SymbolExtension( IASTDeclaration declaration, IASTDeclaration definition ) - { - this.declaration = declaration; - this.definition = definition; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#getDeclaration() - */ - public IASTDeclaration getDeclaration() - { - return declaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#getDefinition() - */ - public IASTDeclaration getDefinition() - { - return definition; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#setDefinition(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setDefinition(IASTDeclaration definition) - { - this.definition = definition; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#hasBeenDefined() - */ - public boolean hasBeenDefined() - { - return ( definition != null ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#getSymbol() - */ - public ISymbol getSymbol() - { - return symbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeclarationExtension#setSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setSymbol(ISymbol s) - { - symbol = s; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTASMDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTASMDefinition.java index 3f2f14cc675..c28f19a9a8e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTASMDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTASMDefinition.java @@ -57,15 +57,15 @@ public class ASTASMDefinition /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() { - return offsets.getElementStartingOffset(); + public int getStartingOffset() { + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() { - return offsets.getElementEndingOffset(); + public int getEndingOffset() { + return offsets.getEndingOffset(); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java index 71b4eafc03a..daf42334006 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java @@ -74,16 +74,16 @@ public class ASTAbstractTypeSpecifierDeclaration /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } private Offsets offsets = new Offsets(); /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java index 577e2daadb6..896b1ed627d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** * @author jcamelon @@ -34,8 +34,7 @@ public class ASTClassSpecifier extends ASTScopedTypeSpecifier implements IASTQCl String name, ASTClassKind kind, ClassNameType type, - ASTAccessVisibility access, - IASTTemplate ownerTemplate) + ASTAccessVisibility access) { super( scope, name ); this.scope = scope; @@ -99,14 +98,14 @@ public class ASTClassSpecifier extends ASTScopedTypeSpecifier implements IASTQCl /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset(o); } @@ -128,16 +127,16 @@ public class ASTClassSpecifier extends ASTScopedTypeSpecifier implements IASTQCl /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.ast.quick.IASTQScope#addDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java index ecf0423d8b4..04503ca80a9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java @@ -69,15 +69,15 @@ public class ASTElaboratedTypeSpecifier implements IASTElaboratedTypeSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java index 352268ba2ab..369e840e9a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java @@ -53,14 +53,14 @@ public class ASTEnumerationSpecifier extends ASTScopedTypeSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset(o); } @@ -81,16 +81,16 @@ public class ASTEnumerationSpecifier extends ASTScopedTypeSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } private List enumerators = new ArrayList(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java index ee8f69ed4b6..21dfb7f9230 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java @@ -54,14 +54,14 @@ public class ASTEnumerator /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset(o); } @@ -82,16 +82,16 @@ public class ASTEnumerator /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#getOwnerEnumerationSpecifier() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java index 0df08cbaef2..d2a92d1d60b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.ast.quick; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTExpression; @@ -60,4 +61,18 @@ public class ASTField extends ASTVariable implements IASTField { return visibility; } + + public void acceptElement( ISourceElementRequestor requestor ) + { + requestor.acceptField( this ); + } + + public void enterScope( ISourceElementRequestor requestor ) + { + } + + public void exitScope( ISourceElementRequestor requestor ) + { + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java index b9a11f4a079..54bef8441ca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.internal.core.parser.ast.*; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** @@ -114,14 +115,14 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset( o ); } @@ -149,16 +150,16 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java index 7444135555d..f48ecebcb8c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java @@ -76,16 +76,16 @@ public class ASTLinkageSpecification /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } private Offsets offsets = new Offsets(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java index 462a076f733..9c6903937f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import java.util.List; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; @@ -18,6 +19,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; /** * @author jcamelon * @@ -155,4 +157,20 @@ public class ASTMethod extends ASTFunction implements IASTMethod /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMember#getOwnerClassSpecifier() */ + + + public void acceptElement( ISourceElementRequestor requestor ) + { + requestor.acceptMethodDeclaration( this ); + } + + public void enterScope( ISourceElementRequestor requestor ) + { + requestor.enterMethodBody(this); + } + + public void exitScope( ISourceElementRequestor requestor ) + { + requestor.exitMethodBody(this); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java index 9ebab6c4e86..116c587bc0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.ast.*; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** @@ -46,14 +47,14 @@ public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamesp /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() { - return offsets.getElementNameOffset(); + public int getNameOffset() { + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) { + public void setNameOffset(int o) { offsets.setNameOffset( o ); } @@ -75,15 +76,15 @@ public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamesp /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() { - return offsets.getElementStartingOffset(); + public int getStartingOffset() { + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() { - return offsets.getElementEndingOffset(); + public int getEndingOffset() { + return offsets.getEndingOffset(); } private List declarations = new ArrayList(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java index 21b2585c957..fc25367238e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier; +import org.eclipse.cdt.internal.core.parser.ast.*; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java index e3962f0241a..e87fac46af7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java @@ -72,16 +72,16 @@ public class ASTTemplateDeclaration extends ASTDeclaration implements IASTTempla /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java index 8bf2b166fef..a20e5be4b93 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java @@ -69,17 +69,17 @@ public class ASTTemplateInstantiation extends ASTDeclaration implements IASTTemp /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java index f279b986815..ba75afc828d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java @@ -57,16 +57,16 @@ public class ASTTemplateSpecialization extends ASTDeclaration implements IASTTem /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java index 50125681952..9783a148320 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.internal.core.parser.ast.*; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** @@ -37,7 +38,7 @@ public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedef this.name = name; this.mapping = mapping; setStartingOffset(startingOffset); - setElementNameOffset(nameOffset); + setNameOffset(nameOffset); qualifiedName = new ASTQualifiedNamedElement( scope, name ); } /* (non-Javadoc) @@ -57,14 +58,14 @@ public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedef /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset(o); } @@ -86,16 +87,16 @@ public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedef /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java index ef2dca322a3..229039dc7e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java @@ -65,16 +65,16 @@ public class ASTUsingDeclaration /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } private Offsets offsets = new Offsets(); /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java index 069e1991976..54a69367ca6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java @@ -11,6 +11,8 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.internal.core.parser.ast.Offsets; @@ -57,16 +59,16 @@ public class ASTUsingDirective /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } private Offsets offsets = new Offsets(); /* (non-Javadoc) @@ -88,4 +90,11 @@ public class ASTUsingDirective public void exitScope(ISourceElementRequestor requestor) { } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceDefinition() + */ + public IASTNamespaceDefinition getNamespaceDefinition() throws ASTNotImplementedException + { + throw new ASTNotImplementedException(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java index 647ed8c51b8..5f2157fa1ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.internal.core.parser.ast.*; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** @@ -141,28 +142,28 @@ public class ASTVariable extends ASTDeclaration implements IASTVariable /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() */ - public int getElementStartingOffset() + public int getStartingOffset() { - return offsets.getElementStartingOffset(); + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() */ - public int getElementEndingOffset() + public int getEndingOffset() { - return offsets.getElementEndingOffset(); + return offsets.getEndingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() */ - public int getElementNameOffset() + public int getNameOffset() { - return offsets.getElementNameOffset(); + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setElementNameOffset(int o) + public void setNameOffset(int o) { offsets.setNameOffset(o); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index de541dfa739..cc11d03c40b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -15,7 +15,6 @@ import java.util.List; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTSemanticException; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; @@ -25,7 +24,6 @@ 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.IASTConstructorMemberInitializer; -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; @@ -59,7 +57,6 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; /** * @author jcamelon @@ -90,7 +87,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory public IASTNamespaceDefinition createNamespaceDefinition(IASTScope scope, String identifier, int first, int nameOffset) { IASTNamespaceDefinition definition = new ASTNamespaceDefinition( scope, identifier ); definition.setStartingOffset( first ); - definition.setElementNameOffset( nameOffset ); + definition.setNameOffset( nameOffset ); return definition; } @@ -118,10 +115,10 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, org.eclipse.cdt.core.parser.ast.ClassKind, org.eclipse.cdt.core.parser.ast.ClassNameType, org.eclipse.cdt.core.parser.ast.AccessVisibility, org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) */ - public IASTClassSpecifier createClassSpecifier(IASTScope scope, String name, ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, IASTTemplate ownerTemplateDeclaration, int startingOffset, int nameOffset) { - IASTClassSpecifier spec = new ASTClassSpecifier( scope, name, kind, type, access, ownerTemplateDeclaration ); + public IASTClassSpecifier createClassSpecifier(IASTScope scope, String name, ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, int startingOffset, int nameOffset) throws ASTSemanticException { + IASTClassSpecifier spec = new ASTClassSpecifier( scope, name, kind, type, access ); spec.setStartingOffset( startingOffset ); - spec.setElementNameOffset( nameOffset ); + spec.setNameOffset( nameOffset ); return spec; } @@ -321,14 +318,4 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory { return new ASTPointerToMethod(scope, name, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, isConst, isVolatile, isConstructor, isDestructor, isVirtual, isExplicit, isPureVirtual, visibility, pointerOperator); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSymbolTableDeclarationExtension(org.eclipse.cdt.core.parser.ast.IASTDeclaration, org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public ISymbolASTExtension createSymbolTableDeclarationExtension(IASTDeclaration declaration, IASTDeclaration definition) throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java new file mode 100644 index 00000000000..582a3535e3c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java @@ -0,0 +1,45 @@ +/********************************************************************** + * 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.internal.core.parser.pst; + +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; + +/** + * @author jcamelon + * + */ +public abstract class AbstractSymbolExtension implements ISymbolASTExtension +{ + protected final ISymbol symbol; + protected final ASTSymbol primaryDeclaration; + + /** + * + */ + public AbstractSymbolExtension( ISymbol symbol, ASTSymbol primaryDeclaration ) + { + this.symbol = symbol; + this.primaryDeclaration = primaryDeclaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() + */ + public ISymbol getSymbol() + { + return symbol; + } + + public ASTSymbol getPrimaryDeclaration() + { + return primaryDeclaration; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java new file mode 100644 index 00000000000..c18052d3d00 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java @@ -0,0 +1,109 @@ +/********************************************************************** + * 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.internal.core.parser.pst; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; + +/** + * @author jcamelon + * + */ +public class ForewardDeclaredSymbolExtension extends AbstractSymbolExtension +{ + /** + * @author jcamelon + * + */ + private class DualIterator implements Iterator + { + private int state = 0; + /** + * + */ + public DualIterator() + { + super(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + if( state == 0 ) return true; + if( state == 1 && definitionSymbol != null ) return true; + return false; + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() + { + switch( state ) + { + case 0: + state = 1; + return primaryDeclaration; + case 1: + if( definitionSymbol != null ) + { + state = 2; + return definitionSymbol; + } + break; + } + throw new NoSuchElementException(); + + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + } + + protected ASTSymbol definitionSymbol = null; + /** + * @param symbol + * @param primaryDeclaration + */ + public ForewardDeclaredSymbolExtension( + ISymbol symbol, + ASTSymbol primaryDeclaration) + { + super(symbol, primaryDeclaration); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() + */ + public Iterator getAllDefinitions() + { + return new DualIterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) + */ + public void addDefinition(ASTSymbol definition) throws ExtensionException + { + if( definitionSymbol != null ) + throw new ExtensionException(); + definitionSymbol = definition; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java index 5c9c7213aea..9b5d325b94f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java @@ -25,8 +25,8 @@ public interface ISymbol { public Object clone(); - public ISymbolASTExtension getASTNode(); - public void setASTNode( ISymbolASTExtension obj ); + public ISymbolASTExtension getASTExtension(); + public void setASTExtension( ISymbolASTExtension obj ); public String getName(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java index 35c98c89222..9555a4d633d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java @@ -10,7 +10,9 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.pst; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import java.util.Iterator; + +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; /** * @author jcamelon @@ -18,8 +20,13 @@ import org.eclipse.cdt.core.parser.ast.IASTDeclaration; */ public interface ISymbolASTExtension extends ISymbolOwner { - public IASTDeclaration getDeclaration(); - public IASTDeclaration getDefinition(); - public void setDefinition( IASTDeclaration definition ); - public boolean hasBeenDefined(); + public class ExtensionException extends Exception + { + } + + + public ASTSymbol getPrimaryDeclaration(); + public Iterator getAllDefinitions(); + public void addDefinition( ASTSymbol definition ) throws ExtensionException; + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java index b5ed01bc735..3f89e8b49b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java @@ -17,6 +17,4 @@ package org.eclipse.cdt.internal.core.parser.pst; public interface ISymbolOwner { public ISymbol getSymbol(); - public void setSymbol( ISymbol s ); - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java new file mode 100644 index 00000000000..aafefa1092d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java @@ -0,0 +1,99 @@ +/********************************************************************** + * 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.internal.core.parser.pst; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; + +/** + * @author jcamelon + * + */ +public class NamespaceSymbolExtension extends AbstractSymbolExtension +{ + /** + * @author jcamelon + * + */ + private class LocalIterator implements Iterator + { + private boolean donePrimary = false; + private Iterator secondaries = otherDefinitions.iterator(); + /** + * + */ + public LocalIterator() + { + super(); + } + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + if( ! donePrimary ) return true; + return secondaries.hasNext(); + } + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() + { + if( ! hasNext() ) + throw new NoSuchElementException(); + + if( ! donePrimary ) + { + donePrimary = true; + return primaryDeclaration; + } + + return secondaries.next(); + } + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + } + protected List otherDefinitions = new ArrayList(); + /** + * @param symbol + * @param primaryDeclaration + */ + public NamespaceSymbolExtension( + ISymbol symbol, + ASTSymbol primaryDeclaration) + { + super(symbol, primaryDeclaration); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() + */ + public Iterator getAllDefinitions() + { + return new LocalIterator(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) + */ + public void addDefinition(ASTSymbol definition) throws ExtensionException + { + otherDefinitions.add( definition ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 4814872c3c2..c58c09ef4a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -2067,8 +2067,8 @@ public class ParserSymbolTable { public String getName() { return _name; } public void setName(String name) { _name = name; } - public ISymbolASTExtension getASTNode() { return _object; } - public void setASTNode( ISymbolASTExtension obj ) { _object = obj; } + public ISymbolASTExtension getASTExtension() { return _object; } + public void setASTExtension( ISymbolASTExtension obj ) { _object = obj; } public IContainerSymbol getContainingSymbol() { return _containingScope; } public void setContainingSymbol( IContainerSymbol scope ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java new file mode 100644 index 00000000000..0c95cd5f150 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java @@ -0,0 +1,95 @@ +/********************************************************************** + * 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.internal.core.parser.pst; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; + + +/** + * @author jcamelon + * + */ +public class StandardSymbolExtension extends AbstractSymbolExtension +{ + + /** + * @author jcamelon + * + */ + private class SimpleIterator implements Iterator + { + boolean hasNext = true; + /** + * + */ + public SimpleIterator() + { + } + + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return hasNext; + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() + { + if( hasNext ) + { + hasNext = false; + return primaryDeclaration; + } + + throw new NoSuchElementException(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + } + /** + * @param symbol + * @param primaryDeclaration + */ + public StandardSymbolExtension(ISymbol symbol, ASTSymbol primaryDeclaration) + { + super(symbol, primaryDeclaration); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() + */ + public Iterator getAllDefinitions() + { + return this.new SimpleIterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) + */ + public void addDefinition(ASTSymbol definition) throws ExtensionException + { + throw new ExtensionException(); + } + +} diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index 3026f3fc4e9..2333e1781e8 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -328,9 +328,9 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants } } - int offset = node.getElementNameOffset(); + int offset = node.getNameOffset(); if( offset == 0 ) - offset = node.getElementStartingOffset(); + offset = node.getStartingOffset(); if( currentResource != null ){