mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Uses new template arguments for the instantiation algorithms, bug 242668.
This commit is contained in:
parent
935103d5a5
commit
d1dc55e8c7
23 changed files with 339 additions and 716 deletions
|
@ -95,15 +95,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
||||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template<int I, int J, class T> class X { };
|
|
||||||
// template<int I, int J> class X<I, J, int> { }; // #1
|
|
||||||
// template<int I> class X<I, I, int> { }; // #2
|
|
||||||
// template<int I, int J> void f(X<I, J, int>); // #A
|
|
||||||
// template<int I> void f(X<I, I, int>); // #B
|
|
||||||
public void _test14_5_4_2s2() throws Exception {
|
|
||||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
|
// template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
|
||||||
// template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1
|
// template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1
|
||||||
// template <int I, int J> A<I-J> f(A<I>, A<J>); // different from #1
|
// template <int I, int J> A<I-J> f(A<I>, A<J>); // different from #1
|
||||||
|
|
|
@ -18,10 +18,12 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
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.IASTProblemDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||||
|
@ -1765,16 +1767,17 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
// S<int()> x; // typeid
|
// S<int()> x; // typeid
|
||||||
// S<int(1)> y; // expression (illformed)
|
// S<int(1)> y; // expression (illformed)
|
||||||
public void test8_2s4() throws Exception {
|
public void test8_2s4() throws Exception {
|
||||||
//test is only for syntax, semantics are not checked here.
|
IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 1);
|
||||||
IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
tu.accept(col);
|
tu.accept(col);
|
||||||
|
|
||||||
assertInstance(col.getName(4), ICPPASTTemplateId.class);
|
assertInstance(col.getName(4), ICPPASTTemplateId.class);
|
||||||
assertInstance(((ICPPASTTemplateId)col.getName(4)).getTemplateArguments()[0], IASTTypeId.class);
|
assertInstance(((ICPPASTTemplateId)col.getName(4)).getTemplateArguments()[0], IASTTypeId.class);
|
||||||
|
|
||||||
assertInstance(col.getName(7), ICPPASTTemplateId.class);
|
final IASTName S_int_1 = col.getName(7);
|
||||||
assertInstance(((ICPPASTTemplateId)col.getName(7)).getTemplateArguments()[0], IASTExpression.class);
|
assertInstance(S_int_1, ICPPASTTemplateId.class);
|
||||||
|
assertInstance(((ICPPASTTemplateId)S_int_1).getTemplateArguments()[0], IASTExpression.class);
|
||||||
|
assertInstance(S_int_1.getBinding(), IProblemBinding.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo()
|
// void foo()
|
||||||
|
@ -4674,6 +4677,15 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(getAboveComment(), ParserLanguage.CPP, true, 1);
|
parse(getAboveComment(), ParserLanguage.CPP, true, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<int I, int J, class T> class X { };
|
||||||
|
// template<int I, int J> class X<I, J, int> { }; // #1
|
||||||
|
// template<int I> class X<I, I, int> { }; // #2
|
||||||
|
// template<int I, int J> void f(X<I, J, int>); // #A
|
||||||
|
// template<int I> void f(X<I, I, int>); // #B
|
||||||
|
public void test14_5_4_2s2() throws Exception {
|
||||||
|
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// // primary template
|
// // primary template
|
||||||
// template<class T, int I> struct A {
|
// template<class T, int I> struct A {
|
||||||
// void f();
|
// void f();
|
||||||
|
|
|
@ -764,30 +764,6 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
assertSame(g1, g2);
|
assertSame(g1, g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template <class T, class U = T > U f(T);
|
|
||||||
// void g() {
|
|
||||||
// f(1);
|
|
||||||
// }
|
|
||||||
public void testBug76951_1() throws Exception {
|
|
||||||
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
|
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
|
||||||
tu.accept(col);
|
|
||||||
|
|
||||||
ICPPTemplateParameter T = (ICPPTemplateParameter) col.getName(0).resolveBinding();
|
|
||||||
ICPPTemplateParameter T2 = (ICPPTemplateParameter) col.getName(2).resolveBinding();
|
|
||||||
assertSame(T, T2);
|
|
||||||
|
|
||||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(4).resolveBinding();
|
|
||||||
ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding();
|
|
||||||
|
|
||||||
assertTrue(f2 instanceof ICPPTemplateInstance);
|
|
||||||
assertSame(((ICPPTemplateInstance)f2).getTemplateDefinition(), f1);
|
|
||||||
|
|
||||||
IFunctionType ft = f2.getType();
|
|
||||||
assertTrue(ft.getReturnType() instanceof IBasicType);
|
|
||||||
assertEquals(((IBasicType)ft.getReturnType()).getType(), IBasicType.t_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
// template <class T, class U = T > class A {
|
// template <class T, class U = T > class A {
|
||||||
// U u;
|
// U u;
|
||||||
// };
|
// };
|
||||||
|
@ -2891,7 +2867,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
ICPPVariable _256= ba.assertNonProblem("_256=0x100", 4, ICPPVariable.class);
|
ICPPVariable _256= ba.assertNonProblem("_256=0x100", 4, ICPPVariable.class);
|
||||||
IQualifierType qt1= assertInstance(_256.getType(), IQualifierType.class);
|
IQualifierType qt1= assertInstance(_256.getType(), IQualifierType.class);
|
||||||
ICPPBasicType bt1= assertInstance(qt1.getType(), ICPPBasicType.class);
|
ICPPBasicType bt1= assertInstance(qt1.getType(), ICPPBasicType.class);
|
||||||
assertEquals(256, CPPVisitor.parseIntegral(bt1.getValue().toString()).intValue());
|
assertEquals(256, _256.getInitialValue().numericalValue().intValue());
|
||||||
|
|
||||||
ICPPVariable t= ba.assertNonProblem("t;", 1, ICPPVariable.class);
|
ICPPVariable t= ba.assertNonProblem("t;", 1, ICPPVariable.class);
|
||||||
ICPPTemplateInstance ci1= assertInstance(t.getType(), ICPPTemplateInstance.class, ICPPClassType.class);
|
ICPPTemplateInstance ci1= assertInstance(t.getType(), ICPPTemplateInstance.class, ICPPClassType.class);
|
||||||
|
@ -2902,7 +2878,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// non-type arguments are currently modelled as a type with attached expression
|
// non-type arguments are currently modelled as a type with attached expression
|
||||||
ICPPBasicType bt0= assertInstance(args1.getAt(0), ICPPBasicType.class);
|
ICPPBasicType bt0= assertInstance(args1.getAt(0), ICPPBasicType.class);
|
||||||
assertEquals(bt0.getType(), IBasicType.t_int);
|
assertEquals(bt0.getType(), IBasicType.t_int);
|
||||||
assertEquals(256, CPPVisitor.parseIntegral(bt0.getValue().toString()).intValue());
|
assertEquals(256, ci1.getTemplateArguments()[0].getNonTypeValue().numericalValue().intValue());
|
||||||
|
|
||||||
ICPPTemplateInstance ct= ba.assertNonProblem("C<_256> ", 7, ICPPTemplateInstance.class, ICPPClassType.class);
|
ICPPTemplateInstance ct= ba.assertNonProblem("C<_256> ", 7, ICPPTemplateInstance.class, ICPPClassType.class);
|
||||||
ObjectMap args= ct.getArgumentMap();
|
ObjectMap args= ct.getArgumentMap();
|
||||||
|
@ -2912,7 +2888,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// non-type arguments are currently modelled as a type with attached expression
|
// non-type arguments are currently modelled as a type with attached expression
|
||||||
ICPPBasicType bt= assertInstance(args.getAt(0), ICPPBasicType.class);
|
ICPPBasicType bt= assertInstance(args.getAt(0), ICPPBasicType.class);
|
||||||
assertEquals(bt.getType(), IBasicType.t_int);
|
assertEquals(bt.getType(), IBasicType.t_int);
|
||||||
assertEquals(256, CPPVisitor.parseIntegral(bt.getValue().toString()).intValue());
|
assertEquals(256, ct.getTemplateArguments()[0].getNonTypeValue().numericalValue().intValue());
|
||||||
|
|
||||||
ba.assertNonProblem("foo(t)", 3);
|
ba.assertNonProblem("foo(t)", 3);
|
||||||
ba.assertNonProblem("bar(t)", 3);
|
ba.assertNonProblem("bar(t)", 3);
|
||||||
|
@ -2939,7 +2915,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// class A {};
|
// class A {};
|
||||||
//
|
//
|
||||||
// A<int> aint; // should be an error
|
// A<int> aint; // should be an error
|
||||||
public void _testTypeArgumentToNonTypeParameter() throws Exception {
|
public void testTypeArgumentToNonTypeParameter() throws Exception {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||||
ba.assertProblem("A<int>", 6);
|
ba.assertProblem("A<int>", 6);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
|
@ -166,33 +166,23 @@ public class AST2UtilTests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseIntegral() throws Exception {
|
public void testParseIntegral() throws Exception {
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("0").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("0".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("+0").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("0x0".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("-0").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("00".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("0x0").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("000".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("00").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("0L".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("000").intValue());
|
assertEquals(0, ExpressionEvaluator.getNumber("0LL".toCharArray()));
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("0L").intValue());
|
|
||||||
assertEquals(0, CPPVisitor.parseIntegral("0LL").intValue());
|
|
||||||
|
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("1").intValue());
|
assertEquals(1, ExpressionEvaluator.getNumber("1".toCharArray()));
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("01").intValue());
|
assertEquals(1, ExpressionEvaluator.getNumber("01".toCharArray()));
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("0x1").intValue());
|
assertEquals(1, ExpressionEvaluator.getNumber("0x1".toCharArray()));
|
||||||
|
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("+1").intValue());
|
assertEquals(10, ExpressionEvaluator.getNumber("10".toCharArray()));
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("+01").intValue());
|
assertEquals(8, ExpressionEvaluator.getNumber("010".toCharArray()));
|
||||||
assertEquals(1, CPPVisitor.parseIntegral("+0x1").intValue());
|
assertEquals(16, ExpressionEvaluator.getNumber("0x10".toCharArray()));
|
||||||
|
|
||||||
assertEquals(-1, CPPVisitor.parseIntegral("-1").intValue());
|
assertEquals(10, ExpressionEvaluator.getNumber("10LLL".toCharArray()));
|
||||||
assertEquals(-1, CPPVisitor.parseIntegral("-01").intValue());
|
assertEquals(8, ExpressionEvaluator.getNumber("010LLL".toCharArray()));
|
||||||
assertEquals(-1, CPPVisitor.parseIntegral("-0x1").intValue());
|
assertEquals(16, ExpressionEvaluator.getNumber("0x10LLL".toCharArray()));
|
||||||
|
|
||||||
assertEquals(-10, CPPVisitor.parseIntegral("-10").intValue());
|
|
||||||
assertEquals(-8, CPPVisitor.parseIntegral("-010").intValue());
|
|
||||||
assertEquals(-16, CPPVisitor.parseIntegral("-0x10").intValue());
|
|
||||||
|
|
||||||
assertEquals(-10, CPPVisitor.parseIntegral("-10LLL").intValue());
|
|
||||||
assertEquals(-8, CPPVisitor.parseIntegral("-010LLL").intValue());
|
|
||||||
assertEquals(-16, CPPVisitor.parseIntegral("-0x10LLL").intValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
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.ICPPTemplateParameter;
|
||||||
|
@ -46,6 +46,7 @@ public class Value implements IValue {
|
||||||
|
|
||||||
private static class UnknownValueException extends Exception {}
|
private static class UnknownValueException extends Exception {}
|
||||||
private static UnknownValueException UNKNOWN_EX= new UnknownValueException();
|
private static UnknownValueException UNKNOWN_EX= new UnknownValueException();
|
||||||
|
private static int sUnique=0;
|
||||||
|
|
||||||
private final String fValue;
|
private final String fValue;
|
||||||
private Value(String rep) {
|
private Value(String rep) {
|
||||||
|
@ -76,16 +77,31 @@ public class Value implements IValue {
|
||||||
return fValue.equals(((IValue) obj).getCanonicalRepresentation());
|
return fValue.equals(((IValue) obj).getCanonicalRepresentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return fValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a value representing the given number.
|
||||||
|
*/
|
||||||
public static IValue create(long value) {
|
public static IValue create(long value) {
|
||||||
if (value >=0 && value < TYPICAL.length)
|
if (value >=0 && value < TYPICAL.length)
|
||||||
return TYPICAL[(int) value];
|
return TYPICAL[(int) value];
|
||||||
return new Value(String.valueOf(value));
|
return new Value(String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a value representing the given template parameter.
|
||||||
|
*/
|
||||||
public static IValue create(ICPPTemplateNonTypeParameter tntp) {
|
public static IValue create(ICPPTemplateNonTypeParameter tntp) {
|
||||||
return new Value(evaluate(tntp));
|
return new Value(evaluate(tntp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the value is a template parameter, returns the parameter position of the
|
||||||
|
* parameter, or <code>null</code> if it is not a template parameter.
|
||||||
|
*/
|
||||||
public static int isTemplateParameter(IValue tval) {
|
public static int isTemplateParameter(IValue tval) {
|
||||||
final String rep= tval.getCanonicalRepresentation();
|
final String rep= tval.getCanonicalRepresentation();
|
||||||
if (rep.indexOf('#') == 0 && rep.indexOf(',') == -1) {
|
if (rep.indexOf('#') == 0 && rep.indexOf(',') == -1) {
|
||||||
|
@ -97,6 +113,17 @@ public class Value implements IValue {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the value depends on a template parameter.
|
||||||
|
*/
|
||||||
|
public static boolean isDependentValue(IValue nonTypeValue) {
|
||||||
|
final String rep= nonTypeValue.getCanonicalRepresentation();
|
||||||
|
return rep.indexOf('#') >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the value for an expression.
|
||||||
|
*/
|
||||||
public static IValue create(IASTExpression expr, int maxRecursionDepth) {
|
public static IValue create(IASTExpression expr, int maxRecursionDepth) {
|
||||||
try {
|
try {
|
||||||
Object obj= evaluate(expr, maxRecursionDepth);
|
Object obj= evaluate(expr, maxRecursionDepth);
|
||||||
|
@ -108,6 +135,9 @@ public class Value implements IValue {
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a value off its canonical representation.
|
||||||
|
*/
|
||||||
public static IValue fromCanonicalRepresentation(String rep) {
|
public static IValue fromCanonicalRepresentation(String rep) {
|
||||||
if (rep.equals(UNKNOWN.getCanonicalRepresentation()))
|
if (rep.equals(UNKNOWN.getCanonicalRepresentation()))
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
|
@ -119,6 +149,13 @@ public class Value implements IValue {
|
||||||
return new Value(rep);
|
return new Value(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a unique value needed during template instantiation.
|
||||||
|
*/
|
||||||
|
public static IValue unique() {
|
||||||
|
return new Value("@" + (++sUnique)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the canonical representation of the value of the expression. Returns a {@code Long} for
|
* Computes the canonical representation of the value of the expression. Returns a {@code Long} for
|
||||||
* numerical values or a {@code String}, otherwise.
|
* numerical values or a {@code String}, otherwise.
|
||||||
|
@ -189,14 +226,29 @@ public class Value implements IValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e instanceof IASTLiteralExpression) {
|
if (e instanceof IASTLiteralExpression) {
|
||||||
if (e.getExpressionType() instanceof IBasicType) {
|
IASTLiteralExpression litEx= (IASTLiteralExpression) e;
|
||||||
|
switch (litEx.getKind()) {
|
||||||
|
case ICPPASTLiteralExpression.lk_false:
|
||||||
|
return "0";
|
||||||
|
case ICPPASTLiteralExpression.lk_true:
|
||||||
|
return "1";
|
||||||
|
case IASTLiteralExpression.lk_integer_constant:
|
||||||
try {
|
try {
|
||||||
return ExpressionEvaluator.getNumber(e.toString().toCharArray());
|
return ExpressionEvaluator.getNumber(e.toString().toCharArray());
|
||||||
} catch (EvalException e1) {
|
} catch (EvalException e1) {
|
||||||
throw UNKNOWN_EX;
|
throw UNKNOWN_EX;
|
||||||
}
|
}
|
||||||
|
case IASTLiteralExpression.lk_char_constant:
|
||||||
|
try {
|
||||||
|
final char[] image= e.toString().toCharArray();
|
||||||
|
if (image.length > 1)
|
||||||
|
if (image[0] == 'L')
|
||||||
|
return ExpressionEvaluator.getChar(image, 2);
|
||||||
|
return ExpressionEvaluator.getChar(image, 1);
|
||||||
|
} catch (EvalException e1) {
|
||||||
|
throw UNKNOWN_EX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return e.toString();
|
|
||||||
}
|
}
|
||||||
throw UNKNOWN_EX;
|
throw UNKNOWN_EX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +35,7 @@ public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements
|
||||||
* in the future
|
* in the future
|
||||||
*/
|
*/
|
||||||
public CPPASTAmbiguousTemplateArgument(IASTNode... nodes) {
|
public CPPASTAmbiguousTemplateArgument(IASTNode... nodes) {
|
||||||
fNodes= new ArrayList<IASTNode>();
|
fNodes= new ArrayList<IASTNode>(2);
|
||||||
for(IASTNode node : nodes) {
|
for(IASTNode node : nodes) {
|
||||||
if(node instanceof IASTTypeId || node instanceof IASTIdExpression) {
|
if(node instanceof IASTTypeId || node instanceof IASTIdExpression) {
|
||||||
fNodes.add(node);
|
fNodes.add(node);
|
||||||
|
@ -62,7 +63,7 @@ public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements
|
||||||
private void addNode(IASTNode node) {
|
private void addNode(IASTNode node) {
|
||||||
fNodes.add(node);
|
fNodes.add(node);
|
||||||
node.setParent(this);
|
node.setParent(this);
|
||||||
node.setPropertyInParent(CPPASTTemplateId.TEMPLATE_ID_ARGUMENT);
|
node.setPropertyInParent(ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,10 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPTemplateArgument[] getTemplateArguments() {
|
public ICPPTemplateArgument[] getTemplateArguments() {
|
||||||
createArguments();
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createArguments() {
|
|
||||||
if (arguments == null) {
|
if (arguments == null) {
|
||||||
arguments= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) getTemplateName());
|
arguments= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) getTemplateName());
|
||||||
}
|
}
|
||||||
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a specialization of a class-template
|
* Represents a specialization of a class-template
|
||||||
|
@ -62,7 +61,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
|
||||||
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
||||||
if (args.length == arguments.length) {
|
if (args.length == arguments.length) {
|
||||||
for (int j=0; j < args.length; j++) {
|
for (int j=0; j < args.length; j++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
if (!args[j].isSameValue(arguments[j])) {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements IC
|
||||||
private ICPPTemplateArgument[] fArguments;
|
private ICPPTemplateArgument[] fArguments;
|
||||||
private ICPPFunctionTemplate fFunctionTemplate;
|
private ICPPFunctionTemplate fFunctionTemplate;
|
||||||
|
|
||||||
private ICPPTemplateParameterMap fArgmap;
|
|
||||||
private IParameter [] fParameters;
|
private IParameter [] fParameters;
|
||||||
private IFunctionType fFunctionType;
|
private IFunctionType fFunctionType;
|
||||||
|
|
||||||
|
@ -59,15 +58,11 @@ public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements IC
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ObjectMap getArgumentMap() {
|
public ObjectMap getArgumentMap() {
|
||||||
return CPPTemplates.getArgumentMap(fFunctionTemplate, getTemplateParameterMap());
|
return ObjectMap.EMPTY_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPTemplateParameterMap getTemplateParameterMap() {
|
public ICPPTemplateParameterMap getTemplateParameterMap() {
|
||||||
// mstodo- deferred function instance and tpmap
|
return CPPTemplateParameterMap.EMPTY;
|
||||||
if (fArgmap == null) {
|
|
||||||
fArgmap= CPPTemplates.createParameterMap(fFunctionTemplate, getTemplateArguments());
|
|
||||||
}
|
|
||||||
return fArgmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -80,7 +75,6 @@ public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements IC
|
||||||
}
|
}
|
||||||
|
|
||||||
public IParameter[] getParameters() throws DOMException {
|
public IParameter[] getParameters() throws DOMException {
|
||||||
// mstodo- deferred function instance and tpmap
|
|
||||||
if( fParameters == null ){
|
if( fParameters == null ){
|
||||||
IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
|
IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
|
||||||
fParameters = new IParameter[ params.length ];
|
fParameters = new IParameter[ params.length ];
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The specialization of a friend function template in the context of a class specialization.
|
* The specialization of a friend function template in the context of a class specialization.
|
||||||
|
@ -51,7 +50,7 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
|
||||||
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
||||||
if (args.length == arguments.length) {
|
if (args.length == arguments.length) {
|
||||||
for (int j=0; j < args.length; j++) {
|
for (int j=0; j < args.length; j++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
if (!args[j].isSameValue(arguments[j])) {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class CPPTemplateArgument implements ICPPTemplateArgument {
|
||||||
|
|
||||||
public boolean isSameValue(ICPPTemplateArgument arg) {
|
public boolean isSameValue(ICPPTemplateArgument arg) {
|
||||||
if (fValue != null) {
|
if (fValue != null) {
|
||||||
return fValue.equals(arg.getNonTypeValue()) && fType.equals(arg.getTypeOfNonTypeValue());
|
return fValue.equals(arg.getNonTypeValue());
|
||||||
}
|
}
|
||||||
return fType.isSameType(arg.getTypeValue());
|
return fType.isSameType(arg.getTypeValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
||||||
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
||||||
if (args.length == arguments.length) {
|
if (args.length == arguments.length) {
|
||||||
for (int j=0; j < args.length; j++) {
|
for (int j=0; j < args.length; j++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
if (!args[j].isSameValue(arguments[j])) {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
|
||||||
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i);
|
||||||
if (args.length == arguments.length) {
|
if (args.length == arguments.length) {
|
||||||
for (int j=0; j < args.length; j++) {
|
for (int j=0; j < args.length; j++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
if (!args[j].isSameValue(arguments[j])) {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Represents a partially instantiated C++ class template, declaration of which is not yet available.
|
* Represents a partially instantiated C++ class template, declaration of which is not yet available.
|
||||||
*
|
*
|
||||||
* @author Sergey Prigogin
|
* @author Sergey Prigogin
|
||||||
|
@ -65,7 +64,7 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i= 0; i < lhsArgs.length; i++) {
|
for (int i= 0; i < lhsArgs.length; i++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(lhsArgs[i],rhsArgs[i]))
|
if (!lhsArgs[i].isSameValue(rhsArgs[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,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.IValue;
|
||||||
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;
|
||||||
|
@ -131,6 +132,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
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.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
|
@ -323,7 +325,10 @@ public class CPPSemantics {
|
||||||
for (int i = 0; useOriginal && i < pars.length; i++) {
|
for (int i = 0; useOriginal && i < pars.length; i++) {
|
||||||
ICPPTemplateParameter par= pars[i];
|
ICPPTemplateParameter par= pars[i];
|
||||||
if (par instanceof ICPPTemplateNonTypeParameter) {
|
if (par instanceof ICPPTemplateNonTypeParameter) {
|
||||||
// mstodo change this
|
IValue val= args[i].getNonTypeValue();
|
||||||
|
if (val == null || par.getParameterPosition() != Value.isTemplateParameter(val)) {
|
||||||
|
useOriginal= false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!((IType) par).isSameType(args[i].getTypeValue())) {
|
if (!((IType) par).isSameType(args[i].getTypeValue())) {
|
||||||
useOriginal= false;
|
useOriginal= false;
|
||||||
|
@ -337,20 +342,6 @@ public class CPPSemantics {
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// mstodo+ remove
|
|
||||||
// final ObjectMap argMap = deferred.getArgumentMap();
|
|
||||||
// if (argMap != null) {
|
|
||||||
// for (int i = 0; useOriginal && i < argMap.size(); i++) {
|
|
||||||
// final Object key = argMap.keyAt(i);
|
|
||||||
// if (!key.equals(argMap.getAt(i))) {
|
|
||||||
// // bug 231868 non type parameters are modeled via their type :-(
|
|
||||||
// if (key instanceof ICPPTemplateNonTypeParameter == false) {
|
|
||||||
// useOriginal= false;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (name.getParent() instanceof ICPPASTTemplateId) {
|
if (name.getParent() instanceof ICPPASTTemplateId) {
|
||||||
|
|
|
@ -13,12 +13,10 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
@ -27,8 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
@ -62,7 +58,6 @@ 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.ICPPASTTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
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.ICPPASTTemplatedTypeTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
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.ICPPClassTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||||
|
@ -96,7 +91,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
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;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
|
||||||
|
@ -186,8 +180,7 @@ public class CPPTemplates {
|
||||||
int numParams = params.length;
|
int numParams = params.length;
|
||||||
for (int i = 0; i < numParams; i++) {
|
for (int i = 0; i < numParams; i++) {
|
||||||
final ICPPTemplateParameter param = params[i];
|
final ICPPTemplateParameter param = params[i];
|
||||||
// mstodo check non-type parameters, also
|
if (tpMap.getArgument(param) == null)
|
||||||
if (param instanceof IType && tpMap.getArgument(param) == null)
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,37 +224,45 @@ public class CPPTemplates {
|
||||||
arg= instantiateArgument(defaultArg, map, null);
|
arg= instantiateArgument(defaultArg, map, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CPPTemplates.matchTemplateParameterAndArgument(param, getArgument(arg), map)) {
|
arg= CPPTemplates.matchTemplateParameterAndArgument(param, arg, map);
|
||||||
if (!param.equals(getArgument(arg))) {
|
if (arg == null)
|
||||||
map.put(param, arg);
|
|
||||||
}
|
|
||||||
actualArgs[i] = arg;
|
|
||||||
if (CPPTemplates.isDependentArgument(arg)) {
|
|
||||||
argsContainDependentType = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ICPPTemplateInstance instance= getInstance(template, arguments);
|
if (!argIsParameter(arg, param)) {
|
||||||
// we do not correctly distinguish between type and non-type parameters, this works
|
map.put(param, arg);
|
||||||
// around getting the wrong instance when providing a value rather than a type.
|
}
|
||||||
if (instance != null) {
|
actualArgs[i] = arg;
|
||||||
if (argsContainDependentType || !(instance instanceof ICPPDeferredClassInstance))
|
if (CPPTemplates.isDependentArgument(arg)) {
|
||||||
return instance;
|
argsContainDependentType = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argsContainDependentType) {
|
if (argsContainDependentType) {
|
||||||
return deferredInstance(template, actualArgs);
|
return deferredInstance(template, actualArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ICPPTemplateInstance instance= getInstance(template, arguments);
|
||||||
|
if (instance != null) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
IBinding owner= template.getOwner();
|
IBinding owner= template.getOwner();
|
||||||
instance = CPPTemplates.createInstance(owner, template, map, actualArgs);
|
instance = CPPTemplates.createInstance(owner, template, map, actualArgs);
|
||||||
addInstance(template, actualArgs, instance);
|
addInstance(template, actualArgs, instance);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean argIsParameter(ICPPTemplateArgument arg, ICPPTemplateParameter param) {
|
||||||
|
if (param instanceof ICPPTemplateNonTypeParameter) {
|
||||||
|
return arg.isNonTypeValue() && Value.isTemplateParameter(arg.getNonTypeValue()) == param.getParameterPosition();
|
||||||
|
}
|
||||||
|
if (param instanceof IType) {
|
||||||
|
return arg.isTypeValue() && ((IType) param).isSameType(arg.getTypeValue());
|
||||||
|
}
|
||||||
|
assert false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains a cached instance from the template.
|
* Obtains a cached instance from the template.
|
||||||
*/
|
*/
|
||||||
|
@ -311,10 +312,7 @@ public class CPPTemplates {
|
||||||
args[i] = new CPPTemplateArgument((IType) tp);
|
args[i] = new CPPTemplateArgument((IType) tp);
|
||||||
} else if (tp instanceof ICPPTemplateNonTypeParameter) {
|
} else if (tp instanceof ICPPTemplateNonTypeParameter) {
|
||||||
final ICPPTemplateNonTypeParameter nttp = (ICPPTemplateNonTypeParameter) tp;
|
final ICPPTemplateNonTypeParameter nttp = (ICPPTemplateNonTypeParameter) tp;
|
||||||
// mstodo for now stick to the type
|
args[i] = new CPPTemplateArgument(Value.create(nttp), nttp.getType());
|
||||||
args[i]= new CPPTemplateArgument(nttp.getType());
|
|
||||||
|
|
||||||
// args[i] = new CPPTemplateArgument(Value.create(nttp), nttp.getType());
|
|
||||||
} else {
|
} else {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
|
@ -572,7 +570,7 @@ public class CPPTemplates {
|
||||||
ICPPTemplateArgument[] args= createTemplateArgumentArray(id);
|
ICPPTemplateArgument[] args= createTemplateArgumentArray(id);
|
||||||
CPPTemplateParameterMap tpMap = new CPPTemplateParameterMap(templateParams.length);
|
CPPTemplateParameterMap tpMap = new CPPTemplateParameterMap(templateParams.length);
|
||||||
if (templateParams.length != args.length) {
|
if (templateParams.length != args.length) {
|
||||||
return null; //TODO problem
|
return null; // mstodo problem or use default args?
|
||||||
}
|
}
|
||||||
for (int i = 0; i < templateParams.length; i++) {
|
for (int i = 0; i < templateParams.length; i++) {
|
||||||
tpMap.put(templateParams[i], args[i]);
|
tpMap.put(templateParams[i], args[i]);
|
||||||
|
@ -723,7 +721,7 @@ public class CPPTemplates {
|
||||||
if (!deduceTemplateParameterMapFromFunctionParameters(tmpl, functionParameters, map))
|
if (!deduceTemplateParameterMapFromFunctionParameters(tmpl, functionParameters, map))
|
||||||
continue;
|
continue;
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
continue; // mstodo potential failure
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ICPPTemplateParameter[] params = null;
|
ICPPTemplateParameter[] params = null;
|
||||||
|
@ -747,11 +745,12 @@ public class CPPTemplates {
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
map.put(param, deducedArg);
|
map.put(param, deducedArg);
|
||||||
arg = deducedArg;
|
arg = deducedArg;
|
||||||
} else if (!CPPTemplates.isSameTemplateArgument(deducedArg, arg)) {
|
} else if (!deducedArg.isSameValue(arg)) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arg == null || !matchTemplateParameterAndArgument(param, getArgument(arg), map)) {
|
arg= matchTemplateParameterAndArgument(param, arg, map);
|
||||||
|
if (arg == null) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -766,8 +765,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return Object[] of { ObjectMap, IType[] }
|
* Deduce arguments for a template function from the template id + the template function parameters.
|
||||||
* @throws DOMException
|
|
||||||
*/
|
*/
|
||||||
static protected ICPPTemplateArgument[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
|
static protected ICPPTemplateArgument[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
|
||||||
IASTParameterDeclaration[] ps, ICPPASTTemplateId id, CPPTemplateParameterMap map) throws DOMException {
|
IASTParameterDeclaration[] ps, ICPPASTTemplateId id, CPPTemplateParameterMap map) throws DOMException {
|
||||||
|
@ -797,11 +795,12 @@ public class CPPTemplates {
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
map.put(param, deducedArg);
|
map.put(param, deducedArg);
|
||||||
arg = deducedArg;
|
arg = deducedArg;
|
||||||
} else if (!CPPTemplates.isSameTemplateArgument(deducedArg, arg)) {
|
} else if (!deducedArg.isSameValue(arg)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arg == null || !matchTemplateParameterAndArgument(param, getArgument(arg), map))
|
arg= matchTemplateParameterAndArgument(param, arg, map);
|
||||||
|
if (arg == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
result[i] = arg;
|
result[i] = arg;
|
||||||
|
@ -1264,7 +1263,7 @@ public class CPPTemplates {
|
||||||
if (args.length == specArgs.length) {
|
if (args.length == specArgs.length) {
|
||||||
result= true;
|
result= true;
|
||||||
for (int i=0; i < args.length; i++) {
|
for (int i=0; i < args.length; i++) {
|
||||||
if (!isSameTemplateArgument(specArgs[i], args[i])) {
|
if (!specArgs[i].isSameValue(args[i])) {
|
||||||
result= false;
|
result= false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1285,37 +1284,6 @@ public class CPPTemplates {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param argA may be null
|
|
||||||
* @param argB may be null
|
|
||||||
* @return whether the two specified template arguments are the same
|
|
||||||
* @deprecated use {@link ICPPTemplateArgument#isSameValue(ICPPTemplateArgument)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static final boolean isSameTemplateArgument(IType argA, IType argB) {
|
|
||||||
if (argA == argB)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// special case treatment for non-type integral parameters
|
|
||||||
if (argA instanceof ICPPBasicType && argB instanceof ICPPBasicType) {
|
|
||||||
try {
|
|
||||||
IASTExpression eA= ((ICPPBasicType) argA).getValue();
|
|
||||||
IASTExpression eB= ((ICPPBasicType) argB).getValue();
|
|
||||||
if (eA != null && eB != null) {
|
|
||||||
// TODO - we should normalize template arguments
|
|
||||||
// rather than check their original expressions
|
|
||||||
// are equivalent.
|
|
||||||
return isNonTypeArgumentConvertible(argA, argB) && expressionsEquivalent(eA, eB);
|
|
||||||
}
|
|
||||||
} catch (DOMException de) {
|
|
||||||
CCorePlugin.log(de);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return argA != null && argB != null && argA.isSameType(argB);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the template id containing the template arguments
|
* @param id the template id containing the template arguments
|
||||||
* @return an array of template arguments, currently modeled as IType objects. The
|
* @return an array of template arguments, currently modeled as IType objects. The
|
||||||
|
@ -1328,23 +1296,20 @@ public class CPPTemplates {
|
||||||
result = new ICPPTemplateArgument[params.length];
|
result = new ICPPTemplateArgument[params.length];
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
IASTNode param= params[i];
|
IASTNode param= params[i];
|
||||||
/*
|
|
||||||
* id-expression's which resolve to const variables can be
|
|
||||||
* modeled by the type of the initialized expression (which
|
|
||||||
* will include its value)
|
|
||||||
*/
|
|
||||||
if (param instanceof IASTIdExpression) {
|
|
||||||
param= CPPVisitor.reverseConstantPropagationLookup((IASTIdExpression)param);
|
|
||||||
}
|
|
||||||
|
|
||||||
IType type= CPPVisitor.createType(param);
|
IType type= CPPVisitor.createType(param);
|
||||||
// prevent null pointer exception when the type cannot be determined
|
// prevent null pointer exception when the type cannot be determined
|
||||||
// happens when templates with still ambiguous template-ids are accessed during
|
// happens when templates with still ambiguous template-ids are accessed during
|
||||||
// resolution of other ambiguities.
|
// resolution of other template-id ambiguities.
|
||||||
|
// mstodo: fix by introducing partially resolved template parameters
|
||||||
if (type == null)
|
if (type == null)
|
||||||
type= new CPPBasicType(-1, 0);
|
type= new CPPBasicType(-1, 0);
|
||||||
|
|
||||||
result[i]= new CPPTemplateArgument(type);
|
if (param instanceof IASTExpression) {
|
||||||
|
IValue value= Value.create((IASTExpression) param, Value.MAX_RECURSION_DEPTH);
|
||||||
|
result[i]= new CPPTemplateArgument(value, type);
|
||||||
|
} else {
|
||||||
|
result[i]= new CPPTemplateArgument(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1381,8 +1346,7 @@ public class CPPTemplates {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected IFunction[] selectTemplateFunctions(
|
static protected IFunction[] selectTemplateFunctions(ObjectSet<IFunction> templates,
|
||||||
ObjectSet<IFunction> templates,
|
|
||||||
Object[] functionArguments, IASTName name) {
|
Object[] functionArguments, IASTName name) {
|
||||||
|
|
||||||
if (templates == null || templates.size() == 0)
|
if (templates == null || templates.size() == 0)
|
||||||
|
@ -1420,47 +1384,24 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
int numTemplateParams = templateParams.length;
|
int numTemplateParams = templateParams.length;
|
||||||
|
|
||||||
IType[] instanceArgs = null;
|
ICPPTemplateArgument[] instanceArgs = null;
|
||||||
for (int i = 0; i < numTemplateParams; i++) {
|
for (int i = 0; i < numTemplateParams; i++) {
|
||||||
IType arg = (i < numTemplateArgs && templateArguments != null) ? getArgument(templateArguments[i]) : null;
|
ICPPTemplateArgument arg = (i < numTemplateArgs && templateArguments != null) ? templateArguments[i] : null;
|
||||||
IType mapped = getArgument(map.getArgument(templateParams[i]));
|
ICPPTemplateArgument mapped = map.getArgument(templateParams[i]);
|
||||||
|
|
||||||
if (arg != null && mapped != null) {
|
if (arg != null && mapped != null) {
|
||||||
if (arg.isSameType(mapped)) // compare as IType: 'mapped' is not a template argument
|
if (arg.isSameValue(mapped))
|
||||||
instanceArgs = (IType[]) ArrayUtil.append(IType.class, instanceArgs, arg);
|
instanceArgs = (ICPPTemplateArgument[]) ArrayUtil.append(ICPPTemplateArgument.class, instanceArgs, arg);
|
||||||
else
|
else
|
||||||
continue outer;
|
continue outer;
|
||||||
} else if (arg == null && mapped == null) {
|
} else if (arg == null && mapped == null) {
|
||||||
IType def = null;
|
continue outer;
|
||||||
try {
|
|
||||||
if (templateParams[i] instanceof ICPPTemplateTypeParameter) {
|
|
||||||
def = ((ICPPTemplateTypeParameter) templateParams[i]).getDefault();
|
|
||||||
} else if (templateParams[i] instanceof ICPPTemplateTemplateParameter) {
|
|
||||||
def = ((ICPPTemplateTemplateParameter) templateParams[i]).getDefault();
|
|
||||||
} else if (templateParams[i] instanceof ICPPTemplateNonTypeParameter) {
|
|
||||||
def = CPPVisitor.getExpressionType(((ICPPTemplateNonTypeParameter) templateParams[i]).getDefault());
|
|
||||||
}
|
|
||||||
} catch (DOMException e) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
if (def != null) {
|
|
||||||
if (def instanceof ICPPTemplateParameter) {
|
|
||||||
for (int j = 0; j < i; j++) {
|
|
||||||
if (templateParams[j] == def && instanceArgs != null) {
|
|
||||||
def = instanceArgs[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instanceArgs = (IType[]) ArrayUtil.append(IType.class, instanceArgs, def);
|
|
||||||
} else {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
instanceArgs = (IType[]) ArrayUtil.append(IType.class, instanceArgs, (arg != null) ? arg : mapped);
|
instanceArgs = (ICPPTemplateArgument[]) ArrayUtil.append(ICPPTemplateArgument.class, instanceArgs, (arg != null) ? arg : mapped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instanceArgs= (IType[]) ArrayUtil.trim(IType.class, instanceArgs);
|
instanceArgs= (ICPPTemplateArgument[]) ArrayUtil.trim(ICPPTemplateArgument.class, instanceArgs);
|
||||||
IBinding temp= instantiate(template, convert(instanceArgs));
|
IBinding temp= instantiate(template, instanceArgs);
|
||||||
if (temp instanceof IFunction) {
|
if (temp instanceof IFunction) {
|
||||||
instances = (IFunction[]) ArrayUtil.append(IFunction.class, instances, temp);
|
instances = (IFunction[]) ArrayUtil.append(IFunction.class, instances, temp);
|
||||||
}
|
}
|
||||||
|
@ -1526,20 +1467,19 @@ public class CPPTemplates {
|
||||||
|
|
||||||
if (p.isNonTypeValue()) {
|
if (p.isNonTypeValue()) {
|
||||||
IValue tval= p.getNonTypeValue();
|
IValue tval= p.getNonTypeValue();
|
||||||
IValue sval= a.getNonTypeValue();
|
|
||||||
if (tval.equals(sval))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int parPos= Value.isTemplateParameter(tval);
|
int parPos= Value.isTemplateParameter(tval);
|
||||||
if (parPos == -1)
|
if (parPos >= 0) {
|
||||||
return false;
|
ICPPTemplateArgument old= map.getArgument(parPos);
|
||||||
|
if (old == null) {
|
||||||
ICPPTemplateArgument old= map.getArgument(parPos);
|
map.put(parPos, a);
|
||||||
if (old == null) {
|
return true;
|
||||||
map.put(parPos, a);
|
}
|
||||||
return true;
|
return old.isSameValue(a);
|
||||||
}
|
}
|
||||||
return old.isSameValue(a);
|
|
||||||
|
IValue sval= a.getNonTypeValue();
|
||||||
|
return tval.equals(sval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deduceTemplateParameterMap(p.getTypeValue(), a.getTypeValue(), map);
|
return deduceTemplateParameterMap(p.getTypeValue(), a.getTypeValue(), map);
|
||||||
|
@ -1603,138 +1543,98 @@ public class CPPTemplates {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean expressionsEquivalent(IASTExpression e1, IASTExpression e2) {
|
|
||||||
if (e1 == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
e1= CPPVisitor.reverseConstantPropagationLookup(e1);
|
|
||||||
e2= CPPVisitor.reverseConstantPropagationLookup(e2);
|
|
||||||
|
|
||||||
if (e1 instanceof IASTLiteralExpression && e2 instanceof IASTLiteralExpression) {
|
|
||||||
IType t1= e1.getExpressionType();
|
|
||||||
IType t2= e2.getExpressionType();
|
|
||||||
try {
|
|
||||||
if (t1 instanceof ICPPBasicType && t2 instanceof ICPPBasicType) {
|
|
||||||
BigInteger i1= CPPVisitor.parseIntegral(e1.toString());
|
|
||||||
BigInteger i2= CPPVisitor.parseIntegral(e2.toString());
|
|
||||||
return i1.equals(i2);
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
/* fall through */
|
|
||||||
}
|
|
||||||
return e1.toString().equals(e2.toString());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean deduceTemplateParameterMap(IType p, IType a, CPPTemplateParameterMap map) throws DOMException {
|
private static boolean deduceTemplateParameterMap(IType p, IType a, CPPTemplateParameterMap map) throws DOMException {
|
||||||
boolean pIsAReferenceType = (p instanceof ICPPReferenceType);
|
boolean pIsAReferenceType = (p instanceof ICPPReferenceType);
|
||||||
p = getParameterTypeForDeduction(p);
|
p = getParameterTypeForDeduction(p);
|
||||||
a = getArgumentTypeForDeduction(a, pIsAReferenceType);
|
a = getArgumentTypeForDeduction(a, pIsAReferenceType);
|
||||||
|
|
||||||
if (p instanceof IBasicType) {
|
while (p != null) {
|
||||||
if (a instanceof IBasicType) {
|
while (a instanceof ITypedef)
|
||||||
IBasicType pbt= (IBasicType) p;
|
a = ((ITypedef) a).getType();
|
||||||
IBasicType abt= (IBasicType) a;
|
if (p instanceof IBasicType) {
|
||||||
|
|
||||||
// non-type argument comparison
|
|
||||||
if (pbt.getValue() != null && abt.getValue() != null) {
|
|
||||||
return isNonTypeArgumentConvertible(p, a)
|
|
||||||
&& expressionsEquivalent(pbt.getValue(), abt.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
// type argument comparison
|
|
||||||
return p.isSameType(a);
|
return p.isSameType(a);
|
||||||
}
|
} else if (p instanceof ICPPPointerToMemberType) {
|
||||||
} else {
|
if (!(a instanceof ICPPPointerToMemberType))
|
||||||
while (p != null) {
|
return false;
|
||||||
while (a instanceof ITypedef)
|
if (!deduceTemplateParameterMap(((ICPPPointerToMemberType) p).getMemberOfClass(), ((ICPPPointerToMemberType) a).getMemberOfClass(),
|
||||||
a = ((ITypedef) a).getType();
|
map)) {
|
||||||
if (p instanceof IBasicType) {
|
return false;
|
||||||
return p.isSameType(a);
|
|
||||||
} else if (p instanceof ICPPPointerToMemberType) {
|
|
||||||
if (!(a instanceof ICPPPointerToMemberType))
|
|
||||||
return false;
|
|
||||||
if (!deduceTemplateParameterMap(((ICPPPointerToMemberType) p).getMemberOfClass(), ((ICPPPointerToMemberType) a).getMemberOfClass(),
|
|
||||||
map)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
p = ((ICPPPointerToMemberType) p).getType();
|
|
||||||
a = ((ICPPPointerToMemberType) a).getType();
|
|
||||||
} else if (p instanceof IPointerType) {
|
|
||||||
if (!(a instanceof IPointerType)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
p = ((IPointerType) p).getType();
|
|
||||||
a = ((IPointerType) a).getType();
|
|
||||||
} else if (p instanceof IQualifierType) {
|
|
||||||
if (a instanceof IQualifierType) {
|
|
||||||
a = ((IQualifierType) a).getType(); //TODO a = strip qualifiers from p out of a
|
|
||||||
}
|
|
||||||
p = ((IQualifierType) p).getType();
|
|
||||||
} else if (p instanceof IFunctionType) {
|
|
||||||
if (!(a instanceof IFunctionType))
|
|
||||||
return false;
|
|
||||||
if (!deduceTemplateParameterMap(((IFunctionType) p).getReturnType(), ((IFunctionType) a).getReturnType(),
|
|
||||||
map)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
IType[] pParams = ((IFunctionType) p).getParameterTypes();
|
|
||||||
IType[] aParams = ((IFunctionType) a).getParameterTypes();
|
|
||||||
if (pParams.length != aParams.length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < pParams.length; i++) {
|
|
||||||
if (!deduceTemplateParameterMap(pParams[i], aParams[i], map))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (p instanceof ICPPTemplateParameter) {
|
|
||||||
ICPPTemplateArgument current= map.getArgument((ICPPTemplateParameter) p);
|
|
||||||
if (current != null) {
|
|
||||||
if (current.isNonTypeValue())
|
|
||||||
return false;
|
|
||||||
return current.getTypeValue().isSameType(a);
|
|
||||||
}
|
|
||||||
if (a == null)
|
|
||||||
return false;
|
|
||||||
map.put((ICPPTemplateParameter)p, new CPPTemplateArgument(a));
|
|
||||||
return true;
|
|
||||||
} else if (p instanceof ICPPTemplateInstance) {
|
|
||||||
if (!(a instanceof ICPPTemplateInstance))
|
|
||||||
return false;
|
|
||||||
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
|
|
||||||
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
|
|
||||||
|
|
||||||
ICPPTemplateArgument[] pArgs = pInst.getTemplateArguments();
|
|
||||||
pArgs= pArgs == null ? ICPPTemplateArgument.EMPTY_ARGUMENTS : pArgs; // aftodo - unnecessary?
|
|
||||||
|
|
||||||
ICPPTemplateParameterMap aMap = aInst.getTemplateParameterMap();
|
|
||||||
if (aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization)) {
|
|
||||||
ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
|
|
||||||
if (pArgs.length != aParams.length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < pArgs.length; i++) {
|
|
||||||
ICPPTemplateArgument t = aMap.getArgument(aParams[i]);
|
|
||||||
if (t == null || !deduceTemplateParameterMap(pArgs[i], t, map))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ICPPTemplateArgument[] aArgs = aInst.getTemplateArguments();
|
|
||||||
aArgs= aArgs == null ? ICPPTemplateArgument.EMPTY_ARGUMENTS : aArgs; // aftodo - unnecessary?
|
|
||||||
|
|
||||||
if (aArgs.length != pArgs.length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < pArgs.length; i++) {
|
|
||||||
if (!deduceTemplateParameterMap(pArgs[i], aArgs[i], map))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (p instanceof ICPPUnknownBinding) {
|
|
||||||
return true; // An unknown type may match anything.
|
|
||||||
} else {
|
|
||||||
return p.isSameType(a);
|
|
||||||
}
|
}
|
||||||
|
p = ((ICPPPointerToMemberType) p).getType();
|
||||||
|
a = ((ICPPPointerToMemberType) a).getType();
|
||||||
|
} else if (p instanceof IPointerType) {
|
||||||
|
if (!(a instanceof IPointerType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
p = ((IPointerType) p).getType();
|
||||||
|
a = ((IPointerType) a).getType();
|
||||||
|
} else if (p instanceof IQualifierType) {
|
||||||
|
if (a instanceof IQualifierType) {
|
||||||
|
a = ((IQualifierType) a).getType(); //TODO a = strip qualifiers from p out of a
|
||||||
|
}
|
||||||
|
p = ((IQualifierType) p).getType();
|
||||||
|
} else if (p instanceof IFunctionType) {
|
||||||
|
if (!(a instanceof IFunctionType))
|
||||||
|
return false;
|
||||||
|
if (!deduceTemplateParameterMap(((IFunctionType) p).getReturnType(), ((IFunctionType) a).getReturnType(),
|
||||||
|
map)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IType[] pParams = ((IFunctionType) p).getParameterTypes();
|
||||||
|
IType[] aParams = ((IFunctionType) a).getParameterTypes();
|
||||||
|
if (pParams.length != aParams.length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < pParams.length; i++) {
|
||||||
|
if (!deduceTemplateParameterMap(pParams[i], aParams[i], map))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (p instanceof ICPPTemplateParameter) {
|
||||||
|
ICPPTemplateArgument current= map.getArgument((ICPPTemplateParameter) p);
|
||||||
|
if (current != null) {
|
||||||
|
if (current.isNonTypeValue())
|
||||||
|
return false;
|
||||||
|
return current.getTypeValue().isSameType(a);
|
||||||
|
}
|
||||||
|
if (a == null)
|
||||||
|
return false;
|
||||||
|
map.put((ICPPTemplateParameter)p, new CPPTemplateArgument(a));
|
||||||
|
return true;
|
||||||
|
} else if (p instanceof ICPPTemplateInstance) {
|
||||||
|
if (!(a instanceof ICPPTemplateInstance))
|
||||||
|
return false;
|
||||||
|
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
|
||||||
|
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
|
||||||
|
|
||||||
|
ICPPTemplateArgument[] pArgs = pInst.getTemplateArguments();
|
||||||
|
pArgs= pArgs == null ? ICPPTemplateArgument.EMPTY_ARGUMENTS : pArgs; // aftodo - unnecessary?
|
||||||
|
|
||||||
|
ICPPTemplateParameterMap aMap = aInst.getTemplateParameterMap();
|
||||||
|
if (aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization)) {
|
||||||
|
ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
|
||||||
|
if (pArgs.length != aParams.length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < pArgs.length; i++) {
|
||||||
|
ICPPTemplateArgument t = aMap.getArgument(aParams[i]);
|
||||||
|
if (t == null || !deduceTemplateParameterMap(pArgs[i], t, map))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ICPPTemplateArgument[] aArgs = aInst.getTemplateArguments();
|
||||||
|
aArgs= aArgs == null ? ICPPTemplateArgument.EMPTY_ARGUMENTS : aArgs; // aftodo - unnecessary?
|
||||||
|
|
||||||
|
if (aArgs.length != pArgs.length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < pArgs.length; i++) {
|
||||||
|
if (!deduceTemplateParameterMap(pArgs[i], aArgs[i], map))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (p instanceof ICPPUnknownBinding) {
|
||||||
|
return true; // An unknown type may match anything.
|
||||||
|
} else {
|
||||||
|
return p.isSameType(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1754,24 +1654,17 @@ public class CPPTemplates {
|
||||||
* for each occurrence of that parameter in the function parameter list
|
* for each occurrence of that parameter in the function parameter list
|
||||||
* @throws DOMException
|
* @throws DOMException
|
||||||
*/
|
*/
|
||||||
static private IType[] createArgsForFunctionTemplateOrdering(ICPPFunctionTemplate template)
|
static private ICPPTemplateArgument[] createArgsForFunctionTemplateOrdering(ICPPFunctionTemplate template)
|
||||||
throws DOMException{
|
throws DOMException{
|
||||||
ICPPTemplateParameter[] paramList = template.getTemplateParameters();
|
ICPPTemplateParameter[] paramList = template.getTemplateParameters();
|
||||||
int size = paramList.length;
|
int size = paramList.length;
|
||||||
IType[] args = new IType[size];
|
ICPPTemplateArgument[] args = new ICPPTemplateArgument[size];
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
ICPPTemplateParameter param = paramList[i];
|
ICPPTemplateParameter param = paramList[i];
|
||||||
if (param instanceof ICPPTemplateNonTypeParameter) {
|
if (param instanceof ICPPTemplateNonTypeParameter) {
|
||||||
IType t = ((ICPPTemplateNonTypeParameter) param).getType();
|
args[i]= new CPPTemplateArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) param).getType());
|
||||||
if (t instanceof CPPBasicType) {
|
|
||||||
CPPASTLiteralExpression exp = new CPPASTLiteralExpression();
|
|
||||||
exp.setValue(String.valueOf(i));
|
|
||||||
CPPBasicType temp = (CPPBasicType) t.clone();
|
|
||||||
temp.setFromExpression(exp); // mstodo- is that necessary??
|
|
||||||
args[i] = temp;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
args[i] = new CPPBasicType(-1, 0);
|
args[i] = new CPPTemplateArgument(new CPPBasicType(-1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
|
@ -1784,14 +1677,14 @@ public class CPPTemplates {
|
||||||
CPPTemplateParameterMap m1= new CPPTemplateParameterMap(2);
|
CPPTemplateParameterMap m1= new CPPTemplateParameterMap(2);
|
||||||
CPPTemplateParameterMap m2= new CPPTemplateParameterMap(2);
|
CPPTemplateParameterMap m2= new CPPTemplateParameterMap(2);
|
||||||
|
|
||||||
IType[] args = createArgsForFunctionTemplateOrdering(f1);
|
ICPPTemplateArgument[] args = createArgsForFunctionTemplateOrdering(f1);
|
||||||
IBinding function = instantiate(f1, convert(args));
|
IBinding function = instantiate(f1, args);
|
||||||
if (function instanceof ICPPFunction)
|
if (function instanceof ICPPFunction)
|
||||||
if (!deduceTemplateParameterMapFromFunctionParameters(f2, ((ICPPFunction) function).getType().getParameterTypes(), m1))
|
if (!deduceTemplateParameterMapFromFunctionParameters(f2, ((ICPPFunction) function).getType().getParameterTypes(), m1))
|
||||||
m1= null;
|
m1= null;
|
||||||
|
|
||||||
args = createArgsForFunctionTemplateOrdering(f2);
|
args = createArgsForFunctionTemplateOrdering(f2);
|
||||||
function = instantiate(f2, convert(args));
|
function = instantiate(f2, args);
|
||||||
if (function instanceof ICPPFunction)
|
if (function instanceof ICPPFunction)
|
||||||
if (!deduceTemplateParameterMapFromFunctionParameters(f1, ((ICPPFunction) function).getType().getParameterTypes(), m2))
|
if (!deduceTemplateParameterMapFromFunctionParameters(f1, ((ICPPFunction) function).getType().getParameterTypes(), m2))
|
||||||
m2= null;
|
m2= null;
|
||||||
|
@ -1951,69 +1844,89 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private boolean isValidArgument(ICPPTemplateParameter param, IType argument) {
|
static private boolean isValidArgument(ICPPTemplateParameter param, ICPPTemplateArgument argument) {
|
||||||
|
IType t= argument.getTypeValue();
|
||||||
try {
|
try {
|
||||||
while (argument instanceof ITypeContainer) {
|
while (t instanceof ITypeContainer) {
|
||||||
argument = ((ITypeContainer) argument).getType();
|
t = ((ITypeContainer) t).getType();
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !(argument instanceof IProblemBinding);
|
return !(t instanceof IProblemBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected boolean matchTemplateParameterAndArgument(ICPPTemplateParameter param, IType argument,
|
static protected ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateParameter param,
|
||||||
CPPTemplateParameterMap map) {
|
ICPPTemplateArgument arg, CPPTemplateParameterMap map) {
|
||||||
if (!isValidArgument(param, argument)) {
|
if (arg == null || !isValidArgument(param, arg)) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
if (param instanceof ICPPTemplateTypeParameter) {
|
if (param instanceof ICPPTemplateTypeParameter) {
|
||||||
return true;
|
IType t= arg.getTypeValue();
|
||||||
|
if (t != null && ! (t instanceof ICPPTemplateDefinition))
|
||||||
|
return arg;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param instanceof ICPPTemplateTemplateParameter) {
|
if (param instanceof ICPPTemplateTemplateParameter) {
|
||||||
if (!(argument instanceof ICPPTemplateDefinition))
|
IType t= arg.getTypeValue();
|
||||||
return false;
|
if (!(t instanceof ICPPTemplateDefinition))
|
||||||
|
return null;
|
||||||
|
|
||||||
ICPPTemplateParameter[] pParams = null;
|
ICPPTemplateParameter[] pParams = null;
|
||||||
ICPPTemplateParameter[] aParams = null;
|
ICPPTemplateParameter[] aParams = null;
|
||||||
try {
|
try {
|
||||||
pParams = ((ICPPTemplateTemplateParameter) param).getTemplateParameters();
|
pParams = ((ICPPTemplateTemplateParameter) param).getTemplateParameters();
|
||||||
aParams = ((ICPPTemplateDefinition) argument).getTemplateParameters();
|
aParams = ((ICPPTemplateDefinition) t).getTemplateParameters();
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = pParams.length;
|
int size = pParams.length;
|
||||||
if (aParams.length != size) {
|
if (aParams.length != size) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if ((pParams[i] instanceof ICPPTemplateTypeParameter && !(aParams[i] instanceof ICPPTemplateTypeParameter)) ||
|
final ICPPTemplateParameter pParam = pParams[i];
|
||||||
(pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) ||
|
final ICPPTemplateParameter aParam = aParams[i];
|
||||||
(pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter))) {
|
boolean pb= pParam instanceof ICPPTemplateTypeParameter;
|
||||||
return false;
|
boolean ab= aParam instanceof ICPPTemplateTypeParameter;
|
||||||
|
if (pb != ab)
|
||||||
|
return null;
|
||||||
|
if (!pb) {
|
||||||
|
pb= pParam instanceof ICPPTemplateNonTypeParameter;
|
||||||
|
ab= aParam instanceof ICPPTemplateNonTypeParameter;
|
||||||
|
if (pb != ab)
|
||||||
|
return null;
|
||||||
|
assert pParam instanceof ICPPTemplateTemplateParameter; // no other choice left
|
||||||
|
assert aParam instanceof ICPPTemplateTemplateParameter; // no other choice left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param instanceof ICPPTemplateNonTypeParameter) {
|
if (param instanceof ICPPTemplateNonTypeParameter) {
|
||||||
|
if (!arg.isNonTypeValue())
|
||||||
|
return null;
|
||||||
|
IType argType= arg.getTypeOfNonTypeValue();
|
||||||
try {
|
try {
|
||||||
IType pType = ((ICPPTemplateNonTypeParameter) param).getType();
|
IType pType = ((ICPPTemplateNonTypeParameter) param).getType();
|
||||||
if (map != null && pType != null) {
|
if (map != null && pType != null) {
|
||||||
pType= instantiateType(pType, map, null);
|
pType= instantiateType(pType, map, null);
|
||||||
}
|
}
|
||||||
if (!isNonTypeArgumentConvertible(pType, argument)) {
|
if (isNonTypeArgumentConvertible(pType, argType)) {
|
||||||
return false;
|
return new CPPTemplateArgument(arg.getNonTypeValue(), pType);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
assert false;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2043,8 +1956,7 @@ public class CPPTemplates {
|
||||||
if (arg.isTypeValue())
|
if (arg.isTypeValue())
|
||||||
return isDependentType(arg.getTypeValue());
|
return isDependentType(arg.getTypeValue());
|
||||||
|
|
||||||
// mstodo dependent values
|
return Value.isDependentValue(arg.getNonTypeValue());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public static boolean isDependentType(IType t) {
|
public static boolean isDependentType(IType t) {
|
||||||
// mstodo needs to be extended
|
// mstodo needs to be extended
|
||||||
|
@ -2087,7 +1999,7 @@ public class CPPTemplates {
|
||||||
if (unknown instanceof ICPPUnknownClassInstance) {
|
if (unknown instanceof ICPPUnknownClassInstance) {
|
||||||
ICPPUnknownClassInstance ucli= (ICPPUnknownClassInstance) unknown;
|
ICPPUnknownClassInstance ucli= (ICPPUnknownClassInstance) unknown;
|
||||||
final ICPPTemplateArgument[] arguments = ucli.getArguments();
|
final ICPPTemplateArgument[] arguments = ucli.getArguments();
|
||||||
ICPPTemplateArgument[] newArgs = convert(CPPTemplates.instantiateTypes(getArguments(arguments), tpMap, within));
|
ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments(arguments, tpMap, within);
|
||||||
if (!t.equals(owner) && newArgs != arguments) {
|
if (!t.equals(owner) && newArgs != arguments) {
|
||||||
result= new CPPUnknownClassInstance((ICPPUnknownBinding) t, ucli.getUnknownName(), newArgs);
|
result= new CPPUnknownClassInstance((ICPPUnknownBinding) t, ucli.getUnknownName(), newArgs);
|
||||||
}
|
}
|
||||||
|
@ -2113,8 +2025,8 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) {
|
if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) {
|
||||||
IType[] newArgs = CPPTemplates.instantiateTypes(getArguments(((ICPPUnknownClassInstance) unknown).getArguments()), tpMap, within);
|
ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments(((ICPPUnknownClassInstance) unknown).getArguments(), tpMap, within);
|
||||||
result = instantiate((ICPPTemplateDefinition) result, convert(newArgs));
|
result = instantiate((ICPPTemplateDefinition) result, newArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2158,21 +2070,13 @@ public class CPPTemplates {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < m1.length; i++) {
|
for (int i = 0; i < m1.length; i++) {
|
||||||
if (!isSameTemplateArgument(m1[i], m2[i]))
|
if (!m1[i].isSameValue(m2[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSameTemplateArgument(final ICPPTemplateArgument a1, final ICPPTemplateArgument a2) {
|
|
||||||
// backwards compatibility, mstodo remove
|
|
||||||
if (a1.isTypeValue() && a2.isTypeValue())
|
|
||||||
return isSameTemplateArgument(a1.getTypeValue(), a2.getTypeValue());
|
|
||||||
|
|
||||||
return a1.isSameValue(a2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ICPPTemplateParameterMap createParameterMap(ICPPTemplateDefinition tdef, ICPPTemplateArgument[] args) {
|
public static ICPPTemplateParameterMap createParameterMap(ICPPTemplateDefinition tdef, ICPPTemplateArgument[] args) {
|
||||||
try {
|
try {
|
||||||
ICPPTemplateParameter[] tpars= tdef.getTemplateParameters();
|
ICPPTemplateParameter[] tpars= tdef.getTemplateParameters();
|
||||||
|
@ -2194,26 +2098,18 @@ public class CPPTemplates {
|
||||||
public static IType[] getArguments(ICPPTemplateArgument[] arguments) {
|
public static IType[] getArguments(ICPPTemplateArgument[] arguments) {
|
||||||
IType[] types= new IType[arguments.length];
|
IType[] types= new IType[arguments.length];
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
types[i]= getArgument(arguments[i]);
|
final ICPPTemplateArgument arg= arguments[i];
|
||||||
|
if (arg == null) {
|
||||||
|
types[i]= null;
|
||||||
|
} else if (arg.isNonTypeValue()) {
|
||||||
|
types[i]= arg.getTypeOfNonTypeValue();
|
||||||
|
} else {
|
||||||
|
types[i]= arg.getTypeValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated for backwards compatibility, only.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static IType getArgument(ICPPTemplateArgument arg) {
|
|
||||||
if (arg == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (arg.isNonTypeValue()) {
|
|
||||||
return arg.getTypeOfNonTypeValue();
|
|
||||||
}
|
|
||||||
return arg.getTypeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated for backwards compatibility, only.
|
* @deprecated for backwards compatibility, only.
|
||||||
*/
|
*/
|
||||||
|
@ -2257,45 +2153,4 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
return ObjectMap.EMPTY_MAP;
|
return ObjectMap.EMPTY_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* mstodo for intermediate use only.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static CPPTemplateParameterMap convert(ObjectMap tpMap) {
|
|
||||||
CPPTemplateParameterMap tpmap= new CPPTemplateParameterMap(tpMap.size());
|
|
||||||
Object[] tps= tpMap.keyArray();
|
|
||||||
for (Object tp : tps) {
|
|
||||||
if (tp instanceof ICPPTemplateParameter) {
|
|
||||||
IType t= (IType) tpMap.get(tp);
|
|
||||||
tpmap.put((ICPPTemplateParameter) tp, new CPPTemplateArgument(t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tpmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mstodo for intermediate use only.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static ICPPTemplateArgument[] convert(IType[] args) {
|
|
||||||
ICPPTemplateArgument[] targs= new ICPPTemplateArgument[args.length];
|
|
||||||
for (int i = 0; i < targs.length; i++) {
|
|
||||||
targs[i]= convert(args[i]);
|
|
||||||
}
|
|
||||||
return targs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mstodo for intermediate use only.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private static CPPTemplateArgument convert(IType arg) {
|
|
||||||
if (arg == null)
|
|
||||||
return null;
|
|
||||||
return new CPPTemplateArgument(arg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType;
|
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType;
|
||||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers;
|
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
@ -139,14 +136,12 @@ 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.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
|
@ -1590,17 +1585,6 @@ public class CPPVisitor {
|
||||||
if (nested != null) {
|
if (nested != null) {
|
||||||
return createType(type, nested);
|
return createType(type, nested);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently, CPPBasicType objects are also used to represent non-type template argument
|
|
||||||
// values. We must ensure the initializer expression is attached to the type if available.
|
|
||||||
// mstodo- can be removed
|
|
||||||
if (declarator.getInitializer() instanceof IASTInitializerExpression) {
|
|
||||||
IType utype= getUltimateTypeUptoPointers(baseType);
|
|
||||||
if (utype instanceof CPPBasicType) {
|
|
||||||
((CPPBasicType)utype).setFromExpression(((IASTInitializerExpression) declarator.getInitializer()).getExpression());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2336,89 +2320,6 @@ public class CPPVisitor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integral
|
|
||||||
* @return the (non-null) integer value of the specified literal
|
|
||||||
* @throws NumberFormatException
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Currently unsigned (U,u) is stripped and ignored.
|
|
||||||
*/
|
|
||||||
public static BigInteger parseIntegral(String integral) {
|
|
||||||
int radix= 10;
|
|
||||||
if (integral.length() == 3
|
|
||||||
&& integral.charAt(0) == '\''
|
|
||||||
&& integral.charAt(2) == '\'') {
|
|
||||||
String lo= Long.toString(Character.getNumericValue(integral.charAt(1)));
|
|
||||||
return new BigInteger(lo);
|
|
||||||
} else if (Keywords.TRUE.equals(integral)) {
|
|
||||||
return BigInteger.ONE;
|
|
||||||
} else if (Keywords.FALSE.equals(integral)) {
|
|
||||||
return BigInteger.ZERO;
|
|
||||||
}
|
|
||||||
|
|
||||||
int start=0;
|
|
||||||
int end= integral.length();
|
|
||||||
|
|
||||||
boolean negate= integral.charAt(start) == '-';
|
|
||||||
if (negate || integral.charAt(start) == '+') {
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start < integral.length() && integral.charAt(start) == '0') {
|
|
||||||
if (start + 1 < integral.length()) {
|
|
||||||
if (integral.charAt(start + 1) == 'x') {
|
|
||||||
start += 2;
|
|
||||||
radix= 16;
|
|
||||||
} else {
|
|
||||||
radix= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (end--; end > 0; end--) {
|
|
||||||
final char c= integral.charAt(end);
|
|
||||||
if (c != 'L' && c!='l' && c!='U' && c!='u') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
integral= integral.substring(start, end+1);
|
|
||||||
|
|
||||||
BigInteger result= new BigInteger(integral, radix);
|
|
||||||
return negate ? result.negate() : result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param e1
|
|
||||||
* @return the first non id-expression by following values assigned to basic types.
|
|
||||||
* @deprecated mstodo- remove
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static final IASTExpression reverseConstantPropagationLookup(IASTExpression e1) {
|
|
||||||
try {
|
|
||||||
for (int i= 0; e1 instanceof IASTIdExpression && i < 8; i++) {
|
|
||||||
IBinding b1= ((IASTIdExpression)e1).getName().resolveBinding();
|
|
||||||
if (b1 instanceof ICPPVariable) {
|
|
||||||
ICPPVariable var= (ICPPVariable) b1;
|
|
||||||
IType t1= SemanticUtil.getUltimateTypeViaTypedefs(var.getType());
|
|
||||||
if (t1 instanceof IQualifierType) {
|
|
||||||
IQualifierType qt= (IQualifierType) t1;
|
|
||||||
if (qt.isConst()) {
|
|
||||||
t1= SemanticUtil.getUltimateTypeViaTypedefs(qt.getType());
|
|
||||||
if (t1 instanceof ICPPBasicType) {
|
|
||||||
e1= ((ICPPBasicType) t1).getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (DOMException de) {
|
|
||||||
CCorePlugin.log(de);
|
|
||||||
}
|
|
||||||
return e1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the outermost declarator the given <code>declarator</code> nests within, or
|
* Returns the outermost declarator the given <code>declarator</code> nests within, or
|
||||||
* <code>declarator</code> itself.
|
* <code>declarator</code> itself.
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
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.ICPPTemplateTypeParameter;
|
||||||
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.Value;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||||
|
@ -742,17 +743,11 @@ public class Conversions {
|
||||||
if (src instanceof CPPBasicType && trg instanceof IPointerType) {
|
if (src instanceof CPPBasicType && trg instanceof IPointerType) {
|
||||||
//4.10-1 an integral constant expression of integer type that evaluates to 0 can be converted to a pointer type
|
//4.10-1 an integral constant expression of integer type that evaluates to 0 can be converted to a pointer type
|
||||||
IASTExpression exp = ((CPPBasicType)src).getCreatedFromExpression();
|
IASTExpression exp = ((CPPBasicType)src).getCreatedFromExpression();
|
||||||
// mstodo- improve by checking evaluation
|
if (exp != null) {
|
||||||
if (exp instanceof IASTLiteralExpression &&
|
Long val= Value.create(exp, Value.MAX_RECURSION_DEPTH).numericalValue();
|
||||||
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant) {
|
if (val != null && val == 0) {
|
||||||
try {
|
cost.rank = Cost.CONVERSION_RANK;
|
||||||
String val = exp.toString().toLowerCase().replace('u', '0');
|
cost.conversion = 1;
|
||||||
val.replace('l', '0');
|
|
||||||
if (Integer.decode(val).intValue() == 0) {
|
|
||||||
cost.rank = Cost.CONVERSION_RANK;
|
|
||||||
cost.conversion = 1;
|
|
||||||
}
|
|
||||||
} catch(NumberFormatException e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sPrev instanceof IPointerType) {
|
} else if (sPrev instanceof IPointerType) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.index;
|
package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,19 +19,15 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
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.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,14 +101,6 @@ public class IndexCPPSignatureUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.append(((ICPPTemplateParameter)type).getName());
|
buffer.append(((ICPPTemplateParameter)type).getName());
|
||||||
} else if (type instanceof ICPPBasicType){
|
|
||||||
// mstodo remove
|
|
||||||
IASTExpression expr= ((ICPPBasicType) type).getValue();
|
|
||||||
if (expr != null) {
|
|
||||||
buffer.append(getValueString(expr));
|
|
||||||
} else {
|
|
||||||
buffer.append(ASTTypeUtil.getType(type));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
buffer.append(ASTTypeUtil.getType(type));
|
buffer.append(ASTTypeUtil.getType(type));
|
||||||
}
|
}
|
||||||
|
@ -123,24 +110,6 @@ public class IndexCPPSignatureUtil {
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getValueString(IASTExpression e) {
|
|
||||||
e= CPPVisitor.reverseConstantPropagationLookup(e);
|
|
||||||
if (e instanceof IASTLiteralExpression) {
|
|
||||||
IType t1= e.getExpressionType();
|
|
||||||
try {
|
|
||||||
if(t1 instanceof ICPPBasicType) {
|
|
||||||
BigInteger i1= CPPVisitor.parseIntegral(e.toString());
|
|
||||||
return i1.toString();
|
|
||||||
}
|
|
||||||
} catch(NumberFormatException nfe) {
|
|
||||||
/* fall through */
|
|
||||||
}
|
|
||||||
return e.toString();
|
|
||||||
}
|
|
||||||
return "?"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void appendTemplateArgs(ICPPTemplateArgument[] values, StringBuilder buffer) {
|
private static void appendTemplateArgs(ICPPTemplateArgument[] values, StringBuilder buffer) {
|
||||||
boolean needcomma= false;
|
boolean needcomma= false;
|
||||||
buffer.append('<');
|
buffer.append('<');
|
||||||
|
|
|
@ -377,7 +377,7 @@ public class ExpressionEvaluator {
|
||||||
return getNumber(image, 0, image.length, 10, IProblem.SCANNER_BAD_DECIMAL_FORMAT);
|
return getNumber(image, 0, image.length, 10, IProblem.SCANNER_BAD_DECIMAL_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getChar(char[] tokenImage, int i) throws EvalException {
|
public static long getChar(char[] tokenImage, int i) throws EvalException {
|
||||||
if (i>=tokenImage.length) {
|
if (i>=tokenImage.length) {
|
||||||
throw new EvalException(IProblem.SCANNER_BAD_CHARACTER, tokenImage);
|
throw new EvalException(IProblem.SCANNER_BAD_CHARACTER, tokenImage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,10 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
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.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
@ -39,11 +34,9 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
|
||||||
|
|
||||||
private static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
|
private static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
|
||||||
private static final int QUALIFIER_FLAGS = PDOMNode.RECORD_SIZE + 2; // short
|
private static final int QUALIFIER_FLAGS = PDOMNode.RECORD_SIZE + 2; // short
|
||||||
private static final int INTEGRAL = PDOMNode.RECORD_SIZE + 4; // int
|
|
||||||
private static final int INTERNAL_FLAGS = PDOMNode.RECORD_SIZE + 8; // byte
|
|
||||||
|
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 9;
|
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||||
|
|
||||||
protected short fFlags= -1;
|
protected short fFlags= -1;
|
||||||
|
|
||||||
|
@ -61,19 +54,6 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
|
||||||
fFlags= flags;
|
fFlags= flags;
|
||||||
Database db = pdom.getDB();
|
Database db = pdom.getDB();
|
||||||
db.putShort(record + TYPE_ID, getTypeCode(type));
|
db.putShort(record + TYPE_ID, getTypeCode(type));
|
||||||
try {
|
|
||||||
if(type.getValue() != null) {
|
|
||||||
IASTExpression e= CPPVisitor.reverseConstantPropagationLookup(type.getValue());
|
|
||||||
if(e != null) {
|
|
||||||
db.putInt(record + INTEGRAL, CPPVisitor.parseIntegral(e.toString()).intValue());
|
|
||||||
db.putByte(record + INTERNAL_FLAGS, (byte)1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(DOMException de) {
|
|
||||||
CCorePlugin.log(de);
|
|
||||||
} catch(NumberFormatException nfe) {
|
|
||||||
/* fall-through */
|
|
||||||
}
|
|
||||||
db.putShort(record + QUALIFIER_FLAGS, flags);
|
db.putShort(record + QUALIFIER_FLAGS, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,31 +103,6 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public IASTExpression getValue() throws DOMException {
|
public IASTExpression getValue() throws DOMException {
|
||||||
// mstodo remove implementation
|
|
||||||
try {
|
|
||||||
/*
|
|
||||||
* If the expression was an integral we can emulate what would
|
|
||||||
* have been returned in a limited way.
|
|
||||||
*/
|
|
||||||
if(pdom.getDB().getByte(record + INTERNAL_FLAGS) != 0) {
|
|
||||||
int integral= pdom.getDB().getInt(record + INTEGRAL);
|
|
||||||
String literal= Integer.toString(integral);
|
|
||||||
int type= getType();
|
|
||||||
if(type == t_char) {
|
|
||||||
return new CPPASTLiteralExpression(IASTLiteralExpression.lk_char_constant, literal);
|
|
||||||
} else if(type == t_int) {
|
|
||||||
return new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, literal);
|
|
||||||
} else if(type == t_bool) {
|
|
||||||
if(integral == 0) {
|
|
||||||
return new CPPASTLiteralExpression(ICPPASTLiteralExpression.lk_false, Keywords.FALSE);
|
|
||||||
} else {
|
|
||||||
return new CPPASTLiteralExpression(ICPPASTLiteralExpression.lk_true, Keywords.TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(CoreException ce) {
|
|
||||||
CCorePlugin.log(ce);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,24 +18,16 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
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.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
|
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
|
@ -45,7 +37,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* @author Bryan Wilkinson
|
* @author Bryan Wilkinson
|
||||||
*/
|
*/
|
||||||
class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
||||||
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, IIndexScope {
|
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner {
|
||||||
|
|
||||||
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE + 0;
|
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE + 0;
|
||||||
|
|
||||||
|
@ -64,10 +56,6 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
||||||
super(pdom, bindingRecord);
|
super(pdom, bindingRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EScopeKind getKind() {
|
|
||||||
return EScopeKind.eLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(PDOMLinkage linkage, IBinding name) {
|
public void update(PDOMLinkage linkage, IBinding name) {
|
||||||
// no support for updating templates, yet.
|
// no support for updating templates, yet.
|
||||||
|
@ -125,45 +113,6 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
||||||
list.accept(visitor);
|
list.accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding[] find(String name) throws DOMException {
|
|
||||||
return CPPSemantics.findBindings( this, name, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
|
|
||||||
throws DOMException {
|
|
||||||
try {
|
|
||||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
|
|
||||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl());
|
|
||||||
list.accept(visitor);
|
|
||||||
|
|
||||||
return CPPSemantics.resolveAmbiguities(name, visitor.getBindings());
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
|
|
||||||
throws DOMException {
|
|
||||||
IBinding[] result = null;
|
|
||||||
try {
|
|
||||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null,
|
|
||||||
prefixLookup, !prefixLookup);
|
|
||||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl());
|
|
||||||
list.accept(visitor);
|
|
||||||
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IIndexBinding getScopeBinding() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) {
|
public ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) {
|
||||||
return PDOMInstanceCache.getCache(this).getInstance(arguments);
|
return PDOMInstanceCache.getCache(this).getInstance(arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
|
@ -104,7 +103,7 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i= 0; i < lhsArgs.length; i++) {
|
for (int i= 0; i < lhsArgs.length; i++) {
|
||||||
if (!CPPTemplates.isSameTemplateArgument(lhsArgs[i], rhsArgs[i]))
|
if (!lhsArgs[i].isSameValue(rhsArgs[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue