mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Make sure AST is available to C getExpressionType too
C++ parser methods already store current lookup point which makes AST available via thread-local variable. Do the same for C parser to enable SizeofCalculator accessing type size macros via AST while processing C code.
This commit is contained in:
parent
b84b0f62eb
commit
c973dd5e80
4 changed files with 29 additions and 1 deletions
|
@ -425,6 +425,10 @@ public abstract class ArithmeticConversion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a target integral type can represent all values of a source integral type.
|
* Checks whether a target integral type can represent all values of a source integral type.
|
||||||
|
* <br><br>
|
||||||
|
* If CPPSemantics current lookup point is set, size and alignment information is derived
|
||||||
|
* from predefined type size macros available through current AST. If there is no current
|
||||||
|
* lookup point, {@link #getApproximateSize(IBasicType)} is used to guess size of integral types.
|
||||||
*
|
*
|
||||||
* @param target the target integral type
|
* @param target the target integral type
|
||||||
* @param source the source integral type
|
* @param source the source integral type
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binary expression for c
|
* Binary expression for c
|
||||||
|
@ -213,6 +214,15 @@ public class CASTBinaryExpression extends ASTNode implements IASTBinaryExpressio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IType getExpressionType() {
|
public IType getExpressionType() {
|
||||||
|
CPPSemantics.pushLookupPoint(this);
|
||||||
|
try {
|
||||||
|
return getExpressionTypeImpl();
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IType getExpressionTypeImpl() {
|
||||||
final int op = getOperator();
|
final int op = getOperator();
|
||||||
IType originalType1 = getOperand1().getExpressionType();
|
IType originalType1 = getOperand1().getExpressionType();
|
||||||
IType originalType2 = getOperand2().getExpressionType();
|
IType originalType2 = getOperand2().getExpressionType();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,6 +164,15 @@ public class CASTConditionalExpression extends ASTNode implements IASTConditiona
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IType getExpressionType() {
|
public IType getExpressionType() {
|
||||||
|
CPPSemantics.pushLookupPoint(this);
|
||||||
|
try {
|
||||||
|
return getExpressionTypeImpl();
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IType getExpressionTypeImpl() {
|
||||||
IASTExpression positiveExpression = getPositiveResultExpression();
|
IASTExpression positiveExpression = getPositiveResultExpression();
|
||||||
if (positiveExpression == null) {
|
if (positiveExpression == null) {
|
||||||
positiveExpression = getLogicalConditionExpression();
|
positiveExpression = getLogicalConditionExpression();
|
||||||
|
|
|
@ -212,6 +212,7 @@ import org.eclipse.cdt.internal.core.dom.parser.IRecursionResolvingBinding;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
|
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
|
@ -323,12 +324,15 @@ public class CPPSemantics {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current point of instantiation / point of lookup for name lookups.
|
* Get the current point of instantiation / point of lookup for name lookups.
|
||||||
*
|
* <br><br>
|
||||||
* NOTE: This is meant to be used primarily for "declaredBefore" purposes, that is,
|
* NOTE: This is meant to be used primarily for "declaredBefore" purposes, that is,
|
||||||
* for determining whether something was declared before or after the point
|
* for determining whether something was declared before or after the point
|
||||||
* of lookup. It is NOT meant to be used as a general mechanism for accessing
|
* of lookup. It is NOT meant to be used as a general mechanism for accessing
|
||||||
* information about a call site without having to pass that information along
|
* information about a call site without having to pass that information along
|
||||||
* the usual way (via function arguments).
|
* the usual way (via function arguments).
|
||||||
|
* <br><br>
|
||||||
|
* NOTE: This is also used to provide {@link SizeofCalculator} with access to predefined
|
||||||
|
* type size macros of current translation unit via AST object.
|
||||||
*/
|
*/
|
||||||
public static IASTNode getCurrentLookupPoint() {
|
public static IASTNode getCurrentLookupPoint() {
|
||||||
Deque<IASTNode> lookupPoints = fLookupPoints.get();
|
Deque<IASTNode> lookupPoints = fLookupPoints.get();
|
||||||
|
|
Loading…
Add table
Reference in a new issue