mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 08:46:02 +02:00
Bug 471907 - Correctly resolve 'typeof' inside a qualifier type in C
Change-Id: I96825ce0012f6fd86284ef2ac8643c31c0d29ae4 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
f3141139f8
commit
17b4ad3d67
2 changed files with 14 additions and 36 deletions
|
@ -4690,6 +4690,19 @@ public class AST2Tests extends AST2TestBase {
|
||||||
parseAndCheckBindings(code, CPP, true);
|
parseAndCheckBindings(code, CPP, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct test {
|
||||||
|
// int field;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// int main() {
|
||||||
|
// struct test t;
|
||||||
|
// const typeof(t) x;
|
||||||
|
// x.field;
|
||||||
|
// }
|
||||||
|
public void testTypeofInsideQualifier_471907() throws Exception {
|
||||||
|
parseAndCheckBindings(getAboveComment(), C);
|
||||||
|
}
|
||||||
|
|
||||||
// void test(int count) {
|
// void test(int count) {
|
||||||
// switch(count) {
|
// switch(count) {
|
||||||
// case 1 ... 3: break;
|
// case 1 ... 3: break;
|
||||||
|
|
|
@ -10,22 +10,13 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
|
import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
|
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class CQualifierType implements ICQualifierType, ITypeContainer, ISerializableType {
|
public class CQualifierType implements ICQualifierType, ITypeContainer, ISerializableType {
|
||||||
|
@ -38,7 +29,7 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali
|
||||||
* CQualifierType has an IBasicType to keep track of the basic type information.
|
* CQualifierType has an IBasicType to keep track of the basic type information.
|
||||||
*/
|
*/
|
||||||
public CQualifierType(ICASTDeclSpecifier declSpec) {
|
public CQualifierType(ICASTDeclSpecifier declSpec) {
|
||||||
this.type = resolveType(declSpec);
|
this.type = CVisitor.createBaseType(declSpec);
|
||||||
this.isConst = declSpec.isConst();
|
this.isConst = declSpec.isConst();
|
||||||
this.isVolatile = declSpec.isVolatile();
|
this.isVolatile = declSpec.isVolatile();
|
||||||
this.isRestrict = declSpec.isRestrict();
|
this.isRestrict = declSpec.isRestrict();
|
||||||
|
@ -95,32 +86,6 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali
|
||||||
return isRestrict;
|
return isRestrict;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IQualifierType#getType()
|
|
||||||
*/
|
|
||||||
private IType resolveType(ICASTDeclSpecifier declSpec) {
|
|
||||||
IBinding b = null;
|
|
||||||
if (declSpec instanceof ICASTTypedefNameSpecifier) {
|
|
||||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
|
||||||
b = nameSpec.getName().resolveBinding();
|
|
||||||
} else if (declSpec instanceof IASTElaboratedTypeSpecifier) {
|
|
||||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
|
||||||
b = elabTypeSpec.getName().resolveBinding();
|
|
||||||
} else if (declSpec instanceof IASTCompositeTypeSpecifier) {
|
|
||||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
|
||||||
b = compTypeSpec.getName().resolveBinding();
|
|
||||||
} else if (declSpec instanceof IASTEnumerationSpecifier) {
|
|
||||||
return new CEnumeration(((IASTEnumerationSpecifier) declSpec).getName());
|
|
||||||
} else {
|
|
||||||
return new CBasicType((ICASTSimpleDeclSpecifier) declSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b instanceof IType && !(b instanceof IProblemBinding))
|
|
||||||
return (IType) b;
|
|
||||||
|
|
||||||
return new ProblemType(ISemanticProblem.TYPE_UNRESOLVED_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IType getType() {
|
public IType getType() {
|
||||||
return type;
|
return type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue