mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes order of ambiguity resolution, bug 259373.
This commit is contained in:
parent
29d9ee28c1
commit
a3c36bd408
28 changed files with 724 additions and 537 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
|||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
|
||||
|
||||
/**
|
||||
* Tests for C model builder bugs.
|
||||
|
@ -56,7 +55,6 @@ public class CModelBuilderBugsTest extends BaseTestCase {
|
|||
}
|
||||
|
||||
public void testModelBuilderBug222398() throws Exception {
|
||||
CPPASTNameBase.sAllowNameComputation= true;
|
||||
IStructure clazz= (IStructure) fTU.getElement("Test");
|
||||
assertNotNull(clazz);
|
||||
ICElement[] methods= clazz.getChildren();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -4390,7 +4390,9 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, false, 0);
|
||||
}
|
||||
|
||||
// template<typename T> class complex {};
|
||||
// template<typename T> class complex {
|
||||
// complex(T,T) {}
|
||||
// };
|
||||
// template<class T> class Array {
|
||||
// T* v;
|
||||
// int sz;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -6374,4 +6374,33 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
ba.assertNonProblem("a; //4", 1, ICPPField.class);
|
||||
ba.assertNonProblem("a; //5", 1, ICPPField.class);
|
||||
}
|
||||
|
||||
// int a,b,c,d ;
|
||||
// class X {
|
||||
// void m() {
|
||||
// T* a;
|
||||
// I* b;
|
||||
// S1* c;
|
||||
// S2* d;
|
||||
// }
|
||||
// typedef int T;
|
||||
// int I;
|
||||
// typedef int S1 (int(T)); // resolve this ambiguity first
|
||||
// typedef int S2 (int(t)); // resolve this ambiguity first
|
||||
// };
|
||||
public void testOrderOfAmbiguityResolution_259373() throws Exception {
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||
ICPPVariable a= ba.assertNonProblem("a;", 1);
|
||||
assertInstance(a.getType(), IPointerType.class);
|
||||
ICPPVariable b= ba.assertNonProblem("b;", 1);
|
||||
assertInstance(b.getType(), IBasicType.class);
|
||||
ICPPVariable c= ba.assertNonProblem("c;", 1);
|
||||
assertInstance(c.getType(), IPointerType.class);
|
||||
ITypedef s1= (ITypedef) ((IPointerType) c.getType()).getType();
|
||||
assertInstance(((IFunctionType) s1.getType()).getParameterTypes()[0], IPointerType.class);
|
||||
ICPPVariable d= ba.assertNonProblem("d;", 1);
|
||||
assertInstance(d.getType(), IPointerType.class);
|
||||
ITypedef s2= (ITypedef) ((IPointerType) d.getType()).getType();
|
||||
assertInstance(((IFunctionType) s2.getType()).getParameterTypes()[0], IBasicType.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -464,8 +464,6 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// A <int, char*, 1> a4; //uses #5, T is int, T2 is char, I is1
|
||||
// A <int*, int*, 2> a5; //ambiguous, matches #3 & #5.
|
||||
public void test_14_5_4_1s2_MatchingTemplateSpecializations() throws Exception{
|
||||
CPPASTNameBase.sAllowNameComputation= true;
|
||||
|
||||
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
@ -2756,7 +2754,6 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// C c1;
|
||||
// C<> c2; // ok - default args
|
||||
public void testMissingTemplateArgumentLists() throws Exception {
|
||||
CPPASTNameBase.sAllowNameComputation=true;
|
||||
BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true);
|
||||
ba.assertProblem("B b1", 1);
|
||||
ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class);
|
||||
|
@ -2929,7 +2926,6 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
//
|
||||
// A<int> aint; // should be an error
|
||||
public void testTypeArgumentToNonTypeParameter() throws Exception {
|
||||
CPPASTNameBase.sAllowNameComputation=true;
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||
ba.assertProblem("A<int>", 6);
|
||||
}
|
||||
|
@ -3458,7 +3454,8 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// T::b.f();
|
||||
// T::b.f().d;
|
||||
// T::f1();
|
||||
// T.x; T.y();
|
||||
// T v;
|
||||
// v.x; v.y();
|
||||
// }
|
||||
// };
|
||||
public void testTypeOfUnknownReferences_Bug257194a() throws Exception {
|
||||
|
@ -3482,7 +3479,8 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// T::b->f();
|
||||
// T::b->f()->d;
|
||||
// T::f1();
|
||||
// T->x; T->y();
|
||||
// T v;
|
||||
// v->x; v->y();
|
||||
// }
|
||||
// };
|
||||
public void testTypeOfUnknownReferences_Bug257194b() throws Exception {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -1110,16 +1110,17 @@ public class CompleteParser2Tests extends BaseTestCase {
|
|||
assertInstances( col, counter, 3 );
|
||||
}
|
||||
|
||||
public void testThrowStatement() throws Exception
|
||||
{
|
||||
IASTTranslationUnit tu = parse( "class A { }; void foo() throw ( A ) { throw A; throw; } "); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
assertEquals( col.size(), 4 );
|
||||
ICompositeType A = (ICompositeType) col.getName(0).resolveBinding();
|
||||
public void testThrowStatement() throws Exception {
|
||||
IASTTranslationUnit tu = parse("class A { }; void foo() throw ( A ) { A a; throw a; throw; } "); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
assertInstances( col, A, 3 );
|
||||
assertEquals(6, col.size());
|
||||
ICompositeType A = (ICompositeType) col.getName(0).resolveBinding();
|
||||
assertInstances(col, A, 3);
|
||||
|
||||
IVariable a = (IVariable) col.getName(4).resolveBinding();
|
||||
assertInstances(col, a, 2);
|
||||
}
|
||||
|
||||
public void testScoping() throws Exception
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* Generic visitor for ast-nodes.
|
||||
* <p> Clients may subclass. </p>
|
||||
* @since 5.1
|
||||
*/
|
||||
public abstract class ASTGenericVisitor extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor {
|
||||
public ASTGenericVisitor(boolean visitNodes) {
|
||||
super(visitNodes);
|
||||
}
|
||||
|
||||
protected int genericVisit(IASTNode node) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
protected int genericLeave(IASTNode node) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int visit(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return genericVisit(baseSpecifier);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return genericVisit(namespaceDefinition);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTTemplateParameter templateParameter) {
|
||||
return genericVisit(templateParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTArrayModifier arrayModifier) {
|
||||
return genericVisit(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
return genericVisit(declaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
return genericVisit(declarator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
return genericVisit(declSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTEnumerator enumerator) {
|
||||
return genericVisit(enumerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
return genericVisit(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTInitializer initializer) {
|
||||
return genericVisit(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
return genericVisit(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTParameterDeclaration parameterDeclaration) {
|
||||
return genericVisit(parameterDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTProblem problem) {
|
||||
return genericVisit(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
return genericVisit(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTranslationUnit tu) {
|
||||
return genericVisit(tu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTypeId typeId) {
|
||||
return genericVisit(typeId);
|
||||
}
|
||||
|
||||
public int visit(ICASTDesignator designator) {
|
||||
return genericVisit(designator);
|
||||
}
|
||||
|
||||
public int leave(ICASTDesignator designator) {
|
||||
return genericLeave(designator);
|
||||
}
|
||||
|
||||
public int leave(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return genericLeave(baseSpecifier);
|
||||
}
|
||||
|
||||
public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return genericLeave(namespaceDefinition);
|
||||
}
|
||||
|
||||
public int leave(ICPPASTTemplateParameter templateParameter) {
|
||||
return genericLeave(templateParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTArrayModifier arrayModifier) {
|
||||
return genericLeave(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclaration declaration) {
|
||||
return genericLeave(declaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclarator declarator) {
|
||||
return genericLeave(declarator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclSpecifier declSpec) {
|
||||
return genericLeave(declSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTEnumerator enumerator) {
|
||||
return genericLeave(enumerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTExpression expression) {
|
||||
return genericLeave(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTInitializer initializer) {
|
||||
return genericLeave(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTName name) {
|
||||
return genericLeave(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTParameterDeclaration parameterDeclaration) {
|
||||
return genericLeave(parameterDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTProblem problem) {
|
||||
return genericLeave(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTStatement statement) {
|
||||
return genericLeave(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTTranslationUnit tu) {
|
||||
return genericLeave(tu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTTypeId typeId) {
|
||||
return genericLeave(typeId);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
|
||||
|
||||
/**
|
||||
* Abstract base class for all visitors to traverse ast nodes. <br>
|
||||
|
@ -23,6 +24,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
|||
*
|
||||
* To visit c- or c++-specific nodes you need to implement {@link ICASTVisitor}
|
||||
* and/or {@link ICPPASTVisitor} in addition to deriving from this class.
|
||||
*
|
||||
* <p> Clients may subclass. </p>
|
||||
*/
|
||||
public abstract class ASTVisitor {
|
||||
/**
|
||||
|
@ -116,6 +119,12 @@ public abstract class ASTVisitor {
|
|||
*/
|
||||
public boolean shouldVisitTemplateParameters = false;
|
||||
|
||||
/**
|
||||
* For internal use, only.
|
||||
* @noreference This field is not intended to be referenced by clients.
|
||||
*/
|
||||
public boolean shouldVisitAmbiguousNodes = false;
|
||||
|
||||
/**
|
||||
* Creates a visitor that does not visit any kind of node per default.
|
||||
*/
|
||||
|
@ -274,4 +283,15 @@ public abstract class ASTVisitor {
|
|||
public int leave( IASTComment comment){
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use, only. When {@link ASTVisitor#shouldVisitAmbiguousNodes} is set to true, the
|
||||
* visitor will be called for ambiguous nodes. However, the children of an ambiguous will not be
|
||||
* traversed.
|
||||
* @nooverride This method is not intended to be re-implemented or extended by clients.
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
public int visit(ASTAmbiguousNode astAmbiguousNode) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,11 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
|
@ -59,7 +62,15 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
|||
protected abstract IScope getAffectedScope();
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
public final boolean accept(ASTVisitor visitor) {
|
||||
if (visitor.shouldVisitAmbiguousNodes && visitor.visit(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
// alternatives are not visited on purpose.
|
||||
return true;
|
||||
}
|
||||
|
||||
public void resolveAmbiguity(ASTVisitor resolver) {
|
||||
final IScope scope= getAffectedScope();
|
||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||
IASTNode nodeToReplace= this;
|
||||
|
@ -83,7 +94,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
|||
nodeToReplace= alternative;
|
||||
|
||||
// handle nested ambiguities first, otherwise we cannot visit the alternative
|
||||
alternative.accept(visitor);
|
||||
alternative.accept(resolver);
|
||||
|
||||
// find nested names
|
||||
final NameCollector nameCollector= new NameCollector();
|
||||
|
@ -97,6 +108,12 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
|||
IBinding b= name.resolvePreBinding();
|
||||
if (b instanceof IProblemBinding) {
|
||||
issues++;
|
||||
} else if (b instanceof IType && name.getPropertyInParent() == IASTIdExpression.ID_NAME) {
|
||||
// mstodo misused types, should be part of postResolution.
|
||||
IASTNode grand= name.getParent().getParent();
|
||||
if (!(grand instanceof ICPPASTTemplatedTypeTemplateParameter)) {
|
||||
issues++;
|
||||
}
|
||||
}
|
||||
} catch (Exception t) {
|
||||
issues++;
|
||||
|
@ -124,6 +141,5 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
|||
}
|
||||
owner.replace(nodeToReplace, bestAlternative);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
|
|||
|
||||
/**
|
||||
* Access to methods on scopes and bindings internal to the parser.
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ASTInternal {
|
||||
|
||||
|
@ -70,8 +69,8 @@ public class ASTInternal {
|
|||
}
|
||||
|
||||
public static void removeBinding(IScope scope, IBinding binding) throws DOMException {
|
||||
if (scope instanceof IASTInternalScope) {
|
||||
((IASTInternalScope) scope).removeBinding(binding);
|
||||
if (scope instanceof CScope) {
|
||||
((CScope) scope).removeBinding(binding);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -10,32 +10,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTGenericVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* Utility class to search for siblings of an ast node
|
||||
*/
|
||||
public class ASTNodeSearch extends ASTVisitor implements ICASTVisitor, ICPPASTVisitor {
|
||||
public class ASTNodeSearch extends ASTGenericVisitor {
|
||||
private static final int LEFT = 0;
|
||||
private static final int RIGHT= 1;
|
||||
private int fMode;
|
||||
|
@ -70,7 +51,8 @@ public class ASTNodeSearch extends ASTVisitor implements ICASTVisitor, ICPPASTVi
|
|||
return fRight;
|
||||
}
|
||||
|
||||
private int process(IASTNode node) {
|
||||
@Override
|
||||
protected int genericVisit(IASTNode node) {
|
||||
if (node == fParent)
|
||||
return PROCESS_CONTINUE;
|
||||
|
||||
|
@ -91,101 +73,4 @@ public class ASTNodeSearch extends ASTVisitor implements ICASTVisitor, ICPPASTVi
|
|||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
public int visit(ICASTDesignator designator) {
|
||||
return process(designator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTArrayModifier arrayModifier) {
|
||||
return process(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
return process(declaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
return process(declarator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
return process(declSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTEnumerator enumerator) {
|
||||
return process(enumerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
return process(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTInitializer initializer) {
|
||||
return process(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
return process(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTParameterDeclaration parameterDeclaration) {
|
||||
return process(parameterDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTProblem problem) {
|
||||
return process(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
return process(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTranslationUnit tu) {
|
||||
return process(tu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTypeId typeId) {
|
||||
return process(typeId);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return process(baseSpecifier);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return process(namespaceDefinition);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTTemplateParameter templateParameter) {
|
||||
return process(templateParameter);
|
||||
}
|
||||
|
||||
public int leave(ICASTDesignator designator) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public int leave(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int leave(ICPPASTTemplateParameter templateParameter) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,32 +13,13 @@ package org.eclipse.cdt.internal.core.dom.parser;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTGenericVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* Collector to find all children for an ast-node.
|
||||
*/
|
||||
class ChildCollector extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor {
|
||||
class ChildCollector extends ASTGenericVisitor {
|
||||
|
||||
private final IASTNode fNode;
|
||||
private List<IASTNode> fNodes;
|
||||
|
@ -56,7 +37,8 @@ class ChildCollector extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor
|
|||
return fNodes.toArray(new IASTNode[fNodes.size()]);
|
||||
}
|
||||
|
||||
private int addChild(IASTNode child) {
|
||||
@Override
|
||||
protected int genericVisit(IASTNode child) {
|
||||
if (fNodes == null) {
|
||||
if (child == fNode)
|
||||
return PROCESS_CONTINUE;
|
||||
|
@ -65,101 +47,4 @@ class ChildCollector extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor
|
|||
fNodes.add(child);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
public int visit(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return addChild(baseSpecifier);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return addChild(namespaceDefinition);
|
||||
}
|
||||
|
||||
public int visit(ICPPASTTemplateParameter templateParameter) {
|
||||
return addChild(templateParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTArrayModifier arrayModifier) {
|
||||
return addChild(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
return addChild(declaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
return addChild(declarator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
return addChild(declSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTEnumerator enumerator) {
|
||||
return addChild(enumerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
return addChild(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTInitializer initializer) {
|
||||
return addChild(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
return addChild(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTParameterDeclaration parameterDeclaration) {
|
||||
return addChild(parameterDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTProblem problem) {
|
||||
return addChild(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
return addChild(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTranslationUnit tu) {
|
||||
return addChild(tu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTypeId typeId) {
|
||||
return addChild(typeId);
|
||||
}
|
||||
|
||||
public int visit(ICASTDesignator designator) {
|
||||
return addChild(designator);
|
||||
}
|
||||
|
||||
public int leave(ICASTDesignator designator) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
public int leave(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
public int leave(ICPPASTTemplateParameter templateParameter) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
|
||||
/**
|
||||
* Interface for methods on scopes that are internal to the AST.
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface IASTInternalScope extends IScope {
|
||||
/**
|
||||
|
@ -41,14 +40,6 @@ public interface IASTInternalScope extends IScope {
|
|||
*/
|
||||
public void addBinding(IBinding binding) throws DOMException;
|
||||
|
||||
/**
|
||||
* remove the given binding from this scope
|
||||
*
|
||||
* @param binding
|
||||
* @throws DOMException
|
||||
*/
|
||||
void removeBinding(IBinding binding) throws DOMException;
|
||||
|
||||
/**
|
||||
* Add an IASTName to be cached in this scope
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -41,6 +41,10 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
protected IASTNode node;
|
||||
private String message = null;
|
||||
|
||||
public ProblemBinding(IASTName name, int id) {
|
||||
this(name, id, null);
|
||||
}
|
||||
|
||||
public ProblemBinding(IASTNode node, int id, char[] arg) {
|
||||
this.id = id;
|
||||
this.arg = arg;
|
||||
|
@ -91,6 +95,9 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
|
||||
String msg = (id > 0 && id <= errorMessages.length) ? errorMessages[id - 1] : ""; //$NON-NLS-1$
|
||||
|
||||
if (arg == null && node instanceof IASTName)
|
||||
arg= ((IASTName) node).toCharArray();
|
||||
|
||||
if (arg != null) {
|
||||
msg = MessageFormat.format(msg, new Object[] { new String(arg) });
|
||||
}
|
||||
|
@ -160,13 +167,6 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||
*/
|
||||
public void removeBinding(IBinding binding) throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
|
@ -236,10 +236,10 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
return null;
|
||||
}
|
||||
|
||||
public void setASTNode(IASTNode node, char[] arg) {
|
||||
if (node != null)
|
||||
this.node= node;
|
||||
if (arg != null)
|
||||
this.arg= arg;
|
||||
public void setASTNode(IASTName name) {
|
||||
if (name != null) {
|
||||
this.node= name;
|
||||
this.arg= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
|
||||
|
||||
/**
|
||||
* Visitor to resolve ast ambiguities in the right order, which is simply a depth
|
||||
* first traversal.
|
||||
*/
|
||||
final class CASTAmbiguityResolver extends ASTVisitor {
|
||||
CASTAmbiguityResolver() {
|
||||
super(false);
|
||||
shouldVisitAmbiguousNodes= true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ASTAmbiguousNode astAmbiguousNode) {
|
||||
astAmbiguousNode.resolveAmbiguity(this);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -103,7 +103,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
|||
public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
|
||||
private static final int DEFAULT_PARAMETERS_LIST_SIZE = 4;
|
||||
private static final ASTVisitor EMPTY_VISITOR = new ASTVisitor() {};
|
||||
|
||||
private final boolean supportGCCStyleDesignators;
|
||||
private IIndex index;
|
||||
|
@ -1956,7 +1955,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
@Override
|
||||
protected ASTVisitor createAmbiguityNodeVisitor() {
|
||||
return EMPTY_VISITOR;
|
||||
return new CASTAmbiguityResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* Visitor to resolve ast ambiguities in the right order
|
||||
*/
|
||||
final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||
private static class ClassContext {
|
||||
ArrayList<IASTNode> fDeferredNodes;
|
||||
final IASTNode fNode;
|
||||
public ClassContext(IASTNode node) {
|
||||
fNode= node;
|
||||
}
|
||||
public void deferNode(IASTNode node) {
|
||||
if (fDeferredNodes == null)
|
||||
fDeferredNodes= new ArrayList<IASTNode>();
|
||||
fDeferredNodes.add(node);
|
||||
}
|
||||
}
|
||||
private LinkedList<ClassContext> fContextStack;
|
||||
private ClassContext fCurrentContext;
|
||||
private boolean fSkipInitializers;
|
||||
|
||||
CPPASTAmbiguityResolver() {
|
||||
super(false);
|
||||
shouldVisitAmbiguousNodes= true;
|
||||
shouldVisitDeclarations= true;
|
||||
shouldVisitDeclSpecifiers= true;
|
||||
shouldVisitInitializers= true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ASTAmbiguousNode astAmbiguousNode) {
|
||||
astAmbiguousNode.resolveAmbiguity(this);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
if (fCurrentContext != null) {
|
||||
// defer visiting nested classes until the outer class body has been visited.
|
||||
fCurrentContext.deferNode(declSpec);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
pushContext();
|
||||
fCurrentContext= new ClassContext(declSpec);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
assert fCurrentContext != null;
|
||||
assert fCurrentContext.fNode == declSpec;
|
||||
if (fCurrentContext != null) {
|
||||
final List<IASTNode> deferredNodes = fCurrentContext.fDeferredNodes;
|
||||
fCurrentContext= null;
|
||||
if (deferredNodes != null) {
|
||||
for (IASTNode node : deferredNodes) {
|
||||
node.accept(this);
|
||||
}
|
||||
}
|
||||
popContext();
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
private void pushContext() {
|
||||
if (fCurrentContext==null) {
|
||||
if (fContextStack != null && !fContextStack.isEmpty()) {
|
||||
fContextStack.addLast(null);
|
||||
}
|
||||
} else {
|
||||
if (fContextStack == null) {
|
||||
fContextStack= new LinkedList<ClassContext>();
|
||||
}
|
||||
fContextStack.addLast(fCurrentContext);
|
||||
}
|
||||
}
|
||||
|
||||
private void popContext() {
|
||||
if (fContextStack == null || fContextStack.isEmpty()) {
|
||||
fCurrentContext= null;
|
||||
} else {
|
||||
fCurrentContext= fContextStack.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration decl) {
|
||||
if (decl instanceof IASTFunctionDefinition) {
|
||||
final IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl;
|
||||
|
||||
// visit the declarator first, it may contain ambiguous template arguments needed
|
||||
// for associating the template declarations.
|
||||
fSkipInitializers= true;
|
||||
CPPVisitor.findOutermostDeclarator(fdef.getDeclarator()).accept(this);
|
||||
fSkipInitializers= false;
|
||||
|
||||
if (fCurrentContext != null) {
|
||||
// defer visiting the body of the function until the class body has been visited.
|
||||
fdef.getDeclSpecifier().accept(this);
|
||||
fCurrentContext.deferNode(decl);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTInitializer initializer) {
|
||||
if (fSkipInitializers)
|
||||
return PROCESS_SKIP;
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -41,7 +41,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
|
|||
|
||||
protected final static class RecursionResolvingBinding extends ProblemBinding {
|
||||
public RecursionResolvingBinding(IASTName node) {
|
||||
super(node, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, node.toCharArray());
|
||||
super(node, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP);
|
||||
Assert.isTrue(sAllowRecursionBindings, getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
|
|||
ProblemBinding pb= (ProblemBinding) b;
|
||||
final IASTNode node= pb.getASTNode();
|
||||
if (node == null || node.getParent() == null) {
|
||||
pb.setASTNode(this, toCharArray());
|
||||
pb.setASTNode(this);
|
||||
}
|
||||
}
|
||||
fBinding= b;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -382,18 +382,6 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||
*/
|
||||
@Override
|
||||
public void removeBinding(IBinding binding) {
|
||||
if (binding instanceof ICPPConstructor) {
|
||||
removeBinding(CONSTRUCTOR_KEY, binding);
|
||||
} else {
|
||||
removeBinding(binding.getNameCharArray(), binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -31,6 +31,5 @@ public class CPPClassSpecializationScope extends AbstractCPPClassSpecializationS
|
|||
public void flushCache() {}
|
||||
public void addName(IASTName name) {}
|
||||
public IASTNode getPhysicalNode() { return null; }
|
||||
public void removeBinding(IBinding binding) {}
|
||||
public void addBinding(IBinding binding) {}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -293,39 +293,6 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||
*/
|
||||
public void removeBinding(IBinding binding) {
|
||||
char[] key = binding.getNameCharArray();
|
||||
removeBinding(key, binding);
|
||||
}
|
||||
|
||||
protected void removeBinding(char[] key, IBinding binding) {
|
||||
if (bindings == null || ! bindings.containsKey(key))
|
||||
return;
|
||||
|
||||
Object obj = bindings.get(key);
|
||||
if (obj instanceof ObjectSet<?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectSet<Object> set = (ObjectSet<Object>) obj;
|
||||
for (int i = set.size() - 1; i >= 0; i--) {
|
||||
Object o = set.keyAt(i);
|
||||
if ((o instanceof IBinding && o == binding) ||
|
||||
(o instanceof IASTName && ((IASTName)o).getBinding() == binding)) {
|
||||
set.remove(o);
|
||||
}
|
||||
}
|
||||
if (set.isEmpty()) {
|
||||
bindings.remove(key, 0, key.length);
|
||||
}
|
||||
} else if ((obj instanceof IBinding && obj == binding) ||
|
||||
(obj instanceof IASTName && ((IASTName)obj).getBinding() == binding)) {
|
||||
bindings.remove(key, 0, key.length);
|
||||
}
|
||||
isCached = false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -250,6 +250,6 @@ public abstract class CPPTemplateParameter extends PlatformObject
|
|||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
return new ProblemBinding(getPrimaryDeclaration(), IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray());
|
||||
return new ProblemBinding(getPrimaryDeclaration(), IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -85,22 +85,12 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public void addName(IASTName name) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||
*/
|
||||
public void removeBinding(IBinding binding) {
|
||||
}
|
||||
|
||||
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
|
||||
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
|
@ -169,14 +159,22 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
|
|||
return result;
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
|
||||
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
|
||||
return getBindings(name, resolve, prefixLookup, fileSet, true);
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings, boolean checkPointOfDecl) {
|
||||
if (prefixLookup)
|
||||
return IBinding.EMPTY_BINDING_ARRAY;
|
||||
|
||||
return new IBinding[] {getBinding(name, resolve, fileSet)};
|
||||
}
|
||||
return new IBinding[] {getBinding(name, resolve, acceptLocalBindings)};
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#flushCache()
|
||||
*/
|
||||
public void flushCache() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -143,7 +143,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
private static final int DEFAULT_PARM_LIST_SIZE = 4;
|
||||
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
|
||||
private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE= 4;
|
||||
private static final ASTVisitor EMPTY_VISITOR = new ASTVisitor() {};
|
||||
private static enum DtorStrategy {PREFER_FUNCTION, PREFER_NESTED}
|
||||
|
||||
private final boolean allowCPPRestrict;
|
||||
|
@ -153,7 +152,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
private final IIndex index;
|
||||
protected ICPPASTTranslationUnit translationUnit;
|
||||
|
||||
private int templateCount = 0;
|
||||
private int functionBodyCount= 0;
|
||||
private int rejectLogicalOperatorInTemplateID= 0;
|
||||
private char[] currentClassName;
|
||||
|
@ -1418,98 +1416,92 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* request for a backtrack
|
||||
*/
|
||||
protected IASTDeclaration templateDeclaration(DeclarationOptions option) throws EndOfFileException, BacktrackException {
|
||||
++templateCount;
|
||||
try {
|
||||
IToken mark = mark();
|
||||
IToken firstToken = null;
|
||||
boolean exported = false;
|
||||
boolean encounteredExtraMod = false;
|
||||
if (LT(1) == IToken.t_export) {
|
||||
exported = true;
|
||||
firstToken = consume();
|
||||
consume(IToken.t_template);
|
||||
} else {
|
||||
if (supportExtendedTemplateSyntax) {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_static:
|
||||
case IToken.t_extern:
|
||||
case IToken.t_inline:
|
||||
firstToken = consume();
|
||||
consume(IToken.t_template);
|
||||
encounteredExtraMod = true;
|
||||
break;
|
||||
default:
|
||||
firstToken = consume(IToken.t_template);
|
||||
IToken mark = mark();
|
||||
IToken firstToken = null;
|
||||
boolean exported = false;
|
||||
boolean encounteredExtraMod = false;
|
||||
if (LT(1) == IToken.t_export) {
|
||||
exported = true;
|
||||
firstToken = consume();
|
||||
consume(IToken.t_template);
|
||||
} else {
|
||||
if (supportExtendedTemplateSyntax) {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_static:
|
||||
case IToken.t_extern:
|
||||
case IToken.t_inline:
|
||||
firstToken = consume();
|
||||
consume(IToken.t_template);
|
||||
encounteredExtraMod = true;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
default:
|
||||
firstToken = consume(IToken.t_template);
|
||||
}
|
||||
if (LT(1) != IToken.tLT) {
|
||||
// explicit-instantiation
|
||||
ICPPASTExplicitTemplateInstantiation templateInstantiation = null;
|
||||
if (encounteredExtraMod && supportExtendedTemplateSyntax) {
|
||||
IGPPASTExplicitTemplateInstantiation temp = nodeFactory.newExplicitTemplateInstantiationGPP(null);
|
||||
switch (firstToken.getType()) {
|
||||
case IToken.t_static:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_static);
|
||||
break;
|
||||
case IToken.t_extern:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_extern);
|
||||
break;
|
||||
case IToken.t_inline:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_inline);
|
||||
break;
|
||||
}
|
||||
templateInstantiation = temp;
|
||||
} else {
|
||||
templateInstantiation = nodeFactory.newExplicitTemplateInstantiation(null);
|
||||
break;
|
||||
}
|
||||
IASTDeclaration d = declaration(option);
|
||||
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
||||
.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateInstantiation.setDeclaration(d);
|
||||
return templateInstantiation;
|
||||
}
|
||||
consume(); // check for LT made before
|
||||
if (LT(1) == IToken.tGT) {
|
||||
// explicit-specialization
|
||||
consume();
|
||||
IASTDeclaration d = declaration(option);
|
||||
ICPPASTTemplateSpecialization templateSpecialization = nodeFactory.newTemplateSpecialization(d);
|
||||
((ASTNode) templateSpecialization).setOffsetAndLength(firstToken.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
return templateSpecialization;
|
||||
} else
|
||||
firstToken = consume(IToken.t_template);
|
||||
}
|
||||
if (LT(1) != IToken.tLT) {
|
||||
// explicit-instantiation
|
||||
ICPPASTExplicitTemplateInstantiation templateInstantiation = null;
|
||||
if (encounteredExtraMod && supportExtendedTemplateSyntax) {
|
||||
IGPPASTExplicitTemplateInstantiation temp = nodeFactory.newExplicitTemplateInstantiationGPP(null);
|
||||
switch (firstToken.getType()) {
|
||||
case IToken.t_static:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_static);
|
||||
break;
|
||||
case IToken.t_extern:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_extern);
|
||||
break;
|
||||
case IToken.t_inline:
|
||||
temp.setModifier(IGPPASTExplicitTemplateInstantiation.ti_inline);
|
||||
break;
|
||||
}
|
||||
templateInstantiation = temp;
|
||||
} else {
|
||||
templateInstantiation = nodeFactory.newExplicitTemplateInstantiation(null);
|
||||
}
|
||||
IASTDeclaration d = declaration(option);
|
||||
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
||||
.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateInstantiation.setDeclaration(d);
|
||||
return templateInstantiation;
|
||||
}
|
||||
consume(); // check for LT made before
|
||||
if (LT(1) == IToken.tGT) {
|
||||
// explicit-specialization
|
||||
consume();
|
||||
IASTDeclaration d = declaration(option);
|
||||
ICPPASTTemplateSpecialization templateSpecialization = nodeFactory.newTemplateSpecialization(d);
|
||||
((ASTNode) templateSpecialization).setOffsetAndLength(firstToken.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
return templateSpecialization;
|
||||
}
|
||||
|
||||
try {
|
||||
final boolean wasOnTop= onTopInTemplateArgs;
|
||||
onTopInTemplateArgs= true;
|
||||
List<ICPPASTTemplateParameter> parms;
|
||||
try {
|
||||
final boolean wasOnTop= onTopInTemplateArgs;
|
||||
onTopInTemplateArgs= true;
|
||||
List<ICPPASTTemplateParameter> parms;
|
||||
try {
|
||||
parms = templateParameterList();
|
||||
consume(IToken.tGT);
|
||||
} finally {
|
||||
onTopInTemplateArgs= wasOnTop;
|
||||
}
|
||||
IASTDeclaration d = declaration(option);
|
||||
ICPPASTTemplateDeclaration templateDecl = nodeFactory.newTemplateDeclaration(d);
|
||||
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateDecl.setExported(exported);
|
||||
for (int i = 0; i < parms.size(); ++i) {
|
||||
ICPPASTTemplateParameter parm = parms.get(i);
|
||||
templateDecl.addTemplateParamter(parm);
|
||||
}
|
||||
return templateDecl;
|
||||
} catch (BacktrackException bt) {
|
||||
backup(mark);
|
||||
throw bt;
|
||||
parms = templateParameterList();
|
||||
consume(IToken.tGT);
|
||||
} finally {
|
||||
onTopInTemplateArgs= wasOnTop;
|
||||
}
|
||||
} finally {
|
||||
templateCount--;
|
||||
IASTDeclaration d = declaration(option);
|
||||
ICPPASTTemplateDeclaration templateDecl = nodeFactory.newTemplateDeclaration(d);
|
||||
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(), calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateDecl.setExported(exported);
|
||||
for (int i = 0; i < parms.size(); ++i) {
|
||||
ICPPASTTemplateParameter parm = parms.get(i);
|
||||
templateDecl.addTemplateParamter(parm);
|
||||
}
|
||||
return templateDecl;
|
||||
} catch (BacktrackException bt) {
|
||||
backup(mark);
|
||||
throw bt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* template-parameter-list: template-parameter template-parameter-list ,
|
||||
* template-parameter template-parameter: type-parameter
|
||||
|
@ -2538,7 +2530,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return dtor1;
|
||||
|
||||
// optimization outside of function bodies and inside of templates
|
||||
if (functionBodyCount == 0 || templateCount != 0)
|
||||
if (functionBodyCount == 0)
|
||||
return dtor1;
|
||||
|
||||
// avoid second option for function definitions
|
||||
|
@ -3692,7 +3684,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
@Override
|
||||
protected ASTVisitor createAmbiguityNodeVisitor() {
|
||||
return EMPTY_VISITOR;
|
||||
return new CPPASTAmbiguityResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Google, Inc and others.
|
||||
* Copyright (c) 2008, 2009 Google, Inc and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,18 +7,16 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
|
||||
|
||||
/**
|
||||
* Scope corresponding to an unknown binding.
|
||||
*
|
||||
* @author Sergey Prigogin
|
||||
*/
|
||||
public interface ICPPInternalUnknownScope extends IASTInternalScope {
|
||||
public interface ICPPInternalUnknownScope extends ICPPASTInternalScope {
|
||||
|
||||
/**
|
||||
* @return Returns the binding corresponding to the scope.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -293,7 +293,7 @@ public class CPPSemantics {
|
|||
node= node.getParent();
|
||||
}
|
||||
if (!ok) {
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,31 +309,43 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
if (binding instanceof ICPPClassType && data.considerConstructors) {
|
||||
try {
|
||||
ICPPClassType cls = (ICPPClassType) binding;
|
||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) {
|
||||
if (data.tu != null) {
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||
ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id);
|
||||
IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args);
|
||||
if (inst instanceof ICPPClassType) {
|
||||
cls= (ICPPClassType) inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cls instanceof ICPPDeferredClassInstance) {
|
||||
binding= new CPPUnknownConstructor(cls, data.astName);
|
||||
} else {
|
||||
// Force resolution of constructor bindings
|
||||
final ICPPConstructor[] constructors = cls.getConstructors();
|
||||
if (constructors.length > 0) {
|
||||
binding= CPPSemantics.resolveAmbiguities(data.astName, constructors);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
binding = e.getProblem();
|
||||
}
|
||||
if (data.considerConstructors) {
|
||||
ICPPClassType cls= null;
|
||||
// if (binding instanceof ITypedef) {
|
||||
// // mstodo constructor off typedef
|
||||
// IType t= SemanticUtil.getUltimateTypeViaTypedefs((IType) binding);
|
||||
// if (t instanceof ICPPClassType) {
|
||||
// cls= (ICPPClassType) t;
|
||||
// }
|
||||
// } else
|
||||
if (binding instanceof ICPPClassType) {
|
||||
cls= (ICPPClassType) binding;
|
||||
}
|
||||
if (cls != null) {
|
||||
try {
|
||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) {
|
||||
if (data.tu != null) {
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||
ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id);
|
||||
IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args);
|
||||
if (inst instanceof ICPPClassType) {
|
||||
cls= (ICPPClassType) inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cls instanceof ICPPDeferredClassInstance) {
|
||||
binding= new CPPUnknownConstructor(cls, data.astName);
|
||||
} else {
|
||||
// Force resolution of constructor bindings
|
||||
final ICPPConstructor[] constructors = cls.getConstructors();
|
||||
if (constructors.length > 0) {
|
||||
binding= CPPSemantics.resolveAmbiguities(data.astName, constructors);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
binding = e.getProblem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IASTName name= data.astName;
|
||||
|
@ -356,11 +368,12 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
// if the lookup in base-classes ran into a deferred instance, use the computed unknown binding.
|
||||
final ASTNodeProperty namePropertyInParent = name.getPropertyInParent();
|
||||
if (binding == null && data.skippedScope != null) {
|
||||
if (data.functionParameters != null) {
|
||||
binding= new CPPUnknownFunction(data.skippedScope, name.getLastName());
|
||||
} else {
|
||||
if (name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME) {
|
||||
if (namePropertyInParent == IASTNamedTypeSpecifier.NAME) {
|
||||
binding= new CPPUnknownClass(data.skippedScope, name.getLastName());
|
||||
} else {
|
||||
binding= new CPPUnknownBinding(data.skippedScope, name.getLastName());
|
||||
|
@ -368,18 +381,30 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
if (binding != null) {
|
||||
if (name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !(binding instanceof IType || binding instanceof ICPPConstructor)) {
|
||||
IASTNode parent = name.getParent().getParent();
|
||||
if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
||||
if (!(binding instanceof IType)) {
|
||||
// a type id needs to hold a type
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
|
||||
if (binding != null && !(binding instanceof IProblemBinding)) {
|
||||
if (namePropertyInParent == IASTNamedTypeSpecifier.NAME) {
|
||||
if (!(binding instanceof IType || binding instanceof ICPPConstructor)) {
|
||||
IASTNode parent = name.getParent().getParent();
|
||||
if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
||||
if (!(binding instanceof IType)) {
|
||||
// a type id needs to hold a type
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
// don't create a problem here
|
||||
} else {
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
// don't create a problem here
|
||||
} else {
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
|
||||
}
|
||||
}
|
||||
// mstodo misused types, important for ambiguity resolution.
|
||||
// } else if (namePropertyInParent == IASTIdExpression.ID_NAME) {
|
||||
// if (binding instanceof IType) {
|
||||
// IASTNode parent= name.getParent().getParent();
|
||||
// if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||
// // default for template template parameter is an id-expression, which is a type.
|
||||
// } else {
|
||||
// binding= new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,9 +416,9 @@ public class CPPSemantics {
|
|||
// If we're still null...
|
||||
if (binding == null) {
|
||||
if (name instanceof ICPPASTQualifiedName && data.forFunctionDeclaration())
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.getNameCharArray());
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND);
|
||||
else
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getNameCharArray());
|
||||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
@ -919,14 +944,14 @@ public class CPPSemantics {
|
|||
for (int j = 0; j < r.length && r[j] != null; j++) {
|
||||
if (checkForAmbiguity(data, r[j], inherited)) {
|
||||
data.problem = new ProblemBinding(data.astName,
|
||||
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkForAmbiguity(data, result, inherited)) {
|
||||
data.problem = new ProblemBinding(data.astName,
|
||||
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1825,7 +1850,7 @@ public class CPPSemantics {
|
|||
if (i1)
|
||||
type= temp;
|
||||
} else {
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1842,7 +1867,7 @@ public class CPPSemantics {
|
|||
if (ibobj)
|
||||
obj= temp;
|
||||
} else {
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1850,7 +1875,7 @@ public class CPPSemantics {
|
|||
if (data.forUsingDeclaration()) {
|
||||
IBinding[] bindings = null;
|
||||
if (obj != null) {
|
||||
if (fns.size() > 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
if (fns.size() > 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
// if (type == null) return obj;
|
||||
bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, obj);
|
||||
bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, type);
|
||||
|
@ -1890,7 +1915,7 @@ public class CPPSemantics {
|
|||
|
||||
if (numFns > 0) {
|
||||
if (obj != null)
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
return resolveFunction(data, fns.keyArray(IFunction.class));
|
||||
}
|
||||
|
||||
|
@ -2225,7 +2250,7 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
if (ambiguous || bestHasAmbiguousParam) {
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
}
|
||||
|
||||
return bestFn;
|
||||
|
@ -2234,7 +2259,7 @@ public class CPPSemantics {
|
|||
private static IBinding resolveUserDefinedConversion(ICPPASTConversionName astName, IFunction[] fns) {
|
||||
IType t= CPPVisitor.createType(astName.getTypeId());
|
||||
if (t == null) {
|
||||
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE, astName.toCharArray());
|
||||
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
for (IFunction function : fns) {
|
||||
if (function != null) {
|
||||
|
@ -2247,7 +2272,7 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
}
|
||||
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, astName.toCharArray());
|
||||
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
|
||||
}
|
||||
|
||||
private static ICPPFunctionTemplate asTemplate(IFunction function) {
|
||||
|
@ -2289,7 +2314,7 @@ public class CPPSemantics {
|
|||
while (type != null) {
|
||||
type = getUltimateType(type, false);
|
||||
if (type == null || !(type instanceof IFunctionType))
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
|
||||
for (IBinding fn2 : fns) {
|
||||
IFunction fn = (IFunction) fn2;
|
||||
|
@ -2301,8 +2326,7 @@ public class CPPSemantics {
|
|||
}
|
||||
if (type.isSameType(ft)) {
|
||||
if (result != null) {
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP,
|
||||
data.getNameCharArray());
|
||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
}
|
||||
result = fn;
|
||||
}
|
||||
|
@ -2315,9 +2339,7 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
return result != null ?
|
||||
result :
|
||||
new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
|
||||
return result != null ? result : new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||
}
|
||||
|
||||
private static Object getTargetType(LookupData data) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -1284,7 +1284,7 @@ public class CPPTemplates {
|
|||
IASTNode param= params[i];
|
||||
IType type= CPPVisitor.createType(param);
|
||||
if (type == null)
|
||||
throw new DOMException(new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, id.toCharArray()));
|
||||
throw new DOMException(new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE));
|
||||
|
||||
if (param instanceof IASTExpression) {
|
||||
IValue value= Value.create((IASTExpression) param, Value.MAX_RECURSION_DEPTH);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -415,8 +415,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
if ((binding instanceof ICPPClassTemplate) == template) {
|
||||
((ICPPInternalBinding) binding).addDeclaration(elabType);
|
||||
} else {
|
||||
binding = new ProblemBinding(name,
|
||||
IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray());
|
||||
binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
|
@ -461,8 +460,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
(binding instanceof ICPPClassTemplate) == template) {
|
||||
internal.addDefinition(compType);
|
||||
} else {
|
||||
binding = new ProblemBinding(name,
|
||||
IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray());
|
||||
binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
|
@ -505,8 +503,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
binding = new CPPNamespaceAlias(alias.getAlias(), (ICPPNamespace) namespace);
|
||||
ASTInternal.addName(scope, alias.getAlias());
|
||||
} else {
|
||||
binding = new ProblemBinding(alias.getAlias(),
|
||||
IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray());
|
||||
binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
|
@ -628,7 +625,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
} catch (DOMException e1) {
|
||||
return e1.getProblem();
|
||||
}
|
||||
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray());
|
||||
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION);
|
||||
}
|
||||
// if we don't resolve the target type first, we get a problem binding in case the typedef
|
||||
// redeclares the target type:
|
||||
|
@ -651,8 +648,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
if (def instanceof IASTDeclarator)
|
||||
def = ((IASTDeclarator)def).getName();
|
||||
if (def != name) {
|
||||
return new ProblemBinding(name,
|
||||
IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray());
|
||||
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -686,7 +682,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
if (binding instanceof ICPPInternalBinding)
|
||||
((ICPPInternalBinding) binding).addDeclaration(name);
|
||||
} else {
|
||||
binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, declarator.getName().toCharArray());
|
||||
binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION);
|
||||
}
|
||||
} else if (simpleDecl != null && simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
binding = new CPPField(name);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -18,7 +18,27 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.*;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
|
@ -273,19 +293,29 @@ public class LookupData {
|
|||
}
|
||||
|
||||
public static boolean checkWholeClassScope(IASTName name) {
|
||||
if (name == null) return false;
|
||||
if (name.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return true;
|
||||
if (name == null)
|
||||
return false;
|
||||
|
||||
ASTNodeProperty lastProp= name.getPropertyInParent();
|
||||
if (lastProp == CPPSemantics.STRING_LOOKUP_PROPERTY)
|
||||
return true;
|
||||
|
||||
boolean inInitializer= false;
|
||||
IASTNode parent = name.getParent();
|
||||
while (parent != null && !(parent instanceof IASTFunctionDefinition)) {
|
||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||
if (prop == IASTParameterDeclaration.DECL_SPECIFIER ||
|
||||
prop == IASTFunctionDefinition.DECL_SPECIFIER) {
|
||||
return false;
|
||||
}
|
||||
if (parent instanceof IASTInitializer) {
|
||||
inInitializer= true;
|
||||
}
|
||||
lastProp= parent.getPropertyInParent();
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof IASTFunctionDefinition) {
|
||||
if (lastProp == IASTFunctionDefinition.DECL_SPECIFIER ||
|
||||
lastProp == IASTFunctionDefinition.DECLARATOR) {
|
||||
if (!inInitializer)
|
||||
return false;
|
||||
}
|
||||
|
||||
while (parent.getParent() instanceof ICPPASTTemplateDeclaration)
|
||||
parent = parent.getParent();
|
||||
if (parent.getPropertyInParent() != IASTCompositeTypeSpecifier.MEMBER_DECLARATION)
|
||||
|
|
Loading…
Add table
Reference in a new issue