diff options
56 files changed, 800 insertions, 391 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 19a44469df0..22d27399419 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -7313,7 +7313,8 @@ public class AST2CPPTests extends AST2BaseTest { IASTExpressionStatement stmt= getStatement(test, 1); long now= System.currentTimeMillis(); IType t= stmt.getExpression().getExpressionType(); - assertInstance(t, ICPPReferenceType.class); + assertInstance(t, ICPPClassType.class); + assertTrue(stmt.getExpression().isLValue()); final long time = System.currentTimeMillis() - now; assertTrue("Lasted " + time + "ms", time < 5000); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java index ce7f1d0a09f..6dd9b1eeacd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; + /** * This is the root class of expressions. * @@ -19,6 +20,37 @@ package org.eclipse.cdt.core.dom.ast; */ public interface IASTExpression extends IASTInitializerClause { /** + * @since 5.3 + */ + public enum ValueCategory { + /** + * Traditional lvalue + */ + LVALUE, + /** + * Expiring value as introduced by c++ 0x. + */ + XVALUE, + /** + * Pure rvalue. + */ + PRVALUE; + + /** + * Both prvalues and xvalues are rvalues. + */ + public boolean isRValue() { + return this != LVALUE; + } + /** + * A generalized lvalue is either an lvalue or an xvalue. + */ + public boolean isGLValue() { + return this != PRVALUE; + } + } + + /** * Empty expression array. */ public static final IASTExpression[] EMPTY_EXPRESSION_ARRAY = new IASTExpression[0]; @@ -33,6 +65,12 @@ public interface IASTExpression extends IASTInitializerClause { public boolean isLValue(); /** + * Returns the value category of this expression. + * @since 5.3 + */ + ValueCategory getValueCategory(); + + /** * @since 5.1 */ public IASTExpression copy(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java index 2bd9d7f6606..01684e6a950 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -36,8 +36,9 @@ public interface ICPPASTLiteralExpression extends IASTLiteralExpression { public static final int lk_false = IASTLiteralExpression.lk_false; /** - * <code>lk_last</code> is maintained for future subinterfaces. + * @deprecated All constants must be defined in {@link IASTLiteralExpression}. */ + @Deprecated public static final int lk_last = lk_false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java index 718832a5ade..89987eb3b6e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -19,7 +19,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. + * @deprecated Use {@link IASTTypeIdExpression}, instead. */ +@Deprecated public interface IGNUASTTypeIdExpression extends IASTTypeIdExpression { /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java index 9d1c306e4f3..f49f59b8eaa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2010 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 @@ -19,8 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.core.runtime.Assert; /** * Handles the ambiguity between a binary- and a cast-expression. (type)+var versus (var)+var. @@ -46,14 +44,10 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod throw new UnsupportedOperationException(); } - public void addExpression(IASTExpression e) { - Assert.isLegal(false); + public final void addExpression(IASTExpression e) { + throw new UnsupportedOperationException(); } - public IType getExpressionType() { - return null; - } - @Override public final IASTNode[] getNodes() { return getExpressions(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java index 41b01aa6ef4..8ebef4fc505 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java @@ -23,8 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.core.runtime.Assert; /** * Handles the ambiguity between cast and function-call expressions: (type)(expr) versus (function)(expr); @@ -56,13 +54,9 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu } public void addExpression(IASTExpression e) { - Assert.isLegal(false); + throw new UnsupportedOperationException(); } - public IType getExpressionType() { - return fCastExpression.getExpressionType(); - } - public IASTExpression[] getExpressions() { return new IASTExpression[] {fCastExpression, fFunctionCallExpression}; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java index 29e971a47a3..9ab1ba8dc78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java @@ -13,11 +13,13 @@ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.ArrayUtil; /** @@ -139,7 +141,13 @@ public abstract class ASTAmbiguousNode extends ASTNode { return bestAlternative; } - public boolean isLValue() { - return false; + public final IType getExpressionType() { + throw new UnsupportedOperationException(); + } + public final ValueCategory getValueCategory() { + throw new UnsupportedOperationException(); + } + public final boolean isLValue() { + throw new UnsupportedOperationException(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTypeIdInitializerExpression.java index 8d3141854ca..2041d33ab61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTypeIdInitializerExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -87,7 +87,11 @@ public abstract class ASTTypeIdInitializerExpression extends ASTNode implements return true; } - public boolean isLValue() { + public final boolean isLValue() { return false; } + + public final ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index eb0375bd01b..612e05249cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -1174,6 +1174,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { public boolean isLValue() { throw new UnsupportedOperationException(); } + + public ValueCategory getValueCategory() { + throw new UnsupportedOperationException(); + } } protected final IASTExpression castExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java index f2999b0fbd3..ec8a2491b0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; @@ -48,10 +47,6 @@ public class CASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmb return getExpressions(); } - public IType getExpressionType() { - return null; - } - public IASTExpression copy() { throw new UnsupportedOperationException(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java index d9a66aaa98a..9939349053a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java @@ -137,4 +137,8 @@ public class CASTArraySubscriptExpression extends ASTNode implements public boolean isLValue() { return true; } + + public final ValueCategory getValueCategory() { + return ValueCategory.LVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java index 605240a6679..6fb31b32818 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java @@ -18,9 +18,9 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IArrayType; +import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; 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.IASTAmbiguityParent; @@ -258,4 +258,8 @@ public class CASTBinaryExpression extends ASTNode implements } return false; } + + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java index a75801117ec..fcdc01835a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -125,4 +125,8 @@ public class CASTCastExpression extends ASTNode implements IASTCastExpression, I public boolean isLValue() { return false; } + + public final ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java index 77101763296..0cf00d711d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -96,4 +96,8 @@ public class CASTCompoundStatementExpression extends ASTNode implements IGNUASTC } return false; } + + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java index 2851a25c383..46e03e13739 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -148,4 +148,8 @@ public class CASTConditionalExpression extends ASTNode implements public boolean isLValue() { return false; } + + public final ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java index 7e49e7f6f0a..8e363185839 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -111,4 +111,8 @@ public class CASTExpressionList extends ASTNode implements IASTExpressionList, } return false; } + + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java index cc33582510e..e3f0ad3490f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -152,6 +152,10 @@ public class CASTFieldReference extends ASTNode implements IASTFieldReference, I return getFieldOwner().isLValue(); } + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } + public IBinding[] findBindings(IASTName n, boolean isPrefix) { return CVisitor.findBindingsForContentAssist(n, isPrefix); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java index 6f08ca8d85e..b54535f816e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java @@ -15,8 +15,8 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; -import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IType; @@ -140,6 +140,10 @@ public class CASTFunctionCallExpression extends ASTNode implements return false; } + public final ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } + @Deprecated public IASTExpression getParameterExpression() { if (fArguments.length == 0) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java index 67927aad6e7..88aef53215f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -114,6 +114,11 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC public boolean isLValue() { return true; } + + public final ValueCategory getValueCategory() { + return ValueCategory.LVALUE; + } + public IBinding[] findBindings(IASTName n, boolean isPrefix) { IBinding[] bindings = CVisitor.findBindingsForContentAssist(n, isPrefix); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java index 039be3d0497..49ef3dc1972 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -15,8 +15,8 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IBasicType; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -104,6 +104,10 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress return getKind() == IASTLiteralExpression.lk_string_literal; } + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } + private IType classifyTypeOfFloatLiteral() { final char[] lit= getValue(); final int len= lit.length; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java index de5442d8015..9a32d0f3656 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * John Camelon (IBM) - Initial API and implementation * Yuan Zhang / Beth Tibbitts (IBM Research) * Markus Schorn (Wind River Systems) *******************************************************************************/ @@ -17,9 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; import org.eclipse.cdt.core.dom.ast.IType; -/** - * @author jcamelon - */ public class CASTProblemExpression extends CASTProblemOwner implements IASTProblemExpression { public CASTProblemExpression() { @@ -63,4 +60,8 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl public boolean isLValue() { return false; } + + public ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java index 4f8279e42c8..03ffa41d0b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -94,4 +94,8 @@ public class CASTTypeIdExpression extends ASTNode implements IASTTypeIdExpressio public boolean isLValue() { return false; } + + public ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java index a4dc96ef3f8..7c492ec19f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation 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 @@ -134,4 +134,8 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, return false; } } + + public final ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java index 9257b512f16..688159d2224 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2010 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 @@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; @@ -53,8 +52,4 @@ public class CPPASTAmbiguousCondition extends ASTAmbiguousNode implements IASTAm public IASTExpression copy() { throw new UnsupportedOperationException(); } - - public IType getExpressionType() { - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java index f5fce475edf..6457d1ab91a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; @@ -52,9 +51,4 @@ public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements public IASTNode[] getNodes() { return getExpressions(); } - - public IType getExpressionType() { - return exp[0].getExpressionType(); - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java index afa4b5270a8..8ef8c0e7ed6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java @@ -12,13 +12,17 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression; @@ -27,7 +31,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent { @@ -120,8 +125,8 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr if (overload == UNINITIALIZED_FUNCTION) { overload= null; IType t = getArrayExpression().getExpressionType(); - t= SemanticUtil.getUltimateTypeUptoPointers(t); - if (t instanceof ICPPClassType && !(t instanceof ICPPUnknownType)) { + t= SemanticUtil.getNestedType(t, TDEF | REF | CVTYPE); + if (t instanceof ICPPClassType) { overload= CPPSemantics.findOverloadedOperator(this); } } @@ -177,34 +182,42 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr public IType getExpressionType() { ICPPFunction op = getOverload(); if (op != null) { - try { - return op.getType().getReturnType(); - } catch (DOMException e) { - return e.getProblem(); - } + return ExpressionTypes.typeFromFunctionCall(op); } - IType t = getArrayExpression().getExpressionType(); - t= SemanticUtil.getUltimateTypeUptoPointers(t); - if (t instanceof ICPPUnknownType) { - return CPPUnknownClass.createUnnamedInstance(); + IType t1 = getArrayExpression().getExpressionType(); + t1= Conversions.lvalue_to_rvalue(t1); + if (t1 instanceof IPointerType) { + t1= ((IPointerType) t1).getType(); + return glvalueType(t1); } - if (t instanceof IPointerType) { - return ((IPointerType) t).getType(); + + IType t2= null; + IASTInitializerClause arg = getArgument(); + if (arg instanceof IASTExpression) { + t2= Conversions.lvalue_to_rvalue(t2); + if (t2 instanceof IPointerType) { + t2= ((IPointerType) t2).getType(); + return glvalueType(t2); + } } - if (t instanceof IArrayType) { - return ((IArrayType) t).getType(); + if (t1 instanceof ICPPUnknownType || t2 instanceof ICPPUnknownType) { + // mstodo type of unknown + return CPPUnknownClass.createUnnamedInstance(); } + + // mstodo return problem type return null; } public boolean isLValue() { + return getValueCategory() == LVALUE; + } + + public ValueCategory getValueCategory() { ICPPFunction op = getOverload(); if (op != null) { - try { - return CPPVisitor.isLValueReference(op.getType().getReturnType()); - } catch (DOMException e) { - } + return ExpressionTypes.valueCategoryFromFunctionCall(op); } - return true; + return ValueCategory.LVALUE; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java index fa2275f6834..560b8cd19a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java @@ -12,21 +12,24 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -34,7 +37,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpression, IASTAmbiguityParent { @@ -252,13 +254,10 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr return overload = CPPSemantics.findOverloadedOperator(this); } - public boolean isLValue() { - ICPPFunction op = getOverload(); + public ValueCategory getValueCategory() { + ICPPFunction op = getOverload(); if (op != null) { - try { - return CPPVisitor.isLValueReference(op.getType().getReturnType()); - } catch (DOMException e) { - } + return valueCategoryFromFunctionCall(op); } switch (getOperator()) { case op_assign: @@ -272,31 +271,46 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr case op_plusAssign: case op_shiftLeftAssign: case op_shiftRightAssign: - return true; + return LVALUE; + + case op_pmdot: + if (!(getExpressionType() instanceof ICPPFunctionType)) { + return operand1.getValueCategory(); + } + return PRVALUE; + + case op_pmarrow: + if (!(getExpressionType() instanceof ICPPFunctionType)) + return LVALUE; + return PRVALUE; } - return false; + + return PRVALUE; + } + + public boolean isLValue() { + return getValueCategory() == LVALUE; } - + private IType createExpressionType() { // Check for overloaded operator. ICPPFunction o= getOverload(); if (o != null) { - try { - return o.getType().getReturnType(); - } catch (DOMException e) { - e.getProblem(); - } + return typeFromFunctionCall(o); } final int op = getOperator(); - IType type1 = SemanticUtil.getUltimateTypeUptoPointers(getOperand1().getExpressionType()); + IType type1 = prvalueType(operand1.getExpressionType()); if (type1 instanceof IProblemBinding) { return type1; } - IType type2 = SemanticUtil.getUltimateTypeUptoPointers(getOperand2().getExpressionType()); - if (type2 instanceof IProblemBinding) { - return type2; + IType type2 = null; + if (operand2 instanceof IASTExpression) { + type2= prvalueType(((IASTExpression) operand2).getExpressionType()); + if (type2 instanceof IProblemBinding) { + return type2; + } } IType type= CPPArithmeticConversion.convertCppOperandTypes(op, type1, type2); @@ -316,35 +330,38 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr return new CPPBasicType(Kind.eBoolean, 0, this); case IASTBinaryExpression.op_plus: - if (type1 instanceof IArrayType) { - return arrayTypeToPointerType((IArrayType) type1); - } else if (type2 instanceof IPointerType) { + if (type1 instanceof IPointerType) { + return type1; + } + if (type2 instanceof IPointerType) { return type2; - } else if (type2 instanceof IArrayType) { - return arrayTypeToPointerType((IArrayType) type2); - } + } + // mstodo problem type break; case IASTBinaryExpression.op_minus: - if (type2 instanceof IPointerType || type2 instanceof IArrayType) { - if (type1 instanceof IPointerType || type1 instanceof IArrayType) { - return CPPVisitor.getPointerDiffType(this); + if (type1 instanceof IPointerType) { + if (type2 instanceof IPointerType) { + return CPPVisitor.getPointerDiffType(this); } return type1; } + // mstodo problem type break; case ICPPASTBinaryExpression.op_pmarrow: case ICPPASTBinaryExpression.op_pmdot: if (type2 instanceof ICPPPointerToMemberType) { - return ((ICPPPointerToMemberType) type2).getType(); + IType t= ((ICPPPointerToMemberType) type2).getType(); + if (t instanceof ICPPFunctionType) + return t; + if (op == ICPPASTBinaryExpression.op_pmdot && operand1.getValueCategory() == PRVALUE) { + return prvalueType(t); + } + return glvalueType(t); } return new ProblemBinding(this, IProblemBinding.SEMANTIC_INVALID_TYPE, getRawSignature().toCharArray()); } - return type1; - } - - private IType arrayTypeToPointerType(IArrayType type) { - return new CPPPointerType(type.getType()); + return type1; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java index f6224debc3b..fc41c04a261 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -11,6 +11,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -29,6 +33,7 @@ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpressi private IASTExpression operand; private IASTTypeId typeId; private IType fType; + private ValueCategory fValueCategory; public CPPASTCastExpression() { } @@ -119,13 +124,22 @@ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpressi public IType getExpressionType() { if (fType == null) { - fType= CPPVisitor.createType(typeId.getAbstractDeclarator()); + IType t= CPPVisitor.createType(typeId.getAbstractDeclarator()); + fValueCategory= valueCategoryFromReturnType(t); + fType= typeFromReturnType(t); } return fType; } + public ValueCategory getValueCategory() { + if (fValueCategory == null) { + getExpressionType(); // as a side effect fValueCategory is computed + } + return fValueCategory; + } + public boolean isLValue() { - return CPPVisitor.isLValueReference(getExpressionType()); + return getValueCategory() == LVALUE; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java index bd4be362270..b40bd05b46d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; @@ -20,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** - * @author jcamelon + * Gnu-extension: ({ ... }) */ public class CPPASTCompoundStatementExpression extends ASTNode implements IGNUASTCompoundStatementExpression { @@ -82,19 +85,16 @@ public class CPPASTCompoundStatementExpression extends ASTNode implements IGNUAS if (statements.length > 0) { IASTStatement st = statements[statements.length - 1]; if (st instanceof IASTExpressionStatement) - return ((IASTExpressionStatement) st).getExpression().getExpressionType(); + return prvalueType(((IASTExpressionStatement) st).getExpression().getExpressionType()); } return null; } public boolean isLValue() { - IASTCompoundStatement compound = getCompoundStatement(); - IASTStatement[] statements = compound.getStatements(); - if (statements.length > 0) { - IASTStatement st = statements[statements.length - 1]; - if (st instanceof IASTExpressionStatement) - return ((IASTExpressionStatement)st).getExpression().isLValue(); - } return false; } + + public ValueCategory getValueCategory() { + return PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java index 59c90b28eb5..78038424fc6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -20,11 +23,8 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; -/** - * @author jcamelon - */ -public class CPPASTConditionalExpression extends ASTNode implements - IASTConditionalExpression, IASTAmbiguityParent { +public class CPPASTConditionalExpression extends ASTNode implements IASTConditionalExpression, + IASTAmbiguityParent { private IASTExpression condition; private IASTExpression negative; @@ -134,6 +134,7 @@ public class CPPASTConditionalExpression extends ASTNode implements } } + // mstodo type of conditional operator public IType getExpressionType() { IASTExpression positiveExpression = getPositiveResultExpression(); if (positiveExpression == null) { @@ -146,7 +147,12 @@ public class CPPASTConditionalExpression extends ASTNode implements return t2; } + // mstodo + public ValueCategory getValueCategory() { + return PRVALUE; + } + public boolean isLValue() { - return false; + return getValueCategory() == LVALUE; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java index 9d7a6e06bca..f40039879f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + import java.util.ArrayList; import java.util.List; @@ -20,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; + import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; @@ -155,4 +158,8 @@ public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpr public boolean isLValue() { return false; } + + public ValueCategory getValueCategory() { + return PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index c59cb91b50c..3ef72524c25 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall; + import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -29,18 +34,18 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; 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.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionList, IASTAmbiguityParent { private static final ICPPFunction[] NO_FUNCTIONS = new ICPPFunction[0]; + private IASTExpression [] expressions = new IASTExpression[2]; + /** * Caution: may contain nulls. * @see CPPASTExpressionList#computeImplicitNames */ private IASTImplicitName[] implicitNames; - private ICPPFunction[] overloads = null; @@ -59,15 +64,13 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi public void addExpression(IASTExpression expression) { assertNotFrozen(); - expressions = (IASTExpression [])ArrayUtil.append( IASTExpression.class, expressions, expression ); + expressions = ArrayUtil.append(expressions, expression); if (expression != null) { expression.setParent(this); expression.setPropertyInParent(NESTED_EXPRESSION); } } - private IASTExpression [] expressions = new IASTExpression[2]; - @Override public boolean accept( ASTVisitor action ){ if( action.shouldVisitExpressions ){ @@ -190,10 +193,7 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi if (overloads.length > 0) { ICPPFunction last = overloads[overloads.length - 1]; if (last != null) { - try { - return last.getType().getReturnType(); - } catch (DOMException e) { - } + return typeFromFunctionCall(last); } } @@ -205,24 +205,24 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi return null; } - public boolean isLValue() { + public ValueCategory getValueCategory() { ICPPFunction[] overloads = getOverloads(); if (overloads.length > 0) { ICPPFunction last = overloads[overloads.length - 1]; if (last != null) { - try { - return CPPVisitor.isLValueReference(last.getType().getReturnType()); - } catch (DOMException e) { - return false; - } + return valueCategoryFromFunctionCall(last); } } for (int i = expressions.length-1; i >= 0; i--) { IASTExpression expr= expressions[i]; if (expr != null) - return expr.isLValue(); + return expr.getValueCategory(); } - return false; + return PRVALUE; + } + + public boolean isLValue() { + return getValueCategory() == LVALUE; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index cec6727ac1e..baf6726c481 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; import java.util.ArrayList; @@ -35,7 +39,6 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -202,7 +205,10 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen try { if (binding instanceof IVariable) { IType e2= ((IVariable) binding).getType(); - if (binding instanceof ICPPField && !((ICPPField) binding).isStatic()) { + e2= SemanticUtil.getNestedType(e2, TDEF); + if (e2 instanceof ICPPReferenceType) { + e2= glvalueType(e2); + } else if (binding instanceof ICPPField && !((ICPPField) binding).isStatic()) { IType e1= getFieldOwner().getExpressionType(); if (isPointerDereference()) { e1= SemanticUtil.getNestedType(e1, TDEF | REF | CVTYPE); @@ -211,23 +217,34 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen } } e2 = addQualifiersForAccess((ICPPField) binding, e2, e1); - } + if (!isPointerDereference() && owner.getValueCategory() == PRVALUE) { + e2= prvalueType(e2); + } else { + e2= glvalueType(e2); + } + } return SemanticUtil.mapToAST(e2, this); - } else if (binding instanceof IEnumerator) { + } + if (binding instanceof IEnumerator) { return ((IEnumerator) binding).getType(); - } else if (binding instanceof IFunction) { + } + if (binding instanceof IFunction) { return SemanticUtil.mapToAST(((IFunction) binding).getType(), this); - } else if (binding instanceof ICPPUnknownBinding) { + } + if (binding instanceof ICPPUnknownBinding) { + // mstodo type of unknown. return CPPUnknownClass.createUnnamedInstance(); - } else if (binding instanceof IProblemBinding) { + } + if (binding instanceof IProblemBinding) { return (IType) binding; } + // mstodo problem type. + return null; } catch (DOMException e) { return e.getProblem(); } - return null; } - + public static IType addQualifiersForAccess(ICPPField field, IType fieldType, IType ownerType) throws DOMException { CVQualifier cvq1 = SemanticUtil.getCVQualifier(ownerType); if (field.isMutable()) { @@ -244,23 +261,34 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen } - public boolean isLValue() { - if (isPointerDereference()) - return true; - - IBinding b= getFieldName().resolveBinding(); + public ValueCategory getValueCategory() { + IASTName name= getFieldName(); + IBinding binding = name.resolvePreBinding(); try { - if (b instanceof ICPPMember && ((ICPPMember) b).isStatic()) - return true; - if (b instanceof IVariable) { - if (SemanticUtil.getNestedType(((IVariable) b).getType(), TDEF) instanceof ICPPReferenceType) { - return true; + if (binding instanceof IVariable) { + IType e2= ((IVariable) binding).getType(); + e2= SemanticUtil.getNestedType(e2, TDEF); + if (e2 instanceof ICPPReferenceType) { + return LVALUE; + } + if (binding instanceof ICPPField && !((ICPPField) binding).isStatic()) { + if (isPointerDereference()) + return LVALUE; + + return owner.getValueCategory(); } - return getFieldOwner().isLValue(); - } - } catch (DOMException e) { - } - return false; + return LVALUE; + } + if (binding instanceof IFunction) { + return LVALUE; + } + } catch (DOMException e) { + } + return PRVALUE; + } + + public boolean isLValue() { + return getValueCategory() == LVALUE; } public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 0288025321d..2fcf5929fe5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -12,8 +12,13 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; @@ -21,12 +26,10 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -38,7 +41,6 @@ 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.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; @@ -49,7 +51,6 @@ public class CPPASTFunctionCallExpression extends ASTNode implements private IASTInitializerClause[] fArguments; private IASTImplicitName[] implicitNames; - private IType type; // cached type of expression private ICPPFunction overload= UNINITIALIZED_FUNCTION; @@ -203,67 +204,79 @@ public class CPPASTFunctionCallExpression extends ASTNode implements public ICPPFunction getOperator() { if (overload == UNINITIALIZED_FUNCTION) { overload= null; - // as a side effect this computes the overload - getExpressionType(); - } + IType t= functionName.getExpressionType(); + t= SemanticUtil.getNestedType(t, TDEF | REF | CVTYPE); + if (t instanceof ICPPClassType) { + overload = CPPSemantics.findOverloadedOperator(this, (ICPPClassType)t); + } + } return overload; } public IType getExpressionType() { - if (type == null) { - type= computeExpressionType(); - } - return type; + if (functionName instanceof IASTIdExpression) { + // Handle misused id-expression in functional type conversions or simple type initializers. + final IBinding binding= ((IASTIdExpression) functionName).getName().resolvePreBinding(); + if (binding instanceof ICPPConstructor) { + IBinding owner= binding.getOwner(); + if (owner instanceof ICPPClassType) { + return (ICPPClassType) owner; + } + return new ProblemBinding(this, IProblemBinding.SEMANTIC_BAD_SCOPE, binding.getNameCharArray()); + } + if (binding instanceof IProblemBinding) { + return (IProblemBinding) binding; + } + if (binding instanceof IType) { + return prvalueType((IType) binding); + } + } + + IType t= SemanticUtil.getNestedType(functionName.getExpressionType(), TDEF|REF|CVTYPE); + if (t instanceof ICPPClassType) { + if (overload == UNINITIALIZED_FUNCTION) { + overload = CPPSemantics.findOverloadedOperator(this, (ICPPClassType)t); + } + if (overload != null) { + return typeFromFunctionCall(overload); + } + // mstodo problem type + return null; + } + + if (t instanceof IPointerType) { + t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); + } + if (t instanceof IFunctionType) { + return typeFromReturnType(((IFunctionType) t).getReturnType()); + } + + // mstodo problem type + return null; } public boolean isLValue() { - return CPPVisitor.isLValueReference(getExpressionType()); + return getValueCategory() == LVALUE; } - - private IType computeExpressionType() { - overload= null; - try { - IType t= null; - if (functionName instanceof IASTIdExpression) { - final IBinding binding= ((IASTIdExpression) functionName).getName().resolvePreBinding(); - if (binding instanceof ICPPConstructor) { - IBinding owner= binding.getOwner(); - if (owner instanceof ICPPClassType) { - return (ICPPClassType) owner; - } - return new ProblemBinding(this, IProblemBinding.SEMANTIC_BAD_SCOPE, - binding.getName().toCharArray()); - } else if (binding instanceof IFunction) { - t = SemanticUtil.mapToAST(((IFunction) binding).getType(), this); - } else if (binding instanceof IVariable) { - t = SemanticUtil.mapToAST(((IVariable) binding).getType(), this); - } else if (binding instanceof IType) { - return (IType) binding; // constructor or simple type initializer - } else if (binding instanceof IProblemBinding) { - return (IProblemBinding) binding; - } - } else { - t= functionName.getExpressionType(); - } - - t= SemanticUtil.getUltimateTypeUptoPointers(t); - if (t instanceof IFunctionType) { - return ((IFunctionType) t).getReturnType(); - } else if (t instanceof ICPPClassType) { - overload = CPPSemantics.findOverloadedOperator(this, (ICPPClassType)t); - if (overload != null) { - return overload.getType().getReturnType(); - } - } else if (t instanceof IPointerType) { - t= SemanticUtil.getUltimateTypeUptoPointers(((IPointerType) t).getType()); - if (t instanceof IFunctionType) { - return ((IFunctionType) t).getReturnType(); - } - } - } catch (DOMException e) { - return e.getProblem(); - } - return null; + + public ValueCategory getValueCategory() { + IType t= functionName.getExpressionType(); + if (t instanceof ICPPClassType) { + if (overload == UNINITIALIZED_FUNCTION) { + overload = CPPSemantics.findOverloadedOperator(this, (ICPPClassType)t); + } + if (overload != null) { + return valueCategoryFromFunctionCall(overload); + } + } else { + if (t instanceof IPointerType) { + t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); + } + if (t instanceof IFunctionType) { + return valueCategoryFromReturnType(((IFunctionType) t).getReturnType()); + } + } + return ValueCategory.PRVALUE; } @Deprecated diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java index 474dd539fd7..086c2aa0173 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java @@ -12,22 +12,35 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; 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.IBinding; import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; @@ -35,7 +48,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICPPASTCompletionContext { + private static final ICPPASTFieldReference NOT_INITIALIZED = new CPPASTFieldReference(); + private IASTName name; + private ICPPASTFieldReference fTransformedExpression= NOT_INITIALIZED; public CPPASTIdExpression() { } @@ -92,21 +108,18 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICP public IType getExpressionType() { IBinding binding = name.resolvePreBinding(); + if (checkForTransformation(binding)) { + return fTransformedExpression.getExpressionType(); + } try { - if (binding instanceof IVariable) { - final IVariable var = (IVariable) binding; - IType type= SemanticUtil.mapToAST(var.getType(), this); - if (var instanceof ICPPField && !var.isStatic()) { - IScope scope= CPPVisitor.getContainingScope(name); - if (scope != null) { - IType containerType= CPPVisitor.getImpliedObjectType(scope); - if (containerType != null) { - type= CPPASTFieldReference.addQualifiersForAccess((ICPPField) var, type, containerType); - } - } - } - return type; - } else if (binding instanceof IEnumerator) { + if (binding instanceof IProblemBinding) { + return (IProblemBinding) binding; + } + if (binding instanceof IType || binding instanceof ICPPConstructor) { + // mstodo return problem type + return null; + } + if (binding instanceof IEnumerator) { IType type= ((IEnumerator) binding).getType(); if (type instanceof ICPPEnumeration) { ICPPEnumeration enumType= (ICPPEnumeration) type; @@ -122,29 +135,84 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICP } } return type; - } else if (binding instanceof IProblemBinding) { - return (IType) binding; - } else if (binding instanceof IFunction) { + } + if (binding instanceof IVariable) { + final IType t = glvalueType(((IVariable) binding).getType()); + return SemanticUtil.mapToAST(t, this); + } + if (binding instanceof IFunction) { return SemanticUtil.mapToAST(((IFunction) binding).getType(), this); - } else if (binding instanceof ICPPTemplateNonTypeParameter) { - return ((ICPPTemplateNonTypeParameter) binding).getType(); - } else if (binding instanceof ICPPClassType) { - return ((ICPPClassType) binding); - } else if (binding instanceof ICPPUnknownBinding) { + } + if (binding instanceof ICPPTemplateNonTypeParameter) { + return prvalueType(((ICPPTemplateNonTypeParameter) binding).getType()); + } + if (binding instanceof ICPPUnknownBinding) { + // mstodo typeof unknown binding return CPPUnknownClass.createUnnamedInstance(); } } catch (DOMException e) { return e.getProblem(); } + // mstodo return problem type return null; } + /** + * 9.3.1-3 Transformation to class member access within the definition of a non-static + * member function. + */ + public boolean checkForTransformation(IBinding binding) { + if (fTransformedExpression == NOT_INITIALIZED) { + fTransformedExpression= null; + if (name instanceof ICPPASTQualifiedName) { + IASTNode parent= name.getParent(); + if (parent instanceof ICPPASTUnaryExpression) { + if (((ICPPASTUnaryExpression) parent).getOperator() == IASTUnaryExpression.op_amper) { + return false; + } + } + } + if (binding instanceof ICPPMember && !(binding instanceof IType) && !(binding instanceof ICPPConstructor) + &&!((ICPPMember) binding).isStatic()) { + IASTNode parent= getParent(); + while (parent != null && !(parent instanceof ICPPASTFunctionDefinition)) { + parent= parent.getParent(); + } + if (parent instanceof ICPPASTFunctionDefinition) { + ICPPASTFunctionDefinition fdef= (ICPPASTFunctionDefinition) parent; + final IBinding methodBinding = fdef.getDeclarator().getName().resolvePreBinding(); + if (methodBinding instanceof ICPPMethod && !((ICPPMethod) methodBinding).isStatic()) { + IASTName nameDummy= new CPPASTName(); + nameDummy.setBinding(binding); + IASTExpression owner= new CPPASTLiteralExpression(IASTLiteralExpression.lk_this, CharArrayUtils.EMPTY); + owner= new CPPASTUnaryExpression(IASTUnaryExpression.op_star, owner); + fTransformedExpression= new CPPASTFieldReference(nameDummy, owner); + fTransformedExpression.setParent(getParent()); + fTransformedExpression.setPropertyInParent(getPropertyInParent()); + } + } + } + } + + return fTransformedExpression != null; + } + public boolean isLValue() { - IBinding b= getName().resolveBinding(); - if (b instanceof IVariable || b instanceof IFunction) { - return true; + return getValueCategory() == LVALUE; + } + + public ValueCategory getValueCategory() { + IBinding binding = name.resolvePreBinding(); + if (checkForTransformation(binding)) { + return fTransformedExpression.getValueCategory(); + } + if (binding instanceof ICPPTemplateNonTypeParameter) + return ValueCategory.PRVALUE; + + if (binding instanceof IVariable || binding instanceof IFunction) { + return ValueCategory.LVALUE; } - return false; + return ValueCategory.PRVALUE; } public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java index 7b26865abff..8146049ed45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java @@ -12,12 +12,12 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; -import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; + import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -44,7 +44,7 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTExpression#copy() */ - public IASTExpression copy() { + public CPPASTLambdaExpression copy() { CPPASTLambdaExpression result= new CPPASTLambdaExpression(); result.fCaptureDefault= fCaptureDefault; if (fCaptures != null) { @@ -191,4 +191,8 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr public boolean isLValue() { return false; } + + public ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java index fa8f0214044..3755bbcc743 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; + import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -122,6 +123,10 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx public boolean isLValue() { return getKind() == IASTLiteralExpression.lk_string_literal; } + + public ValueCategory getValueCategory() { + return isLValue() ? ValueCategory.LVALUE : ValueCategory.PRVALUE; + } private IValue getStringLiteralSize() { char[] value= getValue(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index b96c0bcca1c..c6725e5c96f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; @@ -29,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; + import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -224,7 +227,11 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression return false; } - @Deprecated + public ValueCategory getValueCategory() { + return PRVALUE; + } + + @Deprecated public IASTExpression[] getNewTypeIdArrayExpressions() { if (cachedArraySizes == null) { if (typeId != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java index a8c8707411b..cadd07aec6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2010 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 @@ -41,12 +41,11 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac } } - public IASTExpression getPattern() { return fPattern; } - public IASTExpression copy() { + public CPPASTPackExpansionExpression copy() { CPPASTPackExpansionExpression copy = new CPPASTPackExpansionExpression(fPattern.copy()); copy.setOffsetAndLength(this); return copy; @@ -63,6 +62,10 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac public boolean isLValue() { return fPattern.isLValue(); } + + public ValueCategory getValueCategory() { + return fPattern.getValueCategory(); + } @Override public boolean accept(ASTVisitor visitor) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java index a0e061e4eb5..bdcf0f8ffff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -59,4 +59,8 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTP public boolean isLValue() { return false; } + + public ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java index 3bff8997c7b..6d0750e5ab3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java @@ -11,15 +11,19 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializer; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; + import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; @@ -73,7 +77,7 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements public IType getExpressionType() { if (fType == null) { - fType= CPPVisitor.createType(fDeclSpec); + fType= prvalueType(CPPVisitor.createType(fDeclSpec)); } return fType; } @@ -82,7 +86,11 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements return false; } - @Override + public ValueCategory getValueCategory() { + return PRVALUE; + } + + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitExpressions) { switch (action.visit(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java index c9e661699f3..664461a36a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation 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 @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IType; @@ -84,6 +87,7 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr public IType getExpressionType() { switch (getOperator()) { case op_sizeof: + case op_alignof: return CPPVisitor.get_SIZE_T(this); case op_typeid: return CPPVisitor.get_type_info(this); @@ -98,6 +102,8 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr } return false; } - - + + public ValueCategory getValueCategory() { + return isLValue() ? LVALUE : PRVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java index a40db14f41c..a68ba91ef0b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2010 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 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; + import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression; @@ -18,7 +20,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTypeIdInitializerExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** - * C++ variant of type id initializer expression. + * C++ variant of type id initializer expression. type-id { initializer } */ public class CPPASTTypeIdInitializerExpression extends ASTTypeIdInitializerExpression { @@ -37,6 +39,6 @@ public class CPPASTTypeIdInitializerExpression extends ASTTypeIdInitializerExpre public IType getExpressionType() { final IASTTypeId typeId = getTypeId(); - return CPPVisitor.createType(typeId.getAbstractDeclarator()); + return prvalueType(CPPVisitor.createType(typeId.getAbstractDeclarator())); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index c699a1da229..553a1a96d87 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; @@ -48,7 +51,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; * Unary expression in c++ */ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpression, IASTAmbiguityParent { - private int op; + private static final CPPBasicType BOOLEAN_TYPE = new CPPBasicType(Kind.eBoolean, 0); + + private int op; private IASTExpression operand; private ICPPFunction overload = UNINITIALIZED_FUNCTION; @@ -187,6 +192,7 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres try { if (name instanceof ICPPASTQualifiedName) { if (!member.isStatic()) { // so if the member is static it will fall through + overload= null; if (!inParenthesis) { return new CPPPointerToMemberType(member.getType(), member.getClassOwner(), false, false); } else if (member instanceof IFunction) { @@ -210,6 +216,8 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres return CPPVisitor.get_SIZE_T(this); case op_typeid: return CPPVisitor.get_type_info(this); + case op_bracketedPrimary: + return getOperand().getExpressionType(); } final IASTExpression operand = getOperand(); @@ -219,88 +227,90 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres if (ptm != null) return ptm; - IType operator = findOperatorReturnType(); - if (operator != null) - return operator; + ICPPFunction overload = getOverload(); + if (overload != null) + return typeFromFunctionCall(overload); - IType type= operand.getExpressionType(); - type = SemanticUtil.getNestedType(type, TDEF | REF); - return new CPPPointerType(type); + return new CPPPointerType(operand.getExpressionType()); } + ICPPFunction overload = getOverload(); + if (overload != null) + return typeFromFunctionCall(overload); + if (op == op_star) { IType type= operand.getExpressionType(); type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (type instanceof IProblemBinding) { return type; } - IType operator = findOperatorReturnType(); - if (operator != null) { - return operator; - } else if (type instanceof IPointerType || type instanceof IArrayType) { - return ((ITypeContainer) type).getType(); - } else if (type instanceof ICPPUnknownType) { + + if (type instanceof IPointerType || type instanceof IArrayType) { + type= ((ITypeContainer) type).getType(); + return glvalueType(type); + } + if (type instanceof ICPPUnknownType) { + // mstodo Type of unknown return CPPUnknownClass.createUnnamedInstance(); } return new ProblemBinding(this, IProblemBinding.SEMANTIC_INVALID_TYPE, this.getRawSignature().toCharArray()); } - IType origType= operand.getExpressionType(); - IType type = SemanticUtil.getUltimateTypeUptoPointers(origType); - IType operator = findOperatorReturnType(); - if (operator != null) { - return operator; - } - + IType typeOfOperand= operand.getExpressionType(); + switch (op) { case op_not: - return new CPPBasicType(Kind.eBoolean, 0); + return BOOLEAN_TYPE; + case op_postFixDecr: + case op_postFixIncr: + typeOfOperand= prvalueType(typeOfOperand); + break; case op_minus: case op_plus: case op_tilde: - IType t= CPPArithmeticConversion.promoteCppType(type); + IType t= CPPArithmeticConversion.promoteCppType(prvalueType(typeOfOperand)); if (t != null) { return t; } break; } - if (origType instanceof CPPBasicType) { - ((CPPBasicType) origType).setFromExpression(this); + if (typeOfOperand instanceof CPPBasicType) { + ((CPPBasicType) typeOfOperand).setFromExpression(this); } - return origType; + return typeOfOperand; } - public boolean isLValue() { - ICPPFunction op = getOverload(); - if (op != null) { - try { - return CPPVisitor.isLValueReference(op.getType().getReturnType()); - } catch (DOMException e) { - } - } - - switch (getOperator()) { + public ValueCategory getValueCategory() { + final int op= getOperator(); + switch (op) { + case op_typeid: + return LVALUE; + case op_sizeof: + case op_sizeofParameterPack: + return PRVALUE; case op_bracketedPrimary: - return getOperand().isLValue(); - case op_star: - case op_prefixDecr: - case op_prefixIncr: - return true; - default: - return false; + return (operand).getValueCategory(); + } + + if (op == op_amper && computePointerToMemberType() != null) { + return PRVALUE; } - } - private IType findOperatorReturnType() { - ICPPFunction operatorFunction = getOverload(); - if (operatorFunction != null) { - try { - return operatorFunction.getType().getReturnType(); - } catch (DOMException e) { - return e.getProblem(); - } + ICPPFunction overload = getOverload(); + if (overload != null) + return valueCategoryFromFunctionCall(overload); + + switch(op) { + case op_star: + case op_prefixDecr: + case op_prefixIncr: + return LVALUE; } - return null; + return PRVALUE; } + + public boolean isLValue() { + return getValueCategory() == LVALUE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index b71af457f09..a04128c2310 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -153,8 +153,6 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP if (expr != null) { IType type= expr.getExpressionType(); type= Conversions.lvalue_to_rvalue(type); - type= Conversions.array_to_pointer(type); - type= Conversions.function_to_pointer(type); if (type != null) { return type; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 7070db72482..f71c16c0885 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -338,7 +338,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } } - public boolean isStatic() { + public final boolean isStatic() { return isStatic(true); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index a30e501630b..194afcc513e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -273,8 +273,8 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); } - public boolean isStatic() { - return hasStorageClass(IASTDeclSpecifier.sc_static); + public final boolean isStatic() { + return isStatic(true); } public boolean isMutable() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index f3929ac6fbf..8176772a755 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -208,6 +208,18 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { public boolean isMutable() { return hasStorageClass( this, IASTDeclSpecifier.sc_mutable ); } + + @Override + public boolean isStatic(boolean resolveAll) { + IASTDeclaration decl = getPrimaryDeclaration(); + if (decl != null) { + ICPPASTDeclSpecifier declSpec = getDeclSpec(decl); + if (declSpec != null) { + return declSpec.getStorageClass() == IASTDeclSpecifier.sc_static; + } + } + return false; + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java index 60870ade96e..43c111e8317 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; @@ -151,6 +152,18 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod return false; } + @Override + public boolean isStatic(boolean resolveAll) { + IASTDeclaration decl = getPrimaryDeclaration(); + if (decl instanceof ICPPASTTemplateDeclaration) { + ICPPASTDeclSpecifier declSpec= getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); + if (declSpec != null) { + return declSpec.getStorageClass() == IASTDeclSpecifier.sc_static; + } + } + return false; + } + @Override public boolean isInline() { IASTDeclaration decl = getPrimaryDeclaration(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index 104449d07c2..93e731538bf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -38,7 +39,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * A template template parameter. @@ -107,8 +107,13 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) { ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) parent; IASTExpression value = param.getDefaultValue(); - if (value != null) - return CPPVisitor.createType(value); + if (value instanceof IASTIdExpression) { + IASTName name= ((IASTIdExpression) value).getName(); + IBinding b= name.resolveBinding(); + if (b instanceof IType) { + return (IType) b; + } + } } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 2fb119c3393..76cf9fca855 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -115,7 +115,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; -import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.parser.IExtensionToken; @@ -2576,7 +2575,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { simpleType= IASTSimpleDeclSpecifier.t_typeof; consume(IGCCToken.t_typeof); typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), - IGNUASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotBExpr); + IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotBExpr); encounteredTypename= true; endOffset= calculateEndOffset(typeofExpression); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 137d0cb8bbf..43361640af9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -1958,18 +1958,17 @@ public class CPPVisitor extends ASTQueries { } IType type = expr.getExpressionType(); if (spec.getType() == IASTSimpleDeclSpecifier.t_decltype) { - while (expr instanceof IASTUnaryExpression - && ((IASTUnaryExpression) expr).getOperator() == IASTUnaryExpression.op_bracketedPrimary) { - expr = ((IASTUnaryExpression) expr).getOperand(); - } - if (!(expr instanceof IASTFunctionCallExpression)) { - type= SemanticUtil.getNestedType(type, TDEF | REF); - if (expr.isLValue()) - type= new CPPReferenceType(type, false); + switch((expr).getValueCategory()) { + case XVALUE: + type= new CPPReferenceType(type, true); + break; + case LVALUE: + type= new CPPReferenceType(type, false); + break; + case PRVALUE: + break; } - } else { - type= SemanticUtil.getNestedType(type, TDEF | REF); - } + } return type; } @@ -2208,7 +2207,8 @@ public class CPPVisitor extends ASTQueries { } return false; } - + + @Deprecated public static boolean isLValueReference(IType t) { t= SemanticUtil.getNestedType(t, TDEF); return t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index 08b31c432b7..c111f3ec1fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -192,7 +192,7 @@ public class Conversions { } } - // � Otherwise, a temporary of type �cv1 T1� is created and initialized from the initializer + // Otherwise, a temporary of type 'cv1 T1' is created and initialized from the initializer // expression using the rules for a non-reference copy initialization (8.5). The reference is then // bound to the temporary. If T1 is reference-related to T2, cv1 must be the same cv-qualification // as, or greater cv-qualification than, cv2; otherwise, the program is ill-formed. @@ -271,6 +271,7 @@ public class Conversions { } private static Cost nonReferenceConversion(boolean sourceIsLValue, IType source, IType target, UDCMode udc, boolean isImpliedObject) throws DOMException { + // mstodo fix this to better match the specification if (source instanceof InitializerListType) { return listInitializationSequence(((InitializerListType) source), target, udc, false); } @@ -756,6 +757,7 @@ public class Conversions { * [4.3] function-to-ptr */ private static final boolean lvalue_to_rvalue(final Cost cost, boolean isLValue) { + // mstodo request value category // target should not be a reference here. boolean isConverted= false; IType target = getNestedType(cost.target, REF | TDEF); @@ -1095,39 +1097,20 @@ public class Conversions { } /** - * 4.1 + * 4.1, 4.2, 4.3 */ public static IType lvalue_to_rvalue(IType type) { - IType nested= SemanticUtil.getNestedType(type, TDEF | REF); - if (nested == null || nested == type || nested instanceof IArrayType || nested instanceof ICPPFunctionType) { - return type; + type= SemanticUtil.getNestedType(type, TDEF | REF); + if (type instanceof IArrayType) { + return new CPPPointerType(((IArrayType) type).getType()); } - IType unqualified= SemanticUtil.getNestedType(nested, TDEF | ALLCVQ); - if (unqualified instanceof ICPPClassType) - return nested; - - return unqualified; - } - - /** - * 4.2 - */ - public static IType array_to_pointer(IType type) { - IType nested= SemanticUtil.getNestedType(type, TDEF); - if (nested instanceof IArrayType) { - return new CPPPointerType(((IArrayType) nested).getType()); + if (type instanceof IFunctionType) { + return new CPPPointerType(type); } - return type; - } - - /** - * 4.3 - */ - public static IType function_to_pointer(IType type) { - IType nested= SemanticUtil.getNestedType(type, TDEF); - if (nested instanceof IFunctionType) { - return new CPPPointerType(nested); + IType uqType= SemanticUtil.getNestedType(type, TDEF | REF | ALLCVQ); + if (uqType instanceof ICPPClassType) { + return type; } - return type; + return uqType; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java new file mode 100644 index 00000000000..e1eedd416ac --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2010 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; + +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; +import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; + + +/** + * Methods for computing the type of an expression + */ +public class ExpressionTypes { + + public static IType glvalueType(IType type) { + // Reference types are removed. + return SemanticUtil.getNestedType(type, TDEF | REF); + } + + public static IType prvalueType(IType type) { + return Conversions.lvalue_to_rvalue(type); + } + + + public static ValueCategory valueCategoryFromFunctionCall(ICPPFunction function) { + try { + final ICPPFunctionType ft = function.getType(); + return valueCategoryFromReturnType(ft.getReturnType()); + } catch (DOMException e) { + return ValueCategory.PRVALUE; + } + } + + public static ValueCategory valueCategoryFromReturnType(IType r) { + r= SemanticUtil.getNestedType(r, TDEF); + if (r instanceof ICPPReferenceType) { + ICPPReferenceType refType= (ICPPReferenceType) r; + if (!refType.isRValueReference()) { + return ValueCategory.LVALUE; + } + if (SemanticUtil.getNestedType(refType.getType(), TDEF | REF | CVTYPE) instanceof IFunctionType) { + return ValueCategory.LVALUE; + } + return ValueCategory.XVALUE; + } + return ValueCategory.PRVALUE; + } + + public static IType typeFromFunctionCall(ICPPFunction function) { + try { + final ICPPFunctionType ft = function.getType(); + return typeFromReturnType(ft.getReturnType()); + } catch (DOMException e) { + return e.getProblem(); + } + } + + public static IType typeFromReturnType(IType r) { + r= SemanticUtil.getNestedType(r, TDEF); + if (r instanceof ICPPReferenceType) { + return glvalueType(r); + } + return prvalueType(r); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index e63ff8664dd..0044eed621c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -14,13 +14,16 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; 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.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -197,8 +200,24 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } // v.member() - IType type= fr.getFieldOwner().getExpressionType(); - if (type instanceof ICPPReferenceType) { + IASTExpression fieldOwner = fr.getFieldOwner(); + if (fieldOwner.getValueCategory().isGLValue()) { + while (fieldOwner instanceof IASTUnaryExpression + && ((IASTUnaryExpression) fieldOwner).getOperator() == IASTUnaryExpression.op_bracketedPrimary) + fieldOwner = ((IASTUnaryExpression) fieldOwner).getOperand(); + if (fieldOwner instanceof IASTIdExpression) { + IBinding b= ((IASTIdExpression) fieldOwner).getName().resolveBinding(); + if (b instanceof IVariable) { + try { + IType t = ((IVariable) b).getType(); + if (!(t instanceof ICPPReferenceType)) { + return 0; + } + } catch (DOMException e) { + return 0; + } + } + } return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } } diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTKeywordExpression.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTKeywordExpression.java index 1e9a566f46a..08416397b19 100644 --- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTKeywordExpression.java +++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTKeywordExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * Copyright (c) 2006, 2010 IBM Corporation 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 @@ -11,8 +11,8 @@ package org.eclipse.cdt.internal.core.dom.parser.upc.ast; import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.upc.ast.IUPCASTKeywordExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType; @@ -53,6 +53,10 @@ public class UPCASTKeywordExpression extends ASTNode implements IUPCASTKeywordEx return false; } + public ValueCategory getValueCategory() { + return ValueCategory.PRVALUE; + } + @Override public boolean accept(ASTVisitor visitor) { if(visitor.shouldVisitExpressions) { |