diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 492aabd0777..9037eb299f7 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-07-24 John Camelon + Updated CompleteParseASTTests for Method/Field updates. + Fixed TortureTest's parser mode switch (was always QuickParsing). + 2003-07-24 Hoda Amer Moved part of the CModelElementsTest (Templates of Variables ) to the failed tests. Moved the same test (Templates of Variables) from ITemplateTests to failed tests. 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 index 264e791edb9..228beba0c51 100644 --- 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 @@ -48,6 +48,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; +import org.eclipse.cdt.core.parser.ast.IASTReference; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; @@ -705,6 +706,65 @@ public class CompleteParseASTTest extends TestCase assertEquals( ((IASTSimpleTypeSpecifier)varE.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), enumE ); } + public void testSimpleFunction() throws Exception + { + Iterator declarations = parse( "void foo( void );").getDeclarations(); + IASTFunction function = (IASTFunction)declarations.next(); + assertEquals( function.getName(), "foo" ); + assertEquals( callback.getReferences().size(), 0 ); + } + + public void testSimpleFunctionWithTypes() throws Exception + { + Iterator declarations = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );").getDeclarations(); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + IASTFunction function = (IASTFunction)declarations.next(); + assertEquals( callback.getReferences().size(), 3 ); + } + + public void testSimpleMethod() throws Exception + { + Iterator declarations = parse( "class A { void foo(); };").getDeclarations(); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); + assertEquals( method.getName(), "foo" ); + } + + public void testSimpleMethodWithTypes() throws Exception + { + Iterator declarations = parse( "class U { }; class A { U foo( U areDumb ); };").getDeclarations(); + IASTClassSpecifier classU = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); + assertEquals( method.getName(), "foo" ); + assertEquals( callback.getReferences().size(), 2 ); + } + + public void testUsingDeclarationWithFunctionsAndMethods() throws Exception + { + Iterator declarations = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ).getDeclarations(); + IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); + IASTFunction fooFunction = (IASTFunction)(getDeclarations(namespaceN).next()); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + IASTMethod methodM = (IASTMethod)(getDeclarations(classA).next()); + IASTUsingDeclaration using1 = (IASTUsingDeclaration)declarations.next(); + IASTUsingDeclaration using2 = (IASTUsingDeclaration)declarations.next(); + assertEquals( callback.getReferences().size(), 4 ); + Iterator references = callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), namespaceN ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), fooFunction ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), classA ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), methodM ); + } + + public void testLinkageSpec() throws Exception + { + IASTLinkageSpecification linkage = (IASTLinkageSpecification)parse( "extern \"C\" { int foo(); }").getDeclarations().next(); + Iterator i = getDeclarations( linkage ); + IASTFunction f = (IASTFunction)i.next(); + assertEquals( f.getName(),"foo"); + } + protected void assertQualifiedName(String [] fromAST, String [] theTruth) { assertNotNull( fromAST ); @@ -715,4 +775,6 @@ public class CompleteParseASTTest extends TestCase assertEquals( fromAST[i], theTruth[i]); } } + + } 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 7bb095a6387..6139a4e19a7 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,7 +18,6 @@ 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.ASTSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; @@ -26,6 +25,7 @@ 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.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance; @@ -102,52 +102,12 @@ 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 NullSymbolExtension (); + ISymbolASTExtension extension = new StandardSymbolExtension(x,null); x.setASTExtension( extension ); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java index 942cb1a8717..a56f0a18cc5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java @@ -277,9 +277,10 @@ public class TortureTest extends FractionalAutomatedTest { public void run(){ try { - DOMBuilder domBuilder = new DOMBuilder(); + DOMBuilder domBuilder = new DOMBuilder(); + ParserMode parserMode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; parser = ParserFactory.createParser( - ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), ParserMode.QUICK_PARSE, nullCallback ), nullCallback, ParserMode.QUICK_PARSE); + ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), parserMode, nullCallback ), nullCallback, parserMode); parser.setCppNature(cppNature); mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) ); diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 1521a6bf679..a9a67e1672d 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-07-24 John Camelon + Added COMPLETE_PARSE support for Method and Field declarations and cross-references. + Fixed some small ParserSymbolTable bugs. + Added support for linkage specification under COMPLETE_PARSE. + 2003-07-24 John Camelon Added CompleteParse - UsingDirective & UsingDeclarations w/namespace/class/field variable references. Added CompleteParse support for enumeration specifiers and references in variables & fields. 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 df687cec552..08ea4a02f99 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 @@ -134,7 +134,7 @@ public interface IASTFactory boolean isStatic, int startOffset, int nameOffset, - IASTTemplate ownerTemplate); + IASTTemplate ownerTemplate) throws ASTSemanticException; public IASTAbstractDeclaration createAbstractDeclaration( boolean isConst, IASTTypeSpecifier typeSpecifier, @@ -159,7 +159,7 @@ public interface IASTFactory boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - ASTAccessVisibility visibility); + ASTAccessVisibility visibility) throws ASTSemanticException; public IASTVariable createVariable(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset ) throws ASTSemanticException; 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 1c268f79138..c716c7cf2cc 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 @@ -363,7 +363,7 @@ public class DeclarationWrapper implements IDeclaratorOwner * @param declarator * @return */ - private IASTMethod createMethodASTNode(Declarator declarator) + private IASTMethod createMethodASTNode(Declarator declarator) throws ASTSemanticException { return astFactory .createMethod( @@ -396,7 +396,7 @@ public class DeclarationWrapper implements IDeclaratorOwner * @param declarator * @return */ - private IASTFunction createFunctionASTNode(Declarator declarator) + private IASTFunction createFunctionASTNode(Declarator declarator) throws ASTSemanticException { return astFactory.createFunction( scope, 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 1c2236a74bb..1da1c53fdf2 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 @@ -897,7 +897,7 @@ public class Parser implements IParser } protected void handleFunctionBody(Declarator d) throws Backtrack, EndOfFile { - if (mode == ParserMode.QUICK_PARSE) + if ( true ) // TODO - Enable parsing within function bodies i.e. mode == ParserMode.QUICK_PARSE) { // speed up the parser by skiping the body // simply look for matching brace and return diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTParameterDeclaration.java similarity index 98% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTParameterDeclaration.java index 6b5ded9ce08..18d7a2d27ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTParameterDeclaration.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.Iterator; import java.util.List; 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 9ed2cc25f66..c444f1b4d8f 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 @@ -10,8 +10,14 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.ast; +import java.util.List; + +import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTInclusion; +import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; import org.eclipse.cdt.core.parser.ast.IASTMacro; +import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; /** @@ -42,5 +48,15 @@ public class BaseASTFactory { return inclusion; } + public IASTAbstractDeclaration createAbstractDeclaration(boolean isConst, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers) + { + return new ASTAbstractDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers ); + } + + public IASTParameterDeclaration createParameterDeclaration(boolean isConst, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, String parameterName, IASTInitializerClause initializerClause) + { + return new ASTParameterDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers, parameterName, initializerClause ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java index b4ea06f9565..589535ed6ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java @@ -11,196 +11,200 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.Iterator; +import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTFunction; -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; +import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; +import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; /** * @author jcamelon * */ -public class ASTFunction implements IASTFunction +public class ASTFunction extends ASTScope implements IASTFunction { + private boolean hasFunctionBody = false; + private final IASTTemplate ownerTemplate; + private final IASTAbstractDeclaration returnType; + private final IASTExceptionSpecification exception; + private NamedOffsets offsets = new NamedOffsets(); + private final ASTQualifiedNamedElement qualifiedName; + private final List parameters; + protected final ASTReferenceStore references; + /** - * + * @param symbol + * @param parameters + * @param returnType + * @param exception + * @param startOffset + * @param nameOffset + * @param ownerTemplate + * @param references */ - public ASTFunction() + public ASTFunction(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references) { - super(); - // TODO Auto-generated constructor stub + super( symbol ); + this.parameters = parameters; + + this.returnType = returnType; + this.exception = exception; + setStartingOffset(startOffset); + setNameOffset(nameOffset); + this.ownerTemplate = ownerTemplate; + this.references = new ASTReferenceStore( references ); + qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); } + + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isInline() */ public boolean isInline() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isInline ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend() */ public boolean isFriend() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isFriend ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isStatic() */ public boolean isStatic() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isStatic ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() */ public String getName() { - // TODO Auto-generated method stub - return null; + return symbol.getName(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getReturnType() */ public IASTAbstractDeclaration getReturnType() { - // TODO Auto-generated method stub - return null; + return returnType; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getParameters() */ public Iterator getParameters() { - // TODO Auto-generated method stub - return null; + return parameters.iterator(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getExceptionSpec() */ public IASTExceptionSpecification getExceptionSpec() { - // TODO Auto-generated method stub - return null; + return exception; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionBody(boolean) */ public void setHasFunctionBody(boolean b) { - // TODO Auto-generated method stub + hasFunctionBody = true; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody() */ public boolean hasFunctionBody() { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException - { - // TODO Auto-generated method stub - return null; + return hasFunctionBody; } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() */ public int getNameOffset() { - // TODO Auto-generated method stub - return 0; + return offsets.getNameOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ public void setNameOffset(int o) { - // TODO Auto-generated method stub + offsets.setNameOffset(o); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() */ public IASTTemplate getOwnerTemplateDeclaration() { - // TODO Auto-generated method stub - return null; + return ownerTemplate; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() */ public String[] getFullyQualifiedName() { - // TODO Auto-generated method stub - return null; + return qualifiedName.getFullyQualifiedName(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) */ public void setStartingOffset(int o) { - // TODO Auto-generated method stub + offsets.setStartingOffset(o); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) */ public void setEndingOffset(int o) { - // TODO Auto-generated method stub + offsets.setEndingOffset(o); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() */ public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() */ public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - // TODO Auto-generated method stub - return null; + 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 + requestor.acceptFunctionDeclaration(this); + references.processReferences(requestor); } /* (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 + requestor.enterFunctionBody( this ); + references.processReferences(requestor); } /* (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 + requestor.exitFunctionBody( this ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java new file mode 100644 index 00000000000..a232e623eea --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java @@ -0,0 +1,65 @@ +/********************************************************************** + * 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.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; +import org.eclipse.cdt.core.parser.ast.IASTReference; + +/** + * @author jcamelon + * + */ +public class ASTFunctionReference + extends ASTReference + implements IASTReference, IASTFunctionReference +{ + private final IASTFunction declaration; + /** + * @param offset + * @param name + */ + public ASTFunctionReference(int offset, String name, IASTFunction referencedDeclaration ) + { + super(offset, name); + this.declaration = referencedDeclaration; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() + */ + public ISourceElementCallbackDelegate getReferencedElement() + { + return declaration; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + requestor.acceptFunctionReference( 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) + { + + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java index 6b4a7cb0705..9d717d61cb9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java @@ -15,95 +15,87 @@ import java.util.Iterator; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; +import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; /** * @author jcamelon * */ -public class ASTLinkageSpecification implements IASTLinkageSpecification +public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements IASTLinkageSpecification { + private final String linkageString; + private Offsets offsets = new Offsets(); /** * */ - public ASTLinkageSpecification() + public ASTLinkageSpecification( IContainerSymbol scope, String linkageString, int startingOffset ) { - super(); - // TODO Auto-generated constructor stub + super( scope ); + this.linkageString = linkageString; + setStartingOffset(startingOffset); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification#getLinkageString() */ public String getLinkageString() { - // TODO Auto-generated method stub - return null; + return linkageString; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() */ public Iterator getDeclarations() throws ASTNotImplementedException { - // TODO Auto-generated method stub - return null; + throw new ASTNotImplementedException(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) */ public void setStartingOffset(int o) { - // TODO Auto-generated method stub + offsets.setStartingOffset(o); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) */ public void setEndingOffset(int o) { - // TODO Auto-generated method stub + offsets.setEndingOffset(o); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() */ public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; + return offsets.getStartingOffset(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() */ public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - // TODO Auto-generated method stub - return null; + 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 + requestor.enterLinkageSpecification(this); } /* (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 + requestor.exitLinkageSpecification(this); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java index 74680fea676..7cd8683f0d6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java @@ -10,262 +10,133 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.ast.complete; -import java.util.Iterator; +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.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; +import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; /** * @author jcamelon * */ -public class ASTMethod implements IASTMethod +public class ASTMethod extends ASTFunction implements IASTMethod { + private final boolean isConstructor; + private final boolean isPureVirtual; + private final ASTAccessVisibility visibility; + private final boolean isDestructor; /** - * + * @param symbol + * @param parameters + * @param returnType + * @param exception + * @param startOffset + * @param nameOffset + * @param ownerTemplate + * @param references */ - public ASTMethod() + public ASTMethod(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, + boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility ) { - super(); - // TODO Auto-generated constructor stub + super( + symbol, + parameters, + returnType, + exception, + startOffset, + nameOffset, + ownerTemplate, + references); + this.visibility = visibility; + this.isConstructor = isConstructor; + this.isDestructor = isDestructor; + this.isPureVirtual = isPureVirtual; + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVirtual() */ public boolean isVirtual() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isVirtual ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isExplicit() */ public boolean isExplicit() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isExplicit); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConstructor() */ public boolean isConstructor() { - // TODO Auto-generated method stub - return false; + return isConstructor; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isDestructor() */ public boolean isDestructor() { - // TODO Auto-generated method stub - return false; + return isDestructor; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConst() */ public boolean isConst() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isConst); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVolatile() */ public boolean isVolatile() { - // TODO Auto-generated method stub - return false; + return symbol.getTypeInfo().checkBit( TypeInfo.isVolatile ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isPureVirtual() */ public boolean isPureVirtual() { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isInline() - */ - public boolean isInline() - { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend() - */ - public boolean isFriend() - { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isStatic() - */ - public boolean isStatic() - { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getReturnType() - */ - public IASTAbstractDeclaration getReturnType() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getParameters() - */ - public Iterator getParameters() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getExceptionSpec() - */ - public IASTExceptionSpecification getExceptionSpec() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionBody(boolean) - */ - public void setHasFunctionBody(boolean b) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody() - */ - public boolean hasFunctionBody() - { - // TODO Auto-generated method stub - return false; + return isPureVirtual; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity() */ public ASTAccessVisibility getVisiblity() { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() - */ - public IASTTemplate getOwnerTemplateDeclaration() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffset(int o) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffset(int o) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - // TODO Auto-generated method stub - return null; + return visibility; } + /* (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 + requestor.acceptMethodDeclaration(this); + references.processReferences(requestor); } /* (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 + requestor.enterMethodBody(this); + references.processReferences(requestor); } /* (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 + requestor.exitMethodBody( this ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java new file mode 100644 index 00000000000..8e4a12213ab --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java @@ -0,0 +1,62 @@ +/********************************************************************** + * 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.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTMethodReference; + +/** + * @author jcamelon + * + */ +public class ASTMethodReference + extends ASTReference + implements IASTMethodReference +{ + private final IASTMethod method; + /** + * @param offset + * @param name + */ + public ASTMethodReference(int offset, String name, IASTMethod method ) + { + super(offset, name); + this.method = method; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() + */ + public ISourceElementCallbackDelegate getReferencedElement() + { + return method; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + requestor.acceptMethodReference( 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) + { + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java deleted file mode 100644 index 3ee742019e7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java +++ /dev/null @@ -1,81 +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 java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; - -/** - * @author jcamelon - * - */ -public class ASTParameterDeclaration implements IASTParameterDeclaration -{ - /** - * - */ - public ASTParameterDeclaration() - { - super(); - // TODO Auto-generated constructor stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getName() - */ - public String getName() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getDefaultValue() - */ - public IASTInitializerClause getDefaultValue() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#isConst() - */ - public boolean isConst() - { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getPointerOperators() - */ - public Iterator getPointerOperators() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getArrayModifiers() - */ - public Iterator getArrayModifiers() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() - { - // TODO Auto-generated method stub - return null; - } -} 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 6f02b44a300..d5c0c5ce4f4 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 @@ -58,12 +58,12 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescripto import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; 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.ASTAbstractDeclaration; 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.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.ISymbolOwner; @@ -150,7 +150,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } protected IContainerSymbol scopeToSymbol(IASTScope currentScope) { - return ((ASTScope)currentScope).getContainerSymbol(); + if( currentScope instanceof ASTScope ) + return ((ASTScope)currentScope).getContainerSymbol(); + else + return scopeToSymbol(((ASTAnonymousDeclaration)currentScope).getOwnerScope()); } /* (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) @@ -319,8 +322,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto String spec, int startingOffset) { - // TODO FIX THIS - return new ASTLinkageSpecification(); + return new ASTLinkageSpecification( scopeToSymbol( scope ), spec, startingOffset ); } /* (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.ASTClassKind, org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, org.eclipse.cdt.core.parser.ast.IASTTemplate, int, int) @@ -414,6 +416,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto */ protected IASTReference createReference(ISymbol symbol, String string, int offset ) throws ASTSemanticException { + if( symbol == null ) + throw new ASTSemanticException(); + if( symbol.getType() == TypeInfo.t_namespace ) { return new ASTNamespaceReference( offset, string, (IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration()); @@ -426,6 +431,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } else if( symbol.getType() == TypeInfo.t_enumeration ) return new ASTEnumerationReference( offset, string, (IASTEnumerationSpecifier)symbol.getASTExtension().getPrimaryDeclaration() ); + else if( symbol.getType() == TypeInfo.t_function ) + { + if( symbol.getContainingSymbol().getTypeInfo().isType( TypeInfo.t_class, TypeInfo.t_union ) ) + return new ASTMethodReference( offset, string, (IASTMethod)symbol.getASTExtension().getPrimaryDeclaration() ); + else + return new ASTFunctionReference( offset, string, (IASTFunction)symbol.getASTExtension().getPrimaryDeclaration() ); + } else if( ( symbol.getType() == TypeInfo.t_type ) || ( symbol.getType() == TypeInfo.t_bool )|| ( symbol.getType() == TypeInfo.t_char ) || @@ -645,17 +657,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto Iterator i = typeName.iterator(); IToken first = typeName.getFirstToken(); - ISymbol typeSymbol = null; - if( first.getType() == IToken.tCOLONCOLON ) - { - typeSymbol = pst.getCompilationUnit(); - i.next(); // waste this token - } - else - { - typeSymbol = scopeToSymbol( scope ); - } - + ISymbol typeSymbol = getScopeToSearchUpon( scope, first, i ); + while( i.hasNext() ) { IToken current = (IToken)i.next(); @@ -700,22 +703,171 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto boolean isStatic, int startOffset, int nameOffset, - IASTTemplate ownerTemplate) + IASTTemplate ownerTemplate) throws ASTSemanticException { - // TODO Auto-generated method stub - return new ASTFunction(); + IContainerSymbol ownerScope = scopeToSymbol( scope ); + IParameterizedSymbol symbol = pst.newParameterizedSymbol( name, TypeInfo.t_function ); + setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); + List references = new ArrayList(); + + try + { + ownerScope.addSymbol( symbol ); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + + setParameter( symbol, returnType, false, references ); + setParameters( symbol, references, parameters.iterator() ); + + ASTFunction function = new ASTFunction( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references ); + try + { + attachSymbolExtension(symbol, function); + } + catch (ExtensionException e1) + { + throw new ASTSemanticException(); + } + return function; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createAbstractDeclaration(boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List) + protected void setFunctionTypeInfoBits( + boolean isInline, + boolean isFriend, + boolean isStatic, + IParameterizedSymbol symbol) + { + symbol.getTypeInfo().setBit( isInline, TypeInfo.isInline ); + symbol.getTypeInfo().setBit( isFriend, TypeInfo.isFriend ); + symbol.getTypeInfo().setBit( isStatic, TypeInfo.isStatic ); + } + + /** + * @param symbol + * @param iterator */ - public IASTAbstractDeclaration createAbstractDeclaration( - boolean isConst, - IASTTypeSpecifier typeSpecifier, - List pointerOperators, - List arrayModifiers) + protected void setParameters(IParameterizedSymbol symbol, List references, Iterator iterator) throws ASTSemanticException { - return new ASTAbstractDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers ); + while( iterator.hasNext() ) + { + setParameter( symbol, (IASTParameterDeclaration)iterator.next(), true, references ); + } } + + /** + * @param symbol + * @param returnType + */ + protected void setParameter(IParameterizedSymbol symbol, IASTAbstractDeclaration absDecl, boolean isParameter, List references) throws ASTSemanticException + { + TypeInfo.eType type = null; + ISymbol xrefSymbol = null; + List newReferences = null; + if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) + { + IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType(); + if( kind == IASTSimpleTypeSpecifier.Type.BOOL ) + type = TypeInfo.t_bool; + else if( kind == IASTSimpleTypeSpecifier.Type.CHAR ) + type = TypeInfo.t_char; + else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE ) + type = TypeInfo.t_double; + else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT ) + type = TypeInfo.t_float; + else if( kind == IASTSimpleTypeSpecifier.Type.INT ) + type = TypeInfo.t_int; + else if( kind == IASTSimpleTypeSpecifier.Type.VOID ) + type = TypeInfo.t_void; + else if( kind == IASTSimpleTypeSpecifier.Type.WCHAR_T) + type = TypeInfo.t_wchar_t; + else if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ) + { + type = TypeInfo.t_type; + xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol(); + newReferences = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getReferences(); + } + else + throw new ASTSemanticException(); + } + else if( absDecl.getTypeSpecifier() instanceof IASTClassSpecifier ) + { + ASTClassKind kind = ((IASTClassSpecifier)absDecl.getTypeSpecifier()).getClassKind(); + if( kind == ASTClassKind.CLASS ) + type = TypeInfo.t_class; + else if( kind == ASTClassKind.STRUCT ) + type = TypeInfo.t_struct; + else if( kind == ASTClassKind.UNION ) + type = TypeInfo.t_union; + else + throw new ASTSemanticException(); + } + else if( absDecl.getTypeSpecifier() instanceof IASTEnumerationSpecifier ) + { + type = TypeInfo.t_enumeration; + } + else if( absDecl.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier ) + { + ASTClassKind kind = ((IASTElaboratedTypeSpecifier)absDecl.getTypeSpecifier()).getClassKind(); + if( kind == ASTClassKind.CLASS ) + type = TypeInfo.t_class; + else if( kind == ASTClassKind.STRUCT ) + type = TypeInfo.t_struct; + else if( kind == ASTClassKind.UNION ) + type = TypeInfo.t_union; + else if( kind == ASTClassKind.ENUM ) + type = TypeInfo.t_enumeration; + else + throw new ASTSemanticException(); + } + else + throw new ASTSemanticException(); + + ISymbol paramSymbol = pst.newSymbol( "", type ); + if( xrefSymbol != null ) + paramSymbol.setTypeSymbol( xrefSymbol ); + + setPointerOperators( paramSymbol, absDecl.getPointerOperators(), absDecl.getArrayModifiers() ); + + if( isParameter) + symbol.addParameter( paramSymbol ); + else + symbol.setReturnType( paramSymbol ); + + if( newReferences != null ) + references.addAll( newReferences ); + + } + + /** + * @param paramSymbol + * @param iterator + */ + protected void setPointerOperators(ISymbol symbol, Iterator pointerOpsIterator, Iterator arrayModsIterator) throws ASTSemanticException + { + while( pointerOpsIterator.hasNext() ) + { + ASTPointerOperator pointerOperator = (ASTPointerOperator)pointerOpsIterator.next(); + if( pointerOperator == ASTPointerOperator.REFERENCE ) + symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference )); + else if( pointerOperator == ASTPointerOperator.POINTER ) + symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_pointer )); + else if( pointerOperator == ASTPointerOperator.CONST_POINTER ) + symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_pointer, true, false )); + else if( pointerOperator == ASTPointerOperator.VOLATILE_POINTER ) + symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_pointer, false, true)); + else + throw new ASTSemanticException(); + } + + while( arrayModsIterator.hasNext() ) + { + IASTArrayModifier astArrayModifier = (IASTArrayModifier)arrayModsIterator.next(); + symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_array )); + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(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, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) */ @@ -738,11 +890,55 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - ASTAccessVisibility visibility) + ASTAccessVisibility visibility) throws ASTSemanticException { - // TODO Auto-generated method stub - return new ASTMethod(); + IContainerSymbol ownerScope = scopeToSymbol( scope ); + IParameterizedSymbol symbol = pst.newParameterizedSymbol( name, TypeInfo.t_function ); + setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); + setMethodTypeInfoBits( symbol, isConst, isVolatile, isVirtual, isExplicit ); + List references = new ArrayList(); + + try + { + ownerScope.addSymbol( symbol ); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + + setParameter( symbol, returnType, false, references ); + setParameters( symbol, references, parameters.iterator() ); + + ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, isConstructor, isDestructor, isPureVirtual, visibility ); + try + { + attachSymbolExtension( symbol, method ); + } + catch (ExtensionException e1) + { + throw new ASTSemanticException(); + } + return method; } + /** + * @param symbol + * @param isConst + * @param isVolatile + * @param isConstructor + * @param isDestructor + * @param isVirtual + * @param isExplicit + * @param isPureVirtual + */ + protected void setMethodTypeInfoBits(IParameterizedSymbol symbol, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit) + { + symbol.getTypeInfo().setBit( isConst, TypeInfo.isConst ); + symbol.getTypeInfo().setBit( isVolatile, TypeInfo.isConst ); + symbol.getTypeInfo().setBit( isVirtual, TypeInfo.isVirtual ); + symbol.getTypeInfo().setBit( isExplicit, TypeInfo.isExplicit ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createVariable(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean, int, int) */ @@ -761,8 +957,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto int nameOffset) throws ASTSemanticException { List references = new ArrayList(); - ISymbol newSymbol = cloneSimpleTypeSymbol(scope, name, abstractDeclaration, references); - setSymbolBits( + ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references); + setVariableTypeInfoBits( isAuto, abstractDeclaration, isMutable, @@ -770,6 +966,15 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto isRegister, isStatic, newSymbol); + setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() ); + try + { + scopeToSymbol(scope).addSymbol( newSymbol ); + } + catch (ParserSymbolTableException e) + { + // TODO Auto-generated catch block + } ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references ); try @@ -782,7 +987,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } return variable; } - private void setSymbolBits( + protected void setVariableTypeInfoBits( boolean isAuto, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, @@ -799,7 +1004,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto newSymbol.getTypeInfo().setBit( abstractDeclaration.isConst(), TypeInfo.isConst ); } protected ISymbol cloneSimpleTypeSymbol( - IASTScope scope, String name, IASTAbstractDeclaration abstractDeclaration, List references) @@ -810,15 +1014,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ISymbol symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol(); newSymbol = (ISymbol)symbolToBeCloned.clone(); newSymbol.setName( name ); - IContainerSymbol containerSymbol = scopeToSymbol(scope); - try - { - containerSymbol.addSymbol( newSymbol ); - } - catch (ParserSymbolTableException e) - { - // TODO Auto-generated catch block - } references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() ); } return newSymbol; @@ -842,8 +1037,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ASTAccessVisibility visibility) throws ASTSemanticException { List references = new ArrayList(); - ISymbol newSymbol = cloneSimpleTypeSymbol(scope, name, abstractDeclaration, references); - setSymbolBits( + ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references); + setVariableTypeInfoBits( isAuto, abstractDeclaration, isMutable, @@ -851,6 +1046,16 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto isRegister, isStatic, newSymbol); + setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() ); + + try + { + scopeToSymbol(scope).addSymbol( newSymbol ); + } + catch (ParserSymbolTableException e) + { + // TODO Auto-generated catch block + } ASTField field = new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, visibility ); try { @@ -864,20 +1069,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createParameterDeclaration(boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTInitializerClause) - */ - public IASTParameterDeclaration createParameterDeclaration( - boolean isConst, - IASTTypeSpecifier getTypeSpecifier, - List pointerOperators, - List arrayModifiers, - String parameterName, - IASTInitializerClause initializerClause) - { - // TODO Auto-generated method stub - return new ASTParameterDeclaration(); - } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, java.util.List, boolean, int) */ 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 8cca16d3b32..2ae3f3ab4f8 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 @@ -55,7 +55,6 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; 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.*; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; @@ -217,14 +216,6 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory return new ASTFunction(scope, name, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate ); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createAbstractDeclaration(boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List) - */ - public IASTAbstractDeclaration createAbstractDeclaration(boolean isConst, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers) - { - return new ASTAbstractDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers ); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(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.IASTTemplateDeclaration, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) */ @@ -249,14 +240,6 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory return new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, nameOffset, visibility); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createParameterDeclaration(boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTInitializerClause) - */ - public IASTParameterDeclaration createParameterDeclaration(boolean isConst, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, String parameterName, IASTInitializerClause initializerClause) - { - return new ASTParameterDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers, parameterName, initializerClause ); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateDeclaration(java.util.List) */ 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 f1a9ed6eceb..78a22ce37dd 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 @@ -2117,7 +2117,10 @@ public class ParserSymbolTable { if( size != size2 ){ return size2 - size; - } else { + } else if( size == 0 ) + return 0; + else { + Iterator iter1 = symbol.getTypeInfo().getPtrOperators().iterator(); Iterator iter2 = getTypeInfo().getPtrOperators().iterator(); @@ -2560,7 +2563,9 @@ public class ParserSymbolTable { throw new ParserSymbolTableException(); } - if( unnamed || ((origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) )){ + boolean validOverride = ((origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) ); + if( unnamed || validOverride ) + { if( origList == null ){ origList = new LinkedList(); origList.add( origDecl );