mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 374694. Implementation of alias templates.
This commit is contained in:
parent
45206789d6
commit
4e409e9e2f
23 changed files with 1603 additions and 19 deletions
|
@ -366,6 +366,14 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
assertEquals(num, count);
|
||||
}
|
||||
|
||||
protected void assertSameType(IType expected, IType actual) {
|
||||
assertNotNull(expected);
|
||||
assertNotNull(actual);
|
||||
assertTrue("Expected same types, but the types were: '" +
|
||||
ASTTypeUtil.getType(expected, false) + "' and '" + ASTTypeUtil.getType(actual, false) + "'",
|
||||
expected.isSameType(actual));
|
||||
}
|
||||
|
||||
protected void isExpressionStringEqual(IASTInitializerClause exp, String str) {
|
||||
String expressionString = ASTStringUtil.getExpressionString((IASTExpression) exp);
|
||||
assertEquals(str, expressionString);
|
||||
|
@ -527,6 +535,24 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return (IProblemBinding) binding;
|
||||
}
|
||||
|
||||
public IProblemBinding assertProblem(String context, int len, int problemId) {
|
||||
IProblemBinding problemBinding = assertProblem(context, len);
|
||||
assertEquals(problemId, problemBinding.getID());
|
||||
return problemBinding;
|
||||
}
|
||||
|
||||
public IProblemBinding assertProblem(String context, String name) {
|
||||
IBinding binding= binding(context, name);
|
||||
assertTrue("Non-ProblemBinding for name: " + name, binding instanceof IProblemBinding);
|
||||
return (IProblemBinding) binding;
|
||||
}
|
||||
|
||||
public IProblemBinding assertProblem(String context, String name, int problemId) {
|
||||
IProblemBinding problemBinding = assertProblem(context, name);
|
||||
assertEquals(problemId, problemBinding.getID());
|
||||
return problemBinding;
|
||||
}
|
||||
|
||||
public <T extends IBinding> T assertNonProblem(String section, int len) {
|
||||
if (len <= 0)
|
||||
len= section.length() + len;
|
||||
|
|
|
@ -260,6 +260,12 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertEquals(defNames.length, j);
|
||||
}
|
||||
|
||||
protected void assertSameType(IType first, IType second){
|
||||
assertNotNull(first);
|
||||
assertNotNull(second);
|
||||
assertTrue("Expected types to be the same, but first was: '" + first.toString() + "' and second was: '" + second + "'", first.isSameType(second));
|
||||
}
|
||||
|
||||
// #define CURLOPTTYPE_OBJECTPOINT 10000
|
||||
// #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number
|
||||
// typedef enum {
|
||||
|
@ -9894,7 +9900,6 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue(((ICPPASTCompositeTypeSpecifier)sDefinition).isFinal());
|
||||
}
|
||||
|
||||
|
||||
// struct S {
|
||||
// template<typename T>
|
||||
// void foo(T t) final {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
@ -50,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
|
|||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
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.IVariable;
|
||||
|
@ -58,6 +60,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
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.ICPPClassScope;
|
||||
|
@ -87,6 +91,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
|||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
|
||||
|
@ -6153,4 +6159,529 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
public void testTemplateIDAmbiguity_393959() throws Exception {
|
||||
parseAndCheckBindings(getAboveComment(), CPP, true);
|
||||
}
|
||||
|
||||
// template<typename T> class CT {
|
||||
// void m() {
|
||||
// template<typename T> using Alias= T; // nesting level 1
|
||||
// Alias<int> x;
|
||||
// }
|
||||
// };
|
||||
public void testNestedAliasDeclarationNestingLevel() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
|
||||
ICPPAliasTemplate templateParameterAlias = bh.assertNonProblem("Alias=", "Alias", ICPPAliasTemplate.class);
|
||||
ICPPTemplateParameter aliasParameterT= templateParameterAlias.getTemplateParameters()[0];
|
||||
assertEquals(1, aliasParameterT.getTemplateNestingLevel());
|
||||
|
||||
ICPPAliasTemplateInstance aliasIntInstance = bh.assertNonProblem("Alias<int>", ICPPAliasTemplateInstance.class);
|
||||
IType typeOfAliasIntInstance = aliasIntInstance.getType();
|
||||
assertTrue(typeOfAliasIntInstance instanceof ICPPBasicType);
|
||||
assertEquals(((ICPPBasicType)typeOfAliasIntInstance).getKind(), IBasicType.Kind.eInt);
|
||||
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
|
||||
// template<typename T> class CT;
|
||||
// template<typename T> using Alias= CT<T>; // nesting level 0
|
||||
// template<typename T> class CT { // nesting level 0
|
||||
// typedef Alias<T> TYPE;
|
||||
// };
|
||||
public void testAliasDeclarationNestingLevel() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
|
||||
ICPPAliasTemplate templateParameterAlias = bh.assertNonProblem("Alias=", "Alias", ICPPAliasTemplate.class);
|
||||
ICPPTemplateParameter aliasParameterT = templateParameterAlias.getTemplateParameters()[0];
|
||||
assertEquals(0, aliasParameterT.getTemplateNestingLevel());
|
||||
|
||||
ICPPTemplateDefinition templateCT = bh.assertNonProblem("CT {", "CT", ICPPTemplateDefinition.class);
|
||||
ICPPTemplateParameter templateParameterT = templateCT.getTemplateParameters()[0];
|
||||
assertEquals(0, templateParameterT.getTemplateNestingLevel());
|
||||
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
|
||||
// struct S {
|
||||
// int x;
|
||||
// };
|
||||
// using Alias = S;
|
||||
// void foo() {
|
||||
// Alias myA;
|
||||
// myA.x = 42;
|
||||
// }
|
||||
public void testSimpleAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPClassType S = (ICPPClassType) collector.getName(0).resolveBinding();
|
||||
ICPPField x = (ICPPField) collector.getName(1).resolveBinding();
|
||||
ITypedef Alias = (ITypedef) collector.getName(2).resolveBinding();
|
||||
IFunction foo = (IFunction) collector.getName(4).resolveBinding();
|
||||
IVariable myA = (IVariable) collector.getName(6).resolveBinding();
|
||||
|
||||
assertInstances(collector, S, 2);
|
||||
assertInstances(collector, x, 2);
|
||||
assertInstances(collector, Alias, 2);
|
||||
assertInstances(collector, foo, 1);
|
||||
assertInstances(collector, myA, 2);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T x;
|
||||
// };
|
||||
// using Alias = S<int>;
|
||||
// void foo() {
|
||||
// Alias myA;
|
||||
// myA.x = 42;
|
||||
// }
|
||||
public void testSpecifiedTemplateAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPClassType S = (ICPPClassType) collector.getName(1).resolveBinding();
|
||||
ICPPField x = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ITypedef Alias = (ITypedef) collector.getName(4).resolveBinding();
|
||||
IVariable myA = (IVariable) collector.getName(9).resolveBinding();
|
||||
ICPPSpecialization xRef = (ICPPSpecialization) collector.getName(11).resolveBinding();
|
||||
|
||||
assertInstances(collector, S, 2);
|
||||
assertInstances(collector, Alias, 2);
|
||||
assertInstances(collector, myA, 2);
|
||||
assertEquals(x, xRef.getSpecializedBinding());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// using Alias = int;
|
||||
// void foo() {
|
||||
// Alias<float> myA;
|
||||
// myA = 42;
|
||||
// }
|
||||
public void testTemplatedAliasBasicType() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPAliasTemplate Alias = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
|
||||
ICPPAliasTemplateInstance AliasFloatInstance = (ICPPAliasTemplateInstance) collector.getName(3).resolveBinding();
|
||||
assertInstances(collector, Alias, 2);
|
||||
assertSameType(AliasFloatInstance, new CPPBasicType(IBasicType.Kind.eInt, 0));
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename T>
|
||||
// using TAlias = S<T>;
|
||||
// void foo() {
|
||||
// TAlias<int> myA;
|
||||
// myA.t = 42;
|
||||
// }
|
||||
public void testTemplatedAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPClassType S = (ICPPClassType) collector.getName(1).resolveBinding();
|
||||
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ICPPTemplateParameter T = (ICPPTemplateParameter) collector.getName(4).resolveBinding();
|
||||
ICPPTemplateParameter TRef = (ICPPTemplateParameter) collector.getName(8).resolveBinding();
|
||||
ICPPAliasTemplate TAlias = (ICPPAliasTemplate) collector.getName(5).resolveBinding();
|
||||
ICPPVariable myA = (ICPPVariable) collector.getName(12).resolveBinding();
|
||||
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(14).resolveBinding();
|
||||
|
||||
assertInstances(collector, S, 2);
|
||||
assertInstances(collector, T, 2);
|
||||
assertEquals(T, TRef);
|
||||
assertInstances(collector, TAlias, 2);
|
||||
assertInstances(collector, myA, 2);
|
||||
assertEquals(t, tRef.getSpecializedBinding());
|
||||
ICPPDeferredClassInstance aliasedType = (ICPPDeferredClassInstance) TAlias.getType();
|
||||
assertEquals(S, aliasedType.getClassTemplate());
|
||||
}
|
||||
|
||||
// template<typename T1, typename T2, typename T3>
|
||||
// struct S {
|
||||
// T1 t1;
|
||||
// T2 t2;
|
||||
// T3 t3;
|
||||
// };
|
||||
// template<typename P1, typename P2>
|
||||
// using TAlias = S<int, P2, P1>;
|
||||
// void foo() {
|
||||
// TAlias<bool, float> myA;
|
||||
// myA.t1 = 42;
|
||||
// myA.t2 = 42.0f;
|
||||
// myA.t3 = true;
|
||||
// }
|
||||
public void testTemplatedAliasDeclarationMultipleParameters() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPField t1 = (ICPPField) collector.getName(5).resolveBinding();
|
||||
ICPPField t2 = (ICPPField) collector.getName(7).resolveBinding();
|
||||
ICPPField t3 = (ICPPField) collector.getName(9).resolveBinding();
|
||||
|
||||
ICPPTemplateParameter P1 = (ICPPTemplateParameter) collector.getName(10).resolveBinding();
|
||||
ICPPTemplateParameter P2 = (ICPPTemplateParameter) collector.getName(11).resolveBinding();
|
||||
|
||||
ICPPTemplateParameter P1Ref = (ICPPTemplateParameter) collector.getName(16).resolveBinding();
|
||||
ICPPTemplateParameter P2Ref = (ICPPTemplateParameter) collector.getName(15).resolveBinding();
|
||||
|
||||
ICPPAliasTemplateInstance TAliasInstance = (ICPPAliasTemplateInstance) collector.getName(18).resolveBinding();
|
||||
ICPPTemplateInstance aliasedTypeInstance = (ICPPTemplateInstance) TAliasInstance.getType();
|
||||
|
||||
ICPPSpecialization t1Ref = (ICPPSpecialization) collector.getName(22).resolveBinding();
|
||||
ICPPSpecialization t2Ref = (ICPPSpecialization) collector.getName(24).resolveBinding();
|
||||
ICPPSpecialization t3Ref = (ICPPSpecialization) collector.getName(26).resolveBinding();
|
||||
|
||||
assertEquals(P1, P1Ref);
|
||||
assertEquals(P2, P2Ref);
|
||||
|
||||
assertEquals(t1, t1Ref.getSpecializedBinding());
|
||||
assertEquals(t2, t2Ref.getSpecializedBinding());
|
||||
assertEquals(t3, t3Ref.getSpecializedBinding());
|
||||
assertSameType(new CPPBasicType(IBasicType.Kind.eInt, 0), aliasedTypeInstance.getTemplateArguments()[0].getTypeValue());
|
||||
assertSameType(new CPPBasicType(IBasicType.Kind.eFloat, 0), aliasedTypeInstance.getTemplateArguments()[1].getTypeValue());
|
||||
assertSameType(new CPPBasicType(IBasicType.Kind.eBoolean, 0), aliasedTypeInstance.getTemplateArguments()[2].getTypeValue());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename P>
|
||||
// using TAlias = S<P>;
|
||||
// void foo() {
|
||||
// TAlias<S<int> > myA;
|
||||
// myA.t = S<int>();
|
||||
// }
|
||||
public void testTemplatedAliasDeclarationTemplateArgument() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
|
||||
IType TAliasSInt = (IType) collector.getName(10).resolveBinding();
|
||||
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(16).resolveBinding();
|
||||
|
||||
assertEquals(t, tRef.getSpecializedBinding());
|
||||
assertSameType(TAliasSInt, (IType)tRef.getOwner());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename P>
|
||||
// using TAlias = S<P>;
|
||||
// void foo() {
|
||||
// S<TAlias<int> > myA;
|
||||
// myA.t = S<int>();
|
||||
// }
|
||||
public void testTemplatedAliasAsTemplateArgument() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ICPPTemplateInstance STAliasInt = (ICPPTemplateInstance) collector.getName(10).resolveBinding();
|
||||
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(16).resolveBinding();
|
||||
|
||||
assertEquals(t, tRef.getSpecializedBinding());
|
||||
assertEquals(STAliasInt, tRef.getOwner());
|
||||
}
|
||||
|
||||
// template<int Size, int Size2>
|
||||
// struct S {
|
||||
// int buff [Size];
|
||||
// };
|
||||
// template<int SizeArg, int SizeArg2>
|
||||
// using TAlias = S<SizeArg2, SizeArg>;
|
||||
// void foo() {
|
||||
// TAlias<5, 4> myA;
|
||||
// myA.buff[0] = 1;
|
||||
// }
|
||||
public void testTemplatedAliasDeclarationValueArgument() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPField buff = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ICPPSpecialization buffRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
|
||||
|
||||
assertEquals(buff, buffRef.getSpecializedBinding());
|
||||
assertEquals(buffRef.getTemplateParameterMap().getArgument(0).getNonTypeValue().numericalValue(), new Long(4));
|
||||
assertEquals(buffRef.getTemplateParameterMap().getArgument(1).getNonTypeValue().numericalValue(), new Long(5));
|
||||
}
|
||||
|
||||
// template<typename T, int Size>
|
||||
// struct S {
|
||||
// T buff [Size];
|
||||
// };
|
||||
// template<typename Type = int, int Items = 5>
|
||||
// using TAlias = S<Type, Items>;
|
||||
// void foo() {
|
||||
// TAlias<> myA;
|
||||
// myA.buff[0] = 1;
|
||||
// }
|
||||
public void testTemplatedAliasDefaultArguments() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPField buff = (ICPPField) collector.getName(4).resolveBinding();
|
||||
ICPPAliasTemplateInstance myA = (ICPPAliasTemplateInstance) collector.getName(14).resolveBinding();
|
||||
ICPPSpecialization buffRef = (ICPPSpecialization) collector.getName(18).resolveBinding();
|
||||
|
||||
assertEquals(buff, buffRef.getSpecializedBinding());
|
||||
assertSameType(buffRef.getTemplateParameterMap().getArgument(0).getTypeValue(), new CPPBasicType(IBasicType.Kind.eInt, 0));
|
||||
assertEquals(buffRef.getTemplateParameterMap().getArgument(1).getNonTypeValue().numericalValue(), new Long(5));
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename A, typename A2>
|
||||
// using TAlias = S<S<A2> >;
|
||||
// void foo() {
|
||||
// TAlias<float, int> myA;
|
||||
// myA.t = S<int>();
|
||||
// }
|
||||
public void testTemplatedAliasTemplateArgument() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
|
||||
ICPPClassSpecialization Sint = (ICPPClassSpecialization) collector.getName(18).resolveBinding();
|
||||
|
||||
assertEquals(t, tRef.getSpecializedBinding());
|
||||
assertSameType(tRef.getTemplateParameterMap().getArgument(0).getTypeValue(), Sint);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename A>
|
||||
// using TAlias = S<A>;
|
||||
// void bar(TAlias<int> arg){
|
||||
// }
|
||||
// void foo() {
|
||||
// TAlias<int> myA;
|
||||
// bar(myA);
|
||||
// S<int> myS;
|
||||
// bar(myS);
|
||||
// }
|
||||
public void testTemplatedAliasAsFunctionParameter() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPFunction bar = (ICPPFunction) collector.getName(9).resolveBinding();
|
||||
ICPPFunction barRefAlias = (ICPPFunction) collector.getName(17).resolveBinding();
|
||||
ICPPFunction barRefSInt = (ICPPFunction) collector.getName(22).resolveBinding();
|
||||
|
||||
assertEquals(bar, barRefAlias);
|
||||
assertEquals(bar, barRefSInt);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename A>
|
||||
// using TAlias = S<A>;
|
||||
// void bar(S<int> arg){
|
||||
// }
|
||||
// void foo() {
|
||||
// TAlias<int> myA;
|
||||
// bar(myA);
|
||||
// }
|
||||
public void testTemplatedAliasAsFunctionArgument() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPFunction bar = (ICPPFunction) collector.getName(9).resolveBinding();
|
||||
ICPPFunction barRefAlias = (ICPPFunction) collector.getName(17).resolveBinding();
|
||||
|
||||
assertEquals(bar, barRefAlias);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename A>
|
||||
// using TAlias = S<A>;
|
||||
// void bar(S<int> arg){
|
||||
// }
|
||||
// void bar(TAlias<int> arg){
|
||||
// }
|
||||
public void testTemplatedAliasRedefinitionOfSameFunction() throws Exception {
|
||||
BindingAssertionHelper bh= getAssertionHelper();
|
||||
bh.assertNonProblem("bar(S", "bar", ICPPFunction.class);
|
||||
bh.assertProblem("bar(TAlias", "bar", ISemanticProblem.BINDING_INVALID_REDEFINITION);
|
||||
}
|
||||
|
||||
// template<typename VT, typename Allocator> struct vector{};
|
||||
// template<typename AT> struct Alloc{};
|
||||
// template<typename T> using Vec = vector<T, Alloc<T> >;
|
||||
// template<template<typename> class TT>
|
||||
// void f(TT<int>);
|
||||
// template<template<typename, typename> class TT>
|
||||
// void g(TT<int, Alloc<int> >);
|
||||
// void foo(){
|
||||
// Vec<int> v;
|
||||
// g(v);
|
||||
// f(v);
|
||||
// }
|
||||
public void testTemplatedAliasDeduction() throws Exception {
|
||||
BindingAssertionHelper bh= getAssertionHelper();
|
||||
bh.assertNonProblem("g(v)", "g", ICPPFunction.class);
|
||||
bh.assertProblem("f(v)", "f", ISemanticProblem.BINDING_NOT_FOUND);
|
||||
}
|
||||
|
||||
// using function = void (&)(int);
|
||||
// void foo(int) {
|
||||
// function f = &foo;
|
||||
// }
|
||||
public void testSimpleFunctionAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ITypedef function = (ITypedef) collector.getName(0).resolveBinding();
|
||||
ICPPFunction foo = (ICPPFunction) collector.getName(2).resolveBinding();
|
||||
|
||||
assertInstances(collector, function, 2);
|
||||
assertInstances(collector, foo, 2);
|
||||
assertSameType(((ICPPReferenceType)function.getType()).getType(), foo.getType());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename T>
|
||||
// using TAlias = S<T>&;
|
||||
// void foo() {
|
||||
// S<int> myS;
|
||||
// TAlias<int> myA = myS;
|
||||
// myA.t = 42;
|
||||
// }
|
||||
public void testTemplatedAliasForTemplateReference() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
ICPPClassSpecialization SInt = (ICPPClassSpecialization) collector.getName(10).resolveBinding();
|
||||
ICPPAliasTemplateInstance TAliasInt = (ICPPAliasTemplateInstance) collector.getName(13).resolveBinding();
|
||||
assertSameType(new CPPReferenceType(SInt, false), TAliasInt);
|
||||
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// using function = void (int);
|
||||
// void foo(int) {
|
||||
// function<int> f = &foo;
|
||||
// }
|
||||
public void testSimpleFunctionTemplateAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPAliasTemplate function = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
|
||||
ICPPFunction foo = (ICPPFunction) collector.getName(3).resolveBinding();
|
||||
ICPPAliasTemplateInstance functionInt = (ICPPAliasTemplateInstance) collector.getName(5).resolveBinding();
|
||||
|
||||
assertInstances(collector, function, 2);
|
||||
assertInstances(collector, foo, 2);
|
||||
assertSameType(foo.getType(),functionInt);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// using function = void (&)(int);
|
||||
// void foo(int) {
|
||||
// function<int> f = &foo;
|
||||
// }
|
||||
public void testSimpleFunctionReferenceTemplateAliasDeclaration() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPAliasTemplate function = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
|
||||
ICPPFunction foo = (ICPPFunction) collector.getName(3).resolveBinding();
|
||||
ICPPAliasTemplateInstance functionInt = (ICPPAliasTemplateInstance) collector.getName(5).resolveBinding();
|
||||
|
||||
assertInstances(collector, function, 2);
|
||||
assertInstances(collector, foo, 2);
|
||||
assertSameType(new CPPReferenceType(foo.getType(), false),functionInt.getType());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<template<typename> class TA>
|
||||
// using TAlias = S<TA>;
|
||||
// void foo() {
|
||||
// TAlias<S<int> > myA;
|
||||
// myA.t = S<int>();
|
||||
// }
|
||||
public void testTemplatedAliasTemplateParameter() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
|
||||
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
|
||||
ICPPClassSpecialization Sint = (ICPPClassSpecialization) collector.getName(18).resolveBinding();
|
||||
|
||||
assertEquals(t, tRef.getSpecializedBinding());
|
||||
assertSameType(tRef.getTemplateParameterMap().getArgument(0).getTypeValue(), Sint);
|
||||
}
|
||||
|
||||
// namespace NS {
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<typename T>
|
||||
// using Alias = S<T>;
|
||||
// }
|
||||
// using namespace NS;
|
||||
// Alias<int> intAlias;
|
||||
public void testAliasDeclarationContext() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
IASTTranslationUnit ast = parseAndCheckBindings(code);
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
ast.accept(collector);
|
||||
|
||||
ICPPAliasTemplateInstance AliasInt = (ICPPAliasTemplateInstance) collector.getName(11).resolveBinding();
|
||||
assertEquals("Alias<int>", AliasInt.getName());
|
||||
assertEquals("NS", AliasInt.getQualifiedName()[0]);
|
||||
assertEquals("Alias<int>", AliasInt.getQualifiedName()[1]);
|
||||
|
||||
ICPPNamespace namespaceNS = (ICPPNamespace) collector.getName(0).resolveBinding();
|
||||
assertEquals(namespaceNS, AliasInt.getOwner());
|
||||
|
||||
assertTrue(AliasInt.getScope() instanceof ICPPTemplateScope);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
|
@ -21,10 +22,16 @@ import org.eclipse.cdt.core.dom.ast.IField;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
|
@ -34,7 +41,9 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
|||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||
|
@ -316,6 +325,245 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
// template<typename xT>
|
||||
// struct S {
|
||||
// xT x;
|
||||
// };
|
||||
// template<typename aT>
|
||||
// using A = S<aT>;
|
||||
public void testSimpleAliasDefinition() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(1, aliasParameters.length);
|
||||
|
||||
assertTrue(aliasParameters[0] instanceof ICPPTemplateTypeParameter);
|
||||
ICPPTemplateTypeParameter templateParameterAT= (ICPPTemplateTypeParameter) aliasParameters[0];
|
||||
assertEquals("aT", templateParameterAT.getName());
|
||||
assertNull(templateParameterAT.getDefault());
|
||||
assertEquals(0, templateParameterAT.getTemplateNestingLevel());
|
||||
|
||||
assertDeclarationCount(pdom, "S", 1);
|
||||
IIndexFragmentBinding[] bindingS= pdom.findBindings(new char[][] {{'S'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
IType aliasedType = aliasA.getType();
|
||||
assertTrue(aliasedType instanceof ICPPDeferredClassInstance);
|
||||
ICPPDeferredClassInstance deferredClassInstanceS= (ICPPDeferredClassInstance) aliasedType;
|
||||
assertEquals(1, bindingA.length);
|
||||
assertEquals(bindingS[0], deferredClassInstanceS.getSpecializedBinding());
|
||||
}
|
||||
|
||||
// struct D {
|
||||
// };
|
||||
// template<typename sT1, typename sT2>
|
||||
// struct S {
|
||||
// xT x;
|
||||
// };
|
||||
// template<typename aT1, typename aT2 = D>
|
||||
// using A = S<aT1, aT2>;
|
||||
public void testSimpleAliasDefinitionDefaultTemplateArgument() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(2, aliasParameters.length);
|
||||
|
||||
assertTrue(aliasParameters[0] instanceof ICPPTemplateTypeParameter);
|
||||
ICPPTemplateTypeParameter templateParameterAT1= (ICPPTemplateTypeParameter) aliasParameters[0];
|
||||
assertEquals("aT1", templateParameterAT1.getName());
|
||||
assertNull(templateParameterAT1.getDefault());
|
||||
assertEquals(0, templateParameterAT1.getTemplateNestingLevel());
|
||||
|
||||
assertTrue(aliasParameters[1] instanceof ICPPTemplateTypeParameter);
|
||||
ICPPTemplateTypeParameter templateParameterAT2= (ICPPTemplateTypeParameter) aliasParameters[1];
|
||||
assertEquals("aT2", templateParameterAT2.getName());
|
||||
IType aT2DefaultArgument = templateParameterAT2.getDefault();
|
||||
assertNotNull(aT2DefaultArgument);
|
||||
assertDeclarationCount(pdom, "D", 1);
|
||||
IIndexFragmentBinding[] bindingD= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingD.length);
|
||||
assertTrue(bindingD[0] instanceof IType);
|
||||
assertTrue(((IType)bindingD[0]).isSameType(aT2DefaultArgument));
|
||||
assertEquals(0, templateParameterAT2.getTemplateNestingLevel());
|
||||
|
||||
assertDeclarationCount(pdom, "S", 1);
|
||||
IIndexFragmentBinding[] bindingS= pdom.findBindings(new char[][] {{'S'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
IType aliasedType = aliasA.getType();
|
||||
assertTrue(aliasedType instanceof ICPPDeferredClassInstance);
|
||||
ICPPDeferredClassInstance deferredClassInstanceS= (ICPPDeferredClassInstance) aliasedType;
|
||||
assertEquals(1, bindingS.length);
|
||||
assertEquals(bindingS[0], deferredClassInstanceS.getSpecializedBinding());
|
||||
}
|
||||
|
||||
// template<boolean sT1, int sT2>
|
||||
// struct S {
|
||||
// xT x;
|
||||
// };
|
||||
// template<boolean aT1, int aT2 = 5>
|
||||
// using A = S<aT1, aT2>;
|
||||
public void testSimpleAliasDefinitionValueTemplateArguments() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(2, aliasParameters.length);
|
||||
|
||||
assertTrue(aliasParameters[0] instanceof ICPPTemplateNonTypeParameter);
|
||||
ICPPTemplateNonTypeParameter templateParameterAT1= (ICPPTemplateNonTypeParameter) aliasParameters[0];
|
||||
assertEquals("aT1", templateParameterAT1.getName());
|
||||
assertNull(templateParameterAT1.getDefaultValue());
|
||||
assertEquals(0, templateParameterAT1.getTemplateNestingLevel());
|
||||
|
||||
assertTrue(aliasParameters[1] instanceof ICPPTemplateNonTypeParameter);
|
||||
ICPPTemplateNonTypeParameter templateParameterAT2= (ICPPTemplateNonTypeParameter) aliasParameters[1];
|
||||
assertEquals("aT2", templateParameterAT2.getName());
|
||||
ICPPTemplateArgument aT2DefaultArgument = templateParameterAT2.getDefaultValue();
|
||||
assertNotNull(aT2DefaultArgument);
|
||||
assertTrue(new CPPBasicType(IBasicType.Kind.eInt, 0).isSameType(aT2DefaultArgument.getTypeOfNonTypeValue()));
|
||||
assertEquals(5, aT2DefaultArgument.getNonTypeValue().numericalValue().longValue());
|
||||
assertEquals(0, templateParameterAT2.getTemplateNestingLevel());
|
||||
|
||||
assertDeclarationCount(pdom, "S", 1);
|
||||
IIndexFragmentBinding[] bindingS= pdom.findBindings(new char[][] {{'S'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
IType aliasedType = aliasA.getType();
|
||||
assertTrue(aliasedType instanceof ICPPDeferredClassInstance);
|
||||
ICPPDeferredClassInstance deferredClassInstanceS= (ICPPDeferredClassInstance) aliasedType;
|
||||
assertEquals(1, bindingS.length);
|
||||
assertEquals(bindingS[0], deferredClassInstanceS.getSpecializedBinding());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// struct S {
|
||||
// T t;
|
||||
// };
|
||||
// template<template<typename> class TT>
|
||||
// using A = S<TT>;
|
||||
public void testSimpleAliasTemplateParameter() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(1, aliasParameters.length);
|
||||
|
||||
assertTrue(aliasParameters[0] instanceof ICPPTemplateTemplateParameter);
|
||||
ICPPTemplateTemplateParameter templateParameterTT= (ICPPTemplateTemplateParameter) aliasParameters[0];
|
||||
assertEquals("TT", templateParameterTT.getName());
|
||||
assertNull(templateParameterTT.getDefaultValue());
|
||||
assertEquals(0, templateParameterTT.getTemplateNestingLevel());
|
||||
}
|
||||
|
||||
// struct B{};
|
||||
// template<typename xT>
|
||||
// struct S {
|
||||
// xT x;
|
||||
// };
|
||||
// template<typename aT>
|
||||
// using A = S<aT>;
|
||||
// A<B> aB;
|
||||
// S<B> sB;
|
||||
public void testSimpleAliasReference() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(1, aliasParameters.length);
|
||||
|
||||
assertReferenceCount(pdom, "S", 2);
|
||||
assertReferenceCount(pdom, "A", 1);
|
||||
assertDeclarationCount(pdom, "aB", 1);
|
||||
assertDeclarationCount(pdom, "sB", 1);
|
||||
|
||||
IIndexFragmentBinding[] bindingVarSB= pdom.findBindings(new char[][] {"sB".toCharArray()}, IndexFilter.ALL, npm());
|
||||
assertEquals(1, bindingVarSB.length);
|
||||
assertTrue(bindingVarSB[0] instanceof ICPPVariable);
|
||||
ICPPVariable variableSB = (ICPPVariable) bindingVarSB[0];
|
||||
IType varSBType = variableSB.getType();
|
||||
assertTrue(varSBType instanceof ICPPClassSpecialization);
|
||||
ICPPClassSpecialization templateInstanceSB = (ICPPClassSpecialization) varSBType;
|
||||
|
||||
IIndexFragmentBinding[] bindingVarAB= pdom.findBindings(new char[][] {"aB".toCharArray()}, IndexFilter.ALL, npm());
|
||||
assertEquals(1, bindingVarAB.length);
|
||||
assertTrue(bindingVarAB[0] instanceof ICPPVariable);
|
||||
ICPPVariable variableAB = (ICPPVariable) bindingVarAB[0];
|
||||
IType varABType = variableAB.getType();
|
||||
assertTrue(varABType instanceof ICPPAliasTemplateInstance);
|
||||
ICPPAliasTemplateInstance aliasInstanceAB = (ICPPAliasTemplateInstance) varABType;
|
||||
assertTrue(varABType.isSameType(templateInstanceSB));
|
||||
assertTrue(aliasInstanceAB.getTemplateDefinition().isSameType(aliasA));
|
||||
assertEquals("A<B>", aliasInstanceAB.getName());
|
||||
}
|
||||
|
||||
// template<typename T> class CT {
|
||||
// template<typename T> using A= T; // nesting level 1
|
||||
// A<int> x;
|
||||
// };
|
||||
public void testPDOMNestedAliasDeclarationNestingLevel() throws Exception {
|
||||
IIndexFragmentBinding[] bindingCT = pdom.findBindings(new char[][] { "CT".toCharArray() }, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingCT.length);
|
||||
assertTrue(bindingCT[0] instanceof ICPPClassTemplate);
|
||||
ICPPClassTemplate templateCT = (ICPPClassTemplate) bindingCT[0];
|
||||
|
||||
IField[] fields = templateCT.getFields();
|
||||
assertEquals(1, fields.length);
|
||||
IField x = fields[0];
|
||||
IType xType = x.getType();
|
||||
assertTrue(xType instanceof ICPPAliasTemplateInstance);
|
||||
|
||||
ICPPAliasTemplateInstance aliasInstance = (ICPPAliasTemplateInstance) xType;
|
||||
ICPPAliasTemplate alias = aliasInstance.getTemplateDefinition();
|
||||
ICPPTemplateParameter[] aliasParameters = alias.getTemplateParameters();
|
||||
assertEquals(1, aliasParameters.length);
|
||||
ICPPTemplateParameter aliasParameterT = aliasParameters[0];
|
||||
assertEquals(1, aliasParameterT.getTemplateNestingLevel());
|
||||
}
|
||||
|
||||
// template<typename T> class CT;
|
||||
// template<typename T> using A= CT<T>; // nesting level 0
|
||||
// template<typename T> class CT { // nesting level 0
|
||||
// typedef Alias<T> TYPE;
|
||||
// };
|
||||
public void testPDOMAliasDeclarationNestingLevel() throws Exception {
|
||||
assertDeclarationCount(pdom, "A", 1);
|
||||
IIndexFragmentBinding[] bindingA= pdom.findBindings(new char[][] {{'A'}}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingA.length);
|
||||
assertTrue(bindingA[0] instanceof ICPPAliasTemplate);
|
||||
ICPPAliasTemplate aliasA= (ICPPAliasTemplate) bindingA[0];
|
||||
ICPPTemplateParameter[] aliasParameters= aliasA.getTemplateParameters();
|
||||
assertEquals(1, aliasParameters.length);
|
||||
|
||||
assertTrue(aliasParameters[0] instanceof ICPPTemplateTypeParameter);
|
||||
ICPPTemplateTypeParameter templateParameterT= (ICPPTemplateTypeParameter) aliasParameters[0];
|
||||
assertEquals("T", templateParameterT.getName());
|
||||
assertNull(templateParameterT.getDefault());
|
||||
assertEquals(0, templateParameterT.getTemplateNestingLevel());
|
||||
|
||||
assertDeclarationCount(pdom, "CT", 2);
|
||||
IIndexFragmentBinding[] bindingCT= pdom.findBindings(new char[][] {"CT".toCharArray()}, IndexFilter.ALL_DECLARED, npm());
|
||||
assertEquals(1, bindingCT.length);
|
||||
assertTrue(bindingCT[0] instanceof ICPPClassTemplate);
|
||||
ICPPClassTemplate templateCT= (ICPPClassTemplate) bindingCT[0];
|
||||
ICPPTemplateParameter[] ctParameters= templateCT.getTemplateParameters();
|
||||
assertEquals(1, ctParameters.length);
|
||||
|
||||
assertTrue(ctParameters[0] instanceof ICPPTemplateTypeParameter);
|
||||
ICPPTemplateTypeParameter templateParameterTofCT= (ICPPTemplateTypeParameter) ctParameters[0];
|
||||
assertEquals("T", templateParameterTofCT.getName());
|
||||
assertNull(templateParameterTofCT.getDefault());
|
||||
assertEquals(0, templateParameterTofCT.getTemplateNestingLevel());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void assertInstance(Object o, Class c) {
|
||||
assertNotNull(o);
|
||||
|
|
|
@ -10,4 +10,10 @@ void f(T* p)
|
|||
T::template adjust<100>();
|
||||
}
|
||||
|
||||
|
||||
//![temp.alias] Template alias declaration
|
||||
//%CPP
|
||||
template<typename T> struct S
|
||||
{
|
||||
};
|
||||
template<typename T> using Alias = S<T>;
|
||||
Alias<int> sInt;
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
|
||||
/**
|
||||
* This interface represents a C++ alias declaration.
|
||||
* e.g. struct Type {}; using Alias = Type;
|
||||
* @since 5.5
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTAliasDeclaration extends IASTDeclaration, IASTNameOwner {
|
||||
public static final ICPPASTAliasDeclaration[] EMPTY_USINGDIRECTIVE_ARRAY = new ICPPASTAliasDeclaration[0];
|
||||
|
||||
/**
|
||||
* <code>ALIAS_NAME</code> is the name that is brought into local
|
||||
* scope.
|
||||
*/
|
||||
public static final ASTNodeProperty ALIAS_NAME = new ASTNodeProperty(
|
||||
"ICPPASTAliasDeclaration.ALIAS_NAME - New alias name introduced"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* <code>MAPPING_TYPE<ID/code> represents the pre-existing type id which
|
||||
* the new symbol aliases.
|
||||
*/
|
||||
public static final ASTNodeProperty TARGET_TYPEID = new ASTNodeProperty(
|
||||
"ICPPASTAliasDeclaration.TARGET_TYPEID - Pre-existing type ID the new symbol aliases"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Get the alias name.
|
||||
*
|
||||
* @return <code>IASTName</code>
|
||||
*/
|
||||
public IASTName getAlias();
|
||||
|
||||
/**
|
||||
* Set the alias name.
|
||||
*
|
||||
* @param aliasName
|
||||
* <code>IASTName</code>
|
||||
*/
|
||||
public void setAlias(IASTName aliasName);
|
||||
|
||||
/**
|
||||
* Get the mapping type id.
|
||||
*
|
||||
* @return <code>ICPPASTTypeId</code>
|
||||
*/
|
||||
public ICPPASTTypeId getMappingTypeId();
|
||||
|
||||
/**
|
||||
* Set the mapping type id.
|
||||
*
|
||||
* @param mappingTypeId
|
||||
* <code>ICPPASTTypeId</code>
|
||||
*/
|
||||
public void setMappingTypeId(ICPPASTTypeId mappingTypeId);
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration copy(CopyStyle style);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Thomas Corbat (IFS) - Added copy methods
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -20,4 +21,15 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
* @since 5.2
|
||||
*/
|
||||
public interface ICPPASTTypeId extends IASTTypeId, ICPPASTPackExpandable {
|
||||
/**
|
||||
* @since 5.5
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTTypeId copy();
|
||||
|
||||
/**
|
||||
* @since 5.5
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTTypeId copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* Represents an alias template (14.5.7).
|
||||
* @since 5.5
|
||||
*/
|
||||
public interface ICPPAliasTemplate extends IType, ICPPTemplateDefinition {
|
||||
/**
|
||||
* Returns the aliased type.
|
||||
*/
|
||||
public IType getType();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
|
||||
/**
|
||||
* Represents an instance of an alias template (14.5.7).
|
||||
* @since 5.5
|
||||
*/
|
||||
public interface ICPPAliasTemplateInstance extends ITypedef, ICPPBinding {
|
||||
/**
|
||||
* Returns the the alias template specialized by this instance.
|
||||
*/
|
||||
public ICPPAliasTemplate getTemplateDefinition();
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Mike Kucera (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -354,4 +355,9 @@ public interface ICPPNodeFactory extends INodeFactory {
|
|||
|
||||
@Override
|
||||
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
|
||||
|
||||
/**
|
||||
* @since 5.5
|
||||
*/
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId aliasedType);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Thomas Corbat
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -34,6 +35,7 @@ public interface ITypeMarshalBuffer {
|
|||
final static byte UNKNOWN_MEMBER= 12;
|
||||
final static byte UNKNOWN_MEMBER_CLASS_INSTANCE= 13;
|
||||
final static byte DEFERRED_CLASS_INSTANCE= 14;
|
||||
final static byte ALIAS_TEMPLATE = 15;
|
||||
|
||||
final static byte
|
||||
EVAL_BINARY= 1,
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
public class CPPASTAliasDeclaration extends ASTNode implements ICPPASTAliasDeclaration {
|
||||
private IASTName aliasName;
|
||||
private ICPPASTTypeId mappingTypeId;
|
||||
|
||||
public CPPASTAliasDeclaration(IASTName aliasName, ICPPASTTypeId mappingTypeId){
|
||||
setAlias(aliasName);
|
||||
setMappingTypeId(mappingTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRoleForName(IASTName name) {
|
||||
if (aliasName == name) return r_definition;
|
||||
if (mappingTypeId == name) return r_reference;
|
||||
return r_unclear;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName getAlias() {
|
||||
return aliasName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlias(IASTName aliasName) {
|
||||
assertNotFrozen();
|
||||
this.aliasName = aliasName;
|
||||
if (aliasName != null) {
|
||||
aliasName.setParent(this);
|
||||
aliasName.setPropertyInParent(ALIAS_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTTypeId getMappingTypeId() {
|
||||
return mappingTypeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMappingTypeId(ICPPASTTypeId mappingTypeId) {
|
||||
assertNotFrozen();
|
||||
this.mappingTypeId = mappingTypeId;
|
||||
if (mappingTypeId != null) {
|
||||
mappingTypeId.setParent(this);
|
||||
mappingTypeId.setPropertyInParent(TARGET_TYPEID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration copy(CopyStyle style) {
|
||||
CPPASTAliasDeclaration copy = new CPPASTAliasDeclaration(
|
||||
aliasName == null ? null : aliasName.copy(style),
|
||||
mappingTypeId == null ? null : mappingTypeId.copy(style));
|
||||
copy.setOffsetAndLength(this);
|
||||
if (style == CopyStyle.withLocations) {
|
||||
copy.setCopyLocation(this);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitDeclarations) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if (aliasName != null && !aliasName.accept(action)) return false;
|
||||
if (mappingTypeId != null && !mappingTypeId.accept(action)) return false;
|
||||
|
||||
if (action.shouldVisitDeclarations) {
|
||||
switch (action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
public class CPPAliasTemplate extends PlatformObject implements ICPPAliasTemplate {
|
||||
private IASTName aliasName;
|
||||
private IType aliasedType;
|
||||
private ICPPTemplateParameter[] templateParameters;
|
||||
|
||||
public CPPAliasTemplate(IASTName aliasName){
|
||||
this.aliasName = aliasName;
|
||||
aliasName.setBinding(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getType() {
|
||||
return aliasedType;
|
||||
}
|
||||
|
||||
public void setType(IType type) {
|
||||
this.aliasedType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return new String(getNameCharArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getNameCharArray() {
|
||||
return aliasName.getSimpleID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() {
|
||||
return CPPVisitor.findDeclarationOwner(aliasName, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() throws DOMException {
|
||||
return CPPVisitor.getContainingScope(aliasName.getParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IType type) {
|
||||
if(type == null){
|
||||
return false;
|
||||
}
|
||||
IType aliasedType = getType();
|
||||
return type.isSameType(aliasedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
IType t = null;
|
||||
try {
|
||||
t = (IType) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
//not going to happen
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
return CPPVisitor.getQualifiedName(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
return CPPVisitor.getQualifiedNameCharArray(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPTemplateParameter[] getTemplateParameters() {
|
||||
if (templateParameters == null) {
|
||||
ICPPASTTemplateDeclaration template = CPPTemplates.getTemplateDeclaration(aliasName);
|
||||
if (template == null)
|
||||
return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY;
|
||||
ICPPASTTemplateParameter[] params = template.getTemplateParameters();
|
||||
IBinding p = null;
|
||||
ICPPTemplateParameter[] result = null;
|
||||
for (ICPPASTTemplateParameter param : params) {
|
||||
p= CPPTemplates.getTemplateParameterName(param).resolveBinding();
|
||||
if (p instanceof ICPPTemplateParameter) {
|
||||
result = ArrayUtil.append(ICPPTemplateParameter.class, result, (ICPPTemplateParameter) p);
|
||||
}
|
||||
}
|
||||
templateParameters = ArrayUtil.trim(ICPPTemplateParameter.class, result);
|
||||
}
|
||||
return templateParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ASTTypeUtil.getQualifiedName(this) + " -> " + ASTTypeUtil.getType(aliasedType, true); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
public class CPPAliasTemplateInstance extends PlatformObject
|
||||
implements ICPPAliasTemplateInstance, ISerializableType {
|
||||
private final char[] name;
|
||||
private final IType aliasedType;
|
||||
private final ICPPAliasTemplate aliasTemplate;
|
||||
|
||||
public CPPAliasTemplateInstance(char[] name, IType aliasedType, ICPPAliasTemplate aliasTemplate) {
|
||||
this.name = name;
|
||||
this.aliasedType = aliasedType;
|
||||
this.aliasTemplate = aliasTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPAliasTemplate getTemplateDefinition() {
|
||||
return aliasTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IType other) {
|
||||
if (other == aliasedType)
|
||||
return true;
|
||||
if (aliasedType != null) {
|
||||
return aliasedType.isSameType(other);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getType() {
|
||||
return aliasedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return new String(getNameCharArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getNameCharArray() {
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
return new char[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() {
|
||||
if (aliasTemplate != null) {
|
||||
return aliasTemplate.getOwner();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() throws DOMException {
|
||||
if (aliasTemplate != null) {
|
||||
return aliasTemplate.getScope();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
|
||||
int firstByte = ITypeMarshalBuffer.ALIAS_TEMPLATE;
|
||||
buffer.putByte((byte) firstByte);
|
||||
buffer.putCharArray(name);
|
||||
buffer.marshalType(aliasedType);
|
||||
buffer.marshalBinding(aliasTemplate);
|
||||
}
|
||||
|
||||
public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException {
|
||||
char[] name = buffer.getCharArray();
|
||||
IType unmarshalledAliasedTypeInstance = buffer.unmarshalType();
|
||||
ICPPAliasTemplate unmarshalledAlias = (ICPPAliasTemplate)buffer.unmarshalBinding();
|
||||
return new CPPAliasTemplateInstance(name, unmarshalledAliasedTypeInstance, unmarshalledAlias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ASTTypeUtil.getQualifiedName(this) + " -> " + ASTTypeUtil.getType(aliasedType, true); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getQualifiedName() {
|
||||
return CPPVisitor.getQualifiedName(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[][] getQualifiedNameCharArray() {
|
||||
return CPPVisitor.getQualifiedNameCharArray(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
return ((ICPPBinding) aliasTemplate).isGloballyQualified();
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.IASTToken;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTokenList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
|
@ -747,4 +748,9 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
|
||||
return new CPPASTWhileStatement(condition, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTAliasDeclaration newAliasDeclaration(IASTName aliasName, ICPPASTTypeId mappingTypeId) {
|
||||
return new CPPASTAliasDeclaration(aliasName, mappingTypeId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression.CaptureDefault;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
|
@ -1892,7 +1893,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
default:
|
||||
throw backtrack;
|
||||
}
|
||||
|
||||
ICPPASTUsingDirective astUD = nodeFactory.newUsingDirective(name);
|
||||
if (attributes != null) {
|
||||
for (IASTAttribute attribute : attributes) {
|
||||
|
@ -1903,10 +1903,33 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return astUD;
|
||||
}
|
||||
|
||||
if(LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tASSIGN){
|
||||
return aliasDeclaration(offset);
|
||||
|
||||
}
|
||||
ICPPASTUsingDeclaration result = usingDeclaration(offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
private IASTDeclaration aliasDeclaration(final int offset) throws EndOfFileException,
|
||||
BacktrackException {
|
||||
IToken identifierToken = consume();
|
||||
IASTName aliasName = buildName(-1, identifierToken);
|
||||
|
||||
consume();
|
||||
|
||||
ICPPASTTypeId aliasedType = typeId(DeclarationOptions.TYPEID);
|
||||
|
||||
if(LT(1) != IToken.tSEMI){
|
||||
throw backtrack;
|
||||
}
|
||||
int endOffset = consume().getEndOffset();
|
||||
|
||||
ICPPASTAliasDeclaration aliasDeclaration = nodeFactory.newAliasDeclaration(aliasName, aliasedType);
|
||||
setRange(aliasDeclaration, offset, endOffset);
|
||||
return aliasDeclaration;
|
||||
}
|
||||
|
||||
private ICPPASTUsingDeclaration usingDeclaration(final int offset) throws EndOfFileException, BacktrackException {
|
||||
boolean typeName = false;
|
||||
if (LT(1) == IToken.t_typename) {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
* Mike Kucera (IBM)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
|
@ -92,6 +93,7 @@ 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.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
@ -1668,6 +1670,9 @@ public class CPPSemantics {
|
|||
} else if (declaration instanceof ICPPASTNamespaceAlias) {
|
||||
IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias();
|
||||
ASTInternal.addName(scope, alias);
|
||||
} else if (declaration instanceof ICPPASTAliasDeclaration) {
|
||||
IASTName alias = ((ICPPASTAliasDeclaration) declaration).getAlias();
|
||||
ASTInternal.addName(scope, alias);
|
||||
} else if (declaration instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
||||
final IASTDeclSpecifier declSpec = functionDef.getDeclSpecifier();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Bryan Wilkinson (QNX)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
|
@ -66,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
|
@ -103,6 +105,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
|
||||
|
@ -393,7 +396,7 @@ public class CPPTemplates {
|
|||
return instance;
|
||||
}
|
||||
|
||||
private static ICPPTemplateArgument[] addDefaultArguments(ICPPClassTemplate template,
|
||||
private static ICPPTemplateArgument[] addDefaultArguments(ICPPTemplateDefinition template,
|
||||
ICPPTemplateArgument[] arguments, IASTNode point) throws DOMException {
|
||||
if (template instanceof ICPPClassTemplatePartialSpecialization)
|
||||
return arguments;
|
||||
|
@ -642,11 +645,24 @@ public class CPPTemplates {
|
|||
}
|
||||
}
|
||||
try {
|
||||
// Class template instance.
|
||||
IBinding result= null;
|
||||
IASTName templateName = id.getTemplateName();
|
||||
IBinding template = templateName.resolvePreBinding();
|
||||
|
||||
// Template alias.
|
||||
if (template instanceof ICPPAliasTemplate) {
|
||||
ICPPAliasTemplate aliasTemplate = (ICPPAliasTemplate) template;
|
||||
IType aliasedType = aliasTemplate.getType();
|
||||
ICPPTemplateArgument[] args = createTemplateArgumentArray(id);
|
||||
args = addDefaultArguments(aliasTemplate, args, id);
|
||||
ICPPTemplateParameterMap parameterMap = createParameterMap(aliasTemplate, args);
|
||||
IBinding owner = template.getOwner();
|
||||
ICPPClassSpecialization within = getSpecializationContext(owner);
|
||||
IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id);
|
||||
return new CPPAliasTemplateInstance(id.toCharArray(), instantiatedType, aliasTemplate);
|
||||
}
|
||||
|
||||
// Class template.
|
||||
if (template instanceof ICPPConstructor) {
|
||||
template= template.getOwner();
|
||||
}
|
||||
|
@ -716,8 +732,9 @@ public class CPPTemplates {
|
|||
if (parentOfName instanceof ICPPASTElaboratedTypeSpecifier ||
|
||||
parentOfName instanceof ICPPASTCompositeTypeSpecifier ||
|
||||
parentOfName instanceof ICPPASTNamedTypeSpecifier ||
|
||||
parentOfName instanceof ICPPASTBaseSpecifier)
|
||||
parentOfName instanceof ICPPASTBaseSpecifier) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parentOfName instanceof IASTDeclarator) {
|
||||
IASTDeclarator rel= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) parentOfName);
|
||||
|
@ -726,7 +743,6 @@ public class CPPTemplates {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static ICPPTemplateInstance createInstance(IBinding owner, ICPPTemplateDefinition template,
|
||||
CPPTemplateParameterMap tpMap, ICPPTemplateArgument[] args, IASTNode point) {
|
||||
if (owner instanceof ICPPSpecialization) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
|
@ -93,6 +94,7 @@ 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.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
@ -196,6 +198,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplate;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef;
|
||||
|
@ -657,6 +660,36 @@ public class CPPVisitor extends ASTQueries {
|
|||
|
||||
return binding;
|
||||
}
|
||||
else if (declaration instanceof ICPPASTAliasDeclaration){
|
||||
ICPPASTAliasDeclaration alias = (ICPPASTAliasDeclaration) declaration;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope(declaration);
|
||||
IBinding binding = scope.getBinding(alias.getAlias(), false);
|
||||
if(!(binding instanceof ICPPInternalBinding)) {
|
||||
|
||||
IType type = createType(alias.getMappingTypeId());
|
||||
if (type instanceof IProblemBinding) {
|
||||
IProblemBinding problem = (IProblemBinding) type;
|
||||
type = new CPPClassType.CPPClassTypeProblem(problem.getASTNode(), problem.getID(), alias.getMappingTypeId().getAbstractDeclarator().getName().toCharArray());
|
||||
}
|
||||
if (type != null) {
|
||||
if(alias.getParent() instanceof ICPPASTTemplateDeclaration){
|
||||
CPPAliasTemplate templateAlias = new CPPAliasTemplate(alias.getAlias());
|
||||
templateAlias.setType(type);
|
||||
binding = templateAlias;
|
||||
}
|
||||
else{
|
||||
CPPTypedef typedef = new CPPTypedef(alias.getAlias());
|
||||
typedef.setType(type);
|
||||
binding = typedef;
|
||||
}
|
||||
} else {
|
||||
binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
return binding;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Institute for Software - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||
|
||||
|
@ -18,9 +19,11 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
|
@ -32,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
||||
|
@ -93,6 +97,8 @@ public class DeclarationWriter extends NodeWriter {
|
|||
writeUsingDirective((ICPPASTUsingDirective) declaration);
|
||||
} else if (declaration instanceof ICPPASTVisibilityLabel) {
|
||||
writeVisibilityLabel((ICPPASTVisibilityLabel) declaration);
|
||||
} else if (declaration instanceof ICPPASTAliasDeclaration) {
|
||||
writeAliasDeclaration((ICPPASTAliasDeclaration) declaration);
|
||||
}
|
||||
|
||||
writeTrailingComments(declaration, addNewLine);
|
||||
|
@ -104,6 +110,20 @@ public class DeclarationWriter extends NodeWriter {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeAliasDeclaration(ICPPASTAliasDeclaration aliasDeclaration) {
|
||||
scribe.printStringSpace(Keywords.USING);
|
||||
IASTName alias = aliasDeclaration.getAlias();
|
||||
if (alias != null) {
|
||||
alias.accept(visitor);
|
||||
}
|
||||
scribe.print(EQUALS);
|
||||
ICPPASTTypeId aliasedType = aliasDeclaration.getMappingTypeId();
|
||||
if (aliasedType != null) {
|
||||
aliasedType.accept(visitor);
|
||||
}
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeVisibilityLabel(ICPPASTVisibilityLabel visiblityLabel) {
|
||||
scribe.decrementIndentationLevel();
|
||||
switch (visiblityLabel.getVisibility()) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
|
@ -60,4 +61,5 @@ public interface IIndexCPPBindingConstants {
|
|||
int CPP_UNKNOWN_FIELD = IIndexBindingConstants.LAST_CONSTANT + 48;
|
||||
int CPP_USING_DECLARATION_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 49;
|
||||
int CPP_UNKNOWN_METHOD = IIndexBindingConstants.LAST_CONSTANT + 50;
|
||||
int CPP_TEMPLATE_ALIAS = IIndexBindingConstants.LAST_CONSTANT + 51;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Thomas Corbat (IFS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* PDOM binding for alias template.
|
||||
*/
|
||||
class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate {
|
||||
private static final int ALIASED_TYPE_SIZE = Database.TYPE_SIZE;
|
||||
private static final int TEMPLATE_PARAMS_SIZE = PDOMCPPTemplateTemplateParameter.RECORD_SIZE;
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + ALIASED_TYPE_SIZE + TEMPLATE_PARAMS_SIZE;
|
||||
|
||||
private static final int ALIASED_TYPE_OFFSET = PDOMCPPBinding.RECORD_SIZE + 0;
|
||||
private static final int TEMPLATE_PARAMS_OFFSET = ALIASED_TYPE_OFFSET + ALIASED_TYPE_SIZE;
|
||||
|
||||
private volatile IPDOMCPPTemplateParameter[] parameters;
|
||||
|
||||
public PDOMCPPAliasTemplate(PDOMCPPLinkage linkage, PDOMNode parent,
|
||||
ICPPAliasTemplate templateAlias) throws CoreException, DOMException {
|
||||
super(linkage, parent, templateAlias.getNameCharArray());
|
||||
setTemplateParameters(linkage, templateAlias.getTemplateParameters());
|
||||
setType(linkage, templateAlias.getType());
|
||||
}
|
||||
|
||||
public PDOMCPPAliasTemplate(PDOMCPPLinkage linkage, long record) {
|
||||
super(linkage, record);
|
||||
}
|
||||
|
||||
private void setTemplateParameters(PDOMCPPLinkage linkage,
|
||||
final ICPPTemplateParameter[] origParams) throws CoreException, DOMException {
|
||||
parameters = PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
|
||||
final Database db = getDB();
|
||||
long rec= PDOMTemplateParameterArray.putArray(db, parameters);
|
||||
db.putRecPtr(record + TEMPLATE_PARAMS_OFFSET, rec);
|
||||
linkage.new ConfigureTemplateParameters(origParams, parameters);
|
||||
}
|
||||
|
||||
private void setType(PDOMCPPLinkage linkage, IType aliasedType) throws CoreException {
|
||||
linkage.storeType(record + ALIASED_TYPE_OFFSET, aliasedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeType() {
|
||||
return IIndexCPPBindingConstants.CPP_TEMPLATE_ALIAS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IType type) {
|
||||
if(type == null){
|
||||
return false;
|
||||
}
|
||||
IType aliasedType = getType();
|
||||
return type.isSameType(aliasedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPTemplateParameter[] getTemplateParameters() {
|
||||
if (parameters == null) {
|
||||
try {
|
||||
Database db = getDB();
|
||||
long rec= db.getRecPtr(record + TEMPLATE_PARAMS_OFFSET);
|
||||
if (rec == 0) {
|
||||
parameters= IPDOMCPPTemplateParameter.EMPTY_ARRAY;
|
||||
} else {
|
||||
parameters= PDOMTemplateParameterArray.getArray(this, rec);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
parameters = IPDOMCPPTemplateParameter.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getType() {
|
||||
try {
|
||||
return getLinkage().loadType(record + ALIASED_TYPE_OFFSET);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
|
@ -60,6 +61,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
|
@ -86,6 +89,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownMember;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
|
@ -409,6 +413,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
}
|
||||
} else if (binding instanceof ITypedef) {
|
||||
pdomBinding = new PDOMCPPTypedef(this, parent, (ITypedef) binding);
|
||||
} else if (binding instanceof ICPPAliasTemplate) {
|
||||
pdomBinding = new PDOMCPPAliasTemplate(this, parent, (ICPPAliasTemplate) binding);
|
||||
}
|
||||
|
||||
if (pdomBinding != null) {
|
||||
|
@ -601,11 +607,18 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return CPPENUMERATOR;
|
||||
} else if (binding instanceof ITypedef) {
|
||||
return CPPTYPEDEF;
|
||||
} else if (binding instanceof ICPPAliasTemplate) {
|
||||
return CPP_TEMPLATE_ALIAS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean cannotAdapt(final IBinding inputBinding) throws CoreException {
|
||||
return super.cannotAdapt(inputBinding) || inputBinding instanceof ICPPAliasTemplateInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final PDOMBinding adaptBinding(final IBinding inputBinding, boolean includeLocal) throws CoreException {
|
||||
return adaptBinding(null, inputBinding, includeLocal ? FILE_LOCAL_REC_DUMMY : null);
|
||||
|
@ -825,6 +838,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return new PDOMCPPTypedefSpecialization(this, record);
|
||||
case CPP_USING_DECLARATION_SPECIALIZATION:
|
||||
return new PDOMCPPUsingDeclarationSpecialization(this, record);
|
||||
case CPP_TEMPLATE_ALIAS:
|
||||
return new PDOMCPPAliasTemplate(this, record);
|
||||
}
|
||||
assert false : "nodeid= " + nodeType; //$NON-NLS-1$
|
||||
return null;
|
||||
|
@ -1044,6 +1059,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return CPPUnknownClassInstance.unmarshal(getPDOM(), firstByte, buffer);
|
||||
case ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE:
|
||||
return CPPDeferredClassInstance.unmarshal(getPDOM(), firstByte, buffer);
|
||||
case ITypeMarshalBuffer.ALIAS_TEMPLATE:
|
||||
return CPPAliasTemplateInstance.unmarshal(firstByte, buffer);
|
||||
}
|
||||
|
||||
throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$
|
||||
|
|
Loading…
Add table
Reference in a new issue