1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Fixes a performance issue introduced by fix for 261417.

This commit is contained in:
Markus Schorn 2009-01-19 11:35:08 +00:00
parent f18840cf49
commit 7812c51d4d
6 changed files with 30 additions and 27 deletions

View file

@ -1756,7 +1756,7 @@ public class AST2CPPTests extends AST2BaseTest {
IASTExpressionStatement expStatement = (IASTExpressionStatement) ((IASTCompoundStatement) def
.getBody()).getStatements()[0];
assertTrue(expStatement.getExpression() instanceof IASTLiteralExpression);
IType type = CPPVisitor.getExpressionType(expStatement.getExpression());
IType type = expStatement.getExpression().getExpressionType();
assertTrue(type instanceof IPointerType);
assertSame(((IPointerType) type).getType(), A);
@ -1765,7 +1765,7 @@ public class AST2CPPTests extends AST2BaseTest {
expStatement = (IASTExpressionStatement) ((IASTCompoundStatement) def
.getBody()).getStatements()[0];
IASTUnaryExpression ue = (IASTUnaryExpression) expStatement.getExpression();
type = CPPVisitor.getExpressionType(ue);
type = ue.getExpressionType();
assertTrue(type instanceof IQualifierType);
assertSame(((IQualifierType) type).getType(), A);
@ -5556,7 +5556,7 @@ public class AST2CPPTests extends AST2BaseTest {
IASTDeclarator decltor= ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0];
IASTInitializerExpression init= (IASTInitializerExpression) decltor.getInitializer();
ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getExpression();
ICPPBasicType type= (ICPPBasicType) CPPVisitor.getExpressionType(exp);
ICPPBasicType type= (ICPPBasicType) exp.getExpressionType();
assertTrue(type.isLong());
}

View file

@ -78,7 +78,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
@ -1582,7 +1581,7 @@ public class AST2TemplateTests extends AST2BaseTest {
IASTName f = col.getName(6);
IASTFunctionDefinition fdef = (IASTFunctionDefinition) f.getParent().getParent();
IASTExpressionStatement statement = (IASTExpressionStatement) ((IASTCompoundStatement)fdef.getBody()).getStatements()[0];
IType type = CPPVisitor.getExpressionType(statement.getExpression());
IType type = statement.getExpression().getExpressionType();
assertTrue(type.isSameType(p.getType()));
}

View file

@ -28,6 +28,7 @@ public class CPPASTBinaryExpression extends ASTNode implements
private int op;
private IASTExpression operand1;
private IASTExpression operand2;
private IType type;
public CPPASTBinaryExpression() {
}
@ -121,7 +122,9 @@ public class CPPASTBinaryExpression extends ASTNode implements
}
public IType getExpressionType() {
return CPPVisitor.getExpressionType(this);
if (type == null) {
type= CPPVisitor.getExpressionType(this);
}
return type;
}
}

View file

