1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

implicit int now works a lot better (static var;) ,fixed but with globally qualified ids not resolving properly

This commit is contained in:
Mike Kucera 2008-04-03 19:03:02 +00:00
parent a8a0150712
commit 28fc06fe7b
9 changed files with 100 additions and 85 deletions

View file

@ -183,20 +183,30 @@ public class C99SpecTests extends AST2CSpecTest {
}
// @Override
// public void test6_7_8s24() throws Exception { // complex isn't declared as a typedef
// try {
// super.test6_7_8s24();
// fail();
// } catch(AssertionFailedError _) { }
// }
//
//
// @Override
// public void test6_7_8s34() throws Exception { // div_t isn't declared as a typedef
// try {
// super.test6_7_8s34();
// fail();
// } catch(AssertionFailedError _) { }
// }
@Override
public void test6_7_8s24() throws Exception { // complex isn't declared as a typedef
public void test6_7_2_1s17() throws Exception { // what the heck is offsetof
try {
super.test6_7_8s24();
super.test6_7_2_1s17();
fail();
} catch(AssertionFailedError _) { }
}
@Override
public void test6_7_8s34() throws Exception { // div_t isn't declared as a typedef
try {
super.test6_7_8s34();
fail();
} catch(AssertionFailedError _) { }
}
}

View file

@ -964,12 +964,12 @@ declaration_seq_opt
simple_declaration
::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ';'
/. $Build consumeDeclarationSimple(true, true); $EndBuild ./
/. $Build consumeDeclarationSimple(true); $EndBuild ./
simple_declaration_with_declspec
::= declaration_specifiers <openscope-ast> init_declarator_list_opt ';'
/. $Build consumeDeclarationSimple(true, false); $EndBuild ./
/. $Build consumeDeclarationSimple(true); $EndBuild ./
-- declaration specifier nodes not created here, they are created by sub-rules
@ -1567,9 +1567,9 @@ visibility_label
member_declaration
::= declaration_specifiers_opt <openscope-ast> member_declarator_list ';'
/. $Build consumeDeclarationSimple(true, true); $EndBuild ./
/. $Build consumeDeclarationSimple(true); $EndBuild ./
| declaration_specifiers_opt ';'
/. $Build consumeDeclarationSimple(false, false); $EndBuild ./
/. $Build consumeDeclarationSimple(false); $EndBuild ./
| function_definition ';'
| function_definition
| dcolon_opt nested_name_specifier template_opt unqualified_id_name ';'
@ -1828,11 +1828,11 @@ handler
-- open a scope just so that we can reuse consumeDeclarationSimple()
exception_declaration
::= type_specifier_seq <openscope-ast> declarator
/. $Build consumeDeclarationSimple(true, false); $EndBuild ./
/. $Build consumeDeclarationSimple(true); $EndBuild ./
| type_specifier_seq <openscope-ast> abstract_declarator -- TODO might need to be abstract_declarator_without_function, might be too lenient, what exactly can you catch?
/. $Build consumeDeclarationSimple(true, false); $EndBuild ./
/. $Build consumeDeclarationSimple(true); $EndBuild ./
| type_specifier_seq
/. $Build consumeDeclarationSimple(false, false); $EndBuild ./
/. $Build consumeDeclarationSimple(false); $EndBuild ./
-- puts type ids on the stack

