mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +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
|
@ -4689,6 +4689,19 @@ public class AST2Tests extends AST2TestBase {
|
|||
parseAndCheckBindings(code, C, 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) {
|
||||
// switch(count) {
|
||||
|
|
|
@ -10,22 +10,13 @@
|
|||
*******************************************************************************/
|
||||
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.ITypedef;
|
||||
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.internal.core.dom.parser.ISerializableType;
|
||||
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.ProblemType;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
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.
|
||||
*/
|
||||
public CQualifierType(ICASTDeclSpecifier declSpec) {
|
||||
this.type = resolveType(declSpec);
|
||||
this.type = CVisitor.createBaseType(declSpec);
|
||||
this.isConst = declSpec.isConst();
|
||||
this.isVolatile = declSpec.isVolatile();
|
||||
this.isRestrict = declSpec.isRestrict();
|
||||
|
@ -95,32 +86,6 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali
|
|||
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
|
||||
public IType getType() {
|
||||
return type;
|
||||
|
|
Loading…
Add table
Reference in a new issue