@ -1908,7 +1908,7 @@ public class CPPSemantics {
IASTExpression[] exps = (IASTExpression[]) params;
IType[] result = new IType[exps.length];
for (int i = 0; i < exps.length; i++) {
result[i] = CPPVisitor.getExpressionType(exps[i]);
result[i] = exps[i].getExpressionType();
}
return result;
} else if (params instanceof IASTParameterDeclaration[]) {
@ -2257,7 +2257,7 @@ public class CPPSemantics {
// target is the left side of an assignment
IASTBinaryExpression binaryExp = (IASTBinaryExpression) node.getParent();
IASTExpression exp = binaryExp.getOperand1();
return CPPVisitor.getExpressionType(exp);
return exp.getExpressionType();
} else if (prop == IASTFunctionCallExpression.PARAMETERS ||
(prop == IASTExpressionList.NESTED_EXPRESSION &&
node.getParent().getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS)) {
@ -2389,7 +2389,7 @@ public class CPPSemantics {
}
}
} else {
IType type = CPPVisitor.getExpressionType(exp);
IType type = exp.getExpressionType();
type = getUltimateType(type, false);
if (type instanceof IFunctionType) {
result = new IFunctionType[] { (IFunctionType) type };

View file

@ -1601,7 +1601,7 @@ public class CPPVisitor extends ASTQueries {
if (node == null)
return null;
if (node instanceof IASTExpression)
return getExpressionType((IASTExpression) node);
return ((IASTExpression) node).getExpressionType();
if (node instanceof IASTTypeId)
return createType(((IASTTypeId) node).getAbstractDeclarator());
if (node instanceof IASTParameterDeclaration)
@ -1864,7 +1864,7 @@ public class CPPVisitor extends ASTQueries {
final IASTBinaryExpression binary = (IASTBinaryExpression) expression;
// Check for overloaded operator.
IType type1 = getExpressionType(binary.getOperand1());
IType type1 = binary.getOperand1().getExpressionType();
IType ultimateType1 = SemanticUtil.getUltimateTypeUptoPointers(type1);
if (ultimateType1 instanceof IProblemBinding) {
return type1;
@ -1879,7 +1879,7 @@ public class CPPVisitor extends ASTQueries {
}
}
}
IType type2 = getExpressionType(binary.getOperand2());
IType type2 = binary.getOperand2().getExpressionType();
IType ultimateType2 = SemanticUtil.getUltimateTypeUptoPointers(type2);
if (ultimateType2 instanceof IProblemBinding) {
return type2;
@ -1959,7 +1959,7 @@ public class CPPVisitor extends ASTQueries {
return get_type_info(expression);
}
IType type = getExpressionType(((IASTUnaryExpression) expression).getOperand());
IType type= ((IASTUnaryExpression) expression).getOperand().getExpressionType();
type = SemanticUtil.getUltimateTypeViaTypedefs(type);
if (op == IASTUnaryExpression.op_star) {
@ -2029,7 +2029,7 @@ public class CPPVisitor extends ASTQueries {
}
} else if (expression instanceof IASTExpressionList) {
IASTExpression[] exps = ((IASTExpressionList) expression).getExpressions();
return getExpressionType(exps[exps.length - 1]);
return exps[exps.length - 1].getExpressionType();
} else if (expression instanceof ICPPASTTypeIdExpression) {
ICPPASTTypeIdExpression typeidExp = (ICPPASTTypeIdExpression) expression;
switch (typeidExp.getOperator()) {
@ -2040,7 +2040,7 @@ public class CPPVisitor extends ASTQueries {
}
return createType(typeidExp.getTypeId());
} else if (expression instanceof IASTArraySubscriptExpression) {
IType t = getExpressionType(((IASTArraySubscriptExpression) expression).getArrayExpression());
IType t = ((IASTArraySubscriptExpression) expression).getArrayExpression().getExpressionType();
try {
if (t instanceof ICPPReferenceType) {
t = ((ICPPReferenceType) t).getType();
@ -2069,7 +2069,7 @@ public class CPPVisitor extends ASTQueries {
if (statements.length > 0) {
IASTStatement st = statements[statements.length - 1];
if (st instanceof IASTExpressionStatement)
return getExpressionType(((IASTExpressionStatement) st).getExpression());
return ((IASTExpressionStatement) st).getExpression().getExpressionType();
}
} else if (expression instanceof IASTConditionalExpression) {
final IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
@ -2077,8 +2077,8 @@ public class CPPVisitor extends ASTQueries {
if (positiveExpression == null) {
positiveExpression= conditional.getLogicalConditionExpression();
}
IType t2 = getExpressionType(positiveExpression);
IType t3 = getExpressionType(conditional.getNegativeResultExpression());
IType t2 = positiveExpression.getExpressionType();
IType t3 = conditional.getNegativeResultExpression().getExpressionType();
if (t3 instanceof IPointerType || t2 == null)
return t3;
return t2;

View file

@ -64,6 +64,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
@ -180,7 +181,7 @@ public class LookupData {
}
if (p1 instanceof IASTDeclarator) {
IASTNode p2= CPPVisitor.findOutermostDeclarator((IASTDeclarator) p1).getParent();
IASTNode p2= ASTQueries.findOutermostDeclarator((IASTDeclarator) p1).getParent();
if (p2 instanceof IASTSimpleDeclaration) {
if (p2.getParent() instanceof ICPPASTExplicitTemplateInstantiation)
return false;
@ -210,7 +211,7 @@ public class LookupData {
}
if (p1 instanceof IASTDeclarator) {
IASTNode p2= CPPVisitor.findOutermostDeclarator((IASTDeclarator) p1).getParent();
IASTNode p2= ASTQueries.findOutermostDeclarator((IASTDeclarator) p1).getParent();
if (p2 instanceof IASTSimpleDeclaration || p2 instanceof IASTFunctionDefinition) {
ICPPASTTemplateDeclaration tmplDecl = CPPTemplates.getTemplateDeclaration(n);
return tmplDecl instanceof ICPPASTTemplateSpecialization;
@ -234,7 +235,7 @@ public class LookupData {
}
if (p1 instanceof IASTDeclarator) {
IASTNode p2= CPPVisitor.findOutermostDeclarator((IASTDeclarator) p1).getParent();
IASTNode p2= ASTQueries.findOutermostDeclarator((IASTDeclarator) p1).getParent();
if (p2 instanceof IASTDeclaration) {
return p2.getParent() instanceof ICPPASTExplicitTemplateInstantiation;
}
@ -368,11 +369,11 @@ public class LookupData {
if (tempNameParent instanceof ICPPASTUnaryExpression) {
ICPPASTUnaryExpression unaryExp = (ICPPASTUnaryExpression) tempNameParent;
IASTExpression oprd= unaryExp.getOperand();
return CPPVisitor.getExpressionType(oprd);
return oprd.getExpressionType();
}
if (tempNameParent instanceof ICPPASTFieldReference) {
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempNameParent;
IType implied = CPPVisitor.getExpressionType(fieldRef.getFieldOwner());
IType implied = fieldRef.getFieldOwner().getExpressionType();
if (fieldRef.isPointerDereference() && implied instanceof IPointerType) {
return ((IPointerType)implied).getType();
}
@ -380,13 +381,13 @@ public class LookupData {
}
if (tempNameParent instanceof IASTArraySubscriptExpression) {
IASTExpression exp = ((IASTArraySubscriptExpression)tempNameParent).getArrayExpression();
return CPPVisitor.getExpressionType(exp);
return exp.getExpressionType();
}
if (tempNameParent instanceof IASTFunctionCallExpression) {
return CPPVisitor.getExpressionType(((IASTFunctionCallExpression) tempNameParent).getFunctionNameExpression());
return ((IASTFunctionCallExpression) tempNameParent).getFunctionNameExpression().getExpressionType();
}
if (tempNameParent instanceof IASTBinaryExpression) {
return CPPVisitor.getExpressionType(((IASTBinaryExpression) tempNameParent).getOperand1());
return ((IASTBinaryExpression) tempNameParent).getOperand1().getExpressionType();
}
return null;
}