View file

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action;
import java.util.Collections;
import java.util.List;
import lpg.lpgjavaruntime.IToken;
@ -38,7 +37,6 @@ 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.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
@ -70,8 +68,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.core.parser.util.DebugUtil;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym;
import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPParsersym;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -617,6 +613,8 @@ public abstract class BuildASTParserAction {
public void consumeExpressionName() {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
System.out.println("Exression name: " + parser.getRuleTokens());
IASTName name = (IASTName) astStack.pop();
IASTIdExpression expr = nodeFactory.newIdExpression(name);
setOffsetAndLength(expr);

View file

@ -490,17 +490,19 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* | '::' operator_function_id
* | '::' template_id
*/
public void consumeGlobalQualifiedId() {
@SuppressWarnings("restriction")
public void consumeGlobalQualifiedId() {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
IASTName name = (IASTName) astStack.pop();
ICPPASTQualifiedName qualifiedName = nodeFactory.newCPPQualifiedName();
qualifiedName.addName(name);
qualifiedName.setFullyQualified(true);
((CPPASTQualifiedName)qualifiedName).setSignature("::" + name.toString()); //$NON-NLS-1$
setOffsetAndLength(qualifiedName);
astStack.push(name);
astStack.push(qualifiedName);
if(TRACE_AST_STACK) System.out.println(astStack);
}
@ -741,7 +743,7 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
private IASTName createQualifiedName(LinkedList<IASTName> names, int startOffset, int endOffset, boolean startsWithColonColon, boolean endsWithColonColon) {
if(!endsWithColonColon && !startsWithColonColon && names.size() == 1)
return names.getFirst(); // its actually an unqualified name
ICPPASTQualifiedName qualifiedName = nodeFactory.newCPPQualifiedName();
qualifiedName.setFullyQualified(startsWithColonColon);
setOffsetAndLength(qualifiedName, startOffset, endOffset - startOffset);
@ -1182,21 +1184,46 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
*
* TODO: remove attemptAmbiguityResolution parameter
*/
public void consumeDeclarationSimple(boolean hasDeclaratorList, boolean attemptAmbiguityResolution) {
public void consumeDeclarationSimple(boolean hasDeclaratorList) {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
List<Object> declarators = (hasDeclaratorList) ? astStack.closeScope() : Collections.emptyList();
List<Object> declarators = hasDeclaratorList ? astStack.closeScope() : Collections.emptyList();
IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop(); // may be null
List<IToken> ruleTokens = parser.getRuleTokens();
// do not generate nodes for extra EOC tokens
if(matchTokens(parser.getRuleTokens(), CPPParsersym.TK_EndOfCompletion))
if(matchTokens(ruleTokens, CPPParsersym.TK_EndOfCompletion)) {
return;
}
if(declSpecifier == null) { // can happen if implicit int is used
declSpecifier = nodeFactory.newSimpleDeclSpecifier();
setOffsetAndLength(declSpecifier, parser.getLeftIToken().getStartOffset(), 0);
}
// bug 80171, check for situation similar to: static var;
// this will get parsed wrong, the following is a hack to rebuild the AST as it should have been parsed
IToken nameToken = null;
if(declarators.isEmpty() &&
declSpecifier instanceof ICPPASTNamedTypeSpecifier &&
ruleTokens.size() >= 2 &&
(nameToken = ruleTokens.get(ruleTokens.size() - 2)).getKind() == TK_identifier) {
declSpecifier = nodeFactory.newSimpleDeclSpecifier();
for(IToken t : ruleTokens.subList(0, ruleTokens.size()-1))
setSpecifier((ICPPASTDeclSpecifier)declSpecifier, t);
int offset = offset(parser.getLeftIToken());
int length = endOffset(ruleTokens.get(ruleTokens.size()-2)) - offset;
setOffsetAndLength(declSpecifier, offset, length);
IASTName name = createName(nameToken);
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
setOffsetAndLength(declarator, nameToken);
declarators.add(declarator);
}
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
setOffsetAndLength(declaration);
for(Object declarator : declarators)
@ -1204,32 +1231,12 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
astStack.push(declaration);
// IASTNode alternateDeclaration = null;
// if(attemptAmbiguityResolution) {// && hasConstructorInitializer(declaration)) { // try to resolve the constructor initializer ambiguity
// // TODO should this ambiguity be resolved here, or at the level of individual declarators?
// IParser alternateParser = new CPPNoConstructorInitializerParser(parser.getOrderedTerminalSymbols());
// alternateDeclaration = runSecondaryParser(alternateParser);
// }
//
// if(alternateDeclaration == null || alternateDeclaration instanceof IASTProblemDeclaration)
// astStack.push(declaration);
// else {
// System.out.println("Ambiguous Declaration in my parser!");
//// ASTPrinter.print(declaration);
//// System.out.println();
//// ASTPrinter.print(alternateDeclaration);
//// System.out.println();
//
// IASTNode ambiguityNode = nodeFactory.newAmbiguousDeclaration((IASTDeclaration)alternateDeclaration, declaration);
// setOffsetAndLength(ambiguityNode);
// astStack.push(ambiguityNode);
// }
//
if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeInitDeclaratorComplete() {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();

View file

@ -1242,14 +1242,14 @@ public CPPExpressionStatementParser(String[] mapFrom) { // constructor
// Rule 226: simple_declaration ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ;
//
case 226: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 227: simple_declaration_with_declspec ::= declaration_specifiers <openscope-ast> init_declarator_list_opt ;
//
case 227: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
@ -1956,14 +1956,14 @@ public CPPExpressionStatementParser(String[] mapFrom) { // constructor
// Rule 400: member_declaration ::= declaration_specifiers_opt <openscope-ast> member_declarator_list ;
//
case 400: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 401: member_declaration ::= declaration_specifiers_opt ;
//
case 401: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//
@ -2243,21 +2243,21 @@ public CPPExpressionStatementParser(String[] mapFrom) { // constructor
// Rule 520: exception_declaration ::= type_specifier_seq <openscope-ast> declarator
//
case 520: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 521: exception_declaration ::= type_specifier_seq <openscope-ast> abstract_declarator
//
case 521: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 522: exception_declaration ::= type_specifier_seq
//
case 522: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//

View file

@ -1235,14 +1235,14 @@ public CPPNoCastExpressionParser(String[] mapFrom) { // constructor
// Rule 225: simple_declaration ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ;
//
case 225: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 226: simple_declaration_with_declspec ::= declaration_specifiers <openscope-ast> init_declarator_list_opt ;
//
case 226: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
@ -1949,14 +1949,14 @@ public CPPNoCastExpressionParser(String[] mapFrom) { // constructor
// Rule 399: member_declaration ::= declaration_specifiers_opt <openscope-ast> member_declarator_list ;
//
case 399: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 400: member_declaration ::= declaration_specifiers_opt ;
//
case 400: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//
@ -2236,21 +2236,21 @@ public CPPNoCastExpressionParser(String[] mapFrom) { // constructor
// Rule 519: exception_declaration ::= type_specifier_seq <openscope-ast> declarator
//
case 519: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 520: exception_declaration ::= type_specifier_seq <openscope-ast> abstract_declarator
//
case 520: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 521: exception_declaration ::= type_specifier_seq
//
case 521: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//

View file

@ -1242,14 +1242,14 @@ public CPPNoFunctionDeclaratorParser(String[] mapFrom) { // constructor
// Rule 226: simple_declaration ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ;
//
case 226: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 227: simple_declaration_with_declspec ::= declaration_specifiers <openscope-ast> init_declarator_list_opt ;
//
case 227: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
@ -1949,14 +1949,14 @@ public CPPNoFunctionDeclaratorParser(String[] mapFrom) { // constructor
// Rule 398: member_declaration ::= declaration_specifiers_opt <openscope-ast> member_declarator_list ;
//
case 398: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 399: member_declaration ::= declaration_specifiers_opt ;
//
case 399: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//
@ -2236,21 +2236,21 @@ public CPPNoFunctionDeclaratorParser(String[] mapFrom) { // constructor
// Rule 518: exception_declaration ::= type_specifier_seq <openscope-ast> declarator
//
case 518: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 519: exception_declaration ::= type_specifier_seq <openscope-ast> abstract_declarator
//
case 519: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 520: exception_declaration ::= type_specifier_seq
//
case 520: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//

View file

@ -1242,14 +1242,14 @@ public CPPParser(String[] mapFrom) { // constructor
// Rule 226: simple_declaration ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ;
//
case 226: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 227: simple_declaration_with_declspec ::= declaration_specifiers <openscope-ast> init_declarator_list_opt ;
//
case 227: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
@ -1956,14 +1956,14 @@ public CPPParser(String[] mapFrom) { // constructor
// Rule 400: member_declaration ::= declaration_specifiers_opt <openscope-ast> member_declarator_list ;
//
case 400: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 401: member_declaration ::= declaration_specifiers_opt ;
//
case 401: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//
@ -2243,21 +2243,21 @@ public CPPParser(String[] mapFrom) { // constructor
// Rule 520: exception_declaration ::= type_specifier_seq <openscope-ast> declarator
//
case 520: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 521: exception_declaration ::= type_specifier_seq <openscope-ast> abstract_declarator
//
case 521: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 522: exception_declaration ::= type_specifier_seq
//
case 522: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}

View file

@ -1228,14 +1228,14 @@ public CPPSizeofExpressionParser(String[] mapFrom) { // constructor
// Rule 224: simple_declaration ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ;
//
case 224: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 225: simple_declaration_with_declspec ::= declaration_specifiers <openscope-ast> init_declarator_list_opt ;
//
case 225: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
@ -1942,14 +1942,14 @@ public CPPSizeofExpressionParser(String[] mapFrom) { // constructor
// Rule 398: member_declaration ::= declaration_specifiers_opt <openscope-ast> member_declarator_list ;
//
case 398: { action.builder.
consumeDeclarationSimple(true, true); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 399: member_declaration ::= declaration_specifiers_opt ;
//
case 399: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//
@ -2229,21 +2229,21 @@ public CPPSizeofExpressionParser(String[] mapFrom) { // constructor
// Rule 518: exception_declaration ::= type_specifier_seq <openscope-ast> declarator
//
case 518: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 519: exception_declaration ::= type_specifier_seq <openscope-ast> abstract_declarator
//
case 519: { action.builder.
consumeDeclarationSimple(true, false); break;
consumeDeclarationSimple(true); break;
}
//
// Rule 520: exception_declaration ::= type_specifier_seq
//
case 520: { action.builder.
consumeDeclarationSimple(false, false); break;
consumeDeclarationSimple(false); break;
}
//