mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 00:45:28 +02:00
Fixed Bug 84343 - [Offsets] no offset or string info for ICPPASTNamedTypeSpecifier
This commit is contained in:
parent
acc0b10a40
commit
649f447a2d
2 changed files with 18 additions and 0 deletions
|
@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
|
@ -173,6 +175,16 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
assertSoleLocation( expression, code.indexOf( "return ") + "return ".length(), 1 ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug84343() throws Exception {
|
||||
String code = "class A {}; int f() {\nA * b = 0;\nreturn b;}"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement)f.getBody()).getStatements()[0];
|
||||
IASTSimpleDeclaration b = (IASTSimpleDeclaration) ds.getDeclaration();
|
||||
ICPPASTNamedTypeSpecifier namedTypeSpec = (ICPPASTNamedTypeSpecifier) b.getDeclSpecifier();
|
||||
assertSoleLocation( namedTypeSpec, code.indexOf( "\nA") + 1, 1 ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
public void testElaboratedTypeSpecifier() throws ParserException {
|
||||
String code = "/* blah */ struct A anA; /* blah */"; //$NON-NLS-1$
|
||||
|
|
|
@ -2932,6 +2932,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
ICPPASTElaboratedTypeSpecifier elabSpec = null;
|
||||
IASTEnumerationSpecifier enumSpec = null;
|
||||
IASTExpression typeofExpression = null;
|
||||
int startOffset = firstToken.getOffset();
|
||||
|
||||
declSpecifiers: for (;;) {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_inline:
|
||||
|
@ -3140,6 +3142,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
elabSpec.setStorageClass(storageClass);
|
||||
elabSpec.setVirtual(isVirtual);
|
||||
elabSpec.setExplicit(isExplicit);
|
||||
((CPPASTNode)elabSpec).setOffsetAndLength( startOffset, calculateEndOffset(elabSpec)- startOffset );
|
||||
return elabSpec;
|
||||
}
|
||||
if (enumSpec != null) {
|
||||
|
@ -3152,6 +3155,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
((ICPPASTDeclSpecifier) enumSpec).setExplicit(isExplicit);
|
||||
enumSpec.setInline(isInline);
|
||||
enumSpec.setStorageClass(storageClass);
|
||||
((CPPASTNode)enumSpec).setOffsetAndLength( startOffset, calculateEndOffset(enumSpec) - startOffset );
|
||||
return (ICPPASTDeclSpecifier) enumSpec;
|
||||
}
|
||||
if (classSpec != null) {
|
||||
|
@ -3164,6 +3168,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
classSpec.setStorageClass(storageClass);
|
||||
classSpec.setVirtual(isVirtual);
|
||||
classSpec.setExplicit(isExplicit);
|
||||
((CPPASTNode)classSpec).setOffsetAndLength( startOffset, calculateEndOffset(classSpec) - startOffset );
|
||||
return classSpec;
|
||||
}
|
||||
if (duple != null) {
|
||||
|
@ -3183,6 +3188,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
nameSpec.setStorageClass(storageClass);
|
||||
nameSpec.setVirtual(isVirtual);
|
||||
nameSpec.setExplicit(isExplicit);
|
||||
((CPPASTNode)nameSpec).setOffsetAndLength( startOffset, last.getEndOffset() - startOffset );
|
||||
return nameSpec;
|
||||
}
|
||||
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue