1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 362464: Sizeof computation for plain C.

This commit is contained in:
Markus Schorn 2011-11-03 14:01:47 +01:00
parent 058e14d32c
commit 5a62f3280d
7 changed files with 112 additions and 18 deletions

View file

@ -100,12 +100,19 @@ public class AST2BaseTest extends BaseTestCase {
protected static boolean sValidateCopy; protected static boolean sValidateCopy;
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap()); private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(); private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
private static Map<String, String> getGnuMap() { private static Map<String, String> getGnuMap() {
Map<String, String> map= new HashMap<String, String>(); Map<String, String> map= new HashMap<String, String>();
map.put("__GNUC__", "4"); map.put("__GNUC__", "4");
map.put("__GNUC_MINOR__", "5"); map.put("__GNUC_MINOR__", "5");
map.put("__SIZEOF_INT__", "4");
return map;
}
private static Map<String, String> getStdMap() {
Map<String, String> map= new HashMap<String, String>();
map.put("__SIZEOF_INT__", "4");
return map; return map;
} }

View file

@ -7375,4 +7375,16 @@ public class AST2Tests extends AST2BaseTest {
parseAndCheckBindings(); parseAndCheckBindings();
} }
// typedef int T[sizeof(int)];
public void testSizeofExpression_Bug362464() throws Exception {
String code= getAboveComment();
for (ParserLanguage l : ParserLanguage.values()) {
IASTTranslationUnit tu= parseAndCheckBindings(code, l);
IASTSimpleDeclaration sdecl= getDeclaration(tu, 0);
ITypedef tdef= (ITypedef) sdecl.getDeclarators()[0].getName().resolveBinding();
IArrayType at= (IArrayType) tdef.getType();
IValue v= at.getSize();
assertTrue(v.numericalValue() == 4);
}
}
} }

View file

