mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
fixed problem with "template<class T, class U = T>" not parsing correctly
This commit is contained in:
parent
0c05265d7d
commit
749ea13431
22 changed files with 238 additions and 54 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.util;
|
|||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
|
@ -41,8 +42,14 @@ import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
|
||||
|
@ -261,14 +268,14 @@ public class ASTPrinter {
|
|||
}
|
||||
|
||||
|
||||
private static class ProblemVisitor extends CASTVisitor {
|
||||
private static class ProblemVisitor extends ASTVisitor {
|
||||
private PrintStream out;
|
||||
|
||||
ProblemVisitor(PrintStream out) {
|
||||
this.out = out;
|
||||
shouldVisitProblems = true;
|
||||
shouldVisitDeclarations = true;
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitProblems =
|
||||
shouldVisitDeclarations =
|
||||
shouldVisitStatements =
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
|
@ -301,29 +308,37 @@ public class ASTPrinter {
|
|||
}
|
||||
|
||||
|
||||
private static class PrintVisitor extends CASTVisitor {
|
||||
/**
|
||||
* This visitor extends from CPPASTVisitor but you can still
|
||||
* apply it to a plain C AST and it will print everything
|
||||
* except designators.
|
||||
*/
|
||||
private static class PrintVisitor extends CPPASTVisitor {
|
||||
|
||||
|
||||
private PrintStream out;
|
||||
private int indentLevel = 0;
|
||||
|
||||
PrintVisitor(PrintStream out) {
|
||||
this.out = out;
|
||||
shouldVisitDesignators = true;
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
shouldVisitInitializers = true;
|
||||
shouldVisitParameterDeclarations = true;
|
||||
shouldVisitDeclarators = true;
|
||||
shouldVisitDeclSpecifiers = true;
|
||||
shouldVisitExpressions = true;
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitTypeIds = true;
|
||||
shouldVisitEnumerators = true;
|
||||
shouldVisitTranslationUnit = true;
|
||||
shouldVisitProblems = true;
|
||||
shouldVisitNames =
|
||||
shouldVisitDeclarations =
|
||||
shouldVisitInitializers =
|
||||
shouldVisitParameterDeclarations =
|
||||
shouldVisitDeclarators =
|
||||
shouldVisitDeclSpecifiers =
|
||||
shouldVisitExpressions =
|
||||
shouldVisitStatements =
|
||||
shouldVisitTypeIds =
|
||||
shouldVisitEnumerators =
|
||||
shouldVisitTranslationUnit =
|
||||
shouldVisitProblems =
|
||||
shouldVisitDesignators =
|
||||
shouldVisitBaseSpecifiers =
|
||||
shouldVisitNamespaces =
|
||||
shouldVisitTemplateParameters = true;
|
||||
}
|
||||
|
||||
|
||||
private void print(IASTNode node) {
|
||||
ASTPrinter.print(out, indentLevel, node);
|
||||
}
|
||||
|
@ -332,12 +347,12 @@ public class ASTPrinter {
|
|||
ASTPrinter.print(out, indentLevel, binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICASTDesignator designator) {
|
||||
print(designator);
|
||||
indentLevel++;
|
||||
return super.visit(designator);
|
||||
}
|
||||
// @Override
|
||||
// public int visit(ICASTDesignator designator) {
|
||||
// print(designator);
|
||||
// indentLevel++;
|
||||
// return super.visit(designator);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
|
@ -442,13 +457,34 @@ public class ASTPrinter {
|
|||
return super.visit(typeId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int leave(ICASTDesignator designator) {
|
||||
indentLevel--;
|
||||
return super.leave(designator);
|
||||
public int visit(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
print(baseSpecifier);
|
||||
indentLevel++;
|
||||
return super.visit(baseSpecifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
print(namespaceDefinition);
|
||||
indentLevel++;
|
||||
return super.visit(namespaceDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTTemplateParameter templateParameter) {
|
||||
print(templateParameter);
|
||||
indentLevel++;
|
||||
return super.visit(templateParameter);
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public int leave(ICASTDesignator designator) {
|
||||
// indentLevel--;
|
||||
// return super.leave(designator);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclaration declaration) {
|
||||
indentLevel--;
|
||||
|
@ -521,5 +557,23 @@ public class ASTPrinter {
|
|||
return super.leave(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(ICPPASTBaseSpecifier baseSpecifier) {
|
||||
indentLevel--;
|
||||
return super.leave(baseSpecifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
indentLevel--;
|
||||
return super.leave(namespaceDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(ICPPASTTemplateParameter templateParameter) {
|
||||
indentLevel--;
|
||||
return super.leave(templateParameter);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
|
@ -12,6 +14,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRCPPSpecTest extends AST2CPPSpecTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRCPPSpecTest.class);
|
||||
}
|
||||
|
||||
public LRCPPSpecTest() { }
|
||||
public LRCPPSpecTest(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
|
@ -23,6 +24,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRCSpecTests extends AST2CSpecTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRCSpecTests.class);
|
||||
}
|
||||
|
||||
public LRCSpecTests() { }
|
||||
public LRCSpecTests(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -23,7 +25,11 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRCommentTests extends CommentTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRCommentTests.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
|
@ -21,6 +22,10 @@ import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
|
|||
|
||||
public class LRCompleteParser2Tests extends CompleteParser2Tests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRCompleteParser2Tests.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
protected IASTTranslationUnit parse(String code, boolean expectedToPass,
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -25,6 +27,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRCompletionBasicTest extends BasicCompletionTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRCompletionBasicTest.class);
|
||||
}
|
||||
|
||||
public LRCompletionBasicTest() { }
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -34,6 +35,11 @@ import org.eclipse.cdt.core.model.ILanguage;
|
|||
@SuppressWarnings("nls")
|
||||
public class LRCompletionParseTest extends TestCase {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRCompletionParseTest.class);
|
||||
}
|
||||
|
||||
|
||||
public LRCompletionParseTest() { }
|
||||
public LRCompletionParseTest(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -25,6 +27,10 @@ import org.eclipse.core.resources.IFile;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRDOMLocationInclusionTests extends DOMLocationInclusionTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRDOMLocationInclusionTests.class);
|
||||
}
|
||||
|
||||
public LRDOMLocationInclusionTests() {
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -21,15 +23,12 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRDOMLocationMacroTests extends DOMLocationMacroTests {
|
||||
|
||||
|
||||
public LRDOMLocationMacroTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public LRDOMLocationMacroTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
public static TestSuite suite() {
|
||||
return suite(LRDOMLocationMacroTests.class);
|
||||
}
|
||||
|
||||
public LRDOMLocationMacroTests() {}
|
||||
public LRDOMLocationMacroTests(String name) { super(name); }
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
|
@ -23,6 +24,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRDOMLocationTests extends DOMLocationTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRDOMLocationTests.class);
|
||||
}
|
||||
|
||||
public LRDOMLocationTests() { }
|
||||
public LRDOMLocationTests(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -21,6 +23,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRDOMPreprocessorInformationTest extends DOMPreprocessorInformationTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRDOMPreprocessorInformationTest.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
|
@ -41,6 +42,10 @@ import org.eclipse.cdt.core.model.ILanguage;
|
|||
@SuppressWarnings("nls")
|
||||
public class LRDigraphTrigraphTests extends TestCase {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRCSpecTests.class);
|
||||
}
|
||||
|
||||
|
||||
public LRDigraphTrigraphTests() { }
|
||||
public LRDigraphTrigraphTests(String name) { super(name); }
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -21,6 +23,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRGCCTests extends GCCTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRGCCTests.class);
|
||||
}
|
||||
|
||||
public LRGCCTests() {}
|
||||
public LRGCCTests(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -24,7 +26,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRKnRTests extends AST2KnRTests {
|
||||
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRKnRTests.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -28,6 +30,10 @@ import org.eclipse.core.resources.IFile;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRSelectionParseTest extends AST2SelectionParseTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRSelectionParseTest.class);
|
||||
}
|
||||
|
||||
public LRSelectionParseTest() {}
|
||||
public LRSelectionParseTest(String name) { super(name); }
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -21,6 +23,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRTaskParserTest extends TaskParserTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LRTaskParserTest.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
|
@ -23,6 +24,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRUtilOldTests extends AST2UtilOldTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRUtilOldTests.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
@ -21,6 +23,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
@SuppressWarnings("restriction")
|
||||
public class LRUtilTests extends AST2UtilTests {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRUtilTests.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
|
||||
return parse(code, lang, false, true );
|
||||
|
|
|
@ -1791,6 +1791,8 @@ template_argument_list_opt
|
|||
| $empty
|
||||
|
||||
|
||||
-- TODO there are ambiguities here, for example f<i>, i could be variable or type
|
||||
-- may need to double parse
|
||||
template_argument
|
||||
::= assignment_expression
|
||||
| type_id
|
||||
|
|
|
@ -297,12 +297,12 @@ public abstract class BuildASTParserAction {
|
|||
*
|
||||
* @throws NullPointerException if source or pattern is null
|
||||
*/
|
||||
public static boolean matchTokens(List<IToken> source, Integer ... pattern) {
|
||||
public static boolean matchTokens(List<IToken> source, ITokenMap tokenMap, Integer ... pattern) {
|
||||
if(source.size() != pattern.length) // throws NPE if either parameter is null
|
||||
return false;
|
||||
|
||||
for(int i = 0, n = pattern.length; i < n; i++) {
|
||||
if(source.get(i).getKind() != pattern[i].intValue())
|
||||
if(tokenMap.mapKind(source.get(i).getKind()) != pattern[i].intValue())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -352,7 +352,6 @@ public abstract class BuildASTParserAction {
|
|||
* was not parsed.
|
||||
*/
|
||||
public void consumeEmpty() {
|
||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||
astStack.push(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.lrparser.action;
|
|||
|
||||
import static org.eclipse.cdt.core.parser.util.CollectionUtils.reverseIterable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -79,11 +80,11 @@ public class ScopedStack<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Marks the stack then pushes all the items in the given list.
|
||||
* Opens a scope then pushes all the items in the given list.
|
||||
*
|
||||
* @throws NullPointerException if items is null
|
||||
*/
|
||||
public void openScope(List<T> items) {
|
||||
public void openScope(Collection<T> items) {
|
||||
openScope();
|
||||
for(T item : items)
|
||||
push(item);
|
||||
|
|
|
@ -409,22 +409,22 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
|
||||
|
||||
|
||||
private static OverloadableOperator getOverloadableOperator(List<IToken> tokens) {
|
||||
private OverloadableOperator getOverloadableOperator(List<IToken> tokens) {
|
||||
if(tokens.size() == 1) {
|
||||
// TODO this is a hack that I did to save time
|
||||
LPGTokenAdapter coreToken = (LPGTokenAdapter) tokens.get(0);
|
||||
return OverloadableOperator.valueOf(coreToken.getWrappedToken());
|
||||
}
|
||||
else if(matchTokens(tokens, TK_new, TK_LeftBracket, TK_RightBracket)) {
|
||||
else if(matchTokens(tokens, tokenMap, TK_new, TK_LeftBracket, TK_RightBracket)) {
|
||||
return OverloadableOperator.NEW_ARRAY;
|
||||
}
|
||||
else if(matchTokens(tokens, TK_delete, TK_LeftBracket, TK_RightBracket)) {
|
||||
else if(matchTokens(tokens, tokenMap, TK_delete, TK_LeftBracket, TK_RightBracket)) {
|
||||
return OverloadableOperator.DELETE_ARRAY;
|
||||
}
|
||||
else if(matchTokens(tokens, TK_LeftBracket, TK_RightBracket)) {
|
||||
else if(matchTokens(tokens, tokenMap, TK_LeftBracket, TK_RightBracket)) {
|
||||
return OverloadableOperator.BRACKET;
|
||||
}
|
||||
else if(matchTokens(tokens, TK_LeftParen, TK_RightParen)) {
|
||||
else if(matchTokens(tokens, tokenMap, TK_LeftParen, TK_RightParen)) {
|
||||
return OverloadableOperator.PAREN;
|
||||
}
|
||||
|
||||
|
@ -1209,7 +1209,7 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
List<IToken> ruleTokens = parser.getRuleTokens();
|
||||
|
||||
// do not generate nodes for extra EOC tokens
|
||||
if(matchTokens(ruleTokens, CPPParsersym.TK_EndOfCompletion)) {
|
||||
if(matchTokens(ruleTokens, tokenMap, TK_EndOfCompletion)) {
|
||||
return;
|
||||
}
|
||||
if(declSpecifier == null) { // can happen if implicit int is used
|
||||
|
@ -1715,6 +1715,9 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
IASTTypeId typeId = hasTypeId ? (IASTTypeId)astStack.pop() : null;
|
||||
|
||||
IASTName name = (IASTName)astStack.pop();
|
||||
if(name == null)
|
||||
name = nodeFactory.newName();
|
||||
|
||||
int type = getTemplateParameterType(parser.getLeftIToken());
|
||||
|
||||
ICPPASTSimpleTypeTemplateParameter templateParameter = nodeFactory.newSimpleTypeTemplateParameter(type, name, typeId);
|
||||
|
@ -1746,21 +1749,57 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
*
|
||||
* This method detects the incorrect parse, throws away the incorrect AST fragment,
|
||||
* and replaces it with the correct AST fragment.
|
||||
*
|
||||
* Yes its a hack, but it took way less time to just do this than to refactor the grammar.
|
||||
*
|
||||
* TODO: there are more ambiguities with templates, maybe some double parsing is in order.
|
||||
*/
|
||||
public void consumeTemplateParamterDeclaration() {
|
||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||
|
||||
List<IToken> ruleTokens = parser.getRuleTokens();
|
||||
|
||||
if(matchTokens(parser.getRuleTokens(), TK_class, TK_identifier)) {
|
||||
astStack.pop(); // throw away the ICPPASTParameterDeclaration
|
||||
IASTName name = createName(parser.getRightIToken());
|
||||
astStack.push(name);
|
||||
if(matchTokens(ruleTokens, tokenMap, TK_class)) {
|
||||
astStack.pop();
|
||||
astStack.push(null);
|
||||
consumeSimpleTypeTemplateParameter(false);
|
||||
}
|
||||
else if(matchTokens(ruleTokens, tokenMap, TK_class, TK_identifier)) {
|
||||
astStack.pop();
|
||||
astStack.push(createName(ruleTokens.get(1)));
|
||||
consumeSimpleTypeTemplateParameter(false);
|
||||
}
|
||||
else if(matchTokens(ruleTokens, tokenMap, TK_class, TK_Assign, TK_identifier)) {
|
||||
astStack.pop();
|
||||
IASTName typeName = createName(ruleTokens.get(3));
|
||||
fixTemplateParameterDeclarationWithInitializer(null, typeName);
|
||||
}
|
||||
else if(matchTokens(ruleTokens, tokenMap, TK_class, TK_identifier, TK_Assign, TK_identifier)) {
|
||||
astStack.pop();
|
||||
IASTName name = createName(ruleTokens.get(1));
|
||||
IASTName typeName = createName(ruleTokens.get(3));
|
||||
fixTemplateParameterDeclarationWithInitializer(name, typeName);
|
||||
}
|
||||
|
||||
if(TRACE_AST_STACK) System.out.println(astStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manually create the AST for a template parameter with initializer.
|
||||
*/
|
||||
private void fixTemplateParameterDeclarationWithInitializer(IASTName name, IASTName typeName) {
|
||||
astStack.push(name);
|
||||
ICPPASTNamedTypeSpecifier namedTypeSpecifier = nodeFactory.newCPPNamedTypeSpecifier(typeName, false);
|
||||
setOffsetAndLength(namedTypeSpecifier, offset(typeName), length(typeName));
|
||||
IASTDeclarator declarator = nodeFactory.newDeclarator(nodeFactory.newName());
|
||||
IASTTypeId typeId = nodeFactory.newTypeId(namedTypeSpecifier, declarator);
|
||||
setOffsetAndLength(typeId, offset(typeName), length(typeName));
|
||||
astStack.push(typeId);
|
||||
consumeSimpleTypeTemplateParameter(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* type_parameter
|
||||
|
|
Loading…
Add table
Reference in a new issue