mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 12:05:21 +02:00
Cosmetics and refactoring related to commits of bug 84144
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
bf0ac98464
commit
4f239a093a
11 changed files with 121 additions and 186 deletions
|
@ -10,7 +10,6 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Nathan Ridge
|
||||
* Anders Dahlberg (Ericsson) - bug 84144
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
@ -1011,19 +1010,6 @@ public class AST2CPPSpecTest extends AST2SpecTestBase {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 1);
|
||||
}
|
||||
|
||||
// void f()
|
||||
// {
|
||||
// // ...
|
||||
// void* labelPtr;
|
||||
// labelPtr = &&foo;
|
||||
// goto *labelPtr;
|
||||
// foo:
|
||||
// return;
|
||||
// }
|
||||
public void test6_bug84144() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// int foo(int i)
|
||||
// {
|
||||
// static int s = foo(2*i); // recursive call - undefined
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anders Dahlberg (Ericsson) - bug 84144
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
@ -1729,19 +1728,6 @@ public class AST2CSpecTest extends AST2SpecTestBase {
|
|||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
// void f()
|
||||
// {
|
||||
// // ...
|
||||
// void* labelPtr;
|
||||
// labelPtr = &&foo;
|
||||
// goto *labelPtr;
|
||||
// foo:
|
||||
// return;
|
||||
// }
|
||||
public void test6_bug84144() throws Exception {
|
||||
parseCandCPP(getAboveComment(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(C 6.8.6.4-4):
|
||||
struct s { double i; } f(void);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
* Anders Dahlberg (Ericsson) - bug 84144
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
@ -150,9 +151,14 @@ public class AST2Tests extends AST2TestBase {
|
|||
}
|
||||
|
||||
private void parseAndCheckBindings() throws Exception {
|
||||
parseAndCheckBindings(false);
|
||||
}
|
||||
|
||||
private void parseAndCheckBindings(boolean useGnuExtensions) throws Exception {
|
||||
String code= getAboveComment();
|
||||
parseAndCheckBindings(code, C);
|
||||
parseAndCheckBindings(code, CPP);
|
||||
parseAndCheckBindings(code, C, useGnuExtensions);
|
||||
parseAndCheckBindings(code, CPP, useGnuExtensions);
|
||||
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception {
|
||||
|
@ -7548,4 +7554,17 @@ public class AST2Tests extends AST2TestBase {
|
|||
public void testU8TokenAfterIfdef_429361() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// void f()
|
||||
// {
|
||||
// // ...
|
||||
// void* labelPtr;
|
||||
// labelPtr = &&foo;
|
||||
// goto *labelPtr;
|
||||
// foo:
|
||||
// return;
|
||||
// }
|
||||
public void testExpressionLabelReference_84144() throws Exception {
|
||||
parseAndCheckBindings(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ public interface IASTUnaryExpression extends IASTExpression {
|
|||
public static final int op_noexcept = 17;
|
||||
|
||||
/**
|
||||
* For GCC parsers, only. {@code op_labelReference} is used for &&label type
|
||||
* expressions.
|
||||
* For GCC parsers, only. {@code op_labelReference} is used for &&label type expressions.
|
||||
* @since 5.8
|
||||
*/
|
||||
public static final int op_labelReference = 18;
|
||||
|
|
|
@ -124,7 +124,6 @@ public interface INodeFactory {
|
|||
public IASTGotoStatement newGotoStatement(IASTName name);
|
||||
|
||||
/**
|
||||
* Note: Adding as separate function to avoid changing API.
|
||||
* @since 5.8
|
||||
*/
|
||||
public IASTStatement newGotoStatement(IASTExpression expression);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2013 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2014 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -16,9 +16,12 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
|
@ -125,6 +128,26 @@ public class ASTQueries {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the function enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
public static IBinding findEnclosingFunction(IASTNode node) {
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
IASTName name= dtor.getName();
|
||||
if (name != null) {
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the active declarations from an array of declarations.
|
||||
*/
|
||||
|
@ -183,4 +206,16 @@ public class ASTQueries {
|
|||
} while (descendant != null);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static boolean isLabelReference(IASTNode node) {
|
||||
boolean labelReference = false;
|
||||
IASTNode parent = node.getParent();
|
||||
|
||||
if (parent instanceof IASTUnaryExpression) {
|
||||
int operator = ((IASTUnaryExpression) parent).getOperator();
|
||||
labelReference = operator == IASTUnaryExpression.op_labelReference;
|
||||
}
|
||||
|
||||
return labelReference;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1990,21 +1990,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
protected IASTStatement parseGotoStatement() throws EndOfFileException, BacktrackException {
|
||||
int startOffset = consume().getOffset(); // t_goto
|
||||
IASTStatement goto_statement = null;
|
||||
int startOffset = consume(IToken.t_goto).getOffset();
|
||||
IASTStatement gotoStatement = null;
|
||||
|
||||
if (LT(1) == IToken.tSTAR)
|
||||
{
|
||||
IASTExpression goto_label_name_expression = expression();
|
||||
goto_statement = nodeFactory.newGotoStatement(goto_label_name_expression);
|
||||
IASTExpression gotoLabelNameExpression = expression();
|
||||
gotoStatement = nodeFactory.newGotoStatement(gotoLabelNameExpression);
|
||||
} else {
|
||||
IASTName goto_label_name = identifier();
|
||||
goto_statement = nodeFactory.newGotoStatement(goto_label_name);
|
||||
IASTName gotoLabelName = identifier();
|
||||
gotoStatement = nodeFactory.newGotoStatement(gotoLabelName);
|
||||
}
|
||||
|
||||
int lastOffset = consume(IToken.tSEMI).getEndOffset();
|
||||
((ASTNode) goto_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
return goto_statement;
|
||||
((ASTNode) gotoStatement).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
return gotoStatement;
|
||||
}
|
||||
|
||||
protected IASTStatement parseBreakStatement() throws EndOfFileException, BacktrackException {
|
||||
|
|
|
@ -72,7 +72,6 @@ public class BacktrackException extends Exception {
|
|||
length = l;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the length.
|
||||
*/
|
||||
|
@ -88,12 +87,12 @@ public class BacktrackException extends Exception {
|
|||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
// Do nothing, performance optimization
|
||||
return this;
|
||||
// Do nothing, performance optimization
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackTraceElement[] getStackTrace() {
|
||||
return EMPTY_STACK;
|
||||
return EMPTY_STACK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
|
@ -106,7 +105,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPLabel;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
|
||||
|
||||
|
@ -466,8 +464,7 @@ public class CVisitor extends ASTQueries {
|
|||
boolean labelReference = isLabelReference(parent);
|
||||
|
||||
if (labelReference) {
|
||||
IASTUnaryExpression expression = (IASTUnaryExpression) parent.getParent();
|
||||
binding = createLabelReferenceBinding(name, expression);
|
||||
binding = createLabelReferenceBinding(name);
|
||||
} else if (parent instanceof CASTIdExpression) {
|
||||
binding = resolveBinding(parent);
|
||||
} else if (parent instanceof ICASTTypedefNameSpecifier) {
|
||||
|
@ -609,54 +606,32 @@ public class CVisitor extends ASTQueries {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isLabelReference(IASTNode node) {
|
||||
boolean labelReference = false;
|
||||
IASTNode parent = node.getParent();
|
||||
|
||||
if (parent instanceof IASTUnaryExpression) {
|
||||
int operator = ((IASTUnaryExpression) parent).getOperator();
|
||||
labelReference = operator == IASTUnaryExpression.op_labelReference;
|
||||
}
|
||||
|
||||
return labelReference;
|
||||
}
|
||||
|
||||
private static IBinding createLabelReferenceBinding(IASTName name, IASTUnaryExpression expression) {
|
||||
IBinding binding = null;
|
||||
|
||||
private static IBinding createLabelReferenceBinding(IASTName name) {
|
||||
// Find function scope for r-value expression
|
||||
// void* labelPtr = &&foo;
|
||||
// foo: ^^^
|
||||
// return
|
||||
IScope scope = getContainingScope(name);
|
||||
IASTInternalScope s = (IASTInternalScope) scope;
|
||||
IASTNode node = s.getPhysicalNode();
|
||||
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) node;
|
||||
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) definition.getDeclarator();
|
||||
scope = declarator.getFunctionScope();
|
||||
|
||||
if (scope != null) {
|
||||
binding = scope.getBinding(name, false);
|
||||
IBinding binding = null;
|
||||
IBinding enclosingFunction = findEnclosingFunction(name);
|
||||
if (enclosingFunction instanceof IFunction) {
|
||||
IFunction function = (IFunction) enclosingFunction;
|
||||
IScope functionScope = function.getFunctionScope();
|
||||
if (functionScope != null) {
|
||||
binding = functionScope.getBinding(name, false);
|
||||
if (!(binding instanceof ILabel)) {
|
||||
binding = new CPPLabel(name);
|
||||
ASTInternal.addName(scope, name);
|
||||
binding = new CLabel(name);
|
||||
ASTInternal.addName(functionScope, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (binding == null) {
|
||||
binding = new ProblemBinding(expression, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
expression.getRawSignature().toCharArray());
|
||||
}
|
||||
if (binding == null) {
|
||||
IASTNode parentExpression = name.getParent();
|
||||
binding = new ProblemBinding(parentExpression, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
parentExpression.getRawSignature().toCharArray());
|
||||
}
|
||||
|
||||
return binding;
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1726,26 +1701,6 @@ public class CVisitor extends ASTQueries {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the function enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
public static IBinding findEnclosingFunction(IASTNode node) {
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
IASTName name= dtor.getName();
|
||||
if (name != null) {
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first function, struct or union enclosing the declaration the provided
|
||||
* node belongs to and returns the binding for it. Returns <code>null</code>, if the declaration is not
|
||||
|
|
|
@ -179,7 +179,6 @@ import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
|
@ -310,8 +309,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
boolean labelReference = isLabelReference(parent);
|
||||
|
||||
if (labelReference) {
|
||||
IASTUnaryExpression expression = (IASTUnaryExpression) parent.getParent();
|
||||
return createLabelReferenceBinding(name, expression);
|
||||
return createLabelReferenceBinding(name);
|
||||
} else if (parent instanceof IASTIdExpression) {
|
||||
return resolveBinding(parent);
|
||||
} else if (parent instanceof ICPPASTFieldReference) {
|
||||
|
@ -389,53 +387,32 @@ public class CPPVisitor extends ASTQueries {
|
|||
return scope == inScope;
|
||||
}
|
||||
|
||||
private static boolean isLabelReference(IASTNode node) {
|
||||
boolean labelReference = false;
|
||||
IASTNode parent = node.getParent();
|
||||
|
||||
if (parent instanceof IASTUnaryExpression) {
|
||||
int operator = ((IASTUnaryExpression) parent).getOperator();
|
||||
labelReference = operator == IASTUnaryExpression.op_labelReference;
|
||||
}
|
||||
|
||||
return labelReference;
|
||||
}
|
||||
|
||||
private static IBinding createLabelReferenceBinding(IASTName name, IASTUnaryExpression expression) {
|
||||
IBinding binding = null;
|
||||
|
||||
private static IBinding createLabelReferenceBinding(IASTName name) {
|
||||
// Find function scope for r-value expression
|
||||
// void* labelPtr = &&foo;
|
||||
// foo: ^^^
|
||||
// return
|
||||
IScope scope = getContainingScope(name);
|
||||
IASTInternalScope s = (IASTInternalScope) scope;
|
||||
IASTNode node = s.getPhysicalNode();
|
||||
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) node;
|
||||
CPPASTFunctionDeclarator declarator = (CPPASTFunctionDeclarator) definition.getDeclarator();
|
||||
scope = declarator.getFunctionScope();
|
||||
|
||||
if (scope != null) {
|
||||
binding = scope.getBinding(name, false);
|
||||
IBinding binding = null;
|
||||
IBinding enclosingFunction = findEnclosingFunction(name);
|
||||
if (enclosingFunction instanceof IFunction) {
|
||||
IFunction function = (IFunction) enclosingFunction;
|
||||
IScope functionScope = function.getFunctionScope();
|
||||
if (functionScope != null) {
|
||||
binding = functionScope.getBinding(name, false);
|
||||
if (!(binding instanceof ILabel)) {
|
||||
binding = new CPPLabel(name);
|
||||
ASTInternal.addName(scope, name);
|
||||
binding = new CPPLabel(name);
|
||||
ASTInternal.addName(functionScope, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (binding == null) {
|
||||
binding = new CPPScope.CPPScopeProblem(expression, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
expression.getRawSignature().toCharArray());
|
||||
}
|
||||
if (binding == null) {
|
||||
IASTNode parentExpression = name.getParent();
|
||||
binding = new CPPScope.CPPScopeProblem(parentExpression, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
parentExpression.getRawSignature().toCharArray());
|
||||
}
|
||||
|
||||
return binding;
|
||||
return binding;
|
||||
}
|
||||
|
||||
private static IBinding createBinding(IASTGotoStatement gotoStatement) {
|
||||
|
@ -2532,26 +2509,6 @@ public class CPPVisitor extends ASTQueries {
|
|||
return t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the function enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
public static IBinding findEnclosingFunction(IASTNode node) {
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
IASTName name= dtor.getName();
|
||||
if (name != null) {
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the function or class enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anders Dahlberg (Ericsson) - bug 84144
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.lrparser.action;
|
||||
|
||||
|
@ -45,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||
|
@ -598,7 +598,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
|
|||
*/
|
||||
public void consumeStatementGoto() {
|
||||
IASTName name = createName(stream.getRuleTokens().get(1));
|
||||
IASTStatement gotoStat = nodeFactory.newGotoStatement(name);
|
||||
IASTGotoStatement gotoStat = nodeFactory.newGotoStatement(name);
|
||||
setOffsetAndLength(gotoStat);
|
||||
astStack.push(gotoStat);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue