1
0
Fork 0
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:
Markus Schorn 2011-11-07 15:00:44 +01:00
parent 893a36f642
commit 0ebca71a1d
8 changed files with 80 additions and 28 deletions

View file

@ -5574,4 +5574,13 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testDependentUsingDeclaration() throws Exception {
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();
}
}

View file

@ -40,15 +40,18 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod
fCastExpression= castExpression;
}
public final IASTExpression copy() {
@Override
public final IASTExpression copy() {
throw new UnsupportedOperationException();
}
@Override
public final IASTExpression copy(CopyStyle style) {
throw new UnsupportedOperationException();
}
public final void addExpression(IASTExpression e) {
@Override
public final void addExpression(IASTExpression e) {
throw new UnsupportedOperationException();
}
@ -57,12 +60,13 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod
return getExpressions();
}
@Override
public IASTExpression[] getExpressions() {
return new IASTExpression[] {fBinaryExpression, fCastExpression};
}
@Override
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;

View file

@ -49,24 +49,28 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu
return getExpressions();
}
public final IASTExpression copy() {
@Override
public final IASTExpression copy() {
throw new UnsupportedOperationException();
}
@Override
public final IASTExpression copy(CopyStyle style) {
throw new UnsupportedOperationException();
}
public void addExpression(IASTExpression e) {
@Override
public void addExpression(IASTExpression e) {
throw new UnsupportedOperationException();
}
@Override
public IASTExpression[] getExpressions() {
return new IASTExpression[] {fCastExpression, fFunctionCallExpression};
}
@Override
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;

View file

@ -49,6 +49,8 @@ public abstract class ASTAmbiguousNode extends ASTNode {
return names;
}
}
private IASTNode fResolution;
/**
* Return the alternative nodes for this ambiguity.
@ -73,7 +75,11 @@ public abstract class ASTAmbiguousNode extends ASTNode {
protected void afterResolution(ASTVisitor resolver, IASTNode best) {
}
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
return fResolution= doResolveAmbiguity(resolver);
}
protected IASTNode doResolveAmbiguity(ASTVisitor resolver) {
beforeResolution();
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
@ -85,23 +91,23 @@ public abstract class ASTAmbiguousNode extends ASTNode {
for (IASTNode alternative : alternatives) {
// Setup the ast to use the alternative
owner.replace(nodeToReplace, alternative);
nodeToReplace= alternative;
beforeAlternative(alternative);
// Handle nested ambiguities
alternative= resolveNestedAmbiguities(alternative, resolver);
nodeToReplace= alternative;
// handle nested ambiguities first, otherwise we cannot visit the alternative
alternative.accept(resolver);
// find nested names
// Find nested names
final NameCollector nameCollector= new NameCollector();
alternative.accept(nameCollector);
final IASTName[] names= nameCollector.getNames();
// resolve names and count issues
// Resolve names and count issues
int issues= 0;
for (IASTName name : names) {
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,
// while the declarator is still ambiguous. Could be solved by introducing an
// 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) {
owner.replace(nodeToReplace, bestAlternative);
}
@ -141,7 +147,14 @@ public abstract class ASTAmbiguousNode extends ASTNode {
return bestAlternative;
}
public final IType getExpressionType() {
protected IASTNode resolveNestedAmbiguities(IASTNode alternative, ASTVisitor resolver) {
alternative.accept(resolver);
if (alternative instanceof ASTAmbiguousNode)
return ((ASTAmbiguousNode) alternative).fResolution;
return alternative;
}
public final IType getExpressionType() {
throw new UnsupportedOperationException();
}
public final ValueCategory getValueCategory() {

View file

@ -56,39 +56,45 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
}
@Override
public IASTSimpleDeclaration copy() {
throw new UnsupportedOperationException();
}
@Override
public IASTSimpleDeclaration copy(CopyStyle style) {
throw new UnsupportedOperationException();
}
@Override
public void addDeclarator(IASTDeclarator declarator) {
fSimpleDecl.addDeclarator(declarator);
}
@Override
public IASTDeclSpecifier getDeclSpecifier() {
return fSimpleDecl.getDeclSpecifier();
}
@Override
public IASTDeclarator[] getDeclarators() {
return fSimpleDecl.getDeclarators();
}
@Override
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
fSimpleDecl.setDeclSpecifier(declSpec);
}
@Override
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
// handle nested ambiguities first
owner.replace(nodeToReplace, fSimpleDecl);
IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier();
declSpec.accept(visitor);
declSpec.accept(resolver);
// find nested names
@ -118,7 +124,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
}
// resolve further nested ambiguities
fSimpleDecl.accept(visitor);
fSimpleDecl.accept(resolver);
return fSimpleDecl;
}
}

View file

@ -43,13 +43,14 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
fParameterDecl= decl;
}
@Override
public void addParameterDeclaration(IASTParameterDeclaration d) {
assert false;
}
@Override
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
// Setup the ast to use the alternative
@ -79,6 +80,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
}
}
@Override
public IASTParameterDeclaration[] getParameterDeclarations() {
return new IASTParameterDeclaration[] {fParameterDecl};
}
@ -88,32 +90,39 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
return getParameterDeclarations();
}
@Override
public IASTDeclSpecifier getDeclSpecifier() {
return fParameterDecl.getDeclSpecifier();
}
@Override
public ICPPASTDeclarator getDeclarator() {
return fParameterDecl.getDeclarator();
}
@Override
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
Assert.isLegal(false);
}
@Override
public void setDeclarator(IASTDeclarator declarator) {
Assert.isLegal(false);
}
@Override
public ICPPASTParameterDeclaration copy() {
Assert.isLegal(false);
return null;
}
@Override
public ICPPASTParameterDeclaration copy(CopyStyle style) {
Assert.isLegal(false);
return null;
}
@Override
public boolean isParameterPack() {
Assert.isLegal(false);
return true;

View file

@ -58,39 +58,45 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor};
}
@Override
public IASTSimpleDeclaration copy() {
throw new UnsupportedOperationException();
}
@Override
public IASTSimpleDeclaration copy(CopyStyle style) {
throw new UnsupportedOperationException();
}
@Override
public void addDeclarator(IASTDeclarator declarator) {
fSimpleDecl.addDeclarator(declarator);
}
@Override
public IASTDeclSpecifier getDeclSpecifier() {
return fSimpleDecl.getDeclSpecifier();
}
@Override
public IASTDeclarator[] getDeclarators() {
return fSimpleDecl.getDeclarators();
}
@Override
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
fSimpleDecl.setDeclSpecifier(declSpec);
}
@Override
public final IASTNode resolveAmbiguity(ASTVisitor visitor) {
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
// handle nested ambiguities first
owner.replace(nodeToReplace, fSimpleDecl);
IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0];
dtor.accept(visitor);
dtor.accept(resolver);
// find nested names
@ -120,7 +126,7 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
}
// resolve further nested ambiguities
fSimpleDecl.accept(visitor);
fSimpleDecl.accept(resolver);
return fSimpleDecl;
}
}

View file

@ -57,7 +57,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
}
@Override
public IASTNode resolveAmbiguity(ASTVisitor resolver) {
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
IASTNode nodeToReplace= this;
@ -77,10 +77,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
// Setup the ast to use the alternative
owner.replace(nodeToReplace, expression);
nodeToReplace= expression;
// Handle nested ambiguities first
expression.accept(resolver);
nodeToReplace= resolveNestedAmbiguities(expression, resolver);
int count= checkNames(templateNames);
if (count > bestCount) {
@ -163,18 +160,22 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTA
return fNodes;
}
@Override
public IASTExpression copy() {
throw new UnsupportedOperationException();
}
@Override
public IASTExpression copy(CopyStyle style) {
throw new UnsupportedOperationException();
}
@Override
public void addExpression(IASTExpression e) {
throw new UnsupportedOperationException();
}
@Override
public IASTExpression[] getExpressions() {
throw new UnsupportedOperationException();
}