@ -31,9 +31,11 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
@ -84,6 +86,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return this; return this;
} }
@Override
public final void addDeclaration(IASTDeclaration d) { public final void addDeclaration(IASTDeclaration d) {
if (d != null) { if (d != null) {
d.setParent(this); d.setParent(this);
@ -94,6 +97,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
} }
@Override
public final IASTDeclaration[] getDeclarations() { public final IASTDeclaration[] getDeclarations() {
IASTDeclaration[] active= fActiveDeclarations; IASTDeclaration[] active= fActiveDeclarations;
if (active == null) { if (active == null) {
@ -103,6 +107,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return active; return active;
} }
@Override
public final IASTDeclaration[] getDeclarations(boolean includeInactive) { public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
if (includeInactive) { if (includeInactive) {
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class,
@ -130,6 +135,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
@Override
public final IName[] getDeclarations(IBinding binding) { public final IName[] getDeclarations(IBinding binding) {
IName[] names= getDeclarationsInAST(binding); IName[] names= getDeclarationsInAST(binding);
if (names.length == 0 && fIndex != null) { if (names.length == 0 && fIndex != null) {
@ -161,7 +167,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDefinitions(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDefinitions(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public final IName[] getDefinitions(IBinding binding) { @Override
public final IName[] getDefinitions(IBinding binding) {
IName[] names= getDefinitionsInAST(binding); IName[] names= getDefinitionsInAST(binding);
if (names.length == 0 && fIndex != null) { if (names.length == 0 && fIndex != null) {
try { try {
@ -179,6 +186,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/ */
@Override
public final IASTPreprocessorMacroDefinition[] getMacroDefinitions() { public final IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
@ -188,6 +196,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroExpansions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroExpansions()
*/ */
@Override
public IASTPreprocessorMacroExpansion[] getMacroExpansions() { public IASTPreprocessorMacroExpansion[] getMacroExpansions() {
if (fLocationResolver == null) if (fLocationResolver == null)
return IASTPreprocessorMacroExpansion.EMPTY_ARRAY; return IASTPreprocessorMacroExpansion.EMPTY_ARRAY;
@ -199,6 +208,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getBuiltinMacroDefinitions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getBuiltinMacroDefinitions()
*/ */
@Override
public final IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() { public final IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
@ -210,6 +220,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
*/ */
@Override
public final IASTPreprocessorIncludeStatement[] getIncludeDirectives() { public final IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
@ -221,6 +232,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
*/ */
@Override
public final IASTPreprocessorStatement[] getAllPreprocessorStatements() { public final IASTPreprocessorStatement[] getAllPreprocessorStatements() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
@ -242,6 +254,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
*/ */
@Override
public final IASTProblem[] getPreprocessorProblems() { public final IASTProblem[] getPreprocessorProblems() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_PROBLEM_ARRAY; return EMPTY_PROBLEM_ARRAY;
@ -255,6 +268,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
@Override
public final int getPreprocessorProblemsCount() { public final int getPreprocessorProblemsCount() {
return fLocationResolver == null ? 0 : fLocationResolver.getScannerProblemsCount(); return fLocationResolver == null ? 0 : fLocationResolver.getScannerProblemsCount();
} }
@ -264,6 +278,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/ */
@Override
public final String getFilePath() { public final String getFilePath() {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_STRING; return EMPTY_STRING;
@ -290,29 +305,34 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return true; return true;
} }
@Override
public final IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) { public final IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) {
if (fLocationResolver == null) if (fLocationResolver == null)
return null; return null;
return fLocationResolver.flattenLocations(nodeLocations); return fLocationResolver.flattenLocations(nodeLocations);
} }
public final IDependencyTree getDependencyTree() { @Override
public final IDependencyTree getDependencyTree() {
if (fLocationResolver == null) if (fLocationResolver == null)
return null; return null;
return fLocationResolver.getDependencyTree(); return fLocationResolver.getDependencyTree();
} }
@Override
public final String getContainingFilename(int offset) { public final String getContainingFilename(int offset) {
if (fLocationResolver == null) if (fLocationResolver == null)
return EMPTY_STRING; return EMPTY_STRING;
return fLocationResolver.getContainingFilePath(offset); return fLocationResolver.getContainingFilePath(offset);
} }
public final IIndex getIndex() { @Override
public final IIndex getIndex() {
return fIndex; return fIndex;
} }
public final void setIndex(IIndex index) { @Override
public final void setIndex(IIndex index) {
this.fIndex = index; this.fIndex = index;
if (index != null) { if (index != null) {
fIndexFileSet= index.createFileSet(); fIndexFileSet= index.createFileSet();
@ -320,7 +340,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
} }
public final INodeFactory getASTNodeFactory() { @Override
public final INodeFactory getASTNodeFactory() {
return fNodeFactory; return fNodeFactory;
} }
@ -328,6 +349,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
this.fNodeFactory = nodeFactory; this.fNodeFactory = nodeFactory;
} }
@Override
public final IASTComment[] getComments() { public final IASTComment[] getComments() {
if (fLocationResolver != null) { if (fLocationResolver != null) {
return fLocationResolver.getComments(); return fLocationResolver.getComments();
@ -335,6 +357,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return new IASTComment[0]; return new IASTComment[0];
} }
@Override
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public final Object getAdapter(Class adapter) { public final Object getAdapter(Class adapter) {
if (adapter.isAssignableFrom(fLocationResolver.getClass())) { if (adapter.isAssignableFrom(fLocationResolver.getClass())) {
@ -349,10 +372,12 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
return null; return null;
} }
@Override
public final boolean isHeaderUnit() { public final boolean isHeaderUnit() {
return fIsHeader; return fIsHeader;
} }
@Override
public final void setIsHeaderUnit(boolean headerUnit) { public final void setIsHeaderUnit(boolean headerUnit) {
fIsHeader= headerUnit; fIsHeader= headerUnit;
} }
@ -368,6 +393,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent) * @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
*/ */
@Override
public void skippedFile(int offset, InternalFileContent fileContent) { public void skippedFile(int offset, InternalFileContent fileContent) {
if (fIndexFileSet != null) { if (fIndexFileSet != null) {
List<IIndexFile> files= fileContent.getFilesIncluded(); List<IIndexFile> files= fileContent.getFilesIncluded();
@ -378,10 +404,12 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
} }
@Override
public final IIndexFileSet getIndexFileSet() { public final IIndexFileSet getIndexFileSet() {
return fIndexFileSet; return fIndexFileSet;
} }
@Override
public void parsingFile(InternalFileContentProvider provider, InternalFileContent fc) { public void parsingFile(InternalFileContentProvider provider, InternalFileContent fc) {
if (fASTFileSet != null) { if (fASTFileSet != null) {
if (provider instanceof IndexBasedFileContentProvider) { if (provider instanceof IndexBasedFileContentProvider) {
@ -398,6 +426,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
} }
@Override
public final IIndexFileSet getASTFileSet() { public final IIndexFileSet getASTFileSet() {
return fASTFileSet; return fASTFileSet;
} }
@ -407,10 +436,12 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
*/ */
@Override
public final IASTNode selectNodeForLocation(String path, int realOffset, int realLength) { public final IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
return getNodeSelector(path).findNode(realOffset, realLength); return getNodeSelector(path).findNode(realOffset, realLength);
} }
@Override
public final IASTNodeSelector getNodeSelector(String filePath) { public final IASTNodeSelector getNodeSelector(String filePath) {
return new ASTNodeSelector(this, fLocationResolver, filePath); return new ASTNodeSelector(this, fLocationResolver, filePath);
} }
@ -420,6 +451,11 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
*/ */
public abstract void resolveAmbiguities(); public abstract void resolveAmbiguities();
/**
* Can be called to create a type for a type-id.
*/
abstract protected IType createType(IASTTypeId typeid);
protected void copyAbstractTU(ASTTranslationUnit copy, CopyStyle style) { protected void copyAbstractTU(ASTTranslationUnit copy, CopyStyle style) {
copy.setIndex(fIndex); copy.setIndex(fIndex);
copy.fIsHeader = fIsHeader; copy.fIsHeader = fIsHeader;
@ -434,6 +470,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
} }
@Override
public final void freeze() { public final void freeze() {
accept(new ASTGenericVisitor(true) { accept(new ASTGenericVisitor(true) {
@Override @Override
@ -449,6 +486,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getOriginatingTranslationUnit() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getOriginatingTranslationUnit()
*/ */
@Override
public ITranslationUnit getOriginatingTranslationUnit() { public ITranslationUnit getOriginatingTranslationUnit() {
return fOriginatingTranslationUnit; return fOriginatingTranslationUnit;
} }
@ -457,20 +495,24 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
this.fOriginatingTranslationUnit = tu; this.fOriginatingTranslationUnit = tu;
} }
@Override
public ISignificantMacros getSignificantMacros() { public ISignificantMacros getSignificantMacros() {
return fSignificantMacros; return fSignificantMacros;
} }
@Override
public void setSignificantMacros(ISignificantMacros sigMacros) { public void setSignificantMacros(ISignificantMacros sigMacros) {
assertNotFrozen(); assertNotFrozen();
if (sigMacros != null) if (sigMacros != null)
fSignificantMacros= sigMacros; fSignificantMacros= sigMacros;
} }
@Override
public boolean hasPragmaOnceSemantics() { public boolean hasPragmaOnceSemantics() {
return fPragmaOnceSemantics; return fPragmaOnceSemantics;
} }
@Override
public void setPragmaOnceSemantics(boolean value) { public void setPragmaOnceSemantics(boolean value) {
assertNotFrozen(); assertNotFrozen();
fPragmaOnceSemantics= value; fPragmaOnceSemantics= value;

View file

@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@ -111,7 +110,7 @@ public class SizeofCalculator {
public SizeAndAlignment sizeAndAlignment(IType type) { public SizeAndAlignment sizeAndAlignment(IType type) {
type = SemanticUtil.getNestedType(type, SemanticUtil.CVTYPE | SemanticUtil.TDEF); type = SemanticUtil.getNestedType(type, SemanticUtil.CVTYPE | SemanticUtil.TDEF);
if (type instanceof ICPPBasicType) { if (type instanceof IBasicType) {
return sizeAndAlignment((IBasicType) type); return sizeAndAlignment((IBasicType) type);
} }
if (type instanceof IPointerType || type instanceof ICPPReferenceType) { if (type instanceof IPointerType || type instanceof ICPPReferenceType) {

View file

@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException;
import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer;
@ -118,14 +117,17 @@ public class Value implements IValue {
fUnknownBindings= unknown; fUnknownBindings= unknown;
} }
@Override
public char[] getInternalExpression() { public char[] getInternalExpression() {
return fExpression; return fExpression;
} }
@Override
public IBinding[] getUnknownBindings() { public IBinding[] getUnknownBindings() {
return fUnknownBindings; return fUnknownBindings;
} }
@Override
public char[] getSignature() { public char[] getSignature() {
if (fSignature == null) { if (fSignature == null) {
if (fUnknownBindings.length == 0) { if (fUnknownBindings.length == 0) {
@ -148,6 +150,7 @@ public class Value implements IValue {
return fSignature; return fSignature;
} }
@Override
public Long numericalValue() { public Long numericalValue() {
return parseLong(fExpression); return parseLong(fExpression);
} }
@ -468,8 +471,9 @@ public class Value implements IValue {
IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) e; IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) e;
switch (typeIdEx.getOperator()) { switch (typeIdEx.getOperator()) {
case IASTTypeIdExpression.op_sizeof: case IASTTypeIdExpression.op_sizeof:
IType type = CPPVisitor.createType(typeIdEx.getTypeId()); final IType type;
ASTTranslationUnit ast = (ASTTranslationUnit) typeIdEx.getTranslationUnit(); ASTTranslationUnit ast = (ASTTranslationUnit) typeIdEx.getTranslationUnit();
type = ast.createType(typeIdEx.getTypeId());
SizeofCalculator calculator = ast.getSizeofCalculator(); SizeofCalculator calculator = ast.getSizeofCalculator();
SizeAndAlignment info = calculator.sizeAndAlignment(type); SizeAndAlignment info = calculator.sizeAndAlignment(type);
if (info == null) if (info == null)

View file

@ -16,10 +16,12 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.Linkage;
@ -37,10 +39,12 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
fStructMapper= new CStructMapper(this); fStructMapper= new CStructMapper(this);
} }
@Override
public CASTTranslationUnit copy() { public CASTTranslationUnit copy() {
return copy(CopyStyle.withoutLocations); return copy(CopyStyle.withoutLocations);
} }
@Override
public CASTTranslationUnit copy(CopyStyle style) { public CASTTranslationUnit copy(CopyStyle style) {
CASTTranslationUnit copy = new CASTTranslationUnit(); CASTTranslationUnit copy = new CASTTranslationUnit();
copyAbstractTU(copy, style); copyAbstractTU(copy, style);
@ -55,6 +59,7 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/ */
@Override
public IScope getScope() { public IScope getScope() {
if (compilationUnit == null) if (compilationUnit == null)
compilationUnit = new CScope(this, EScopeKind.eGlobal); compilationUnit = new CScope(this, EScopeKind.eGlobal);
@ -62,6 +67,7 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
} }
@Override
public IASTName[] getDeclarationsInAST(IBinding binding) { public IASTName[] getDeclarationsInAST(IBinding binding) {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding) {
return getMacroDefinitionsInAST((IMacroBinding) binding); return getMacroDefinitionsInAST((IMacroBinding) binding);
@ -69,7 +75,8 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
return CVisitor.getDeclarations(this, binding); return CVisitor.getDeclarations(this, binding);
} }
public IASTName[] getDefinitionsInAST(IBinding binding) { @Override
public IASTName[] getDefinitionsInAST(IBinding binding) {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding) {
return getMacroDefinitionsInAST((IMacroBinding) binding); return getMacroDefinitionsInAST((IMacroBinding) binding);
} }
@ -87,17 +94,20 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
@Override
public IASTName[] getReferences(IBinding binding) { public IASTName[] getReferences(IBinding binding) {
if (binding instanceof IMacroBinding) if (binding instanceof IMacroBinding)
return getMacroReferencesInAST((IMacroBinding) binding); return getMacroReferencesInAST((IMacroBinding) binding);
return CVisitor.getReferences(this, binding); return CVisitor.getReferences(this, binding);
} }
@Override
@Deprecated @Deprecated
public ParserLanguage getParserLanguage() { public ParserLanguage getParserLanguage() {
return ParserLanguage.C; return ParserLanguage.C;
} }
@Override
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.C_LINKAGE; return Linkage.C_LINKAGE;
} }
@ -113,4 +123,9 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
public ICompositeType mapToASTType(ICompositeType type) { public ICompositeType mapToASTType(ICompositeType type) {
return fStructMapper.mapToAST(type); return fStructMapper.mapToAST(type);
} }
@Override
protected IType createType(IASTTypeId typeid) {
return CVisitor.createType(typeid.getAbstractDeclarator());
}
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -45,10 +46,12 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
public CPPASTTranslationUnit() { public CPPASTTranslationUnit() {
} }
@Override
public CPPASTTranslationUnit copy() { public CPPASTTranslationUnit copy() {
return copy(CopyStyle.withoutLocations); return copy(CopyStyle.withoutLocations);
} }
@Override
public CPPASTTranslationUnit copy(CopyStyle style) { public CPPASTTranslationUnit copy(CopyStyle style) {
CPPASTTranslationUnit copy = new CPPASTTranslationUnit(); CPPASTTranslationUnit copy = new CPPASTTranslationUnit();
copyAbstractTU(copy, style); copyAbstractTU(copy, style);
@ -58,7 +61,8 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
return copy; return copy;
} }
public CPPNamespaceScope getScope() { @Override
public CPPNamespaceScope getScope() {
if (fScope == null) { if (fScope == null) {
fScope = new CPPNamespaceScope(this); fScope = new CPPNamespaceScope(this);
addBuiltinOperators(fScope); addBuiltinOperators(fScope);
@ -105,14 +109,16 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
theScope.addBinding(temp); theScope.addBinding(temp);
} }
public IASTName[] getDeclarationsInAST(IBinding binding) { @Override
public IASTName[] getDeclarationsInAST(IBinding binding) {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding) {
return getMacroDefinitionsInAST((IMacroBinding) binding); return getMacroDefinitionsInAST((IMacroBinding) binding);
} }
return CPPVisitor.getDeclarations(this, binding); return CPPVisitor.getDeclarations(this, binding);
} }
public IASTName[] getDefinitionsInAST(IBinding binding) { @Override
public IASTName[] getDefinitionsInAST(IBinding binding) {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding) {
return getMacroDefinitionsInAST((IMacroBinding) binding); return getMacroDefinitionsInAST((IMacroBinding) binding);
} }
@ -125,20 +131,23 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
return (IASTName[]) ArrayUtil.removeNulls(IASTName.class, names); return (IASTName[]) ArrayUtil.removeNulls(IASTName.class, names);
} }
public IASTName[] getReferences(IBinding binding) { @Override
public IASTName[] getReferences(IBinding binding) {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding) {
return getMacroReferencesInAST((IMacroBinding) binding); return getMacroReferencesInAST((IMacroBinding) binding);
} }
return CPPVisitor.getReferences(this, binding); return CPPVisitor.getReferences(this, binding);
} }
public IBinding resolveBinding() { @Override
public IBinding resolveBinding() {
if (fBinding == null) if (fBinding == null)
fBinding = new CPPNamespace(this); fBinding = new CPPNamespace(this);
return fBinding; return fBinding;
} }
@Deprecated @Override
@Deprecated
public ParserLanguage getParserLanguage() { public ParserLanguage getParserLanguage() {
return ParserLanguage.CPP; return ParserLanguage.CPP;
} }
@ -146,6 +155,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLinkage() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLinkage()
*/ */
@Override
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
@ -180,4 +190,9 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
public void resolveAmbiguities() { public void resolveAmbiguities() {
accept(new CPPASTAmbiguityResolver()); accept(new CPPASTAmbiguityResolver());
} }
@Override
protected IType createType(IASTTypeId typeid) {
return CPPVisitor.createType(typeid);
}
} }