mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 362976: Directly nested ambiguity node.
This commit is contained in:
parent
893a36f642
commit
0ebca71a1d
8 changed files with 80 additions and 28 deletions
|
@ -5574,4 +5574,13 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
public void testDependentUsingDeclaration() throws Exception {
|
public void testDependentUsingDeclaration() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <int> void* foo(int);
|
||||||
|
// template <typename T> void f(T t) {
|
||||||
|
// if (T* i = foo<0>(0))
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
public void testDirectlyNestedAmbiguity_362976() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,17 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod
|
||||||
fCastExpression= castExpression;
|
fCastExpression= castExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final IASTExpression copy() {
|
public final IASTExpression copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final IASTExpression copy(CopyStyle style) {
|
public final IASTExpression copy(CopyStyle style) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void addExpression(IASTExpression e) {
|
public final void addExpression(IASTExpression e) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -57,12 +60,13 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod
|
||||||
return getExpressions();
|
return getExpressions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression[] getExpressions() {
|
public IASTExpression[] getExpressions() {
|
||||||
return new IASTExpression[] {fBinaryExpression, fCastExpression};
|
return new IASTExpression[] {fBinaryExpression, fCastExpression};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
|
||||||
|
|
|
@ -49,24 +49,28 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu
|
||||||
return getExpressions();
|
return getExpressions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final IASTExpression copy() {
|
public final IASTExpression copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final IASTExpression copy(CopyStyle style) {
|
public final IASTExpression copy(CopyStyle style) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addExpression(IASTExpression e) {
|
public void addExpression(IASTExpression e) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression[] getExpressions() {
|
public IASTExpression[] getExpressions() {
|
||||||
return new IASTExpression[] {fCastExpression, fFunctionCallExpression};
|
return new IASTExpression[] {fCastExpression, fFunctionCallExpression};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IASTNode fResolution;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the alternative nodes for this ambiguity.
|
* Return the alternative nodes for this ambiguity.
|
||||||
*/
|
*/
|
||||||
|
@ -74,6 +76,10 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
|
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
|
||||||
|
return fResolution= doResolveAmbiguity(resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IASTNode doResolveAmbiguity(ASTVisitor resolver) {
|
||||||
beforeResolution();
|
beforeResolution();
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
@ -85,23 +91,23 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
for (IASTNode alternative : alternatives) {
|
for (IASTNode alternative : alternatives) {
|
||||||
// Setup the ast to use the alternative
|
// Setup the ast to use the alternative
|
||||||
owner.replace(nodeToReplace, alternative);
|
owner.replace(nodeToReplace, alternative);
|
||||||
nodeToReplace= alternative;
|
|
||||||
|
|
||||||
beforeAlternative(alternative);
|
beforeAlternative(alternative);
|
||||||
|
|
||||||
// handle nested ambiguities first, otherwise we cannot visit the alternative
|
// Handle nested ambiguities
|
||||||
alternative.accept(resolver);
|
alternative= resolveNestedAmbiguities(alternative, resolver);
|
||||||
|
nodeToReplace= alternative;
|
||||||
|
|
||||||
// find nested names
|
// Find nested names
|
||||||
final NameCollector nameCollector= new NameCollector();
|
final NameCollector nameCollector= new NameCollector();
|
||||||
alternative.accept(nameCollector);
|
alternative.accept(nameCollector);
|
||||||
final IASTName[] names= nameCollector.getNames();
|
final IASTName[] names= nameCollector.getNames();
|
||||||
|
|
||||||
// resolve names and count issues
|
// Resolve names and count issues
|
||||||
int issues= 0;
|
int issues= 0;
|
||||||
for (IASTName name : names) {
|
for (IASTName name : names) {
|
||||||
try {
|
try {
|
||||||
// avoid resolution of parameters (can always be resolved),
|
// Avoid resolution of parameters (can always be resolved),
|
||||||
// it can triggers resolution of declaration it belongs to,
|
// it can triggers resolution of declaration it belongs to,
|
||||||
// while the declarator is still ambiguous. Could be solved by introducing an
|
// while the declarator is still ambiguous. Could be solved by introducing an
|
||||||
// intermediate binding for parameters, similar to template parameters.
|
// intermediate binding for parameters, similar to template parameters.
|
||||||
|
@ -133,7 +139,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch back to the best alternative, if necessary.
|
// Switch back to the best alternative, if necessary.
|
||||||
if (nodeToReplace != bestAlternative) {
|
if (nodeToReplace != bestAlternative) {
|
||||||
owner.replace(nodeToReplace, bestAlternative);
|
owner.replace(nodeToReplace, bestAlternative);
|
||||||
}
|
}
|
||||||
|
@ -141,6 +147,13 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
||||||
return bestAlternative;
|
return bestAlternative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IASTNode resolveNestedAmbiguities(IASTNode alternative, ASTVisitor resolver) {
|
||||||
|
alternative.accept(resolver);
|
||||||
|
if (alternative instanceof ASTAmbiguousNode)
|
||||||
|
return ((ASTAmbiguousNode) alternative).fResolution;
|
||||||
|
return alternative;
|
||||||
|
}
|
||||||
|
|
||||||
public final IType getExpressionType() {
|
public final IType getExpressionType() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,39 +56,45 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
|
||||||
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
|
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTSimpleDeclaration copy() {
|
public IASTSimpleDeclaration copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTSimpleDeclaration copy(CopyStyle style) {
|
public IASTSimpleDeclaration copy(CopyStyle style) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addDeclarator(IASTDeclarator declarator) {
|
public void addDeclarator(IASTDeclarator declarator) {
|
||||||
fSimpleDecl.addDeclarator(declarator);
|
fSimpleDecl.addDeclarator(declarator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTDeclSpecifier getDeclSpecifier() {
|
public IASTDeclSpecifier getDeclSpecifier() {
|
||||||
return fSimpleDecl.getDeclSpecifier();
|
return fSimpleDecl.getDeclSpecifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
return fSimpleDecl.getDeclarators();
|
return fSimpleDecl.getDeclarators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||||
fSimpleDecl.setDeclSpecifier(declSpec);
|
fSimpleDecl.setDeclSpecifier(declSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
|
||||||
// handle nested ambiguities first
|
// handle nested ambiguities first
|
||||||
owner.replace(nodeToReplace, fSimpleDecl);
|
owner.replace(nodeToReplace, fSimpleDecl);
|
||||||
IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier();
|
IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier();
|
||||||
declSpec.accept(visitor);
|
declSpec.accept(resolver);
|
||||||
|
|
||||||
|
|
||||||
// find nested names
|
// find nested names
|
||||||
|
@ -118,7 +124,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve further nested ambiguities
|
// resolve further nested ambiguities
|
||||||
fSimpleDecl.accept(visitor);
|
fSimpleDecl.accept(resolver);
|
||||||
return fSimpleDecl;
|
return fSimpleDecl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,14 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
|
||||||
fParameterDecl= decl;
|
fParameterDecl= decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addParameterDeclaration(IASTParameterDeclaration d) {
|
public void addParameterDeclaration(IASTParameterDeclaration d) {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
|
|
||||||
// Setup the ast to use the alternative
|
// Setup the ast to use the alternative
|
||||||
|
@ -79,6 +80,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTParameterDeclaration[] getParameterDeclarations() {
|
public IASTParameterDeclaration[] getParameterDeclarations() {
|
||||||
return new IASTParameterDeclaration[] {fParameterDecl};
|
return new IASTParameterDeclaration[] {fParameterDecl};
|
||||||
}
|
}
|
||||||
|
@ -88,32 +90,39 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
|
||||||
return getParameterDeclarations();
|
return getParameterDeclarations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTDeclSpecifier getDeclSpecifier() {
|
public IASTDeclSpecifier getDeclSpecifier() {
|
||||||
return fParameterDecl.getDeclSpecifier();
|
return fParameterDecl.getDeclSpecifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ICPPASTDeclarator getDeclarator() {
|
public ICPPASTDeclarator getDeclarator() {
|
||||||
return fParameterDecl.getDeclarator();
|
return fParameterDecl.getDeclarator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||||
Assert.isLegal(false);
|
Assert.isLegal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setDeclarator(IASTDeclarator declarator) {
|
public void setDeclarator(IASTDeclarator declarator) {
|
||||||
Assert.isLegal(false);
|
Assert.isLegal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ICPPASTParameterDeclaration copy() {
|
public ICPPASTParameterDeclaration copy() {
|
||||||
Assert.isLegal(false);
|
Assert.isLegal(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ICPPASTParameterDeclaration copy(CopyStyle style) {
|
public ICPPASTParameterDeclaration copy(CopyStyle style) {
|
||||||
Assert.isLegal(false);
|
Assert.isLegal(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isParameterPack() {
|
public boolean isParameterPack() {
|
||||||
Assert.isLegal(false);
|
Assert.isLegal(false);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -58,39 +58,45 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
|
||||||
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
|
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTSimpleDeclaration copy() {
|
public IASTSimpleDeclaration copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTSimpleDeclaration copy(CopyStyle style) {
|
public IASTSimpleDeclaration copy(CopyStyle style) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addDeclarator(IASTDeclarator declarator) {
|
public void addDeclarator(IASTDeclarator declarator) {
|
||||||
fSimpleDecl.addDeclarator(declarator);
|
fSimpleDecl.addDeclarator(declarator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTDeclSpecifier getDeclSpecifier() {
|
public IASTDeclSpecifier getDeclSpecifier() {
|
||||||
return fSimpleDecl.getDeclSpecifier();
|
return fSimpleDecl.getDeclSpecifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTDeclarator[] getDeclarators() {
|
public IASTDeclarator[] getDeclarators() {
|
||||||
return fSimpleDecl.getDeclarators();
|
return fSimpleDecl.getDeclarators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||||
fSimpleDecl.setDeclSpecifier(declSpec);
|
fSimpleDecl.setDeclSpecifier(declSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
|
||||||
// handle nested ambiguities first
|
// handle nested ambiguities first
|
||||||
owner.replace(nodeToReplace, fSimpleDecl);
|
owner.replace(nodeToReplace, fSimpleDecl);
|
||||||
IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0];
|
IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0];
|
||||||
dtor.accept(visitor);
|
dtor.accept(resolver);
|
||||||
|
|
||||||
|
|
||||||
// find nested names
|
// find nested names
|
||||||
|
@ -120,7 +126,7 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve further nested ambiguities
|
// resolve further nested ambiguities
|
||||||
fSimpleDecl.accept(visitor);
|
fSimpleDecl.accept(resolver);
|
||||||
return fSimpleDecl;
|
return fSimpleDecl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
|
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
|
||||||
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
|
||||||
IASTNode nodeToReplace= this;
|
IASTNode nodeToReplace= this;
|
||||||
|
|
||||||
|
@ -77,10 +77,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
|
||||||
|
|
||||||
// Setup the ast to use the alternative
|
// Setup the ast to use the alternative
|
||||||
owner.replace(nodeToReplace, expression);
|
owner.replace(nodeToReplace, expression);
|
||||||
nodeToReplace= expression;
|
nodeToReplace= resolveNestedAmbiguities(expression, resolver);
|
||||||
|
|
||||||
// Handle nested ambiguities first
|
|
||||||
expression.accept(resolver);
|
|
||||||
|
|
||||||
int count= checkNames(templateNames);
|
int count= checkNames(templateNames);
|
||||||
if (count > bestCount) {
|
if (count > bestCount) {
|
||||||
|
@ -163,18 +160,22 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
|
||||||
return fNodes;
|
return fNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression copy() {
|
public IASTExpression copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression copy(CopyStyle style) {
|
public IASTExpression copy(CopyStyle style) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addExpression(IASTExpression e) {
|
public void addExpression(IASTExpression e) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression[] getExpressions() {
|
public IASTExpression[] getExpressions() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue