mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Additional testcase + minor fix for resolution of structs.
This commit is contained in:
parent
64d23241dd
commit
78a0afeab0
5 changed files with 60 additions and 26 deletions
|
@ -89,6 +89,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
||||||
*/
|
*/
|
||||||
public class AST2BaseTest extends BaseTestCase {
|
public class AST2BaseTest extends BaseTestCase {
|
||||||
protected static final IParserLogService NULL_LOG = new NullLogService();
|
protected static final IParserLogService NULL_LOG = new NullLogService();
|
||||||
|
protected static boolean sValidateCopy;
|
||||||
|
|
||||||
public AST2BaseTest() {
|
public AST2BaseTest() {
|
||||||
super();
|
super();
|
||||||
|
@ -98,6 +99,13 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
sValidateCopy= true;
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException {
|
protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException {
|
||||||
return parse(code, lang, false, true);
|
return parse(code, lang, false, true);
|
||||||
}
|
}
|
||||||
|
@ -144,6 +152,7 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
|
|
||||||
IASTTranslationUnit tu = parser.parse();
|
IASTTranslationUnit tu = parser.parse();
|
||||||
assertTrue(tu.isFrozen());
|
assertTrue(tu.isFrozen());
|
||||||
|
if (sValidateCopy)
|
||||||
validateCopy(tu);
|
validateCopy(tu);
|
||||||
|
|
||||||
if (parser.encounteredError() && expectNoProblems)
|
if (parser.encounteredError() && expectNoProblems)
|
||||||
|
|
|
@ -5799,6 +5799,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
// };
|
// };
|
||||||
public void testScalabilityOfLargeTrivialInitializer_Bug253690() throws Exception {
|
public void testScalabilityOfLargeTrivialInitializer_Bug253690() throws Exception {
|
||||||
|
sValidateCopy= false;
|
||||||
final int AMOUNT= 250000;
|
final int AMOUNT= 250000;
|
||||||
final StringBuffer[] input = getContents(3);
|
final StringBuffer[] input = getContents(3);
|
||||||
StringBuilder buf= new StringBuilder();
|
StringBuilder buf= new StringBuilder();
|
||||||
|
@ -5821,7 +5822,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private long memoryUsed() {
|
private long memoryUsed() {
|
||||||
System.gc();System.gc();System.gc();
|
System.gc();System.gc();System.gc();System.gc();System.gc();
|
||||||
final Runtime runtime = Runtime.getRuntime();
|
final Runtime runtime = Runtime.getRuntime();
|
||||||
return runtime.totalMemory()-runtime.freeMemory();
|
return runtime.totalMemory()-runtime.freeMemory();
|
||||||
}
|
}
|
||||||
|
@ -5951,4 +5952,21 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true);
|
IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef struct A A;
|
||||||
|
// struct A; // struct
|
||||||
|
// struct A* a;
|
||||||
|
public void testTypedefWithSameName() throws Exception {
|
||||||
|
final String code= getAboveComment();
|
||||||
|
for (ParserLanguage lang : ParserLanguage.values()) {
|
||||||
|
IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true);
|
||||||
|
|
||||||
|
BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP);
|
||||||
|
ITypedef t= ba.assertNonProblem("A;", 1);
|
||||||
|
ICompositeType s1= ba.assertNonProblem("A; // struct", 1);
|
||||||
|
ICompositeType s2= ba.assertNonProblem("A*", 1);
|
||||||
|
assertSame(s1, s2);
|
||||||
|
assertSame(s1, t.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||||
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.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||||
|
@ -1751,16 +1752,24 @@ public class CPPSemantics {
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = temp;
|
type = temp;
|
||||||
} else if (type != temp && !((IType)type).isSameType((IType) temp)) {
|
} else if (type != temp) {
|
||||||
boolean i1= isFromIndex(type);
|
boolean i1= isFromIndex(type);
|
||||||
boolean i2= isFromIndex(temp);
|
boolean i2= isFromIndex(temp);
|
||||||
if (i1 != i2) {
|
if (i1 != i2) {
|
||||||
|
// prefer non-index bindings
|
||||||
if (i1)
|
if (i1)
|
||||||
type= temp;
|
type= temp;
|
||||||
|
} else {
|
||||||
|
if (((IType)type).isSameType((IType) temp)) {
|
||||||
|
if (type instanceof ITypedef && !(temp instanceof ITypedef)) {
|
||||||
|
// prefer non-typedefs
|
||||||
|
type= temp;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
obj = temp;
|
obj = temp;
|
||||||
|
|
|
@ -87,6 +87,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
|
||||||
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.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
|
@ -220,7 +221,7 @@ public class CPPTemplates {
|
||||||
IASTName start= name;
|
IASTName start= name;
|
||||||
ICPPASTFunctionDefinition func= CPPVisitor.findEnclosingFunctionDefinition(name);
|
ICPPASTFunctionDefinition func= CPPVisitor.findEnclosingFunctionDefinition(name);
|
||||||
if (func != null) {
|
if (func != null) {
|
||||||
start= CPPVisitor.findInnermostDeclarator(func.getDeclarator()).getName();
|
start= ASTQueries.findInnermostDeclarator(func.getDeclarator()).getName();
|
||||||
start= start.getLastName();
|
start= start.getLastName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +404,7 @@ public class CPPTemplates {
|
||||||
else if (param instanceof ICPPASTTemplatedTypeTemplateParameter)
|
else if (param instanceof ICPPASTTemplatedTypeTemplateParameter)
|
||||||
return ((ICPPASTTemplatedTypeTemplateParameter) param).getName();
|
return ((ICPPASTTemplatedTypeTemplateParameter) param).getName();
|
||||||
else if (param instanceof ICPPASTParameterDeclaration)
|
else if (param instanceof ICPPASTParameterDeclaration)
|
||||||
return CPPVisitor.findInnermostDeclarator(((ICPPASTParameterDeclaration) param).getDeclarator()).getName();
|
return ASTQueries.findInnermostDeclarator(((ICPPASTParameterDeclaration) param).getDeclarator()).getName();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,12 +438,12 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IASTDeclarator dtor = dtors[0];
|
IASTDeclarator dtor = dtors[0];
|
||||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
dtor= ASTQueries.findInnermostDeclarator(dtor);
|
||||||
name = dtor.getName();
|
name = dtor.getName();
|
||||||
}
|
}
|
||||||
} else if (decl instanceof IASTFunctionDefinition) {
|
} else if (decl instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
|
||||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
dtor= ASTQueries.findInnermostDeclarator(dtor);
|
||||||
name = dtor.getName();
|
name = dtor.getName();
|
||||||
}
|
}
|
||||||
if (name == null)
|
if (name == null)
|
||||||
|
@ -482,7 +483,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
assert templateParameter instanceof ICPPASTParameterDeclaration;
|
assert templateParameter instanceof ICPPASTParameterDeclaration;
|
||||||
final IASTDeclarator dtor = ((ICPPASTParameterDeclaration) templateParameter).getDeclarator();
|
final IASTDeclarator dtor = ((ICPPASTParameterDeclaration) templateParameter).getDeclarator();
|
||||||
return new CPPTemplateNonTypeParameter(CPPVisitor.findInnermostDeclarator(dtor).getName());
|
return new CPPTemplateNonTypeParameter(ASTQueries.findInnermostDeclarator(dtor).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
static public ICPPScope getContainingScope(IASTNode node) {
|
static public ICPPScope getContainingScope(IASTNode node) {
|
||||||
|
@ -570,7 +571,6 @@ public class CPPTemplates {
|
||||||
if (isDecl || isDef) {
|
if (isDecl || isDef) {
|
||||||
if (partialSpec == null) {
|
if (partialSpec == null) {
|
||||||
partialSpec = new CPPClassTemplatePartialSpecialization(id);
|
partialSpec = new CPPClassTemplatePartialSpecialization(id);
|
||||||
// mstodo how to add partial specialization to class template from index?
|
|
||||||
if (template instanceof ICPPInternalClassTemplate)
|
if (template instanceof ICPPInternalClassTemplate)
|
||||||
((ICPPInternalClassTemplate) template).addPartialSpecialization(partialSpec);
|
((ICPPInternalClassTemplate) template).addPartialSpecialization(partialSpec);
|
||||||
return partialSpec;
|
return partialSpec;
|
||||||
|
@ -686,7 +686,7 @@ public class CPPTemplates {
|
||||||
|
|
||||||
public static ICPPSpecialization createSpecialization(ICPPClassSpecialization owner, IBinding decl, ICPPTemplateParameterMap tpMap) {
|
public static ICPPSpecialization createSpecialization(ICPPClassSpecialization owner, IBinding decl, ICPPTemplateParameterMap tpMap) {
|
||||||
|
|
||||||
// mstodo- specializations of partial specializations
|
// mstodo specializations of partial specializations
|
||||||
if (decl instanceof ICPPClassTemplatePartialSpecialization)
|
if (decl instanceof ICPPClassTemplatePartialSpecialization)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -1161,7 +1161,7 @@ public class CPPTemplates {
|
||||||
IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) decl;
|
IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) decl;
|
||||||
IASTDeclarator[] dtors = sdecl.getDeclarators();
|
IASTDeclarator[] dtors = sdecl.getDeclarators();
|
||||||
if (dtors != null && dtors.length > 0) {
|
if (dtors != null && dtors.length > 0) {
|
||||||
name= CPPVisitor.findInnermostDeclarator(dtors[0]).getName();
|
name= ASTQueries.findInnermostDeclarator(dtors[0]).getName();
|
||||||
} else {
|
} else {
|
||||||
IASTDeclSpecifier declspec = sdecl.getDeclSpecifier();
|
IASTDeclSpecifier declspec = sdecl.getDeclSpecifier();
|
||||||
if (declspec instanceof IASTCompositeTypeSpecifier) {
|
if (declspec instanceof IASTCompositeTypeSpecifier) {
|
||||||
|
@ -1172,7 +1172,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
} else if (decl instanceof IASTFunctionDefinition) {
|
} else if (decl instanceof IASTFunctionDefinition) {
|
||||||
IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl;
|
IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl;
|
||||||
name= CPPVisitor.findInnermostDeclarator(fdef.getDeclarator()).getName();
|
name= ASTQueries.findInnermostDeclarator(fdef.getDeclarator()).getName();
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -1242,7 +1242,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
} else if (nestedDecl instanceof IASTFunctionDefinition) {
|
} else if (nestedDecl instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator();
|
IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator();
|
||||||
declarator= CPPVisitor.findInnermostDeclarator(declarator);
|
declarator= ASTQueries.findInnermostDeclarator(declarator);
|
||||||
name = declarator.getName();
|
name = declarator.getName();
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|
|
@ -624,9 +624,7 @@ public class CPPVisitor extends ASTQueries {
|
||||||
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION);
|
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION);
|
||||||
}
|
}
|
||||||
// if we don't resolve the target type first, we get a problem binding in case the typedef
|
// if we don't resolve the target type first, we get a problem binding in case the typedef
|
||||||
// redeclares the target type:
|
// redeclares the target type, otherwise it is safer to defer the resolution of the target type.
|
||||||
// typedef struct S S;
|
|
||||||
// mstodo this is a hack, remove it!
|
|
||||||
IType targetType= createType(declarator);
|
IType targetType= createType(declarator);
|
||||||
CPPTypedef td= new CPPTypedef(name);
|
CPPTypedef td= new CPPTypedef(name);
|
||||||
td.setType(targetType);
|
td.setType(targetType);
|
||||||
|
|
Loading…
Add table
Reference in a new issue