diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
index 431954e9489..4fad7fbcd5c 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
@@ -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
@@ -78,7 +78,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -322,8 +322,6 @@ public class CModelBuilder2 implements IContributedModelBuilder {
// TODO [cmodel] asm declaration?
} else if (declaration instanceof IASTProblemDeclaration) {
// TODO [cmodel] problem declaration?
- } else if (declaration instanceof IASTAmbiguousDeclaration) {
- // TODO [cmodel] ambiguous declaration?
} else {
assert false : "TODO: " + declaration.getClass().getName(); //$NON-NLS-1$
}
@@ -467,7 +465,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
if (declSpecifier.getStorageClass() == IASTDeclSpecifier.sc_typedef) {
return createTypeDef(parent, declSpecifier, declarator);
}
- IASTDeclarator typeRelevant= CPPVisitor.findTypeRelevantDeclarator(declarator);
+ IASTDeclarator typeRelevant= ASTQueries.findTypeRelevantDeclarator(declarator);
if (typeRelevant instanceof IASTFunctionDeclarator) {
return createFunctionDeclaration(parent, declSpecifier, (IASTFunctionDeclarator)typeRelevant, isTemplate);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java
index 0f1607677b8..28631bb8055 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java
@@ -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
@@ -19,8 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
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.internal.core.dom.parser.ASTAmbiguousNode.NameCollector;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.core.runtime.Assert;
@@ -28,7 +28,7 @@ import org.eclipse.core.runtime.Assert;
* Handles the ambiguity between a binary- and a cast-expression. (type)+var versus (var)+var.
* It also handles the impact on the grouping of the sub-expressions.
*/
-public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTNode implements IASTAmbiguousExpression {
+public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression {
private final IASTBinaryExpression fBinaryExpression;
private final IASTCastExpression fCastExpression;
@@ -43,6 +43,10 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTNode impleme
fBinaryExpression= binaryExpression;
fCastExpression= castExpression;
}
+
+ public final IASTExpression copy() {
+ throw new UnsupportedOperationException();
+ }
public void addExpression(IASTExpression e) {
Assert.isLegal(false);
@@ -52,12 +56,22 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTNode impleme
return CVisitor.getExpressionType(getExpressions()[0]);
}
+ @Override
+ protected final IScope getAffectedScope() {
+ return null;
+ }
+
+ @Override
+ public final IASTNode[] getNodes() {
+ return getExpressions();
+ }
+
public IASTExpression[] getExpressions() {
return new IASTExpression[] {fBinaryExpression, fCastExpression};
}
@Override
- public boolean accept(ASTVisitor visitor) {
+ public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
@@ -91,7 +105,7 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTNode impleme
}
}
if (hasIssue) {
- return true;
+ return nodeToReplace;
}
final IASTExpression left = fBinaryExpression.getOperand1();
@@ -109,12 +123,11 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTNode impleme
setRange(fCastExpression, primaryInParenthesis, leadingCastExpression);
IASTExpression root= joinExpressions(lp, fCastExpression, rp);
if (root != null) {
-
owner.replace(nodeToReplace, root);
- return true;
+ return root;
}
}
- return true;
+ return nodeToReplace;
}
private void setEnd(IASTNode node, IASTNode end) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
index bf1c1f883da..d63789de889 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
@@ -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,8 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
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.internal.core.dom.parser.ASTAmbiguousNode.NameCollector;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.Assert;
@@ -30,7 +30,7 @@ import org.eclipse.core.runtime.Assert;
* Handles the ambiguity between cast and function-call expressions: (type)(expr) versus (function)(expr);
* It also handles the impact on the grouping of the sub-expressions.
*/
-public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode implements IASTAmbiguousExpression {
+public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression {
private final IASTCastExpression fCastExpression;
private final IASTFunctionCallExpression fFunctionCallExpression;
@@ -46,7 +46,17 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode i
fFunctionCallExpression= functionCall;
}
- public IASTExpression copy() {
+ @Override
+ protected final IScope getAffectedScope() {
+ return null;
+ }
+
+ @Override
+ public final IASTNode[] getNodes() {
+ return getExpressions();
+ }
+
+ public final IASTExpression copy() {
throw new UnsupportedOperationException();
}
@@ -63,7 +73,7 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode i
}
@Override
- public boolean accept(ASTVisitor visitor) {
+ public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
@@ -76,7 +86,7 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode i
// if the operand of the cast-expr is not suitable for a function call, we are done.
final IASTUnaryExpression primaryWithParenthesis= findPrimaryExpressionInParenthesis(fCastExpression.getOperand());
if (primaryWithParenthesis == null)
- return true;
+ return nodeToReplace;
// find nested names
@@ -99,7 +109,7 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode i
}
}
if (!hasIssue)
- return true;
+ return nodeToReplace;
fFunctionCallExpression.setParameterExpression(primaryWithParenthesis.getOperand());
setRange(fFunctionCallExpression, fCastExpression, primaryWithParenthesis);
@@ -145,7 +155,7 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTNode i
owner.replace(nodeToReplace, result);
// resolve ambiguities in the function-call expression
fFunctionCallExpression.getFunctionNameExpression().accept(visitor);
- return true;
+ return result;
}
private IASTUnaryExpression findPrimaryExpressionInParenthesis(IASTExpression operand) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java
index 931dc7ffd4a..7e0fb66277b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java
@@ -12,10 +12,11 @@
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.IASTDeclarator;
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.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
@@ -54,7 +55,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
/**
* Return the alternative nodes for this ambiguity.
*/
- protected abstract IASTNode[] getNodes();
+ public abstract IASTNode[] getNodes();
/**
* Returns the scope that may get polluted by alternatives of this ambiguity.
@@ -70,7 +71,11 @@ public abstract class ASTAmbiguousNode extends ASTNode {
return true;
}
- public void resolveAmbiguity(ASTVisitor resolver) {
+ protected void beforeResolution() {
+ }
+
+ public IASTNode resolveAmbiguity(ASTVisitor resolver) {
+ beforeResolution();
final IScope scope= getAffectedScope();
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
@@ -82,12 +87,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
for (IASTNode alternative : alternatives) {
// flush scope, even if this is the first alternative. The ambiguous node may have contributed an
// invalid binding to the scope during the resolution of other ambiguous nodes.
- if (scope instanceof IASTInternalScope) {
- try {
- ((IASTInternalScope) scope).flushCache();
- } catch (DOMException e) {
- }
- }
+ ASTInternal.flushCache(scope);
// setup the ast to use the alternative
owner.replace(nodeToReplace, alternative);
@@ -105,6 +105,18 @@ public abstract class ASTAmbiguousNode extends ASTNode {
int issues= 0;
for (IASTName name : names) {
try {
+ // avoid resolution of parameters (can always be resolved),
+ // it can triggers resolution of declaration it belongs to,
+ // while the declarator is still ambiguous. Could be solved by introducing an
+ // intermediate binding for parameters, similar to template parameters.
+ if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) {
+ IASTNode parent= name.getParent();
+ if (parent instanceof IASTDeclarator) {
+ parent= ASTQueries.findOutermostDeclarator((IASTDeclarator) parent);
+ if (parent.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR)
+ continue;
+ }
+ }
IBinding b= name.resolvePreBinding();
if (b instanceof IProblemBinding) {
issues++;
@@ -133,13 +145,9 @@ public abstract class ASTAmbiguousNode extends ASTNode {
// switch back to the best alternative, if necessary.
if (nodeToReplace != bestAlternative) {
- if (scope instanceof IASTInternalScope) {
- try {
- ((IASTInternalScope) scope).flushCache();
- } catch (DOMException e) {
- }
- }
+ ASTInternal.flushCache(scope);
owner.replace(nodeToReplace, bestAlternative);
}
+ return bestAlternative;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
index fbda5fbfffc..d1a461a9010 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
@@ -43,9 +43,9 @@ public class ASTInternal {
return null;
}
- public static void flushCache(IScope scope) throws DOMException {
- if (scope instanceof IASTInternalScope) {
- ((IASTInternalScope) scope).flushCache();
+ public static void flushCache(IScope scope) {
+ if (scope instanceof CScope) {
+ ((CScope) scope).flushCache();
}
}
@@ -74,9 +74,13 @@ public class ASTInternal {
}
}
- public static void addName(IScope scope, IASTName name) throws DOMException {
+ public static void addName(IScope scope, IASTName name) {
if (scope instanceof IASTInternalScope) {
- ((IASTInternalScope) scope).addName(name);
+ try {
+ ((IASTInternalScope) scope).addName(name);
+ } catch (DOMException e) {
+ // name is not cached in scope
+ }
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java
index 515795650b0..9943e271821 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java
@@ -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,13 +10,18 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@@ -63,4 +68,50 @@ public class ASTQueries {
}
return true;
}
+
+ /**
+ * Returns the outermost declarator the given declarator nests within, or
+ * declarator itself.
+ */
+ public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
+ IASTDeclarator outermost= null;
+ IASTNode candidate= declarator;
+ while (candidate instanceof IASTDeclarator) {
+ outermost= (IASTDeclarator) candidate;
+ candidate= outermost.getParent();
+ }
+ return outermost;
+ }
+
+ /**
+ * Returns the innermost declarator nested within the given declarator, or
+ * declarator itself.
+ */
+ public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
+ IASTDeclarator innermost= null;
+ while (declarator != null) {
+ innermost= declarator;
+ declarator= declarator.getNestedDeclarator();
+ }
+ return innermost;
+ }
+
+ /**
+ * Searches for the innermost declarator that contributes the the type declared.
+ */
+ public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
+ IASTDeclarator result= findInnermostDeclarator(declarator);
+ while (result.getPointerOperators().length == 0
+ && !(result instanceof IASTFieldDeclarator)
+ && !(result instanceof IASTFunctionDeclarator)
+ && !(result instanceof IASTArrayModifier)) {
+ final IASTNode parent= result.getParent();
+ if (parent instanceof IASTDeclarator) {
+ result= (IASTDeclarator) parent;
+ } else {
+ return result;
+ }
+ }
+ return result;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclaration.java
deleted file mode 100644
index 1b108f709ff..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclaration.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser;
-
-import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
-import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
-
-public interface IASTAmbiguousDeclaration extends IASTDeclaration {
-
- public static final ASTNodeProperty SUBDECLARATION = new ASTNodeProperty( "IASTAmbiguousDeclaration.SUBDECLARATION"); //$NON-NLS-1$
- public void addDeclaration( IASTDeclaration d );
- public IASTDeclaration [] getDeclarations();
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTDeclarationAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTDeclarationAmbiguity.java
deleted file mode 100644
index c95afc9a4d2..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTDeclarationAmbiguity.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser;
-
-import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
-
-/**
- * @author jcamelon
- * @deprecated there is no class that implements this interface. Use {@link IASTAmbiguousDeclaration}, instead.
- */
-@Deprecated
-public interface IASTDeclarationAmbiguity extends IASTDeclaration
-{
-
- public void addDeclaration( IASTDeclaration decl );
-
- public IASTDeclaration [] getDeclarations();
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java
index 3dbd53c3282..c58d4830df9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java
@@ -24,13 +24,7 @@ public interface IASTInternalScope extends IScope {
* Return the physical IASTNode that this scope was created for
*/
public IASTNode getPhysicalNode() throws DOMException;
-
- /**
- * clear the name cache in this scope
- * @throws DOMException
- */
- public void flushCache() throws DOMException;
-
+
/**
* This adds an IBinding to the scope. It is primarily used by the parser to add
* implicit IBindings to the scope (such as GCC built-in functions).
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java
index a71c513790d..af7955f1a55 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java
@@ -200,9 +200,6 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
return type == this;
}
- public void flushCache() {
- }
-
public String getFileName() {
if (node != null)
return node.getContainingFilename();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java
index 5b66ee7495f..f0194295509 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java
@@ -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
@@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousBinaryVsCastExpression;
public class CASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCastExpression {
@@ -20,8 +19,4 @@ public class CASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCas
public CASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression binaryExpr, IASTCastExpression castExpr) {
super(binaryExpr, castExpr);
}
-
- public IASTExpression copy() {
- throw new UnsupportedOperationException();
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
index ffa79493748..93df7c19a0e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2009 IBM 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
@@ -54,7 +54,7 @@ public class CASTAmbiguousDeclarator extends CASTAmbiguity implements IASTAmbigu
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getDeclarators();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java
index 13afb3948e2..d44fc40f560 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -50,7 +50,7 @@ public class CASTAmbiguousExpression extends CASTAmbiguity implements IASTAmbigu
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getExpressions();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java
index 20aa19d522b..04abe4b0a9a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2009 IBM 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
@@ -50,7 +50,7 @@ public class CASTAmbiguousParameterDeclaration extends CASTAmbiguity implements
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getParameterDeclarations();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
index 1d94cc204e4..29974bb4a17 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -44,7 +44,7 @@ public class CASTAmbiguousStatement extends CASTAmbiguity implements IASTAmbiguo
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getStatements();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index aa84fafc3bf..7392fbb7b4d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -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
@@ -36,7 +36,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
-import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@@ -104,6 +103,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException;
@@ -111,7 +111,7 @@ import org.eclipse.core.runtime.CoreException;
/**
* Collection of methods to find information in an AST.
*/
-public class CVisitor {
+public class CVisitor extends ASTQueries {
public static class ClearBindingAction extends CASTVisitor {
{
shouldVisitNames = true;
@@ -530,10 +530,7 @@ public class CVisitor {
}
} else {
binding = new CEnumeration(name);
- try {
- ASTInternal.addName(scope, name);
- } catch (DOMException e1) {
- }
+ ASTInternal.addName(scope, name);
}
return binding;
}
@@ -870,11 +867,9 @@ public class CVisitor {
if (declarator.getParent() instanceof IASTFunctionDefinition) {
IScope scope = ((IASTCompoundStatement)((IASTFunctionDefinition)declarator.getParent()).getBody()).getScope();
- if (scope != null && binding != null)
- try {
- ASTInternal.addName(scope, name);
- } catch (DOMException e) {
- }
+ if (scope != null && binding != null) {
+ ASTInternal.addName(scope, name);
+ }
}
}
} else {
@@ -889,8 +884,8 @@ public class CVisitor {
parent = parent.getParent();
}
- declarator= CVisitor.findInnermostDeclarator(declarator);
- IASTDeclarator typeRelevant= CVisitor.findTypeRelevantDeclarator(declarator);
+ declarator= ASTQueries.findInnermostDeclarator(declarator);
+ IASTDeclarator typeRelevant= ASTQueries.findTypeRelevantDeclarator(declarator);
IASTFunctionDeclarator funcDeclarator= null;
if (typeRelevant instanceof IASTFunctionDeclarator) {
funcDeclarator= (IASTFunctionDeclarator) typeRelevant;
@@ -977,11 +972,9 @@ public class CVisitor {
}
}
- if (scope != null && binding != null)
- try {
- ASTInternal.addName(scope, name);
- } catch (DOMException e) {
- }
+ if (scope != null && binding != null) {
+ ASTInternal.addName(scope, name);
+ }
return binding;
}
@@ -1196,7 +1189,7 @@ public class CVisitor {
scope = getContainingScope((IASTStatement)parent);
} else if (parent instanceof IASTFunctionDefinition) {
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
- IBinding function = CVisitor.findInnermostDeclarator(fnDeclarator).getName().resolveBinding();
+ IBinding function = ASTQueries.findInnermostDeclarator(fnDeclarator).getName().resolveBinding();
try {
if (function instanceof IFunction) {
scope = ((IFunction)function).getFunctionScope();
@@ -1596,7 +1589,7 @@ public class CVisitor {
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
for (IASTDeclarator declarator : declarators) {
- declarator= CVisitor.findInnermostDeclarator(declarator);
+ declarator= ASTQueries.findInnermostDeclarator(declarator);
tempName = declarator.getName();
if (scope != null)
ASTInternal.addName(scope, tempName);
@@ -1616,7 +1609,7 @@ public class CVisitor {
} else if (!typesOnly && declaration instanceof IASTFunctionDefinition) {
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
- IASTDeclarator dtor = CVisitor.findInnermostDeclarator(functionDef.getDeclarator());
+ IASTDeclarator dtor = ASTQueries.findInnermostDeclarator(functionDef.getDeclarator());
tempName = dtor.getName();
if (scope != null)
ASTInternal.addName(scope, tempName);
@@ -1675,7 +1668,7 @@ public class CVisitor {
if (node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator) {
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator();
- IASTName name = CVisitor.findInnermostDeclarator(dtor).getName();
+ IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName();
if (name.toString().equals(declName)) {
return dtor;
}
@@ -2135,57 +2128,6 @@ public class CVisitor {
return true;
}
-
- /**
- * Returns the innermost declarator nested within the given declarator, or
- * declarator itself.
- * @since 5.0
- */
- public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
- IASTDeclarator innermost= null;
- while(declarator != null) {
- innermost= declarator;
- declarator= declarator.getNestedDeclarator();
- }
- return innermost;
- }
-
- /**
- * Returns the outermost declarator the given declarator nests within, or
- * declarator itself.
- * @since 5.0
- */
- public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
- IASTDeclarator outermost= null;
- IASTNode candidate= declarator;
- while(candidate instanceof IASTDeclarator) {
- outermost= (IASTDeclarator) candidate;
- candidate= outermost.getParent();
- }
- return outermost;
- }
-
- /**
- * Searches for the innermost declarator that contributes the the type declared.
- * @since 5.0
- */
- public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
- IASTDeclarator result= findInnermostDeclarator(declarator);
- while (result.getPointerOperators().length == 0
- && result instanceof IASTFieldDeclarator == false
- && result instanceof IASTFunctionDeclarator == false
- && result instanceof IASTArrayModifier == false) {
- final IASTNode parent= result.getParent();
- if (parent instanceof IASTDeclarator) {
- result= (IASTDeclarator) parent;
- } else {
- return result;
- }
- }
- return result;
- }
-
-
/**
* Searches for the function enclosing the given node. May return null.
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
index 699fe224166..8a67647fe01 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
@@ -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,12 +13,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
public abstract class CPPASTAmbiguity extends ASTAmbiguousNode {
@Override
protected IScope getAffectedScope() {
- return CPPVisitor.getContainingScope(this);
+ return null;
}
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
index a918e8ca50e..752bac3bc70 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
@@ -11,17 +11,24 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList;
+import java.util.HashSet;
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.IASTDeclarationStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
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.IScope;
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.ASTQueries;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
@@ -42,7 +49,8 @@ public final class CPPASTAmbiguityResolver extends ASTVisitor {
}
private LinkedList fContextStack;
private ClassContext fCurrentContext;
- private boolean fSkipInitializers;
+ private int fSkipInitializers= 0;
+ private HashSet fRepopulate= new HashSet();
public CPPASTAmbiguityResolver() {
super(false);
@@ -54,7 +62,21 @@ public final class CPPASTAmbiguityResolver extends ASTVisitor {
@Override
public int visit(ASTAmbiguousNode astAmbiguousNode) {
- astAmbiguousNode.resolveAmbiguity(this);
+ IASTNode node= astAmbiguousNode.resolveAmbiguity(this);
+ if (node instanceof IASTDeclarator) {
+ while(node != null) {
+ if (node instanceof IASTDeclaration) {
+ fRepopulate.add((IASTDeclaration) node);
+ break;
+ }
+ if (node instanceof IASTExpression) {
+ break;
+ }
+ node= node.getParent();
+ }
+ } else if (node instanceof IASTDeclarationStatement) {
+ repopulateScope(((IASTDeclarationStatement) node).getDeclaration());
+ }
return PROCESS_SKIP;
}
@@ -119,9 +141,9 @@ public final class CPPASTAmbiguityResolver extends ASTVisitor {
// 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;
+ fSkipInitializers++;
+ ASTQueries.findOutermostDeclarator(fdef.getDeclarator()).accept(this);
+ fSkipInitializers--;
if (fCurrentContext != null) {
// defer visiting the body of the function until the class body has been visited.
@@ -133,9 +155,24 @@ public final class CPPASTAmbiguityResolver extends ASTVisitor {
return PROCESS_CONTINUE;
}
+ @Override
+ public int leave(IASTDeclaration declaration) {
+ if (fRepopulate.remove(declaration)) {
+ repopulateScope(declaration);
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ private void repopulateScope(IASTDeclaration declaration) {
+ IScope scope= CPPVisitor.getContainingScope(declaration);
+ if (scope instanceof ICPPASTInternalScope) {
+ CPPSemantics.populateCache((ICPPASTInternalScope) scope, declaration, false);
+ }
+ }
+
@Override
public int visit(IASTInitializer initializer) {
- if (fSkipInitializers)
+ if (fSkipInitializers > 0)
return PROCESS_SKIP;
return PROCESS_CONTINUE;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
index a13c3c4cbd2..3f362edc1b4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java
@@ -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
@@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousBinaryVsCastExpression;
public class CPPASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCastExpression {
@@ -20,8 +19,4 @@ public class CPPASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsC
public CPPASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression bexp, IASTCastExpression castExpr) {
super(bexp, castExpr);
}
-
- public IASTExpression copy() {
- throw new UnsupportedOperationException();
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java
deleted file mode 100644
index 98c935d31bf..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclaration.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser.cpp;
-
-import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
-
-public class CPPASTAmbiguousDeclaration extends CPPASTAmbiguity implements IASTAmbiguousDeclaration {
-
- @Override
- protected IASTNode[] getNodes() {
- return getDeclarations();
- }
-
- public IASTDeclaration copy() {
- throw new UnsupportedOperationException();
- }
-
- private IASTDeclaration [] decls = new IASTDeclaration[2];
- private int declsPos=-1;
-
- public CPPASTAmbiguousDeclaration(IASTDeclaration... declarations) {
- for(IASTDeclaration d : declarations)
- addDeclaration(d);
- }
-
- public void addDeclaration(IASTDeclaration d) {
- assertNotFrozen();
- if (d != null) {
- decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, ++declsPos, d );
- d.setParent(this);
- d.setPropertyInParent(SUBDECLARATION);
- }
- }
-
- public IASTDeclaration[] getDeclarations() {
- decls = (IASTDeclaration[]) ArrayUtil.removeNullsAfter( IASTDeclaration.class, decls, declsPos );
- return decls;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
index f610c2b0bbb..633bd793f04 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2009 IBM 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
@@ -15,15 +15,16 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.Assert;
/**
* Handles ambiguities when parsing declarators.
*
* Example: void f(int (D)); // is D a type?
- * @since 5.0.1
*/
public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAmbiguousDeclarator {
@@ -39,6 +40,15 @@ public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAm
}
}
+ @Override
+ protected void beforeResolution() {
+ // populate containing scope, so that it will not be affected by the alternative branches.
+ IScope scope= CPPVisitor.getContainingScope(this);
+ if (scope instanceof ICPPASTInternalScope) {
+ ((ICPPASTInternalScope) scope).populateCache();
+ }
+ }
+
public IASTDeclarator copy() {
throw new UnsupportedOperationException();
}
@@ -58,7 +68,7 @@ public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAm
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getDeclarators();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
index c6e8ec80af4..5e4ea023b90 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -55,7 +56,7 @@ public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getExpressions();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
index dda23a5b7d8..2c86296c595 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
@@ -1,19 +1,22 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - 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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements
IASTAmbiguousStatement {
@@ -26,6 +29,15 @@ public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements
addStatement(s);
}
+ @Override
+ protected void beforeResolution() {
+ // populate containing scope, so that it will not be affected by the alternative branches.
+ IScope scope= CPPVisitor.getContainingScope(this);
+ if (scope instanceof ICPPASTInternalScope) {
+ ((ICPPASTInternalScope) scope).populateCache();
+ }
+ }
+
public IASTStatement copy() {
throw new UnsupportedOperationException();
}
@@ -45,7 +57,7 @@ public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return getStatements();
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java
index 3e099d06028..f13b697515b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2008 Symbian Software Systems and others.
+ * Copyright (c) 2008, 2009 Symbian Software Systems 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:
- * Andrew Ferguson (Symbian) - Initial Implementation
+ * Andrew Ferguson (Symbian) - Initial Implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -60,7 +61,7 @@ public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements
}
@Override
- protected IASTNode[] getNodes() {
+ public IASTNode[] getNodes() {
return fNodes.toArray(new IASTNode[fNodes.size()]);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
index 1fbccd5d038..20c9408ab37 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
@@ -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
@@ -55,6 +55,10 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
return copy;
}
+ @Override
+ public void cleanupAfterAmbiguityResolution() {
+ }
+
public CPPNamespaceScope getScope() {
if (fScope == null) {
fScope = new CPPNamespaceScope(this);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java
index 973da68843b..bdb119baa53 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java
@@ -28,8 +28,8 @@ public class CPPClassSpecializationScope extends AbstractCPPClassSpecializationS
}
// This scope does not cache its own names
- public void flushCache() {}
public void addName(IASTName name) {}
public IASTNode getPhysicalNode() { return null; }
public void addBinding(IBinding binding) {}
+ public void populateCache() {}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java
index 30e859cd3eb..82c88fb38ff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java
@@ -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
@@ -130,10 +130,4 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
}
return null;
}
-
- @Override
- public void flushCache() {
- labels.clear();
- super.flushCache();
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
index 6fd4d6e6235..ce7dce41f42 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
@@ -59,6 +59,9 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope {
public CPPScopeProblem(IASTNode node, int id, char[] arg) {
super(node, id, arg);
}
+ public CPPScopeProblem(IASTName name, int id) {
+ super(name, id);
+ }
}
public CPPScope(IASTNode physicalNode) {
@@ -282,13 +285,9 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope {
return result;
}
- protected void populateCache() {
+ public final void populateCache() {
if (!isCached) {
- try {
- CPPSemantics.lookupInScope(null, this, null);
- } catch (DOMException e) {
- CCorePlugin.log(e);
- }
+ CPPSemantics.populateCache(this);
isCached= true;
}
}
@@ -300,49 +299,6 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope {
return CPPSemantics.findBindings(this, name, false);
}
- public void flushCache() {
- final CharArrayObjectMap map= bindings;
- if (map != null) {
- CharArrayObjectMap allBuiltins= null;
- for (int i = 0; i < map.size(); i++) {
- Object o= map.getAt(i);
- if (o instanceof IASTName) {
- ((IASTName) o).setBinding(null);
- } else if (o instanceof IBinding) {
- if (allBuiltins == null) {
- allBuiltins= new CharArrayObjectMap(1);
- }
- allBuiltins.put(map.keyAt(i), o);
- } else if (o instanceof ObjectSet>) {
- @SuppressWarnings("unchecked")
- final ObjectSet