mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 427854 - Encountered an ambiguous node error message produced by
parser
This commit is contained in:
parent
ffa470ee1a
commit
ef9771f9fa
2 changed files with 41 additions and 4 deletions
|
@ -9602,6 +9602,26 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <typename T>
|
||||||
|
// struct A {
|
||||||
|
// typedef char c;
|
||||||
|
// static constexpr int method() {
|
||||||
|
// return sizeof(c);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// static const int x = method();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template<typename T, int x = A<int>::x>
|
||||||
|
// struct B;
|
||||||
|
//
|
||||||
|
// template<>
|
||||||
|
// struct B<int> {
|
||||||
|
// };
|
||||||
|
public void testAmbiguityResolution_427854() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
|
|
||||||
// template<typename T> struct C {
|
// template<typename T> struct C {
|
||||||
// C(const C<T>& c) {}
|
// C(const C<T>& c) {}
|
||||||
// };
|
// };
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||||
|
@ -45,7 +47,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||||
private int fSkipInitializers= 0;
|
private int fSkipInitializers= 0;
|
||||||
private int fDeferFunctions= 1;
|
private int fDeferFunctions= 1;
|
||||||
private HashSet<IASTDeclaration> fRepopulate= new HashSet<>();
|
private HashSet<IASTDeclaration> fRepopulate= new HashSet<>();
|
||||||
private ArrayDeque<IASTNode> fDeferredNodes= new ArrayDeque<>();
|
private Deque<Deque<IASTNode>> fDeferredNodes= new ArrayDeque<>();
|
||||||
|
|
||||||
public CPPASTAmbiguityResolver() {
|
public CPPASTAmbiguityResolver() {
|
||||||
super(false);
|
super(false);
|
||||||
|
@ -94,6 +96,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
fDeferFunctions++;
|
fDeferFunctions++;
|
||||||
|
fDeferredNodes.add(new ArrayDeque<IASTNode>());
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +113,8 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||||
// Trigger computation of implicit members.
|
// Trigger computation of implicit members.
|
||||||
if (declSpec instanceof CPPASTCompositeTypeSpecifier)
|
if (declSpec instanceof CPPASTCompositeTypeSpecifier)
|
||||||
((CPPASTCompositeTypeSpecifier) declSpec).setAmbiguitiesResolved();
|
((CPPASTCompositeTypeSpecifier) declSpec).setAmbiguitiesResolved();
|
||||||
|
|
||||||
|
processDeferredNodes(fDeferredNodes.removeLast());
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +131,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||||
fSkipInitializers--;
|
fSkipInitializers--;
|
||||||
fdef.getDeclSpecifier().accept(this);
|
fdef.getDeclSpecifier().accept(this);
|
||||||
// Defer visiting the body of the function until the class body has been visited.
|
// Defer visiting the body of the function until the class body has been visited.
|
||||||
fDeferredNodes.add(decl);
|
fDeferredNodes.getLast().add(decl);
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
|
@ -173,15 +178,27 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTTranslationUnit tu) {
|
||||||
|
fDeferredNodes.add(new ArrayDeque<IASTNode>());
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int leave(IASTTranslationUnit tu) {
|
public int leave(IASTTranslationUnit tu) {
|
||||||
while (!fDeferredNodes.isEmpty()) {
|
while (!fDeferredNodes.isEmpty()) {
|
||||||
fDeferFunctions= 0;
|
processDeferredNodes(fDeferredNodes.removeLast());
|
||||||
fDeferredNodes.removeFirst().accept(this);
|
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processDeferredNodes(Deque<IASTNode> deferredNodes) {
|
||||||
|
while (!deferredNodes.isEmpty()) {
|
||||||
|
fDeferFunctions= 0;
|
||||||
|
deferredNodes.removeFirst().accept(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void repopulateScope(IASTDeclaration declaration) {
|
private void repopulateScope(IASTDeclaration declaration) {
|
||||||
IScope scope= CPPVisitor.getContainingNonTemplateScope(declaration);
|
IScope scope= CPPVisitor.getContainingNonTemplateScope(declaration);
|
||||||
if (scope instanceof ICPPASTInternalScope) {
|
if (scope instanceof ICPPASTInternalScope) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue