mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 323599: Type of id-expression denoting a field access.
This commit is contained in:
parent
55fd582a63
commit
04303cfd0e
3 changed files with 55 additions and 12 deletions
|
@ -8876,4 +8876,24 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertEquals("MyType &", ASTTypeUtil.getType(g.getType().getParameterTypes()[0], false));
|
||||
assertEquals("int &", ASTTypeUtil.getType(g.getType().getParameterTypes()[0], true));
|
||||
}
|
||||
|
||||
// class container {
|
||||
// public:
|
||||
// void constBegin() const;
|
||||
// void begin();
|
||||
// };
|
||||
// struct test {
|
||||
// void test_func() const {
|
||||
// cnt.constBegin(); //ref
|
||||
// cnt.begin(); //ref
|
||||
// }
|
||||
// container cnt;
|
||||
// };
|
||||
public void testConstMember_323599() throws Exception {
|
||||
String code= getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
IFunction f= bh.assertNonProblem("constBegin(); //ref", 10);
|
||||
bh.assertProblem("begin(); //ref", 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -210,17 +210,7 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen
|
|||
e1= ((IPointerType) e1).getType();
|
||||
}
|
||||
}
|
||||
CVQualifier cvq1 = SemanticUtil.getCVQualifier(e1);
|
||||
if (((ICPPField) binding).isMutable()) {
|
||||
// Remove const, add union of volatile.
|
||||
CVQualifier cvq2 = SemanticUtil.getCVQualifier(e2);
|
||||
if (cvq2.isConst()) {
|
||||
e2= SemanticUtil.getNestedType(e2, ALLCVQ | TDEF | REF);
|
||||
}
|
||||
e2= SemanticUtil.addQualifiers(e2, false, cvq1.isVolatile() || cvq2.isVolatile());
|
||||
} else {
|
||||
e2= SemanticUtil.addQualifiers(e2, cvq1.isConst(), cvq1.isVolatile());
|
||||
}
|
||||
e2 = addQualifiersForAccess((ICPPField) binding, e2, e1);
|
||||
}
|
||||
return SemanticUtil.mapToAST(e2, this);
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
|
@ -238,6 +228,21 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen
|
|||
return null;
|
||||
}
|
||||
|
||||
public static IType addQualifiersForAccess(ICPPField field, IType fieldType, IType ownerType) throws DOMException {
|
||||
CVQualifier cvq1 = SemanticUtil.getCVQualifier(ownerType);
|
||||
if (field.isMutable()) {
|
||||
// Remove const, add union of volatile.
|
||||
CVQualifier cvq2 = SemanticUtil.getCVQualifier(fieldType);
|
||||
if (cvq2.isConst()) {
|
||||
fieldType= SemanticUtil.getNestedType(fieldType, ALLCVQ | TDEF | REF);
|
||||
}
|
||||
fieldType= SemanticUtil.addQualifiers(fieldType, false, cvq1.isVolatile() || cvq2.isVolatile());
|
||||
} else {
|
||||
fieldType= SemanticUtil.addQualifiers(fieldType, cvq1.isConst(), cvq1.isVolatile());
|
||||
}
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLValue() {
|
||||
if (isPointerDereference())
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.PTR;
|
||||
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.IASTIdExpression;
|
||||
|
@ -21,10 +25,12 @@ 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.ICPPEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
@ -92,7 +98,19 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICP
|
|||
IBinding binding = name.resolvePreBinding();
|
||||
try {
|
||||
if (binding instanceof IVariable) {
|
||||
return SemanticUtil.mapToAST(((IVariable) binding).getType(), this);
|
||||
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 thisType= CPPVisitor.getThisType(scope);
|
||||
if (thisType != null) {
|
||||
thisType= SemanticUtil.getNestedType(thisType, TDEF|REF|PTR);
|
||||
type= CPPASTFieldReference.addQualifiersForAccess((ICPPField) var, type, thisType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return type;
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
IType type= ((IEnumerator) binding).getType();
|
||||
if (type instanceof ICPPEnumeration) {
|
||||
|
|
Loading…
Add table
Reference in a new issue