mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Templates.
- better handling of specializations - argument deduction, ranking of specializations and overloaded function templates - this fixes or addresses part of bugs 90682, 90684, 90668, 90686, 90672, 90678
This commit is contained in:
parent
365b5f320c
commit
7d7fa374bf
44 changed files with 4075 additions and 1275 deletions
|
@ -35,7 +35,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("#define arraycheck(a,b) a[b] || b[a]\n"); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// D()’s implicit definition\n"); //$NON-NLS-1$
|
||||
buffer.append("// violates the ODR\n"); //$NON-NLS-1$
|
||||
try{
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("typedef I I; // error, even though no reordering involved\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("friend void A::f2(BT); // parameter type is B::BT\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// equivalent to: ::X C::arr[C::number];\n"); //$NON-NLS-1$
|
||||
buffer.append("// not to: C::X C::arr[C::number];\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("extern int h;\n"); //$NON-NLS-1$
|
||||
buffer.append("T(g)(h,2); //declaration\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("struct x x1; // x1 has class type B::x\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("new (int(*[x])); // new typeid\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, false);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("S<int()> x; // typeid\n"); //$NON-NLS-1$
|
||||
buffer.append("S<int(1)> y; // expression (illformed)\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(g); //OK\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("int b = f(a);\n"); //$NON-NLS-1$
|
||||
buffer.append("int c(b);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("char msg[] = \"Syntax error on line %s\n\";\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("ra[1] = i; // modifies a[1]\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// ...\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// no ambiguity because U::i is static\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("return *this;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("{ }\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -655,36 +655,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("(int (*)(int))&f; // cast expression as selector\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, false);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.1-8):
|
||||
template<int *a> struct R { };
|
||||
template<int b[5]> struct S { };
|
||||
int *p;
|
||||
R<p> w; // OK
|
||||
S<p> x; // OK due to parameter adjustment
|
||||
int v[5];
|
||||
R<v> y; // OK due to implicit argument conversion
|
||||
S<v> z; // OK due to both adjustment and conversion
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_1s8() { // TODO raised bug 90668
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<int *a> struct R { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<int b[5]> struct S { };\n"); //$NON-NLS-1$
|
||||
buffer.append("int *p;\n"); //$NON-NLS-1$
|
||||
buffer.append("R<p> w; // OK\n"); //$NON-NLS-1$
|
||||
buffer.append("S<p> x; // OK due to parameter adjustment\n"); //$NON-NLS-1$
|
||||
buffer.append("int v[5];\n"); //$NON-NLS-1$
|
||||
buffer.append("R<v> y; // OK due to implicit argument conversion\n"); //$NON-NLS-1$
|
||||
buffer.append("S<v> z; // OK due to both adjustment and conversion\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -701,7 +672,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template<class T, T* p, class U = T> class X { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void f(T* p = new T);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -726,34 +697,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f<int()>(); // int() is a typeid:call the first f()\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.3-5):
|
||||
template<class T> struct A {
|
||||
~A();
|
||||
};
|
||||
void f(A<int>* p, A<int>* q) {
|
||||
p->A<int>::~A(); // OK: destructor call
|
||||
q->A<int>::~A<int>(); // OK: destructor call
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_3s5() { // TODO raised bug 90672
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("~A();\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(A<int>* p, A<int>* q) {\n"); //$NON-NLS-1$
|
||||
buffer.append("p->A<int>::~A(); // OK: destructor call\n"); //$NON-NLS-1$
|
||||
buffer.append("q->A<int>::~A<int>(); // OK: destructor call\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -794,12 +738,47 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template<void (*pf)(int)> struct A { };\n"); //$NON-NLS-1$
|
||||
buffer.append("A<&f> a; // selects f(int)\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.2-2):
|
||||
template <class T> struct A {
|
||||
void f(int);
|
||||
template <class T2> void f(T2);
|
||||
};
|
||||
template <> void A<int>::f(int) { } // nontemplate member
|
||||
template <> template <> void A<int>::f<>(int) { } // template member
|
||||
int main()
|
||||
{
|
||||
A<char> ac;
|
||||
ac.f(1); //nontemplate
|
||||
ac.f('c'); //template
|
||||
ac.f<>(1); //template
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_2s2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template <class T> struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append("template <class T2> void f(T2);\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("template <> void A<int>::f(int) { } // nontemplate member\n"); //$NON-NLS-1$
|
||||
buffer.append("template <> template <> void A<int>::f<>(int) { } // template member\n"); //$NON-NLS-1$
|
||||
buffer.append("int main()\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("A<char> ac;\n"); //$NON-NLS-1$
|
||||
buffer.append("ac.f(1); //nontemplate\n"); //$NON-NLS-1$
|
||||
buffer.append("ac.f('c'); //template\n"); //$NON-NLS-1$
|
||||
buffer.append("ac.f<>(1); //template\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 2); //should be 0
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.3-1):
|
||||
template<class T> class task;
|
||||
|
@ -831,67 +810,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// ...\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.3-6):
|
||||
template<class T> struct A {
|
||||
struct B { };
|
||||
void f();
|
||||
};
|
||||
class C {
|
||||
template<class T> friend struct A<T>::B;
|
||||
template<class T> friend void A<T>::f();
|
||||
};
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_3s6() { // TODO raised bug 90678
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("struct B { };\n"); //$NON-NLS-1$
|
||||
buffer.append("void f();\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class C {\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> friend struct A<T>::B;\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> friend void A<T>::f();\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.4-6):
|
||||
template<class T> struct A {
|
||||
class C {
|
||||
template<class T2> struct B { };
|
||||
};
|
||||
};
|
||||
// partial specialization of A<T>::C::B<T2>
|
||||
template<class T> template<class T2>
|
||||
struct A<T>::C::B<T2*> { };
|
||||
A<short>::C::B<int*> absip; // uses partial specialization
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_4s6() { // TODO raised bug 90678
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("class C {\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T2> struct B { };\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("// partial specialization of A<T>::C::B<T2>\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> template<class T2>\n"); //$NON-NLS-1$
|
||||
buffer.append("struct A<T>::C::B<T2*> { };\n"); //$NON-NLS-1$
|
||||
buffer.append("A<short>::C::B<int*> absip; // uses partial specialization\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -922,12 +841,31 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("A<int,int*> a; // uses the partial specialization, which is found through\n"); //$NON-NLS-1$
|
||||
buffer.append("// the using declaration which refers to the primary template\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.4.2-2):
|
||||
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
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_4_2s2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<int I, int J, class T> class X { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<int I, int J> class X<I, J, int> { }; // #1\n"); //$NON-NLS-1$
|
||||
buffer.append("template<int I> class X<I, I, int> { }; // #2\n"); //$NON-NLS-1$
|
||||
buffer.append("template<int I, int J> void f(X<I, J, int>); // #A\n"); //$NON-NLS-1$
|
||||
buffer.append("template<int I> void f(X<I, I, int>); // #B\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.4.3-2):
|
||||
template<class T> struct A {
|
||||
|
@ -951,48 +889,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("A<short>::B<int*> absip; // uses #3\n"); //$NON-NLS-1$
|
||||
buffer.append("A<char>::B<int> abci; // uses #1\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.5.1-1):
|
||||
// file1.c
|
||||
template<class T>
|
||||
void f(T*);
|
||||
void g(int* p) {
|
||||
f(p); // call
|
||||
// f<int>(int*)
|
||||
}
|
||||
// file2.c
|
||||
template<class T>
|
||||
void f(T);
|
||||
void h(int* p) {
|
||||
f(p); // call
|
||||
// f<int*>(int*)
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_5_1s1() { // TODO raised bug 90682
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("// file1.c \n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T>\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(T*);\n"); //$NON-NLS-1$
|
||||
buffer.append("void g(int* p) { \n"); //$NON-NLS-1$
|
||||
buffer.append("f(p); // call \n"); //$NON-NLS-1$
|
||||
buffer.append("// f<int>(int*) \n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("// file2.c\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T>\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(T);\n"); //$NON-NLS-1$
|
||||
buffer.append("void h(int* p) {\n"); //$NON-NLS-1$
|
||||
buffer.append("f(p); // call\n"); //$NON-NLS-1$
|
||||
buffer.append("// f<int*>(int*)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1011,7 +908,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1\n"); //$NON-NLS-1$
|
||||
buffer.append("template <int I, int J> A<IJ> f(A<I>, A<J>); // different from #1\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1028,61 +925,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template <int I, int J> void f(A<I+J>); // #1\n"); //$NON-NLS-1$
|
||||
buffer.append("template <int K, int L> void f(A<K+L>); // same as #1\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.5.5.2-6):
|
||||
template<class T> void f(T); // #1
|
||||
template<class T> void f(T*, int=1); // #2
|
||||
template<class T> void g(T); // #3
|
||||
template<class T> void g(T*, ...); // #4
|
||||
int main() {
|
||||
int* ip;
|
||||
f(ip); //calls #2
|
||||
g(ip); //calls #4
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_5_5_2s6() { // TODO raised bug 90684
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T); // #1\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void f(T*, int=1); // #2\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void g(T); // #3\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void g(T*, ...); // #4\n"); //$NON-NLS-1$
|
||||
buffer.append("int main() {\n"); //$NON-NLS-1$
|
||||
buffer.append("int* ip;\n"); //$NON-NLS-1$
|
||||
buffer.append("f(ip); //calls #2\n"); //$NON-NLS-1$
|
||||
buffer.append("g(ip); //calls #4\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.6.1-1):
|
||||
template<class T> class X {
|
||||
X* p; // meaning X<T>
|
||||
X<T>* p2;
|
||||
X<int>* p3;
|
||||
};
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_6_1s1() { // TODO can not reproduce IProblemBinding via DOMAST View
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> class X {\n"); //$NON-NLS-1$
|
||||
buffer.append("X* p; // meaning X<T>\n"); //$NON-NLS-1$
|
||||
buffer.append("X<T>* p2;\n"); //$NON-NLS-1$
|
||||
buffer.append("X<int>* p3;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1099,7 +942,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template<class T, T* p, class U = T> class X { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void f(T* p = new T);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1121,7 +964,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
public void test14_6_1s6() { // TODO raised bug 90686
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("namespace N {\n"); //$NON-NLS-1$
|
||||
buffer.append("class C { };\n"); //$NON-NLS-1$
|
||||
buffer.append("int C;\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> class B {\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(T);\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
|
@ -1130,7 +973,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("C b; // C is the template parameter, not N::C\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1157,12 +1000,49 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("A a; // a has type double\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.7-3):
|
||||
template<class T = int> struct A {
|
||||
static int x;
|
||||
};
|
||||
template<class U> void g(U) { }
|
||||
template<> struct A<double> { }; // specialize for T == double
|
||||
template<> struct A<> { }; // specialize for T == int
|
||||
template<> void g(char) { } // specialize for U == char
|
||||
// U is deduced from the parameter type
|
||||
template<> void g<int>(int) { } // specialize for U == int
|
||||
template<> int A<char>::x = 0; // specialize for T == char
|
||||
template<class T = int> struct B {
|
||||
static int x;
|
||||
};
|
||||
template<> int B<>::x = 1; // specialize for T == int
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_7s3() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T = int> struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("static int x;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class U> void g(U) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> struct A<double> { }; // specialize for T == double\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> struct A<> { }; // specialize for T == int\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> void g(char) { } // specialize for U == char\n"); //$NON-NLS-1$
|
||||
buffer.append("// U is deduced from the parameter type\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> void g<int>(int) { } // specialize for U == int\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> int A<char>::x = 0; // specialize for T == char\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T = int> struct B {\n"); //$NON-NLS-1$
|
||||
buffer.append("static int x;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> int B<>::x = 1; // specialize for T == int\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.7.1-5):
|
||||
template <class T> struct S {
|
||||
|
@ -1190,35 +1070,37 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// instantiation of S<float> allowed but not required\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.7.1-14):
|
||||
template<class T> class X {
|
||||
X<T>* p; // OK
|
||||
X<T*> a; // implicit generation of X<T> requires
|
||||
// the implicit instantiation of X<T*> which requires
|
||||
// the implicit instantiation of X<T**> which ...
|
||||
};
|
||||
[--Start Example(CPP 14.7.2-2):
|
||||
template<class T> class Array { void mf(); };
|
||||
template class Array<char>;
|
||||
template void Array<int>::mf();
|
||||
template<class T> void sort(Array<T>& v) { }
|
||||
template void sort(Array<char>&); // argument is deduced here
|
||||
namespace N {
|
||||
template<class T> void f(T&) { }
|
||||
}
|
||||
template void N::f<int>(int&);
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_7_1s14() { // TODO can't reproduce via DOMAST View
|
||||
public void test14_7_2s2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> class X {\n"); //$NON-NLS-1$
|
||||
buffer.append("X<T>* p; // OK\n"); //$NON-NLS-1$
|
||||
buffer.append("X<T*> a; // implicit generation of X<T> requires\n"); //$NON-NLS-1$
|
||||
buffer.append("// the implicit instantiation of X<T*> which requires\n"); //$NON-NLS-1$
|
||||
buffer.append("// the implicit instantiation of X<T**> which ...\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
buffer.append("template<class T> class Array { void mf(); };\n"); //$NON-NLS-1$
|
||||
buffer.append("template class Array<char>;\n"); //$NON-NLS-1$
|
||||
buffer.append("template void Array<int>::mf();\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void sort(Array<T>& v) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("template void sort(Array<char>&); // argument is deduced here\n"); //$NON-NLS-1$
|
||||
buffer.append("namespace N {\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void f(T&) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("template void N::f<int>(int&);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1236,7 +1118,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// instantiate sort(Array<int>&) - templateargument deduced\n"); //$NON-NLS-1$
|
||||
buffer.append("template void sort<>(Array<int>&);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1259,31 +1141,30 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template<class T> void sort(Array<T>& v) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> void sort<char*>(Array<char*>&) ;\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.7.3-14):
|
||||
template<class T> void f(T) { }
|
||||
template<class T> inline T g(T) { }
|
||||
template<> inline void f<>(int) { } // OK: inline
|
||||
template<> int g<>(int) { } // OK: not inline
|
||||
[--Start Example(CPP 14.7.3-11):
|
||||
template<class T> class Array { };
|
||||
template<class T> void sort(Array<T>& v);
|
||||
// explicit specialization for sort(Array<int>&)
|
||||
// with deduces templateargument of type int
|
||||
template<> void sort(Array<int>&);
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_7_3s14() { // TODO similar bug already
|
||||
public void test14_7_3s11() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> inline T g(T) { }\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> inline void f<>(int) { } // OK: inline\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> int g<>(int) { } // OK: not inline\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
buffer.append("template<class T> class Array { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void sort(Array<T>& v);\n"); //$NON-NLS-1$
|
||||
buffer.append("// explicit specialization for sort(Array<int>&)\n"); //$NON-NLS-1$
|
||||
buffer.append("// with deduces templateargument of type int\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> void sort(Array<int>&);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1329,7 +1210,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// member specialization even if defined in class definition\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> void A<int>::h(int) { }\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1356,40 +1237,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template<> template<> A<int>::B<double> { };\n"); //$NON-NLS-1$
|
||||
buffer.append("template<> template<> void A<char>::B<char>::mf() { };\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.8-2):
|
||||
template<class T> void f(T* p)
|
||||
{
|
||||
static T s;
|
||||
// ...
|
||||
};
|
||||
void g(int a, char* b)
|
||||
{
|
||||
f(&a); //call f<int>(int*)
|
||||
f(&b); //call f<char*>(char**)
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_8s2() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T* p)\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("static T s;\n"); //$NON-NLS-1$
|
||||
buffer.append("// ...\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("void g(int a, char* b)\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("f(&a); //call f<int>(int*)\n"); //$NON-NLS-1$
|
||||
buffer.append("f(&b); //call f<char*>(char**)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1406,7 +1254,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template <class T> int f(typename T::B*);\n"); //$NON-NLS-1$
|
||||
buffer.append("int i = f<int>(0);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1429,7 +1277,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("int i = f<A>(0);\n"); //$NON-NLS-1$
|
||||
buffer.append("int j = f<C>(0);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1474,7 +1322,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("h<const int>(1,0);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1499,7 +1347,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(p); // f(const int *)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1534,7 +1382,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(d2); //calls f(B<int>&)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1561,7 +1409,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(ab); //calls f(A<B>)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1590,30 +1438,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(di); // f( (B<int>&)di )\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.8.3-6):
|
||||
template<class T> void f(T); // declaration
|
||||
void g()
|
||||
{
|
||||
f("Annemarie"); // call of f<const char*>
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_8_3s6() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T); // declaration\n"); //$NON-NLS-1$
|
||||
buffer.append("void g()\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("f(\"Annemarie\"); // call of f<const char*>\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1638,7 +1463,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template <int I> void f(A<I>, A<I+10>);\n"); //$NON-NLS-1$
|
||||
buffer.append("template <int I> void f(A<I>, A<I+11>);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1657,12 +1482,39 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("template <int I> void f(A<I>, A<I+10>);\n"); //$NON-NLS-1$
|
||||
buffer.append("template <int I> void f(A<I>, A<I+1+2+3+4>);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, false);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.8.1-4):
|
||||
template<class T> void f(T);
|
||||
class Complex {
|
||||
// ...
|
||||
Complex(double);
|
||||
};
|
||||
void g()
|
||||
{
|
||||
f<Complex>(1); // OK, means f<Complex>(Complex(1))
|
||||
}
|
||||
--End Example]
|
||||
*/
|
||||
public void test14_8_1s4() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T);\n"); //$NON-NLS-1$
|
||||
buffer.append("class Complex {\n"); //$NON-NLS-1$
|
||||
buffer.append("// ...\n"); //$NON-NLS-1$
|
||||
buffer.append("Complex(double);\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("void g()\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("f<Complex>(1); // OK, means f<Complex>(Complex(1))\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.8.2.4-14):
|
||||
template<int i, typename T>
|
||||
|
@ -1692,7 +1544,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("// i is explicitly specified to be 77, y.ym must be convertible\n"); //$NON-NLS-1$
|
||||
buffer.append("// to B<77>::Y\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
@ -1723,7 +1575,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(i,i); //#2: f<int>(i,char(i))\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -56,7 +56,7 @@ public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("xglue(HIGH, LOW)\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("char c[2][6] = { str(hello), str() };\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$
|
||||
buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
|||
buffer.append("report(x>y, \"x is %d but y is %d\", x, y);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("#ifdef _ _STDC_IEC_559_ _ /* FE_UPWARD defined */\n"); //$NON-NLS-1$
|
||||
buffer.append("fesetround(FE_UPWARD);\n"); //$NON-NLS-1$
|
||||
buffer.append("#endif\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("char i;\n"); //$NON-NLS-1$
|
||||
buffer.append("int i;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("char c1, c2;\n"); //$NON-NLS-1$
|
||||
buffer.append("c1 = c1 + c2;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("double d;\n"); //$NON-NLS-1$
|
||||
buffer.append("f1 = f2 * d;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("d1 = f = 1;\n"); //$NON-NLS-1$
|
||||
buffer.append("d2 = (float) 1;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +122,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("z = x + x * y; // not equivalent toz = x * (1.0 + y);\n"); //$NON-NLS-1$
|
||||
buffer.append("y = x / 5.0; // not equivalent toy = x * 0.2;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("a = ((a + 32765) + b);\n"); //$NON-NLS-1$
|
||||
buffer.append("a = (a + (b + 32765));\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +168,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("char *p;\n"); //$NON-NLS-1$
|
||||
buffer.append("sum = sum * 10 - '0' + (*p++ = getchar());\n"); //$NON-NLS-1$
|
||||
buffer.append("sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +179,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_2_5s28() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct tag (* a[5])(float);\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +194,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int f(int (*)(), double (*)[3]);\n"); //$NON-NLS-1$
|
||||
buffer.append("int f(int (*)(char *), double (*)[]);\n"); //$NON-NLS-1$
|
||||
buffer.append("int f(int (*)(char *), double (*)[3]);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,7 +209,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("char x='\\023';\n"); //$NON-NLS-1$
|
||||
buffer.append("char y='\\0';\n"); //$NON-NLS-1$
|
||||
buffer.append("char z='\\x13';\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||
buffer.append("int x=(*pf[f1()]) (f2(), f3() + f4());\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,7 +267,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("vs.i; // volatile int\n"); //$NON-NLS-1$
|
||||
buffer.append("vs.ci; // volatile const int\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,7 +318,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("if (sin(u.nf.doublenode) == 0.0)\n"); //$NON-NLS-1$
|
||||
buffer.append("return 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,7 +359,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("} u;\n"); //$NON-NLS-1$
|
||||
buffer.append("return f(&u.s1, &u.s2);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,7 +370,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_5_2_5s9() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int *p = (int []){2, 4};\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,7 +389,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int *p;\n"); //$NON-NLS-1$
|
||||
buffer.append("p = (int [2]){*p};\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -410,7 +410,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("drawline(&(struct point){.x=1, .y=1},\n"); //$NON-NLS-1$
|
||||
buffer.append("&(struct point){.x=3, .y=4});\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, false, false);
|
||||
parse(buffer.toString(), ParserLanguage.C, false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -425,7 +425,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("(const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6};\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -444,7 +444,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("(char []){\"/tmp/fileXXXXXX\"};\n"); //$NON-NLS-1$
|
||||
buffer.append("(const char []){\"/tmp/fileXXXXXX\"};\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -459,7 +459,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("(const char []){\"abc\"} == \"abc\";\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -478,7 +478,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("struct int_list endless_zeros = {0, &endless_zeros};\n"); //$NON-NLS-1$
|
||||
buffer.append("eval(endless_zeros);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -507,7 +507,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("if (j < 2) goto again;\n"); //$NON-NLS-1$
|
||||
buffer.append("return p == q && q->i == 1;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -520,7 +520,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("extern void *alloc(size_t);\n"); //$NON-NLS-1$
|
||||
buffer.append("double *dp = alloc(sizeof *dp);\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -537,7 +537,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int array[5];\n"); //$NON-NLS-1$
|
||||
buffer.append("int x = sizeof array / sizeof array[0];\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -562,7 +562,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("(*p)[2] = 99; // a[1][2] == 99\n"); //$NON-NLS-1$
|
||||
buffer.append("n = p - a; // n == 1\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -587,7 +587,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int *ip;\n"); //$NON-NLS-1$
|
||||
buffer.append("const char *c_cp;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -608,7 +608,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("long l;\n"); //$NON-NLS-1$
|
||||
buffer.append("l = (c = i);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -633,7 +633,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("*cpp = &c; // valid\n"); //$NON-NLS-1$
|
||||
buffer.append("*p = 0; // valid\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -656,7 +656,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("offsetof(struct s, d);\n"); //$NON-NLS-1$
|
||||
buffer.append("offsetof(struct ss, d);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -677,7 +677,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("s1 = malloc(sizeof (struct s) + 64);\n"); //$NON-NLS-1$
|
||||
buffer.append("s2 = malloc(sizeof (struct s) + 46);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -690,7 +690,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct { int n; double d[8]; } *s1;\n"); //$NON-NLS-1$
|
||||
buffer.append("struct { int n; double d[5]; } *s2;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -715,7 +715,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("if (*cp != burgundy)\n"); //$NON-NLS-1$
|
||||
buffer.append("return 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -734,7 +734,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("struct tnode *left, *right;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("struct tnode s, *sp;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -755,7 +755,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("TNODE *left, *right;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("TNODE s, *sp;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -770,7 +770,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("struct s2;\n"); //$NON-NLS-1$
|
||||
buffer.append("struct s1 { struct s2 *s2p; }; // D1\n"); //$NON-NLS-1$
|
||||
buffer.append("struct s2 { struct s1 *s1p; }; // D2\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -781,7 +781,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_3s10() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("extern const volatile int real_time_clock;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -818,7 +818,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("pci = &cs.mem; // valid\n"); //$NON-NLS-1$
|
||||
buffer.append("pi = a[0]; // invalid: a[0] has type ‘‘const int *’’\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -833,7 +833,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int * restrict a;\n"); //$NON-NLS-1$
|
||||
buffer.append("int * restrict b;\n"); //$NON-NLS-1$
|
||||
buffer.append("extern int c[];\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -852,7 +852,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("while (n-- > 0)\n"); //$NON-NLS-1$
|
||||
buffer.append("*p++ = *q++;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -883,7 +883,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(50, d + 50, d); // valid\n"); //$NON-NLS-1$
|
||||
buffer.append("f(50, d + 1, d); // undefined behavior\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -904,7 +904,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("for (i = 0; i < n; i++)\n"); //$NON-NLS-1$
|
||||
buffer.append("p[i] = q[i] + r[i];\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -937,7 +937,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("p2 = q2; // undefined behavior\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -962,7 +962,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("t.v = malloc(n * sizeof (float));\n"); //$NON-NLS-1$
|
||||
buffer.append("return t;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, false, false);
|
||||
parse(buffer.toString(), ParserLanguage.C, false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -997,7 +997,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("return is_fahr ? cels(temp) : fahr(temp);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1014,7 +1014,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int *const constant_ptr1;\n"); //$NON-NLS-1$
|
||||
buffer.append("typedef int *int_ptr;\n"); //$NON-NLS-1$
|
||||
buffer.append("const int_ptr constant_ptr2;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1025,7 +1025,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_5_2s7() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("float fa[11], *afp[17];\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1038,7 +1038,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("extern int *x;\n"); //$NON-NLS-1$
|
||||
buffer.append("extern int y[];\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1071,7 +1071,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("r = c; // compatible, but defined behavior only if\n"); //$NON-NLS-1$
|
||||
buffer.append("// n == 6 andm == n+1\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, false, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1118,7 +1118,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("extern int (*r)[m]; // invalid: r has linkage and points to VLA\n"); //$NON-NLS-1$
|
||||
buffer.append("static int (*q)[m] = &B; // valid: q is a static block pointer to VLA\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1129,7 +1129,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_5_3s16() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int f(void), *fip(), (*pfi)();\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1140,7 +1140,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_5_3s18() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int (*apfi[3])(int *x, int *y);\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1151,7 +1151,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_5_3s19() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int (*fpfi(int (*)(long), int))(int, ...);\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1192,7 +1192,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("// a is a pointer to a VLA with n*m+300 elements\n"); //$NON-NLS-1$
|
||||
buffer.append("a[i][j] += x;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1217,7 +1217,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("void f2(double a[restrict][5]);\n"); //$NON-NLS-1$
|
||||
buffer.append("void f3(double a[restrict 3][5]);\n"); //$NON-NLS-1$
|
||||
buffer.append("void f4(double a[restrict static 3][5]);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1238,7 +1238,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("extern KLICKSP *metricp;\n"); //$NON-NLS-1$
|
||||
buffer.append("range x;\n"); //$NON-NLS-1$
|
||||
buffer.append("range z, *zp;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1251,7 +1251,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("typedef struct s1 { int x; } t1, *tp1;\n"); //$NON-NLS-1$
|
||||
buffer.append("typedef struct s2 { int x; } t2, *tp2;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1278,7 +1278,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("t f(t (t));\n"); //$NON-NLS-1$
|
||||
buffer.append("long t;\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1295,7 +1295,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("void (*signal(int, void (*)(int)))(int);\n"); //$NON-NLS-1$
|
||||
buffer.append("fv *signal(int, fv *);\n"); //$NON-NLS-1$
|
||||
buffer.append("pfv signal(int, pfv);\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1322,7 +1322,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("for (int i = 1; i < n; i++)\n"); //$NON-NLS-1$
|
||||
buffer.append("a[i-1] = b[i];\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1335,7 +1335,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int i = 3.5;\n"); //$NON-NLS-1$
|
||||
buffer.append("complex c = 5 + 3 * I;\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1346,7 +1346,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_8s25() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int x[] = { 1, 3, 5 };\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1365,7 +1365,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("{ 2, 4, 6 },\n"); //$NON-NLS-1$
|
||||
buffer.append("{ 3, 5, 7 },\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1380,7 +1380,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int y[4][3] = {\n"); //$NON-NLS-1$
|
||||
buffer.append("1, 3, 5, 2, 4, 6, 3, 5, 7\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1395,7 +1395,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int z[4][3] = {\n"); //$NON-NLS-1$
|
||||
buffer.append("{ 1 }, { 2 }, { 3 }, { 4 }\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1406,7 +1406,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_8s28() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct { int a[3], b; } w[] = { { 1 }, 2 };\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1459,7 +1459,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("{ 6 },\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1474,7 +1474,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("typedef int A[]; // OK - declared with block scope\n"); //$NON-NLS-1$
|
||||
buffer.append("A a1 = { 1, 2 }, b1 = { 3, 4, 5 };\n"); //$NON-NLS-1$
|
||||
buffer.append("int a2[] = { 1, 2 }, b2[] = { 3, 4, 5 };\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1495,7 +1495,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("t2[] = { 'a', 'b', 'c' };\n"); //$NON-NLS-1$
|
||||
buffer.append("char *p = \"abc\";\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1514,7 +1514,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("[member_two] = \"member two\",\n"); //$NON-NLS-1$
|
||||
buffer.append("[member_one] = \"member one\",\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1525,7 +1525,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_8s34() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("div_t answer = { .quot = 2, .rem = -1 };\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1538,7 +1538,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct { int a[3], b; } w[] =\n"); //$NON-NLS-1$
|
||||
buffer.append("{ [0].a = {1}, [1].a[0] = 2 };\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1555,7 +1555,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int a[MAX] = {\n"); //$NON-NLS-1$
|
||||
buffer.append("1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1566,7 +1566,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_7_8s38() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("union { int any_member; } u = { .any_member = 42 };\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1583,7 +1583,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("(void)p(0);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1602,7 +1602,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("while (*s++ != '\0')\n"); //$NON-NLS-1$
|
||||
buffer.append(";\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1633,7 +1633,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("end_loop1: ;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1666,7 +1666,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("f(i+1);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1701,7 +1701,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("// handle other operations\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1738,7 +1738,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("goto lab4; // invalid: going INTO scope of VLA.\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), false, false);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1783,7 +1783,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||
buffer.append("g.u2.f3 = f();\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||
parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1800,7 +1800,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("return a > b ? a : b;\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1819,7 +1819,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("(*funcp)();\n"); //$NON-NLS-1$
|
||||
buffer.append("funcp();\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1858,7 +1858,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("extern int i3; // refers to pre vious, whose linkage is external\n"); //$NON-NLS-1$
|
||||
buffer.append("extern int i4; // refers to pre vious, whose linkage is external\n"); //$NON-NLS-1$
|
||||
buffer.append("extern int i5; // refers to pre vious, whose linkage is internal\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1883,7 +1883,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("if ('z' - 'a' == 25)\n"); //$NON-NLS-1$
|
||||
buffer.append("g();\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1904,7 +1904,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("#define join(c, d) in_between(c hash_hash d)\n"); //$NON-NLS-1$
|
||||
buffer.append("char p[] = join(x, y); // equivalent to\n"); //$NON-NLS-1$
|
||||
buffer.append("// char p[] = \"x ## y\";\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1917,7 +1917,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("#define TABSIZE 100\n"); //$NON-NLS-1$
|
||||
buffer.append("int table[TABSIZE];\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1928,7 +1928,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
public void test6_10_3_5s4() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("#define max(a, b) ((a) > (b) ? (a) : (b))\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1951,7 +1951,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("#define FUNC_LIKE2( a )( \\n"); //$NON-NLS-1$
|
||||
buffer.append(" a \\n"); //$NON-NLS-1$
|
||||
buffer.append(" )\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, true);
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -56,26 +56,25 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
* checkSemantics is used to specify whether the example should have semantics checked
|
||||
* since several spec examples have syntactically correct code ONLY this flag was added
|
||||
* so that future tests can ensure that examples are checked against syntax/semantics where necessary
|
||||
*
|
||||
* @param code
|
||||
* @param checkSemantics
|
||||
* @param expectedProblemBindings the number of problem bindings you expect to encounter
|
||||
* @throws ParserException
|
||||
*/
|
||||
protected void parseCandCPP( String code, boolean checkSemantics, boolean checkBindings ) throws ParserException {
|
||||
parse( code, ParserLanguage.C, false, true, checkSemantics, checkBindings);
|
||||
parse( code, ParserLanguage.CPP, false, true, checkSemantics, checkBindings );
|
||||
protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
|
||||
parse( code, ParserLanguage.C, false, true, checkBindings, expectedProblemBindings);
|
||||
parse( code, ParserLanguage.CPP, false, true, checkBindings, expectedProblemBindings );
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkSemantics, boolean checkBindings ) throws ParserException {
|
||||
return parse(code, lang, false, true, checkSemantics, checkBindings );
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
|
||||
return parse(code, lang, false, true, checkBindings, expectedProblemBindings );
|
||||
}
|
||||
|
||||
private IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean checkSemantics, boolean checkBindings ) throws ParserException {
|
||||
private IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
|
||||
// TODO beef this up with tests... i.e. run once with \n, and then run again with \r\n replacing \n ... etc
|
||||
// TODO another example might be to replace all characters with corresponding trigraph/digraph tests...
|
||||
|
||||
CodeReader codeReader = new CodeReader(code.toCharArray());
|
||||
return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkSemantics, checkBindings);
|
||||
return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings);
|
||||
}
|
||||
|
||||
// private IASTTranslationUnit parse( IFile filename, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
|
@ -91,7 +90,7 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
// return parse(codeReader, lang, useGNUExtensions, expectNoProblems);
|
||||
// }
|
||||
|
||||
private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean checkSemantics, boolean checkBindings) throws ParserException {
|
||||
private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings) throws ParserException {
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
IScannerExtensionConfiguration configuration = null;
|
||||
if( lang == ParserLanguage.C )
|
||||
|
@ -132,13 +131,13 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
if ( lang == ParserLanguage.CPP ) {
|
||||
CPPNameResolver res = new CPPNameResolver();
|
||||
tu.accept( res );
|
||||
if (res.foundProblemBinding)
|
||||
throw new ParserException("found IProblemBinding"); //$NON-NLS-1$
|
||||
if (res.numProblemBindings != expectedProblemBindings )
|
||||
throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.numProblemBindings ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else if (lang == ParserLanguage.C ) {
|
||||
CNameResolver res = new CNameResolver();
|
||||
tu.accept( res );
|
||||
if (res.foundProblemBinding)
|
||||
throw new ParserException("found IProblemBinding"); //$NON-NLS-1$
|
||||
if (res.numProblemBindings != expectedProblemBindings )
|
||||
throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.numProblemBindings ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,12 +170,13 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public boolean foundProblemBinding=false;
|
||||
public int numProblemBindings=0;
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding)
|
||||
foundProblemBinding=true;
|
||||
numProblemBindings++;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
|
@ -191,12 +191,13 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public boolean foundProblemBinding=false;
|
||||
public int numProblemBindings=0;
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding)
|
||||
foundProblemBinding=true;
|
||||
numProblemBindings++;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
|
|
|
@ -16,9 +16,11 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
|
@ -29,9 +31,12 @@ 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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
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.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
|
@ -277,8 +282,476 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
ICPPMethod f1 = (ICPPMethod) col.getName(2).resolveBinding();
|
||||
ICPPMethod f2 = (ICPPMethod) col.getName(8).resolveBinding();
|
||||
|
||||
//TODO this isn't right, but its close enough for now
|
||||
assertSame( f2, f1 );
|
||||
}
|
||||
|
||||
public void testTemplateFunctionImplicitInstantiation() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template < class T > void f ( T ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void main() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" f( 1 ); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
IFunction f2 = (IFunction) col.getName(5).resolveBinding();
|
||||
|
||||
assertTrue( f2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* template< class T > void f( T ); //#1
|
||||
* template< class T > void f( T* ); //#2
|
||||
* template< class T > void f( const T* ); //#3
|
||||
*
|
||||
* const int *p;
|
||||
* f( p ); //calls f( const T * ) , 3 is more specialized than 1 or 2
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
public void test_14_5_5_2s5_OrderingFunctionTemplates_1() throws Exception{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "template < class T > void f( T ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T > void f( T* ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T > void f( const T* ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "void main() { \n"); //$NON-NLS-1$
|
||||
buffer.append( " const int *p; \n"); //$NON-NLS-1$
|
||||
buffer.append( " f( p ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunctionTemplate f2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding();
|
||||
ICPPFunctionTemplate f3 = (ICPPFunctionTemplate) col.getName(9).resolveBinding();
|
||||
|
||||
assertNotSame( f1, f2 );
|
||||
assertNotSame( f2, f3 );
|
||||
assertNotSame( f3, f1 );
|
||||
|
||||
IFunction f = (IFunction) col.getName(14).resolveBinding();
|
||||
assertTrue( f instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)f).getOriginalBinding(), f3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* template< class T > void g( T ); //#1
|
||||
* template< class T > void g( T& ); //#2
|
||||
|
||||
* float x;
|
||||
* g( x ); //ambiguous 1 or 2
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void test_14_5_5_2s5_OrderingFunctionTemplates_2() throws Exception{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "template < class T > void f( T ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T > void f( T& ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "void main() { \n"); //$NON-NLS-1$
|
||||
buffer.append( " float x; \n"); //$NON-NLS-1$
|
||||
buffer.append( " f( x ); \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunctionTemplate f2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding();
|
||||
|
||||
assertNotSame( f1, f2 );
|
||||
|
||||
IProblemBinding f = (IProblemBinding) col.getName(10).resolveBinding();
|
||||
assertEquals( f.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP );
|
||||
}
|
||||
|
||||
public void testTemplateParameters() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "template < class T, template < class X > class U, T *pT > class A { \n"); //$NON-NLS-1$
|
||||
buffer.append( "}; \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPTemplateTypeParameter T = (ICPPTemplateTypeParameter) col.getName(0).resolveBinding();
|
||||
ICPPTemplateTemplateParameter U = (ICPPTemplateTemplateParameter) col.getName(2).resolveBinding();
|
||||
ICPPTemplateNonTypeParameter pT = (ICPPTemplateNonTypeParameter) col.getName(4).resolveBinding();
|
||||
|
||||
ICPPTemplateTypeParameter X = (ICPPTemplateTypeParameter) col.getName(1).resolveBinding();
|
||||
|
||||
ICPPTemplateParameter [] ps = U.getTemplateParameters();
|
||||
assertEquals( ps.length, 1 );
|
||||
assertSame( ps[0], X );
|
||||
|
||||
IPointerType ptype = (IPointerType) pT.getType();
|
||||
assertSame( ptype.getType(), T );
|
||||
}
|
||||
|
||||
public void testDeferredInstances() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "template <class T> class A { \n"); //$NON-NLS-1$
|
||||
buffer.append( " A<T>* a; \n"); //$NON-NLS-1$
|
||||
buffer.append( " A<T>* a2; \n"); //$NON-NLS-1$
|
||||
buffer.append( "}; \n"); //$NON-NLS-1$
|
||||
buffer.append( "void f(){ \n"); //$NON-NLS-1$
|
||||
buffer.append( " A<int> * b; \n"); //$NON-NLS-1$
|
||||
buffer.append( " b->a; \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding();
|
||||
ICPPTemplateInstance A_T = (ICPPTemplateInstance) col.getName(2).resolveBinding();
|
||||
assertSame( A_T.getOriginalBinding(), A );
|
||||
|
||||
ICPPTemplateInstance A_T2 = (ICPPTemplateInstance) col.getName(6).resolveBinding();
|
||||
assertSame( A_T, A_T2 );
|
||||
|
||||
ICPPVariable a = (ICPPVariable) col.getName(5).resolveBinding();
|
||||
IPointerType pt = (IPointerType) a.getType();
|
||||
assertSame( pt.getType(), A_T );
|
||||
|
||||
ICPPVariable b = (ICPPVariable) col.getName(13).resolveBinding();
|
||||
IType bt = b.getType();
|
||||
assertTrue( bt instanceof IPointerType );
|
||||
|
||||
ICPPVariable a2 = (ICPPVariable) col.getName(15).resolveBinding();
|
||||
assertTrue( a2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a );
|
||||
IType at = a2.getType();
|
||||
assertTrue( at instanceof IPointerType );
|
||||
|
||||
assertSame( ((IPointerType)at).getType(), ((IPointerType)bt).getType() );
|
||||
}
|
||||
|
||||
public void test_14_5_4_1s2_MatchingTemplateSpecializations() throws Exception{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "template < class T1, class T2, int I > class A {}; //#1 \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T, int I > class A < T, T*, I > {}; //#2 \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T1, class T2, int I > class A < T1*, T2, I > {}; //#3 \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T > class A < int, T*, 5 > {}; //#4 \n"); //$NON-NLS-1$
|
||||
buffer.append( "template < class T1, class T2, int I > class A < T1, T2*, I > {}; //#5 \n"); //$NON-NLS-1$
|
||||
|
||||
buffer.append( "A <int, int, 1> a1; //uses #1 \n"); //$NON-NLS-1$
|
||||
buffer.append( "A <int, int*, 1> a2; //uses #2, T is int, I is 1 \n"); //$NON-NLS-1$
|
||||
buffer.append( "A <int, char*, 5> a3; //uses #4, T is char \n"); //$NON-NLS-1$
|
||||
buffer.append( "A <int, char*, 1> a4; //uses #5, T is int, T2 is char, I is1 \n"); //$NON-NLS-1$
|
||||
buffer.append( "A <int*, int*, 2> a5; //ambiguous, matches #3 & #5. \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(3).resolveBinding();
|
||||
ICPPClassTemplate A2 = (ICPPClassTemplate) col.getName(6).resolveBinding();
|
||||
ICPPClassTemplate A3 = (ICPPClassTemplate) col.getName(14).resolveBinding();
|
||||
ICPPClassTemplate A4 = (ICPPClassTemplate) col.getName(20).resolveBinding();
|
||||
ICPPClassTemplate A5 = (ICPPClassTemplate) col.getName(26).resolveBinding();
|
||||
|
||||
assertTrue( A3 instanceof ICPPTemplateSpecialization );
|
||||
assertSame( ((ICPPTemplateSpecialization)A3).getPrimaryTemplateDefinition(), A1 );
|
||||
|
||||
ICPPTemplateTypeParameter T1 = (ICPPTemplateTypeParameter) col.getName(11).resolveBinding();
|
||||
ICPPTemplateTypeParameter T2 = (ICPPTemplateTypeParameter) col.getName(12).resolveBinding();
|
||||
ICPPTemplateNonTypeParameter I = (ICPPTemplateNonTypeParameter) col.getName(13).resolveBinding();
|
||||
|
||||
ICPPTemplateParameter TR1 = (ICPPTemplateParameter) col.getName(16).resolveBinding();
|
||||
ICPPTemplateParameter TR2 = (ICPPTemplateParameter) col.getName(17).resolveBinding();
|
||||
ICPPTemplateParameter TR3 = (ICPPTemplateParameter) col.getName(18).resolveBinding();
|
||||
|
||||
assertSame( T1, TR1 );
|
||||
assertSame( T2, TR2 );
|
||||
assertSame( I, TR3 );
|
||||
|
||||
ICPPTemplateInstance R1 = (ICPPTemplateInstance) col.getName(31).resolveBinding();
|
||||
ICPPTemplateInstance R2 = (ICPPTemplateInstance) col.getName(34).resolveBinding();
|
||||
ICPPTemplateInstance R3 = (ICPPTemplateInstance) col.getName(37).resolveBinding();
|
||||
ICPPTemplateInstance R4 = (ICPPTemplateInstance) col.getName(40).resolveBinding();
|
||||
IProblemBinding R5 = (IProblemBinding) col.getName(43).resolveBinding();
|
||||
assertEquals( R5.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP );
|
||||
|
||||
assertSame( R1.getOriginalBinding(), A1 );
|
||||
assertSame( R2.getOriginalBinding(), A2 );
|
||||
assertSame( R4.getOriginalBinding(), A5 );
|
||||
assertSame( R3.getOriginalBinding(), A4 );
|
||||
}
|
||||
|
||||
public void test14_7_3_FunctionExplicitSpecialization() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template <class T> void f(T); \n"); //$NON-NLS-1$
|
||||
buffer.append("template <class T> void f(T*); \n"); //$NON-NLS-1$
|
||||
buffer.append("template <> void f(int); //ok \n"); //$NON-NLS-1$
|
||||
buffer.append("template <> void f<int>(int*); // OK \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate fT1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunctionTemplate fT2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding();
|
||||
|
||||
ICPPTemplateSpecialization f1 = (ICPPTemplateSpecialization) col.getName(8).resolveBinding();
|
||||
ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(10).resolveBinding();
|
||||
|
||||
assertFalse( f1.isPartialSpecialization() );
|
||||
assertFalse( f2.isPartialSpecialization() );
|
||||
|
||||
assertSame( f1.getPrimaryTemplateDefinition(), fT1 );
|
||||
assertSame( f2.getPrimaryTemplateDefinition(), fT2 );
|
||||
}
|
||||
|
||||
public void test_14_5_5_1_FunctionTemplates_1() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T*); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g(int* p) { f(p); } \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
|
||||
ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding();
|
||||
assertTrue( ref instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f );
|
||||
}
|
||||
|
||||
public void test_14_5_5_1_FunctionTemplates_2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g(int* p) { f(p); } \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
|
||||
ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding();
|
||||
assertTrue( ref instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f );
|
||||
}
|
||||
|
||||
public void test_14_8_1s2_FunctionTemplates() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class X, class Y> X f(Y); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g(){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" int i = f<int>(5); // Y is int \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(3).resolveBinding();
|
||||
ICPPFunction ref1 = (ICPPFunction) col.getName(8).resolveBinding();
|
||||
|
||||
assertTrue( ref1 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f );
|
||||
}
|
||||
|
||||
public void test14_8_3s6_FunctionTemplates() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g(){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" f(\"Annemarie\"); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunction ref = (ICPPFunction) col.getName(5).resolveBinding();
|
||||
assertTrue( ref instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f );
|
||||
}
|
||||
|
||||
public void test14_5_5_2s6_FunctionTemplates() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T); // #1\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void f(T*, int=1); // #2\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void g(T); // #3\n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> void g(T*, ...); // #4\n"); //$NON-NLS-1$
|
||||
buffer.append("int main() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" int* ip; \n"); //$NON-NLS-1$
|
||||
buffer.append(" f(ip); //calls #2\n"); //$NON-NLS-1$
|
||||
buffer.append(" g(ip); //calls #4\n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunctionTemplate f2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding();
|
||||
assertNotSame( f1, f2 );
|
||||
|
||||
ICPPFunctionTemplate g1 = (ICPPFunctionTemplate) col.getName(10).resolveBinding();
|
||||
ICPPFunctionTemplate g2 = (ICPPFunctionTemplate) col.getName(14).resolveBinding();
|
||||
assertNotSame( g1, g2 );
|
||||
|
||||
ICPPFunction ref1 = (ICPPFunction) col.getName(19).resolveBinding();
|
||||
ICPPFunction ref2 = (ICPPFunction) col.getName(21).resolveBinding();
|
||||
|
||||
assertTrue( ref1 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f2 );
|
||||
|
||||
assertTrue( ref2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance) ref2).getOriginalBinding(), g2 );
|
||||
}
|
||||
|
||||
public void test14_6_1s1_LocalNames() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> class X { \n"); //$NON-NLS-1$
|
||||
buffer.append(" X* p; // meaning X<T>\n"); //$NON-NLS-1$
|
||||
buffer.append(" X<T>* p2; \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPClassTemplate X = (ICPPClassTemplate) col.getName(1).resolveBinding();
|
||||
ICPPClassType x1 = (ICPPClassType) col.getName(2).resolveBinding();
|
||||
ICPPClassType x2 = (ICPPClassType) col.getName(4).resolveBinding();
|
||||
|
||||
assertTrue( x1 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)x1).getOriginalBinding(), X );
|
||||
|
||||
assertSame( x1, x2 );
|
||||
}
|
||||
|
||||
public void test14_8s2_() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> T f(T* p){ \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
buffer.append("void g(int a, char* b){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" f(&a); //call f<int>(int*) \n"); //$NON-NLS-1$
|
||||
buffer.append(" f(&b); //call f<char*>(char**)\n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(2).resolveBinding();
|
||||
|
||||
ICPPFunction f1 = (ICPPFunction) col.getName(8).resolveBinding();
|
||||
ICPPFunction f2 = (ICPPFunction) col.getName(10).resolveBinding();
|
||||
|
||||
assertNotSame( f1, f2 );
|
||||
assertTrue( f1 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)f1).getOriginalBinding(), f );
|
||||
assertTrue( f2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f );
|
||||
|
||||
IType fr1 = f1.getType().getReturnType();
|
||||
IType fr2 = f2.getType().getReturnType();
|
||||
|
||||
assertTrue( fr1 instanceof IBasicType );
|
||||
assertEquals( ((IBasicType)fr1).getType(), IBasicType.t_int );
|
||||
|
||||
assertTrue( fr2 instanceof IPointerType );
|
||||
assertTrue( ((IPointerType)fr2).getType() instanceof IBasicType );
|
||||
assertEquals( ((IBasicType) ((IPointerType)fr2).getType()).getType(), IBasicType.t_char );
|
||||
}
|
||||
|
||||
public void test14_7_3s14() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> void f(T) { } \n"); //$NON-NLS-1$
|
||||
buffer.append("template<class T> inline T g(T) { } \n"); //$NON-NLS-1$
|
||||
buffer.append("template<> inline void f<>(int) { } //OK: inline \n"); //$NON-NLS-1$
|
||||
buffer.append("template<> int g<>(int) { } // OK: not inline\n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
|
||||
ICPPFunctionTemplate g1 = (ICPPFunctionTemplate) col.getName(6).resolveBinding();
|
||||
|
||||
ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(9).resolveBinding();
|
||||
ICPPTemplateSpecialization g2 = (ICPPTemplateSpecialization) col.getName(12).resolveBinding();
|
||||
|
||||
assertFalse( ((ICPPFunction)f1).isInline() );
|
||||
assertTrue( ((ICPPFunction)g1).isInline() );
|
||||
assertTrue( ((ICPPFunction)f2).isInline() );
|
||||
assertFalse( ((ICPPFunction)g2).isInline() );
|
||||
}
|
||||
|
||||
public void test14_7_1s14_InfiniteInstantiation() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> class X { \n"); //$NON-NLS-1$
|
||||
buffer.append(" X<T*> a; // implicit generation of X<T> requires \n"); //$NON-NLS-1$
|
||||
buffer.append(" // the implicit instantiation of X<T*> which requires \n"); //$NON-NLS-1$
|
||||
buffer.append(" // the implicit instantiation of X<T**> which ... \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" X<int> x; \n"); //$NON-NLS-1$
|
||||
buffer.append(" x.a.a.a.a; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPClassTemplate X = (ICPPClassTemplate) col.getName(1).resolveBinding();
|
||||
ICPPVariable x = (ICPPVariable) col.getName(9).resolveBinding();
|
||||
IType t = x.getType();
|
||||
assertTrue( t instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance) t).getOriginalBinding(), X );
|
||||
|
||||
ICPPField a = (ICPPField) col.getName(5).resolveBinding();
|
||||
ICPPField a1 = (ICPPField) col.getName(11).resolveBinding();
|
||||
ICPPField a2 = (ICPPField) col.getName(12).resolveBinding();
|
||||
ICPPField a3 = (ICPPField) col.getName(13).resolveBinding();
|
||||
ICPPField a4 = (ICPPField) col.getName(14).resolveBinding();
|
||||
|
||||
assertTrue( a1 instanceof ICPPTemplateInstance );
|
||||
assertTrue( a2 instanceof ICPPTemplateInstance );
|
||||
assertTrue( a3 instanceof ICPPTemplateInstance );
|
||||
assertTrue( a4 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)a1).getOriginalBinding(), a );
|
||||
assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a );
|
||||
assertSame( ((ICPPTemplateInstance)a3).getOriginalBinding(), a );
|
||||
assertSame( ((ICPPTemplateInstance)a4).getOriginalBinding(), a );
|
||||
}
|
||||
|
||||
public void test14_6_1s2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("template<class T> class Y; \n"); //$NON-NLS-1$
|
||||
buffer.append("template<> class Y<int> { \n"); //$NON-NLS-1$
|
||||
buffer.append(" Y* p; // meaning Y<int> \n"); //$NON-NLS-1$
|
||||
buffer.append(" Y<char>* q; // meaning Y<char> \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPClassTemplate Y = (ICPPClassTemplate) col.getName(1).resolveBinding();
|
||||
ICPPTemplateSpecialization Yspec = (ICPPTemplateSpecialization) col.getName(2).resolveBinding();
|
||||
|
||||
assertTrue( Yspec instanceof ICPPClassType );
|
||||
assertSame( Yspec.getPrimaryTemplateDefinition(), Y );
|
||||
|
||||
ICPPClassType y1 = (ICPPClassType) col.getName(4).resolveBinding();
|
||||
assertTrue( y1 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)y1).getOriginalBinding(), Yspec );
|
||||
|
||||
ICPPClassType y2 = (ICPPClassType) col.getName(6).resolveBinding();
|
||||
assertTrue( y2 instanceof ICPPTemplateInstance );
|
||||
assertSame( ((ICPPTemplateInstance)y2).getOriginalBinding(), Y );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -17,7 +17,7 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
* @author Doug Schaefer
|
||||
*/
|
||||
public interface IASTNode {
|
||||
|
||||
public static final IASTNode [] EMPTY_NODE_ARRAY = new IASTNode[0];
|
||||
/**
|
||||
* Get the translation unit (master) node that is the ancestor of all nodes
|
||||
* in this AST.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -28,6 +28,14 @@ public interface IBasicType extends IType {
|
|||
*/
|
||||
public int getType() throws DOMException;
|
||||
|
||||
/**
|
||||
* Returns the IASTExpression for the value of this type. May be null.
|
||||
*
|
||||
* @return IASTExpression or null
|
||||
* @throws DOMException
|
||||
*/
|
||||
public IASTExpression getValue() throws DOMException;
|
||||
|
||||
public static final int t_unspecified = IASTSimpleDeclSpecifier.t_unspecified;
|
||||
public static final int t_void = IASTSimpleDeclSpecifier.t_void;
|
||||
public static final int t_char = IASTSimpleDeclSpecifier.t_char;
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
/*
|
||||
* Created on Apr 20, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
*/
|
||||
public interface ICPPParameter extends IParameter, ICPPVariable {
|
||||
|
||||
/**
|
||||
* the default value of this parameter or null if there is none.
|
||||
* @return
|
||||
*/
|
||||
public IASTInitializer getDefaultValue();
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -22,5 +24,7 @@ public interface ICPPTemplateDefinition extends ICPPBinding{
|
|||
* a partial specialization will have the specialized parameter list
|
||||
* @return array of ICPPTemplateParameter
|
||||
*/
|
||||
public ICPPTemplateParameter[] getTemplateParameters();
|
||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException;
|
||||
|
||||
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -34,6 +35,8 @@ public interface ICPPTemplateInstance extends IBinding {
|
|||
*/
|
||||
public ObjectMap getArgumentMap();
|
||||
|
||||
public IType [] getArguments();
|
||||
|
||||
public ICPPTemplateDefinition getTemplate();
|
||||
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@ package org.eclipse.cdt.core.dom.ast.cpp;
|
|||
* @author Doug Schaefer
|
||||
*/
|
||||
public interface ICPPTemplateParameter extends ICPPBinding {
|
||||
|
||||
public static final ICPPTemplateParameter[] EMPTY_TEMPLATE_PARAMETER_ARRAY = new ICPPTemplateParameter[0];
|
||||
}
|
||||
|
|
|
@ -13,28 +13,29 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public interface ICPPTemplateSpecialization extends ICPPTemplateDefinition {
|
||||
|
||||
public static final ICPPTemplateSpecialization[] EMPTY_TEMPLATE_SPECIALIZATION_ARRAY = new ICPPTemplateSpecialization[0];
|
||||
/**
|
||||
* get the arguments to this specialization
|
||||
* @return
|
||||
*/
|
||||
public IASTNode [] getArguments();
|
||||
public IType [] getArguments() throws DOMException;
|
||||
|
||||
/**
|
||||
* is this a partial specialization? if not, this will be an explicit specialization
|
||||
* @return
|
||||
*/
|
||||
public boolean isPartialSpecialization();
|
||||
public boolean isPartialSpecialization() throws DOMException;
|
||||
|
||||
/**
|
||||
* get the ICPPTemplateDefinition which this is a specialization of
|
||||
* @return
|
||||
*/
|
||||
public ICPPTemplateDefinition getPrimaryTemplateDefinition();
|
||||
public ICPPTemplateDefinition getPrimaryTemplateDefinition() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 13, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public interface ICPPTemplateTemplateParameter extends ICPPTemplateParameter, ICPPClassTemplate {
|
||||
|
||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException;
|
||||
|
||||
/**
|
||||
* The default type for this parameter. May be null
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IType getDefault() throws DOMException;
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
|
@ -97,4 +98,12 @@ public class CBasicType implements ICBasicType {
|
|||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBasicType#getValue()
|
||||
*/
|
||||
public IASTExpression getValue() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -102,11 +102,11 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements
|
|||
}
|
||||
}
|
||||
|
||||
if( name != null ) if( !name.accept( action ) ) return false;
|
||||
ICPPASTTemplateParameter [] ps = getTemplateParameters();
|
||||
for ( int i = 0; i < ps.length; i++ ) {
|
||||
if( !ps[i].accept( action ) ) return false;
|
||||
}
|
||||
if( name != null ) if( !name.accept( action ) ) return false;
|
||||
if( defaultValue != null ) if( !defaultValue.accept( action ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
|
||||
/**
|
||||
|
@ -28,19 +30,32 @@ public class CPPBasicType implements ICPPBasicType {
|
|||
|
||||
protected int qualifierBits = 0;
|
||||
protected int type;
|
||||
protected IASTExpression value = null;
|
||||
|
||||
public CPPBasicType( int t, int bits ){
|
||||
type = t;
|
||||
qualifierBits = bits;
|
||||
}
|
||||
|
||||
public CPPBasicType( int t, int bits, IASTExpression val ){
|
||||
type = t;
|
||||
qualifierBits = bits;
|
||||
value = val;
|
||||
}
|
||||
|
||||
public boolean isSameType( IType object ) {
|
||||
if( object instanceof CPPTypedef )
|
||||
if( object == this )
|
||||
return true;
|
||||
|
||||
if( object instanceof ITypedef )
|
||||
return object.isSameType( this );
|
||||
|
||||
if( !(object instanceof CPPBasicType) )
|
||||
return false;
|
||||
|
||||
if( type == -1 )
|
||||
return false;
|
||||
|
||||
CPPBasicType t = (CPPBasicType) object;
|
||||
return ( type == t.type && qualifierBits == t.qualifierBits );
|
||||
}
|
||||
|
@ -88,4 +103,15 @@ public class CPPBasicType implements ICPPBasicType {
|
|||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBasicType#getValue()
|
||||
*/
|
||||
public IASTExpression getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue( IASTExpression val ){
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,16 +34,15 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPPInternalBinding {
|
||||
private IASTName id;
|
||||
private CPPClassInstanceScope instanceScope;
|
||||
|
||||
/**
|
||||
* @param decl
|
||||
* @param args
|
||||
* @param arguments
|
||||
*/
|
||||
public CPPClassInstance( IASTName id, ICPPScope scope, IBinding decl, ObjectMap argMap ) {
|
||||
super( scope, decl, argMap );
|
||||
this.id = id;
|
||||
public CPPClassInstance( ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args ) {
|
||||
super( scope, decl, argMap, args );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -163,7 +162,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
|
|||
*/
|
||||
public Object clone(){
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -178,7 +177,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
return id;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -83,7 +83,7 @@ public class CPPClassInstanceScope implements ICPPClassScope {
|
|||
} else {
|
||||
binding = forceResolve ? n.resolveBinding() : n.getBinding();
|
||||
if( binding != null ){
|
||||
binding = CPPTemplates.createInstance( n, this, binding, instance.getArgumentMap() );
|
||||
binding = CPPTemplates.createInstance( this, binding, instance.getArgumentMap(), instance.getArguments() );
|
||||
if( instanceMap == ObjectMap.EMPTY_MAP )
|
||||
instanceMap = new ObjectMap(2);
|
||||
instanceMap.put( n, binding );
|
||||
|
@ -93,7 +93,7 @@ public class CPPClassInstanceScope implements ICPPClassScope {
|
|||
if( instanceMap.containsKey( obj ) ){
|
||||
binding = (IBinding) instanceMap.get( obj );
|
||||
} else {
|
||||
binding = CPPTemplates.createInstance( null, this, (IBinding) obj, instance.getArgumentMap() );
|
||||
binding = CPPTemplates.createInstance( this, (IBinding) obj, instance.getArgumentMap(), instance.getArguments() );
|
||||
if( instanceMap == ObjectMap.EMPTY_MAP )
|
||||
instanceMap = new ObjectMap(2);
|
||||
instanceMap.put( obj, binding );
|
||||
|
@ -175,8 +175,16 @@ public class CPPClassInstanceScope implements ICPPClassScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
|
||||
*/
|
||||
public IScope getParent() {
|
||||
// TODO Auto-generated method stub
|
||||
public IScope getParent() throws DOMException {
|
||||
ICPPClassType cls = getOriginalClass();
|
||||
ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope();
|
||||
if( scope != null )
|
||||
return scope.getParent();
|
||||
if( cls instanceof ICPPInternalBinding ){
|
||||
IASTNode [] nds = ((ICPPInternalBinding)cls).getDeclarations();
|
||||
if( nds != null && nds.length > 0 )
|
||||
return CPPVisitor.getContainingScope( nds[0] );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -192,8 +200,17 @@ public class CPPClassInstanceScope implements ICPPClassScope {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() throws DOMException {
|
||||
ICPPClassScope scope = (ICPPClassScope) getOriginalClass().getCompositeScope();
|
||||
ICPPClassType cls = getOriginalClass();
|
||||
ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope();
|
||||
if( scope != null )
|
||||
return scope.getPhysicalNode();
|
||||
|
||||
if( cls instanceof ICPPInternalBinding ){
|
||||
IASTNode [] nds = ((ICPPInternalBinding)cls).getDeclarations();
|
||||
if( nds != null && nds.length > 0 )
|
||||
return nds[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -23,18 +23,15 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -49,24 +46,14 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
|
|||
super(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplate#instantiate(org.eclipse.cdt.core.dom.ast.IASTNode[])
|
||||
*/
|
||||
public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) {
|
||||
ICPPTemplateParameter [] params = getTemplateParameters();
|
||||
IASTNode [] arguments = templateId.getTemplateArguments();
|
||||
|
||||
ObjectMap map = new ObjectMap(params.length);
|
||||
if( arguments.length == params.length ){
|
||||
for( int i = 0; i < arguments.length; i++ ){
|
||||
IType t = CPPVisitor.createType( arguments[i] );
|
||||
map.put( params[i], t );
|
||||
public ICPPTemplateInstance deferredInstance( IType [] arguments ){
|
||||
ICPPTemplateInstance instance = getInstance( arguments );
|
||||
if( instance == null ){
|
||||
instance = new CPPDeferredClassInstance( this, arguments );
|
||||
addInstance( arguments, instance );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
return CPPTemplates.createInstance( templateId, (ICPPScope) getScope(), this, map );
|
||||
}
|
||||
|
||||
private void checkForDefinition(){
|
||||
// CPPClassType.FindDefinitionAction action = new FindDefinitionAction();
|
||||
// IASTNode node = CPPVisitor.getContainingBlockItem( getPhysicalNode() ).getParent();
|
||||
|
|
|
@ -13,10 +13,16 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
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.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -24,19 +30,22 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
|||
public class CPPClassTemplateSpecialization extends CPPClassTemplate implements
|
||||
ICPPTemplateSpecialization {
|
||||
|
||||
private IASTNode [] arguments;
|
||||
private IType [] arguments;
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CPPClassTemplateSpecialization(ICPPASTTemplateId name) {
|
||||
super(name);
|
||||
this.arguments = name.getTemplateArguments();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#getArguments()
|
||||
*/
|
||||
public IASTNode[] getArguments() {
|
||||
public IType[] getArguments() {
|
||||
if( arguments == null ){
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
|
||||
arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() );
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
@ -55,4 +64,45 @@ public class CPPClassTemplateSpecialization extends CPPClassTemplate implements
|
|||
return (ICPPTemplateDefinition) id.getTemplateName().resolveBinding();
|
||||
}
|
||||
|
||||
public IBinding instantiate( IType [] args ){
|
||||
ICPPTemplateInstance instance = getInstance( args );
|
||||
if( instance != null ){
|
||||
return instance;
|
||||
}
|
||||
|
||||
IType [] specArgs = getArguments();
|
||||
if( specArgs.length != arguments.length ){
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectMap argMap = new ObjectMap( specArgs.length );
|
||||
int numSpecArgs = specArgs.length;
|
||||
for( int i = 0; i < numSpecArgs; i++ ){
|
||||
IType spec = specArgs[i];
|
||||
IType arg = args[i];
|
||||
|
||||
//If the argument is a template parameter, we can't instantiate yet, defer for later
|
||||
if( arg instanceof ICPPTemplateParameter ){
|
||||
return deferredInstance( args );
|
||||
}
|
||||
try {
|
||||
if( !CPPTemplates.deduceTemplateArgument( argMap, spec, arg ) )
|
||||
return null;
|
||||
} catch (DOMException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ICPPTemplateParameter [] params = getTemplateParameters();
|
||||
int numParams = params.length;
|
||||
for( int i = 0; i < numParams; i++ ){
|
||||
if( params[i] instanceof IType && !argMap.containsKey( params[i] ) )
|
||||
return null;
|
||||
}
|
||||
|
||||
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args );
|
||||
addInstance( args, instance );
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
|
@ -634,10 +635,14 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType {
|
|||
ObjectSet resultSet = new ObjectSet(2);
|
||||
IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i] instanceof IASTSimpleDeclaration ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)members[i]).getDeclSpecifier();
|
||||
IASTDeclaration decl = members[i];
|
||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
|
||||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier();
|
||||
if( declSpec.isFriend() ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
if( declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0 ){
|
||||
resultSet.put( ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding() );
|
||||
} else {
|
||||
|
@ -647,10 +652,10 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if( members[i] instanceof IASTFunctionDefinition ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)members[i]).getDeclSpecifier();
|
||||
} else if( decl instanceof IASTFunctionDefinition ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
|
||||
if( declSpec.isFriend() ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)members[i]).getDeclarator();
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
resultSet.put( dtor.getName().resolveBinding() );
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,280 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 14, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPDeferredClassInstance /*extends CPPInstance*/ implements
|
||||
ICPPTemplateInstance, ICPPClassType, ICPPInternalBinding {
|
||||
|
||||
public IType [] arguments = null;
|
||||
public ICPPClassTemplate classTemplate = null;
|
||||
|
||||
public CPPDeferredClassInstance(ICPPClassTemplate orig, IType [] arguments ) {
|
||||
this.arguments = arguments;
|
||||
this.classTemplate = orig;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments()
|
||||
*/
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
||||
*/
|
||||
public ICPPBase[] getBases() throws DOMException {
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
|
||||
*/
|
||||
public IField[] getFields() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
|
||||
*/
|
||||
public IField findField(String name) throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
|
||||
*/
|
||||
public ICPPField[] getDeclaredFields() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
|
||||
*/
|
||||
public ICPPMethod[] getMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
|
||||
*/
|
||||
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
|
||||
*/
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors()
|
||||
*/
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
|
||||
*/
|
||||
public IBinding[] getFriends() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
|
||||
*/
|
||||
public IASTNode[] getDeclarations() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public ICPPDelegate createDelegate(IASTName name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
|
||||
*/
|
||||
public int getKey() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
|
||||
*/
|
||||
public IScope getCompositeScope() throws DOMException {
|
||||
return ((ICPPClassType)classTemplate).getCompositeScope();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
|
||||
*/
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
|
||||
*/
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
|
||||
*/
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
public Object clone(){
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getOriginalBinding()
|
||||
*/
|
||||
public IBinding getOriginalBinding() {
|
||||
return classTemplate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArgumentMap()
|
||||
*/
|
||||
public ObjectMap getArgumentMap() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getTemplate()
|
||||
*/
|
||||
public ICPPTemplateDefinition getTemplate() {
|
||||
return classTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param argMap
|
||||
* @return
|
||||
*/
|
||||
public IType instantiate(ObjectMap argMap) {
|
||||
|
||||
IType [] newArgs = new IType[ arguments.length ];
|
||||
int size = arguments.length;
|
||||
for( int i = 0; i < size; i++ ){
|
||||
newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap );
|
||||
}
|
||||
|
||||
return (IType) ((CPPTemplateDefinition)classTemplate).instantiate( newArgs );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
public boolean isSameType(IType type) {
|
||||
// TODO Auto-generated method stub
|
||||
return type == this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,247 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 14, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
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.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
|
||||
ICPPFunction, ICPPTemplateInstance, ICPPInternalBinding {
|
||||
|
||||
private IType[] arguments;
|
||||
private ICPPFunctionTemplate functionTemplate;
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
*/
|
||||
public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) {
|
||||
this.functionTemplate = template;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments()
|
||||
*/
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
*/
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
return ((ICPPFunction)functionTemplate).getParameters();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
|
||||
*/
|
||||
public IScope getFunctionScope() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
||||
*/
|
||||
public IFunctionType getType() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
public boolean isStatic() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
|
||||
*/
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
|
||||
*/
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
|
||||
*/
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getOriginalBinding()
|
||||
*/
|
||||
public IBinding getOriginalBinding() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArgumentMap()
|
||||
*/
|
||||
public ObjectMap getArgumentMap() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getTemplate()
|
||||
*/
|
||||
public ICPPTemplateDefinition getTemplate() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
|
||||
*/
|
||||
public boolean isMutable() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
|
||||
*/
|
||||
public boolean isInline() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
|
||||
*/
|
||||
public boolean isExtern() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
|
||||
*/
|
||||
public boolean isAuto() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
|
||||
*/
|
||||
public boolean isRegister() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
|
||||
*/
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
|
||||
*/
|
||||
public IASTNode[] getDeclarations() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public ICPPDelegate createDelegate(IASTName name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -30,9 +30,10 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField {
|
|||
/**
|
||||
* @param orig
|
||||
* @param args
|
||||
* @param args
|
||||
*/
|
||||
public CPPFieldInstance(ICPPScope scope, IBinding orig, ObjectMap argMap ) {
|
||||
super(scope, orig, argMap);
|
||||
public CPPFieldInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args ) {
|
||||
super(scope, orig, argMap, args);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
|
@ -35,9 +36,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
|
|||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap) {
|
||||
super(scope, orig, argMap);
|
||||
public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
@ -72,7 +74,7 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
|
|||
IParameter [] params = ((ICPPFunction)getOriginalBinding()).getParameters();
|
||||
parameters = new IParameter[ params.length ];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
parameters[i] = new CPPParameterInstance( null, params[i], getArgumentMap() );
|
||||
parameters[i] = new CPPParameterInstance( null, params[i], getArgumentMap(), getArguments() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,18 +31,68 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFunctionTemplate, ICPPFunction {
|
||||
IFunctionType type = null;
|
||||
public static final class CPPFunctionTemplateProblem extends ProblemBinding implements ICPPFunctionTemplate, ICPPFunction {
|
||||
public CPPFunctionTemplateProblem(IASTNode node, int id, char[] arg) {
|
||||
super(node, id, arg);
|
||||
}
|
||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isMutable() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isInline() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public IScope getFunctionScope() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public IFunctionType getType() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
protected IFunctionType type = null;
|
||||
/**
|
||||
* @param decl
|
||||
*/
|
||||
|
@ -85,24 +135,6 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplate#instantiate(org.eclipse.cdt.core.dom.ast.IASTNode[])
|
||||
*/
|
||||
public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) {
|
||||
ICPPTemplateParameter [] params = getTemplateParameters();
|
||||
IASTNode [] arguments = templateId.getTemplateArguments();
|
||||
|
||||
ObjectMap map = new ObjectMap(params.length);
|
||||
if( arguments.length == params.length ){
|
||||
for( int i = 0; i < arguments.length; i++ ){
|
||||
IType t = CPPVisitor.createType( arguments[i] );
|
||||
map.put( params[i], t );
|
||||
}
|
||||
}
|
||||
|
||||
return CPPTemplates.createInstance( templateId, (ICPPScope) getScope(), this, map );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateParameter
|
||||
* @return
|
||||
|
@ -232,6 +264,12 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
return binding;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition#deferredInstance(org.eclipse.cdt.core.dom.ast.IType[])
|
||||
*/
|
||||
public ICPPTemplateInstance deferredInstance(IType[] arguments) {
|
||||
return new CPPDeferredFunctionInstance( this, arguments );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
|
||||
public class CPPFunctionTemplateSpecialization extends CPPFunction implements
|
||||
ICPPTemplateSpecialization {
|
||||
|
||||
private IASTName name = null;
|
||||
private IType [] argumentTypes = null;
|
||||
private ICPPFunctionTemplate primaryTemplate = null;
|
||||
|
||||
public CPPFunctionTemplateSpecialization(ICPPASTFunctionDeclarator declarator, ICPPFunctionTemplate primaryTemplate ) {
|
||||
super(declarator);
|
||||
this.primaryTemplate = primaryTemplate;
|
||||
IASTName n = declarator.getName();
|
||||
if( n instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)n).getNames();
|
||||
n = ns[ ns.length - 1 ];
|
||||
}
|
||||
this.name = n;
|
||||
}
|
||||
|
||||
public IType [] getArguments() throws DOMException{
|
||||
if( argumentTypes == null ){
|
||||
IASTNode [] specArgs = ( name instanceof ICPPASTTemplateId ) ? ((ICPPASTTemplateId)name).getTemplateArguments()
|
||||
: IASTNode.EMPTY_NODE_ARRAY;
|
||||
argumentTypes = CPPTemplates.deduceTemplateFunctionArguments( this, specArgs );
|
||||
}
|
||||
return argumentTypes;
|
||||
}
|
||||
|
||||
public boolean isPartialSpecialization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICPPTemplateDefinition getPrimaryTemplateDefinition() {
|
||||
return primaryTemplate;
|
||||
}
|
||||
|
||||
public ICPPTemplateParameter[] getTemplateParameters() {
|
||||
return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY;
|
||||
}
|
||||
|
||||
public ICPPTemplateSpecialization[] getTemplateSpecializations() {
|
||||
return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
|
@ -26,13 +27,15 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
*/
|
||||
public class CPPInstance implements ICPPTemplateInstance {
|
||||
private IBinding binding;
|
||||
private IType [] arguments;
|
||||
private ObjectMap argMap;
|
||||
private ICPPScope scope;
|
||||
|
||||
public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap ){
|
||||
public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] arguments ){
|
||||
this.binding = orig;
|
||||
this.argMap = argMap;
|
||||
this.scope = scope;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getOriginalBinding()
|
||||
|
@ -91,4 +94,10 @@ public class CPPInstance implements ICPPTemplateInstance {
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments()
|
||||
*/
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
@ -29,9 +30,10 @@ public class CPPMethodInstance extends CPPFunctionInstance implements
|
|||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap) {
|
||||
super(scope, orig, argMap);
|
||||
public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
|
@ -25,14 +26,14 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPParameter implements IParameter, ICPPInternalBinding, ICPPVariable {
|
||||
public static class CPPParameterDelegate extends CPPDelegate implements IParameter, ICPPVariable {
|
||||
public class CPPParameter implements ICPPParameter, ICPPInternalBinding {
|
||||
public static class CPPParameterDelegate extends CPPDelegate implements ICPPParameter {
|
||||
public CPPParameterDelegate( IASTName name, IParameter binding ) {
|
||||
super( name, binding );
|
||||
}
|
||||
|
@ -54,6 +55,9 @@ public class CPPParameter implements IParameter, ICPPInternalBinding, ICPPVariab
|
|||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
public IASTInitializer getDefaultValue() {
|
||||
return ((ICPPParameter)getBinding()).getDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
private IType type = null;
|
||||
|
@ -244,4 +248,18 @@ public class CPPParameter implements IParameter, ICPPInternalBinding, ICPPVariab
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IASTInitializer getDefaultValue() {
|
||||
if( declarations == null )
|
||||
return null;
|
||||
for (int i = 0; i < declarations.length && declarations[i] != null; i++) {
|
||||
IASTNode parent = declarations[i].getParent();
|
||||
while( parent.getPropertyInParent() == IASTDeclarator.NESTED_DECLARATOR )
|
||||
parent = parent.getParent();
|
||||
IASTInitializer init = ((IASTDeclarator)parent).getInitializer();
|
||||
if( init != null )
|
||||
return init;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,21 +14,21 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPParameterInstance extends CPPInstance implements IParameter,
|
||||
ICPPVariable, ICPPInternalBinding {
|
||||
public class CPPParameterInstance extends CPPInstance implements ICPPParameter, ICPPInternalBinding {
|
||||
|
||||
private IType type = null;
|
||||
|
||||
|
@ -37,8 +37,8 @@ public class CPPParameterInstance extends CPPInstance implements IParameter,
|
|||
* @param orig
|
||||
* @param argMap
|
||||
*/
|
||||
public CPPParameterInstance(ICPPScope scope, IBinding orig, ObjectMap argMap) {
|
||||
super(scope, orig, argMap);
|
||||
public CPPParameterInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] args ) {
|
||||
super(scope, orig, argMap, args);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -131,4 +131,8 @@ public class CPPParameterInstance extends CPPInstance implements IParameter,
|
|||
return false;
|
||||
}
|
||||
|
||||
public IASTInitializer getDefaultValue() {
|
||||
return ((ICPPParameter)getOriginalBinding()).getDefaultValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -49,6 +49,16 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public IType stripQualifiers(){
|
||||
CPPPointerType result = this;
|
||||
if( isConst || isVolatile ){
|
||||
result = (CPPPointerType) clone();
|
||||
result.isConst = false;
|
||||
result.isVolatile = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isSameType( IType o ){
|
||||
if( o == this )
|
||||
return true;
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
public class CPPQualifierType implements IQualifierType, ITypeContainer {
|
||||
private boolean isConst = false;
|
||||
private boolean isVolatile = false;
|
||||
private boolean fromStringLiteral = false;
|
||||
private IType type = null;
|
||||
|
||||
public CPPQualifierType( IType type, boolean isConst, boolean isVolatile ){
|
||||
|
@ -80,15 +79,4 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
|
|||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean fromStringLiteral() {
|
||||
return fromStringLiteral;
|
||||
}
|
||||
|
||||
public void setFromStringLiteral( boolean fromString ){
|
||||
fromStringLiteral = fromString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -75,11 +76,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
|
@ -88,11 +91,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
|
@ -136,7 +141,7 @@ public class CPPSemantics {
|
|||
public boolean considerConstructors = false;
|
||||
public Object foundItems = null;
|
||||
public Object [] functionParameters;
|
||||
public IASTNode [] templateParameters;
|
||||
public IASTNode [] templateArguments;
|
||||
public ProblemBinding problem;
|
||||
|
||||
|
||||
|
@ -155,7 +160,8 @@ public class CPPSemantics {
|
|||
if( astName.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
|
||||
if( ( astName != null && astName.getParent() instanceof IASTIdExpression ) ||
|
||||
item instanceof IASTNamespaceDefinition ||
|
||||
(item instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)item).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier ) )
|
||||
(item instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)item).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier ) ||
|
||||
item instanceof ICPPASTTemplateDeclaration )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -463,6 +469,18 @@ public class CPPSemantics {
|
|||
binding = e.getProblem();
|
||||
}
|
||||
}
|
||||
if( binding instanceof ICPPClassTemplate ){
|
||||
ASTNodeProperty prop = data.astName.getPropertyInParent();
|
||||
if( prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME ){
|
||||
try {
|
||||
IScope scope = ((ICPPClassType)binding).getCompositeScope();
|
||||
if( CPPVisitor.getContainingScope( data.astName ) == scope ){
|
||||
binding = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) binding );
|
||||
}
|
||||
} catch( DOMException e ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if( binding instanceof ICPPClassType && data.considerConstructors ){
|
||||
ICPPClassType cls = (ICPPClassType) binding;
|
||||
try {
|
||||
|
@ -479,9 +497,14 @@ public class CPPSemantics {
|
|||
}
|
||||
if( binding != null ) {
|
||||
if( data.astName.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){
|
||||
IASTNode parent = data.astName.getParent().getParent();
|
||||
if( parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){
|
||||
//don't do a problem here
|
||||
} else {
|
||||
binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( binding != null && !( binding instanceof IProblemBinding ) ){
|
||||
if( data.forDefinition() ){
|
||||
|
@ -497,13 +520,14 @@ public class CPPSemantics {
|
|||
CPPSemantics.LookupData data = new CPPSemantics.LookupData( name );
|
||||
IASTNode parent = name.getParent();
|
||||
|
||||
if( parent instanceof ICPPASTTemplateId ){
|
||||
data.templateParameters = ((ICPPASTTemplateId)parent).getTemplateArguments();
|
||||
parent = parent.getParent();
|
||||
if( name instanceof ICPPASTTemplateId ){
|
||||
data.templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments();
|
||||
}
|
||||
if( parent instanceof ICPPASTQualifiedName ){
|
||||
|
||||
if( parent instanceof ICPPASTTemplateId )
|
||||
parent = parent.getParent();
|
||||
if( parent instanceof ICPPASTQualifiedName )
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if( parent instanceof IASTDeclarator && parent.getPropertyInParent() == IASTSimpleDeclaration.DECLARATOR ){
|
||||
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) parent.getParent();
|
||||
|
@ -583,7 +607,9 @@ public class CPPSemantics {
|
|||
if( t instanceof ICPPClassType ){
|
||||
if( !classes.containsKey( t ) ){
|
||||
classes.put( t );
|
||||
namespaces.put( getContainingNamespaceScope( (IBinding) t ) );
|
||||
IScope scope = getContainingNamespaceScope( (IBinding) t );
|
||||
if( scope != null )
|
||||
namespaces.put( scope );
|
||||
|
||||
ICPPClassType cls = (ICPPClassType) t;
|
||||
ICPPBase[] bases = cls.getBases();
|
||||
|
@ -694,7 +720,7 @@ public class CPPSemantics {
|
|||
|
||||
return resultMap;
|
||||
}
|
||||
static private void lookup( CPPSemantics.LookupData data, Object start ) throws DOMException{
|
||||
static protected void lookup( CPPSemantics.LookupData data, Object start ) throws DOMException{
|
||||
IASTNode node = data.astName;
|
||||
|
||||
ICPPScope scope = null;
|
||||
|
@ -780,7 +806,11 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
private static Object lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ) throws DOMException{
|
||||
ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) lookIn.getPhysicalNode();
|
||||
IASTNode node = lookIn.getPhysicalNode();
|
||||
if( node == null || !(node instanceof ICPPASTCompositeTypeSpecifier) )
|
||||
return null;
|
||||
|
||||
ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) node;
|
||||
ICPPASTBaseSpecifier [] bases = compositeTypeSpec.getBaseSpecifiers();
|
||||
|
||||
Object inherited = null;
|
||||
|
@ -854,13 +884,13 @@ public class CPPSemantics {
|
|||
if( result instanceof Object [] ){
|
||||
Object [] r = (Object[]) result;
|
||||
for( int j = 0; j < r.length && r[j] != null; j++ ) {
|
||||
if( checkForAmbiguity( r[j], inherited ) ){
|
||||
if( checkForAmbiguity( data, r[j], inherited ) ){
|
||||
data.problem = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( checkForAmbiguity( result, inherited ) ){
|
||||
if( checkForAmbiguity( data, result, inherited ) ){
|
||||
data.problem = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
return null;
|
||||
}
|
||||
|
@ -908,14 +938,13 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
}
|
||||
private static boolean checkForAmbiguity( Object n, Object names ) throws DOMException{
|
||||
private static boolean checkForAmbiguity( LookupData data, Object n, Object names ) throws DOMException{
|
||||
if( names instanceof Object[] ) {
|
||||
names = ArrayUtil.trim( Object.class, (Object[]) names );
|
||||
if( ((Object[])names).length == 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
||||
IBinding binding = ( n instanceof IBinding) ? (IBinding)n : ((IASTName)n).resolveBinding();
|
||||
Object [] objs = ( names instanceof Object[] ) ? (Object[])names : null;
|
||||
int idx = ( objs != null && objs.length > 0 ) ? 0 : -1;
|
||||
|
@ -925,13 +954,29 @@ public class CPPSemantics {
|
|||
|
||||
if( binding != b )
|
||||
return true;
|
||||
if( !(binding instanceof IEnumerator) &&
|
||||
!( (binding instanceof IFunction && ((IFunction)binding).isStatic()) ||
|
||||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
//3.4.5-4 if the id-expression in a class member access is a qualified id... the result
|
||||
//is not required to be a unique base class...
|
||||
if( binding instanceof ICPPClassType ){
|
||||
IASTNode parent = data.astName.getParent();
|
||||
if( parent instanceof ICPPASTQualifiedName &&
|
||||
parent.getPropertyInParent() == IASTFieldReference.FIELD_NAME )
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
||||
if( binding instanceof IEnumerator ||
|
||||
(binding instanceof IFunction && ((IFunction)binding).isStatic()) ||
|
||||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) )
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
if( !ok )
|
||||
return true;
|
||||
|
||||
next:
|
||||
if( idx > -1 && idx < objs.length )
|
||||
o = objs[idx++];
|
||||
else
|
||||
|
@ -1028,6 +1073,12 @@ public class CPPSemantics {
|
|||
} else if ( parent instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
ICPPASTCompositeTypeSpecifier comp = (ICPPASTCompositeTypeSpecifier) parent;
|
||||
nodes = comp.getMembers();
|
||||
|
||||
//9-2 a class name is also inserted into the scope of the class itself
|
||||
IASTName n = comp.getName();
|
||||
if( nameMatches( data, n ) ) {
|
||||
found = (IASTName[]) ArrayUtil.append( IASTName.class, found, n );
|
||||
}
|
||||
} else if ( parent instanceof ICPPASTNamespaceDefinition ){
|
||||
//need binding because namespaces can be split
|
||||
CPPNamespace namespace = (CPPNamespace) ((ICPPASTNamespaceDefinition)parent).getName().resolveBinding();
|
||||
|
@ -1123,6 +1174,8 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scope.setFullyCached( true );
|
||||
|
||||
return found;
|
||||
|
@ -1453,6 +1506,10 @@ public class CPPSemantics {
|
|||
(type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) )
|
||||
{
|
||||
//ok, delegates are synonyms
|
||||
} else if( type instanceof ICPPClassTemplate && temp instanceof ICPPTemplateSpecialization &&
|
||||
((ICPPTemplateSpecialization)temp).getPrimaryTemplateDefinition() == type )
|
||||
{
|
||||
//ok, stay with the template, the specialization, if applicable, will come out during instantiation
|
||||
} else if( type != temp ) {
|
||||
return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
}
|
||||
|
@ -1497,7 +1554,7 @@ public class CPPSemantics {
|
|||
|
||||
int numTemplateFns = templateFns.size();
|
||||
if( numTemplateFns > 0 ){
|
||||
if( data.functionParameters != null && ( !data.forDefinition() || data.templateParameters != null ) ){
|
||||
if( data.functionParameters != null && !data.forDefinition() ){
|
||||
IFunction [] fs = CPPTemplates.selectTemplateFunctions( templateFns, data.functionParameters, data.astName );
|
||||
if( fs != null && fs.length > 0){
|
||||
if( fns == ObjectSet.EMPTY_SET )
|
||||
|
@ -1584,16 +1641,14 @@ public class CPPSemantics {
|
|||
//if there are m arguments in the list, all candidate functions having m parameters
|
||||
//are viable
|
||||
if( num == numParameters ){
|
||||
if( data.forDefinition() && !functionHasParameters( fName, (IASTParameterDeclaration[]) data.functionParameters ) ){
|
||||
if( data.forDefinition() && !isMatchingFunctionDeclaration( fName, data ) ){
|
||||
functions[i] = null;
|
||||
}
|
||||
continue;
|
||||
} else if( function == null ){
|
||||
functions[i] = null;
|
||||
continue;
|
||||
}
|
||||
//check for void
|
||||
else if( numParameters == 0 && num == 1 ){
|
||||
if( function != null ){
|
||||
IASTParameterDeclaration param = function.getParameters()[0];
|
||||
IASTDeclSpecifier declSpec = param.getDeclSpecifier();
|
||||
if( declSpec instanceof IASTSimpleDeclSpecifier ){
|
||||
|
@ -1603,12 +1658,19 @@ public class CPPSemantics {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IParameter p = fName.getParameters()[0];
|
||||
IType t = p.getType();
|
||||
if( t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void )
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//A candidate function having fewer than m parameters is viable only if it has an
|
||||
//ellipsis in its parameter list.
|
||||
if( num < numParameters ){
|
||||
if( function.takesVarArgs() ) {
|
||||
if( (function != null && function.takesVarArgs()) || fName.takesVarArgs() ) {
|
||||
continue;
|
||||
}
|
||||
//not enough parameters, remove it
|
||||
|
@ -1617,6 +1679,7 @@ public class CPPSemantics {
|
|||
//a candidate function having more than m parameters is viable only if the (m+1)-st
|
||||
//parameter has a default argument
|
||||
else {
|
||||
if( function != null ) {
|
||||
IASTParameterDeclaration [] params = function.getParameters();
|
||||
for( int j = num - 1; j >= numParameters; j-- ){
|
||||
if( params[j].getDeclarator().getInitializer() == null ){
|
||||
|
@ -1625,9 +1688,33 @@ public class CPPSemantics {
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IParameter [] params = fName.getParameters();
|
||||
for( int j = num - 1; j >= numParameters; j-- ){
|
||||
if( ((ICPPParameter)params[j]).getDefaultValue() == null ){
|
||||
functions[i] = null;
|
||||
size--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static private boolean isMatchingFunctionDeclaration( IFunction candidate, LookupData data ){
|
||||
IASTName name = data.astName;
|
||||
ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration( name );
|
||||
if( candidate instanceof ICPPTemplateDefinition && decl instanceof ICPPASTTemplateSpecialization ){
|
||||
ICPPFunctionTemplate fn = CPPTemplates.resolveTemplateFunctions( new Object [] { candidate }, data.astName );
|
||||
return ( fn != null && !(fn instanceof IProblemBinding ) );
|
||||
}
|
||||
|
||||
try {
|
||||
return functionHasParameters( candidate, (IASTParameterDeclaration[]) data.functionParameters );
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static private IType getSourceParameterType( Object [] params, int idx ){
|
||||
if( params instanceof IType[] ){
|
||||
|
@ -1815,6 +1902,34 @@ public class CPPSemantics {
|
|||
ambiguous |= ( hasWorse && hasBetter ) || ( !hasWorse && !hasBetter );
|
||||
|
||||
if( !hasWorse ){
|
||||
//if they are both template functions, we can order them that way
|
||||
boolean bestIsTemplate = (bestFn instanceof ICPPTemplateInstance &&
|
||||
((ICPPTemplateInstance)bestFn).getOriginalBinding() instanceof ICPPFunctionTemplate);
|
||||
boolean currIsTemplate = (currFn instanceof ICPPTemplateInstance &&
|
||||
((ICPPTemplateInstance)currFn).getOriginalBinding() instanceof ICPPFunctionTemplate);
|
||||
if( bestIsTemplate && currIsTemplate )
|
||||
{
|
||||
ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)bestFn).getOriginalBinding();
|
||||
ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)currFn).getOriginalBinding();
|
||||
int order = CPPTemplates.orderTemplateFunctions( t1, t2);
|
||||
if ( order < 0 ){
|
||||
hasBetter = true;
|
||||
} else if( order > 0 ){
|
||||
ambiguous = false;
|
||||
}
|
||||
}
|
||||
//we prefer normal functions over template functions, unless we specified template arguments
|
||||
else if( bestIsTemplate && !currIsTemplate ){
|
||||
if( data.templateArguments == null )
|
||||
hasBetter = true;
|
||||
else
|
||||
ambiguous = false;
|
||||
} else if( !bestIsTemplate && currIsTemplate ){
|
||||
if( data.templateArguments == null )
|
||||
ambiguous = false;
|
||||
else
|
||||
hasBetter = true;
|
||||
}
|
||||
if( hasBetter ){
|
||||
//the new best function.
|
||||
ambiguous = false;
|
||||
|
@ -2049,7 +2164,7 @@ public class CPPSemantics {
|
|||
return result;
|
||||
}
|
||||
|
||||
static private Cost checkStandardConversionSequence( IType source, IType target ) throws DOMException {
|
||||
static protected Cost checkStandardConversionSequence( IType source, IType target ) throws DOMException {
|
||||
Cost cost = lvalue_to_rvalue( source, target );
|
||||
|
||||
if( cost.source == null || cost.target == null ){
|
||||
|
@ -2288,8 +2403,18 @@ public class CPPSemantics {
|
|||
else {
|
||||
//4.2-2 a string literal can be converted to pointer to char
|
||||
if( t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char &&
|
||||
s instanceof CPPQualifierType && ((CPPQualifierType)s).fromStringLiteral() )
|
||||
canConvert = true;
|
||||
s instanceof IQualifierType )
|
||||
{
|
||||
IType qt = ((IQualifierType)s).getType();
|
||||
if( qt instanceof IBasicType ){
|
||||
IASTExpression val = ((IBasicType)qt).getValue();
|
||||
canConvert = (val != null &&
|
||||
val instanceof IASTLiteralExpression &&
|
||||
((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal );
|
||||
} else {
|
||||
canConvert = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
canConvert = false;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
|
@ -22,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
|
@ -29,23 +31,52 @@ 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.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
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.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, ICPPInternalBinding {
|
||||
public static final class CPPTemplateProblem extends ProblemBinding implements ICPPTemplateDefinition {
|
||||
public CPPTemplateProblem(IASTNode node, int id, char[] arg) {
|
||||
super(node, id, arg);
|
||||
}
|
||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
//private IASTName templateName;
|
||||
protected IASTName [] declarations = null;
|
||||
protected IASTName definition = null;
|
||||
|
||||
private ICPPTemplateParameter [] templateParameters = null;
|
||||
private ICPPTemplateSpecialization [] specializations = null;
|
||||
private ObjectMap instances = null;
|
||||
|
||||
public CPPTemplateDefinition( IASTName name ) {
|
||||
if( name != null ){
|
||||
ASTNodeProperty prop = name.getPropertyInParent();
|
||||
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ){
|
||||
definition = name;
|
||||
|
@ -61,16 +92,142 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
|
|||
declarations = new IASTName [] { name };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract IBinding instantiate( ICPPASTTemplateId templateId );
|
||||
public abstract ICPPTemplateInstance deferredInstance( IType [] arguments );
|
||||
|
||||
public ICPPTemplateSpecialization [] getSpecializations() {
|
||||
public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) {
|
||||
IASTNode [] args = templateId.getTemplateArguments();
|
||||
IType [] types = CPPTemplates.createTypeArray( args );
|
||||
return instantiate( types );
|
||||
}
|
||||
|
||||
public IBinding instantiate( IType [] arguments ){
|
||||
ICPPTemplateDefinition template;
|
||||
try {
|
||||
template = CPPTemplates.matchTemplatePartialSpecialization( this, arguments );
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
|
||||
if( template != null && template instanceof ICPPTemplateSpecialization ){
|
||||
return ((CPPTemplateDefinition)template).instantiate( arguments );
|
||||
}
|
||||
|
||||
if( template == null ){
|
||||
template = this;
|
||||
}
|
||||
|
||||
ICPPTemplateParameter[] parameters = null;
|
||||
try {
|
||||
parameters = template.getTemplateParameters();
|
||||
} catch (DOMException e1) {
|
||||
return e1.getProblem();
|
||||
}
|
||||
|
||||
int numParams = ( parameters != null ) ? parameters.length : 0;
|
||||
int numArgs = arguments.length;
|
||||
|
||||
if( numParams == 0 ){
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectMap map = new ObjectMap( numParams );
|
||||
ICPPTemplateParameter param = null;
|
||||
IType arg = null;
|
||||
IType[] actualArgs = new IType[ numParams ];
|
||||
|
||||
for( int i = 0; i < numParams; i++ ){
|
||||
|
||||
param = parameters[i];
|
||||
|
||||
if( i < numArgs ){
|
||||
arg = arguments[i];
|
||||
//If the argument is a template parameter, we can't instantiate yet, defer for later
|
||||
if( arg instanceof ICPPTemplateParameter ){
|
||||
return deferredInstance( arguments );
|
||||
}
|
||||
} else {
|
||||
IType defaultType = null;
|
||||
try {
|
||||
if( param instanceof ICPPTemplateTypeParameter )
|
||||
defaultType = ((ICPPTemplateTypeParameter)param).getDefault();
|
||||
else if( param instanceof ICPPTemplateTemplateParameter )
|
||||
defaultType = ((ICPPTemplateTemplateParameter)param).getDefault();
|
||||
else if( param instanceof ICPPTemplateNonTypeParameter )
|
||||
defaultType = CPPVisitor.getExpressionType( ((ICPPTemplateNonTypeParameter)param).getDefault() );
|
||||
} catch (DOMException e) {
|
||||
defaultType = e.getProblem();
|
||||
}
|
||||
if( defaultType != null ){
|
||||
if( defaultType instanceof ICPPTemplateParameter ){
|
||||
if( map.containsKey( defaultType ) ){
|
||||
arg = (IType) map.get( defaultType );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//TODO problem
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if( CPPTemplates.matchTemplateParameterAndArgument( param, arg ) ){
|
||||
map.put( param, arg );
|
||||
actualArgs[i] = arg;
|
||||
} else {
|
||||
//TODO problem
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ICPPTemplateInstance instance = getInstance( actualArgs );
|
||||
if( instance != null ){
|
||||
return instance;
|
||||
}
|
||||
|
||||
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, map, arguments );
|
||||
addInstance( arguments, instance );
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ICPPTemplateSpecialization [] getTemplateSpecializations() {
|
||||
return (ICPPTemplateSpecialization[]) ArrayUtil.trim( ICPPTemplateSpecialization.class, specializations );
|
||||
}
|
||||
public void addSpecialization( ICPPTemplateSpecialization spec ){
|
||||
specializations = (ICPPTemplateSpecialization[]) ArrayUtil.append( ICPPTemplateSpecialization.class, specializations, spec );
|
||||
|
||||
}
|
||||
public ICPPTemplateInstance getInstance( IType [] arguments ) {
|
||||
if( instances == null )
|
||||
return null;
|
||||
|
||||
int found = -1;
|
||||
for( int i = 0; i < instances.size(); i++ ){
|
||||
IType [] args = (IType[]) instances.keyAt( i );
|
||||
if( args.length == arguments.length ){
|
||||
int j = 0;
|
||||
for(; j < args.length; j++) {
|
||||
if( !( args[j].equals( arguments[j] ) ) )
|
||||
break;
|
||||
}
|
||||
if( j == args.length ){
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( found != -1 ){
|
||||
return (ICPPTemplateInstance) instances.getAt(found);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addInstance( IType [] types, ICPPTemplateInstance instance ){
|
||||
if( instances == null )
|
||||
instances = new ObjectMap( 2 );
|
||||
instances.put( types, instance );
|
||||
}
|
||||
|
||||
public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) {
|
||||
IASTName name = CPPTemplates.getTemplateParameterName( templateParameter );
|
||||
|
@ -78,10 +235,6 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
|
|||
if( binding != null )
|
||||
return binding;
|
||||
|
||||
if( templateParameter.getParent() instanceof ICPPASTTemplatedTypeTemplateParameter ){
|
||||
|
||||
}
|
||||
|
||||
ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) templateParameter.getParent();
|
||||
ICPPASTTemplateParameter [] ps = templateDecl.getTemplateParameters();
|
||||
|
||||
|
@ -92,7 +245,13 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
|
|||
}
|
||||
|
||||
//create a new binding and set it for the corresponding parameter in all known decls
|
||||
binding = new CPPTemplateParameter( name );
|
||||
if( templateParameter instanceof ICPPASTSimpleTypeTemplateParameter )
|
||||
binding = new CPPTemplateTypeParameter( name );
|
||||
else if( templateParameter instanceof ICPPASTParameterDeclaration )
|
||||
binding = new CPPTemplateNonTypeParameter( name );
|
||||
else
|
||||
binding = new CPPTemplateTemplateParameter( name );
|
||||
|
||||
ICPPASTTemplateParameter temp = null;
|
||||
ICPPASTTemplateDeclaration template = null;
|
||||
int length = ( declarations != null ) ? declarations.length : 0;
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 13, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
|
||||
ICPPTemplateNonTypeParameter {
|
||||
|
||||
private IType type = null;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CPPTemplateNonTypeParameter(IASTName name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter#getDefault()
|
||||
*/
|
||||
public IASTExpression getDefault() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
|
||||
*/
|
||||
public IType getType() {
|
||||
if( type == null ){
|
||||
IASTName name = getPrimaryDeclaration();
|
||||
IASTDeclarator dtor = (IASTDeclarator) name.getParent();
|
||||
type = CPPVisitor.createType( dtor );
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
|
||||
*/
|
||||
public boolean isStatic() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
|
||||
*/
|
||||
public boolean isExtern() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
|
||||
*/
|
||||
public boolean isAuto() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
|
||||
*/
|
||||
public boolean isRegister() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public ICPPDelegate createDelegate(IASTName name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
|
@ -25,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPTemplateParameter implements ICPPTemplateParameter, IType, ICPPInternalBinding {
|
||||
public class CPPTemplateParameter implements ICPPTemplateParameter, ICPPInternalBinding {
|
||||
private IASTName [] declarations;
|
||||
|
||||
public CPPTemplateParameter( IASTName name ){
|
||||
|
@ -141,15 +140,4 @@ public class CPPTemplateParameter implements ICPPTemplateParameter, IType, ICPPI
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
public boolean isSameType( IType type ) {
|
||||
if( type == this )
|
||||
return true;
|
||||
if( type instanceof ITypedef )
|
||||
return ((ITypedef)type).isSameType( this );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,240 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 13, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements
|
||||
ICPPTemplateTemplateParameter, ICPPClassType {
|
||||
|
||||
private ICPPTemplateParameter [] templateParameters = null;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CPPTemplateTemplateParameter(IASTName name) {
|
||||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter#getTemplateParameters()
|
||||
*/
|
||||
public ICPPTemplateParameter[] getTemplateParameters() {
|
||||
if( templateParameters == null ){
|
||||
ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration().getParent();
|
||||
ICPPASTTemplateParameter [] params = template.getTemplateParameters();
|
||||
ICPPTemplateParameter p = null;
|
||||
ICPPTemplateParameter [] result = null;
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if( params[i] instanceof ICPPASTSimpleTypeTemplateParameter ){
|
||||
p = (ICPPTemplateParameter) ((ICPPASTSimpleTypeTemplateParameter)params[i]).getName().resolveBinding();
|
||||
} else if( params[i] instanceof ICPPASTParameterDeclaration ) {
|
||||
p = (ICPPTemplateParameter) ((ICPPASTParameterDeclaration)params[i]).getDeclarator().getName().resolveBinding();
|
||||
} else if( params[i] instanceof ICPPASTTemplatedTypeTemplateParameter ){
|
||||
p = (ICPPTemplateParameter) ((ICPPASTTemplatedTypeTemplateParameter)params[i]).getName().resolveBinding();
|
||||
}
|
||||
|
||||
if( p != null ){
|
||||
result = (ICPPTemplateParameter[]) ArrayUtil.append( ICPPTemplateParameter.class, result, p );
|
||||
}
|
||||
}
|
||||
templateParameters = (ICPPTemplateParameter[]) ArrayUtil.trim( ICPPTemplateParameter.class, result );
|
||||
}
|
||||
return templateParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateParameter
|
||||
* @return
|
||||
*/
|
||||
public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) {
|
||||
IASTName name = CPPTemplates.getTemplateParameterName( templateParameter );
|
||||
|
||||
IBinding binding = name.getBinding();
|
||||
if( binding == null ){
|
||||
//create a new binding and set it for the corresponding parameter in all known decls
|
||||
if( templateParameter instanceof ICPPASTSimpleTypeTemplateParameter )
|
||||
binding = new CPPTemplateTypeParameter( name );
|
||||
else if( templateParameter instanceof ICPPASTParameterDeclaration )
|
||||
binding = new CPPTemplateNonTypeParameter( name );
|
||||
else
|
||||
binding = new CPPTemplateTemplateParameter( name );
|
||||
name.setBinding( binding );
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateSpecializations()
|
||||
*/
|
||||
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException {
|
||||
return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter#getDefault()
|
||||
*/
|
||||
public IType getDefault() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
||||
*/
|
||||
public ICPPBase[] getBases() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFields()
|
||||
*/
|
||||
public IField[] getFields() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#findField(java.lang.String)
|
||||
*/
|
||||
public IField findField(String name) throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
|
||||
*/
|
||||
public ICPPField[] getDeclaredFields() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
|
||||
*/
|
||||
public ICPPMethod[] getMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
|
||||
*/
|
||||
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
|
||||
*/
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors()
|
||||
*/
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
|
||||
*/
|
||||
public IBinding[] getFriends() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
|
||||
*/
|
||||
public int getKey() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
|
||||
*/
|
||||
public IScope getCompositeScope() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public ICPPDelegate createDelegate(IASTName name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
public boolean isSameType( IType type ) {
|
||||
if( type == this )
|
||||
return true;
|
||||
if( type instanceof ITypedef )
|
||||
return ((ITypedef)type).isSameType( this );
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 13, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
|
||||
ICPPTemplateTypeParameter, IType {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CPPTemplateTypeParameter(IASTName name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter#getDefault()
|
||||
*/
|
||||
public IType getDefault() throws DOMException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
public boolean isSameType( IType type ) {
|
||||
if( type == this )
|
||||
return true;
|
||||
if( type instanceof ITypedef )
|
||||
return ((ITypedef)type).isSameType( this );
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,18 +17,30 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
|
@ -40,18 +52,26 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
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.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
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.cpp.CPPSemantics.Cost;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -90,8 +110,11 @@ public class CPPTemplates {
|
|||
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) decl;
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
if( dtors.length == 0 ){
|
||||
if( simpleDecl.getDeclSpecifier() instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
name = ((ICPPASTCompositeTypeSpecifier)simpleDecl.getDeclSpecifier()).getName();
|
||||
IASTDeclSpecifier spec = simpleDecl.getDeclSpecifier();
|
||||
if( spec instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
name = ((ICPPASTCompositeTypeSpecifier)spec).getName();
|
||||
} else if( spec instanceof ICPPASTElaboratedTypeSpecifier ){
|
||||
name = ((ICPPASTElaboratedTypeSpecifier)spec).getName();
|
||||
}
|
||||
} else {
|
||||
IASTDeclarator dtor = dtors[0];
|
||||
|
@ -126,6 +149,9 @@ public class CPPTemplates {
|
|||
} else {
|
||||
binding = name.resolveBinding();
|
||||
}
|
||||
} else if( parent instanceof ICPPASTTemplatedTypeTemplateParameter ){
|
||||
ICPPASTTemplatedTypeTemplateParameter templatedParam = (ICPPASTTemplatedTypeTemplateParameter) parent;
|
||||
binding = templatedParam.getName().resolveBinding();
|
||||
}
|
||||
return (binding instanceof ICPPTemplateDefinition) ? (ICPPTemplateDefinition) binding : null;
|
||||
}
|
||||
|
@ -135,6 +161,8 @@ public class CPPTemplates {
|
|||
IBinding binding = null;
|
||||
if( template instanceof CPPTemplateDefinition ){
|
||||
binding = ((CPPTemplateDefinition)template).resolveTemplateParameter( templateParameter );
|
||||
} else if( template instanceof CPPTemplateTemplateParameter ){
|
||||
binding = ((CPPTemplateTemplateParameter)template).resolveTemplateParameter( templateParameter );
|
||||
}
|
||||
|
||||
return binding;
|
||||
|
@ -159,26 +187,67 @@ public class CPPTemplates {
|
|||
*/
|
||||
public static IBinding createBinding(ICPPASTTemplateId id) {
|
||||
IASTNode parent = id.getParent();
|
||||
if( parent instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
return createClassPartialSpecialization( (ICPPASTCompositeTypeSpecifier) parent );
|
||||
int segment = -1;
|
||||
if( parent instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
|
||||
segment = ( ns[ ns.length - 1 ] == id ) ? 1 : 0;
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if( parent instanceof ICPPASTCompositeTypeSpecifier && segment == 1 ){
|
||||
return createClassPartialSpecialization( (ICPPASTCompositeTypeSpecifier) parent );
|
||||
} else if( parent instanceof ICPPASTFunctionDeclarator && segment == 1 ){
|
||||
return createFunctionSpecialization( id );
|
||||
}
|
||||
|
||||
//a reference: class or function template?
|
||||
IBinding template = null;
|
||||
if( parent instanceof ICPPASTNamedTypeSpecifier || segment == 0 ){
|
||||
//class template
|
||||
IASTName templateName = id.getTemplateName();
|
||||
IBinding template = templateName.resolveBinding();
|
||||
template = templateName.resolveBinding();
|
||||
if( template instanceof ICPPTemplateSpecialization ){
|
||||
//specializations are selected during the instantiation, start with the primary template
|
||||
try {
|
||||
template = ((ICPPTemplateSpecialization)template).getPrimaryTemplateDefinition();
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
}
|
||||
|
||||
if( template != null && template instanceof ICPPTemplateDefinition ){
|
||||
if( template instanceof CPPTemplateDefinition )
|
||||
if( template instanceof ICPPTemplateTemplateParameter ){
|
||||
return template;//todo
|
||||
} else if( template instanceof CPPTemplateDefinition )
|
||||
return ((CPPTemplateDefinition)template).instantiate( id );
|
||||
}
|
||||
} else {
|
||||
//functions are instatiated as part of the resolution process
|
||||
template = CPPVisitor.createBinding( id );
|
||||
if( template instanceof ICPPTemplateInstance ){
|
||||
IASTName templateName = id.getTemplateName();
|
||||
templateName.setBinding( ((ICPPTemplateInstance)template).getOriginalBinding() );
|
||||
}
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
protected static IBinding createClassPartialSpecialization( ICPPASTCompositeTypeSpecifier compSpec ){
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) compSpec.getName();
|
||||
IASTName name = compSpec.getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) name;
|
||||
|
||||
IBinding binding = id.getTemplateName().resolveBinding();
|
||||
if( !(binding instanceof ICPPClassTemplate) )
|
||||
return null; //TODO: problem?
|
||||
|
||||
CPPClassTemplate template = (CPPClassTemplate) binding;
|
||||
ICPPTemplateSpecialization [] specializations = template.getSpecializations();
|
||||
ICPPTemplateSpecialization [] specializations = template.getTemplateSpecializations();
|
||||
ICPPTemplateSpecialization spec = null;
|
||||
for (int i = 0; i < specializations.length; i++) {
|
||||
if( isSameTemplate( specializations[i], id ) ){
|
||||
|
@ -196,6 +265,165 @@ public class CPPTemplates {
|
|||
template.addSpecialization( spec );
|
||||
return spec;
|
||||
}
|
||||
|
||||
protected static IBinding createFunctionSpecialization( IASTName name ){
|
||||
CPPSemantics.LookupData data = new CPPSemantics.LookupData( name );
|
||||
data.forceQualified = true;
|
||||
IScope scope = CPPVisitor.getContainingScope( name );
|
||||
if( name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME ){
|
||||
try {
|
||||
scope = scope.getParent();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
CPPSemantics.lookup( data, scope );
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
|
||||
ICPPFunctionTemplate function = resolveTemplateFunctions( (Object[]) data.foundItems, name );
|
||||
if( function == null )
|
||||
return new ProblemBinding( name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray() );
|
||||
if( function instanceof IProblemBinding )
|
||||
return function;
|
||||
|
||||
if( name instanceof ICPPASTTemplateId ){
|
||||
((ICPPASTTemplateId)name).getTemplateName().setBinding( function );
|
||||
}
|
||||
IASTNode parent = name.getParent();
|
||||
while( parent instanceof IASTName )
|
||||
parent = parent.getParent();
|
||||
|
||||
ICPPTemplateSpecialization spec = new CPPFunctionTemplateSpecialization( (ICPPASTFunctionDeclarator)parent, function );
|
||||
((CPPTemplateDefinition)function).addSpecialization( spec );
|
||||
return spec;
|
||||
}
|
||||
|
||||
static protected ICPPFunctionTemplate resolveTemplateFunctions( Object [] items, IASTName name ) {
|
||||
if( items == null )
|
||||
return null;
|
||||
ICPPFunctionTemplate [] templates = null;
|
||||
IBinding temp = null;
|
||||
for( int i = 0; i < items.length; i++ ){
|
||||
Object o = items[i];
|
||||
|
||||
if( o instanceof IASTName ){
|
||||
temp = ((IASTName) o).resolveBinding();
|
||||
if( temp == null )
|
||||
continue;
|
||||
} else if( o instanceof IBinding ){
|
||||
temp = (IBinding) o;
|
||||
} else
|
||||
continue;
|
||||
|
||||
if( temp instanceof ICPPTemplateInstance )
|
||||
temp = ((ICPPTemplateInstance)temp).getOriginalBinding();
|
||||
if( temp instanceof ICPPFunctionTemplate )
|
||||
templates = (ICPPFunctionTemplate[]) ArrayUtil.append( ICPPFunctionTemplate.class, templates, temp );
|
||||
}
|
||||
|
||||
if( templates == null )
|
||||
return null;
|
||||
|
||||
IType [] templateArguments = null;
|
||||
|
||||
if( name instanceof ICPPASTTemplateId ){
|
||||
templateArguments = createTypeArray( ((ICPPASTTemplateId)name).getTemplateArguments() );
|
||||
}
|
||||
int numArgs = ( templateArguments != null ) ? templateArguments.length : 0;
|
||||
|
||||
|
||||
if( name.getParent() instanceof IASTName )
|
||||
name = (IASTName) name.getParent();
|
||||
ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) name.getParent();
|
||||
IType [] functionParameters = createTypeArray( fdtor.getParameters() );
|
||||
|
||||
ICPPFunctionTemplate result = null;
|
||||
outer: for( int i = 0; i < templates.length && templates[i] != null; i++ ){
|
||||
ICPPFunctionTemplate tmpl = templates[i];
|
||||
|
||||
ObjectMap map = ObjectMap.EMPTY_MAP;
|
||||
try {
|
||||
map = deduceTemplateArguments( tmpl, functionParameters );
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
|
||||
if( map == null )
|
||||
continue;
|
||||
ICPPTemplateParameter [] params = null;
|
||||
try {
|
||||
params = tmpl.getTemplateParameters();
|
||||
} catch (DOMException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int numParams = params.length;
|
||||
IType arg = null;
|
||||
for( int j = 0; j < numParams; j++ ){
|
||||
ICPPTemplateParameter param = params[j];
|
||||
if( j < numArgs ){
|
||||
arg = templateArguments[j];
|
||||
}
|
||||
if( map.containsKey( param ) ) {
|
||||
IType t = (IType) map.get( param );
|
||||
if( arg == null )
|
||||
arg = t;
|
||||
else if( !t.isSameType( arg ) ){
|
||||
continue outer;
|
||||
}
|
||||
} else if( arg == null || !matchTemplateParameterAndArgument( param, arg )){
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
//made it this far, its a match
|
||||
if( result != null ){
|
||||
return new CPPFunctionTemplate.CPPFunctionTemplateProblem(name, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, name.toCharArray() );
|
||||
}
|
||||
result = tmpl;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static protected IType[] deduceTemplateFunctionArguments( ICPPTemplateSpecialization specialization, IASTNode [] specArgs ) throws DOMException
|
||||
{
|
||||
if( !(specialization instanceof ICPPFunction ) )
|
||||
return null;
|
||||
|
||||
ICPPFunctionTemplate primaryTemplate = (ICPPFunctionTemplate) specialization.getPrimaryTemplateDefinition();
|
||||
ICPPTemplateParameter [] templateParameters = primaryTemplate.getTemplateParameters();
|
||||
IType [] arguments = createTypeArray( specArgs );
|
||||
|
||||
IType [] result = new IType[ templateParameters.length ];
|
||||
ObjectMap map = null;
|
||||
|
||||
for( int i = 0; i < templateParameters.length; i++ ){
|
||||
ICPPTemplateParameter param = templateParameters[i];
|
||||
IType arg = null;
|
||||
if( i < arguments.length ){
|
||||
arg = arguments[i];
|
||||
} else {
|
||||
if( map == null ){
|
||||
IParameter [] functionParameters = ((ICPPFunction)specialization).getParameters();
|
||||
IType [] paramTypes = createTypeArray( functionParameters );
|
||||
map = deduceTemplateArguments( primaryTemplate, paramTypes );
|
||||
if(map == null )
|
||||
return null;
|
||||
}
|
||||
if( map.containsKey( param ) ){
|
||||
arg = (IType) map.get( param );
|
||||
}
|
||||
}
|
||||
|
||||
if( arg == null || !matchTemplateParameterAndArgument( param, arg ) )
|
||||
return null;
|
||||
|
||||
result[i] = arg;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @param scope
|
||||
* @return
|
||||
|
@ -210,16 +438,16 @@ public class CPPTemplates {
|
|||
* @param arguments
|
||||
* @return
|
||||
*/
|
||||
public static IBinding createInstance( IASTName id, ICPPScope scope, IBinding decl, ObjectMap argMap) {
|
||||
public static IBinding createInstance( ICPPScope scope, IBinding decl, ObjectMap argMap, IType [] args ) {
|
||||
ICPPTemplateInstance instance = null;
|
||||
if( decl instanceof ICPPClassType ){
|
||||
instance = new CPPClassInstance( id, scope, decl, argMap );
|
||||
instance = new CPPClassInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPField ){
|
||||
instance = new CPPFieldInstance( scope, decl, argMap );
|
||||
instance = new CPPFieldInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPMethod ) {
|
||||
instance = new CPPMethodInstance( scope, decl, argMap );
|
||||
instance = new CPPMethodInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPFunction ) {
|
||||
instance = new CPPFunctionInstance( scope, decl, argMap );
|
||||
instance = new CPPFunctionInstance( scope, decl, argMap, args );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
@ -260,9 +488,13 @@ public class CPPTemplates {
|
|||
temp = (IType) type.clone();
|
||||
((ITypeContainer)temp).setType( newType );
|
||||
newType = temp;
|
||||
} else {
|
||||
newType = type;
|
||||
}
|
||||
} else if( type instanceof ICPPTemplateParameter && argMap.containsKey( type ) ){
|
||||
newType = (IType) argMap.get( type );
|
||||
} else if( type instanceof CPPDeferredClassInstance ){
|
||||
newType = ((CPPDeferredClassInstance)type).instantiate( argMap );
|
||||
}
|
||||
|
||||
return newType;
|
||||
|
@ -272,8 +504,11 @@ public class CPPTemplates {
|
|||
if( name == null ) return null;
|
||||
|
||||
IASTNode parent = name.getParent();
|
||||
while( !(parent instanceof ICPPASTTemplateDeclaration) )
|
||||
while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) &&
|
||||
!(parent instanceof ICPPASTTemplatedTypeTemplateParameter) )
|
||||
{
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if( parent == null ) return null;
|
||||
|
||||
|
@ -298,14 +533,16 @@ public class CPPTemplates {
|
|||
++i;
|
||||
}
|
||||
if( ns[j] == name ){
|
||||
if( i <= idx )
|
||||
return templates[ i - 1 ];
|
||||
break;
|
||||
if( i < idx )
|
||||
return templates[ i ];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return templates[0];
|
||||
}
|
||||
} else if( parent instanceof ICPPASTTemplatedTypeTemplateParameter ){
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
|
@ -333,7 +570,12 @@ public class CPPTemplates {
|
|||
* @return
|
||||
*/
|
||||
public static boolean isSameTemplate(ICPPTemplateDefinition definition, IASTName name) {
|
||||
ICPPTemplateParameter [] defParams = definition.getTemplateParameters();
|
||||
ICPPTemplateParameter [] defParams = null;
|
||||
try {
|
||||
defParams = definition.getTemplateParameters();
|
||||
} catch (DOMException e1) {
|
||||
return false;
|
||||
}
|
||||
ICPPASTTemplateDeclaration templateDecl = getTemplateDeclaration( name );
|
||||
ICPPASTTemplateParameter [] templateParams = templateDecl.getTemplateParameters();
|
||||
if( defParams.length != templateParams.length )
|
||||
|
@ -353,11 +595,21 @@ public class CPPTemplates {
|
|||
boolean result = false;
|
||||
IASTNode parent = name.getParent();
|
||||
if( parent instanceof ICPPASTFunctionDeclarator ){
|
||||
IType type = CPPVisitor.createType( (IASTDeclarator) parent );
|
||||
try {
|
||||
IType ftype = ((ICPPFunction)definition).getType();
|
||||
if( ftype.isSameType( type ) )
|
||||
IASTParameterDeclaration [] params = ((ICPPASTFunctionDeclarator)parent).getParameters();
|
||||
IParameter [] ps = ((ICPPFunction)definition).getParameters();
|
||||
if( ps.length == params.length ) {
|
||||
int i = 0;
|
||||
for(; i < ps.length; i++) {
|
||||
IType t1 = CPPVisitor.createType( params[i].getDeclarator() );
|
||||
IType t2 = ps[0].getType();
|
||||
if( ! t1.isSameType( t2 ) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( i == ps.length )
|
||||
result = true;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
} else if( parent instanceof IASTDeclSpecifier ){
|
||||
|
@ -365,10 +617,16 @@ public class CPPTemplates {
|
|||
if( definition instanceof ICPPTemplateSpecialization ){
|
||||
ICPPTemplateSpecialization spec = (ICPPTemplateSpecialization) definition;
|
||||
IASTNode [] args = ((ICPPASTTemplateId)name).getTemplateArguments();
|
||||
if( args.length == spec.getArguments().length ){
|
||||
IType [] specArgs = null;
|
||||
try {
|
||||
specArgs = spec.getArguments();
|
||||
} catch (DOMException e) {
|
||||
result = false;
|
||||
}
|
||||
if( specArgs != null && args.length == specArgs.length ){
|
||||
int i = 0;
|
||||
for (; i < args.length; i++) {
|
||||
IType t1 = CPPVisitor.createType( spec.getArguments()[i] );
|
||||
IType t1 = specArgs[i];
|
||||
IType t2 = CPPVisitor.createType( args[i] );
|
||||
if( t1 != null && t2 != null && t1.isSameType( t2 ) )
|
||||
continue;
|
||||
|
@ -390,20 +648,527 @@ public class CPPTemplates {
|
|||
return result;
|
||||
}
|
||||
|
||||
static public IType [] createTypeArray( Object [] params ){
|
||||
if( params instanceof IType[] )
|
||||
return (IType[]) params;
|
||||
|
||||
IType [] result = new IType[ params.length ];
|
||||
for( int i = 0; i < params.length; i++ ) {
|
||||
if( params[i] instanceof IASTNode ){
|
||||
result[i] = CPPVisitor.createType( (IASTNode) params[ i ] );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static protected IFunction[] selectTemplateFunctions( ObjectSet templates, Object[] functionArguments, IASTName name ) {//IASTNode[] templateArguments ){
|
||||
if( templates == null || templates.size() == 0 )
|
||||
return null;
|
||||
|
||||
IFunction [] instances = null;
|
||||
if( name.getParent() instanceof ICPPASTTemplateId )
|
||||
name = (IASTName) name.getParent();
|
||||
|
||||
int size = templates.size();
|
||||
|
||||
int numTemplateArgs = 0;
|
||||
IASTNode [] templateArguments = null;
|
||||
if( name instanceof ICPPASTTemplateId ) {
|
||||
Object [] keys = templates.keyArray();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
CPPTemplateDefinition templateDef = (CPPTemplateDefinition) keys[i];
|
||||
ICPPTemplateInstance temp = (ICPPTemplateInstance) templateDef.instantiate( (ICPPASTTemplateId) name );
|
||||
templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments();
|
||||
numTemplateArgs = templateArguments.length;
|
||||
}
|
||||
|
||||
IType [] fnArgs = createTypeArray( functionArguments );
|
||||
|
||||
outer: for( int idx = 0; idx < size; idx++ ){
|
||||
CPPFunctionTemplate template = (CPPFunctionTemplate) templates.keyAt( idx );
|
||||
|
||||
ObjectMap map = null;
|
||||
try {
|
||||
map = deduceTemplateArguments( template, fnArgs );
|
||||
} catch (DOMException e) {
|
||||
continue;
|
||||
}
|
||||
if( map == null )
|
||||
continue;
|
||||
|
||||
ICPPTemplateParameter [] templateParams = template.getTemplateParameters();
|
||||
int numTemplateParams = templateParams.length;
|
||||
|
||||
IType [] instanceArgs = null;
|
||||
for( int i = 0; i < numTemplateParams; i++ ){
|
||||
IType arg = ( i < numTemplateArgs ) ? CPPVisitor.createType( templateArguments[i] ) : null;
|
||||
IType mapped = (IType) map.get( templateParams[i] );
|
||||
|
||||
if( arg != null && mapped != null )
|
||||
if( arg.isSameType( mapped ) )
|
||||
instanceArgs = (IType[]) ArrayUtil.append( IType.class, instanceArgs, arg );
|
||||
else
|
||||
continue outer;
|
||||
else if( arg == null && mapped == null )
|
||||
continue outer;
|
||||
else
|
||||
instanceArgs = (IType[]) ArrayUtil.append( IType.class, instanceArgs, (arg != null) ? arg : mapped );
|
||||
}
|
||||
instanceArgs = (IType[]) ArrayUtil.trim( IType.class, instanceArgs );
|
||||
ICPPTemplateInstance temp = (ICPPTemplateInstance) template.instantiate( instanceArgs );
|
||||
if( temp != null )
|
||||
instances = (IFunction[]) ArrayUtil.append( IFunction.class, instances, temp );
|
||||
}
|
||||
|
||||
return (IFunction[]) ArrayUtil.trim( IFunction.class, instances );
|
||||
}
|
||||
return instances;
|
||||
//TODO, instead of the above, do proper argument checking, deduction
|
||||
|
||||
/**
|
||||
*
|
||||
* @param template
|
||||
* @param args
|
||||
* @return
|
||||
*
|
||||
* A type that is specified in terms of template parameters (P) is compared with an actual
|
||||
* type (A), and an attempt is made to find template argument vaules that will make P,
|
||||
* after substitution of the deduced values, compatible with A.
|
||||
* @throws DOMException
|
||||
*/
|
||||
static private ObjectMap deduceTemplateArguments( ICPPFunctionTemplate template, IType[] arguments ) throws DOMException{
|
||||
ICPPFunction function = (ICPPFunction) template;
|
||||
IParameter [] functionParameters = null;
|
||||
try {
|
||||
functionParameters = function.getParameters();
|
||||
} catch (DOMException e) {
|
||||
return null;
|
||||
}
|
||||
if( arguments == null /*|| functionParameters.length != arguments.length*/ ){
|
||||
return null;
|
||||
}
|
||||
|
||||
int numParams = functionParameters.length;
|
||||
int numArgs = arguments.length;
|
||||
ObjectMap map = new ObjectMap(numParams);
|
||||
for( int i = 0; i < numArgs && i < numParams; i++ ){
|
||||
if( !deduceTemplateArgument( map, functionParameters[i].getType(), arguments[i] ) ){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 14.8.2.1-2 If P is a cv-qualified type, the top level cv-qualifiers of P's type are ignored for type
|
||||
* deduction. If P is a reference type, the type referred to by P is used for Type deduction.
|
||||
* @param pSymbol
|
||||
* @return
|
||||
*/
|
||||
static private IType getParameterTypeForDeduction( IType pType ){
|
||||
IType result = pType;
|
||||
try {
|
||||
if( pType instanceof IQualifierType ){
|
||||
result = ((IQualifierType)pType).getType();
|
||||
} else if( pType instanceof ICPPReferenceType ){
|
||||
result = ((ICPPReferenceType)pType).getType();
|
||||
} else if( pType instanceof CPPPointerType ){
|
||||
result = ((CPPPointerType)pType).stripQualifiers();
|
||||
}
|
||||
} catch ( DOMException e ){
|
||||
result = e.getProblem();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 14.8.2.1-2
|
||||
* if P is not a reference type
|
||||
* - If A is an array type, the pointer type produced by the array-to-pointer conversion is used instead
|
||||
* - If A is a function type, the pointer type produced by the function-to-pointer conversion is used instead
|
||||
* - If A is a cv-qualified type, the top level cv-qualifiers are ignored for type deduction
|
||||
* @param aInfo
|
||||
* @return
|
||||
*/
|
||||
static private IType getArgumentTypeForDeduction( IType aType, boolean pIsAReferenceType ) {
|
||||
IType result = aType;
|
||||
if( !pIsAReferenceType ){
|
||||
try {
|
||||
if( aType instanceof IArrayType ){
|
||||
result = new CPPPointerType( ((IArrayType)aType).getType() );
|
||||
} else if( aType instanceof IFunctionType ){
|
||||
result = new CPPPointerType( aType );
|
||||
} else if( aType instanceof IQualifierType ){
|
||||
result = ((IQualifierType)aType).getType();
|
||||
} else if( aType instanceof CPPPointerType ){
|
||||
result = ((CPPPointerType)aType).stripQualifiers();
|
||||
}
|
||||
} catch( DOMException e ){
|
||||
result = e.getProblem();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static private boolean expressionsEquivalent( IASTExpression p, IASTExpression a ){
|
||||
if( p == null )
|
||||
return true;
|
||||
|
||||
if( p instanceof IASTLiteralExpression && a instanceof IASTLiteralExpression ){
|
||||
return p.toString().equals( a.toString () );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static protected boolean deduceTemplateArgument( ObjectMap map, IType p, IType a ) throws DOMException {
|
||||
boolean pIsAReferenceType = ( p instanceof ICPPReferenceType );
|
||||
p = getParameterTypeForDeduction( p );
|
||||
a = getArgumentTypeForDeduction( a, pIsAReferenceType );
|
||||
|
||||
if( p instanceof IBasicType ) {
|
||||
if( p.isSameType( a ) && a instanceof IBasicType ) {
|
||||
return expressionsEquivalent( ((IBasicType)p).getValue(), ((IBasicType)a).getValue() );
|
||||
}
|
||||
} else {
|
||||
while( p != null ){
|
||||
if( p instanceof IBasicType ){
|
||||
return p.isSameType( a );
|
||||
} else if( p instanceof ICPPPointerToMemberType ){
|
||||
if( !(a instanceof ICPPPointerToMemberType ) )
|
||||
return false;
|
||||
|
||||
if( !deduceTemplateArgument( map, ((ICPPPointerToMemberType)p).getMemberOfClass(), ((ICPPPointerToMemberType)a).getMemberOfClass() ) )
|
||||
return false;
|
||||
|
||||
p = ((ICPPPointerToMemberType)p).getType();
|
||||
p = ((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) )
|
||||
return false;
|
||||
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( !deduceTemplateArgument( map, ((IFunctionType)p).getReturnType(), ((IFunctionType)a).getReturnType() ) )
|
||||
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( !deduceTemplateArgument( map, pParams[i], aParams[i] ) )
|
||||
return false;
|
||||
}
|
||||
} else if( p instanceof ICPPTemplateParameter ){
|
||||
if( map.containsKey( p ) ){
|
||||
IType current = (IType)map.get( p );
|
||||
return current.isSameType( a );
|
||||
}
|
||||
if( a == null )
|
||||
return false;
|
||||
map.put( p, a );
|
||||
return true;
|
||||
} else if( p instanceof ICPPTemplateInstance ){
|
||||
if( !(a instanceof ICPPTemplateInstance ) )
|
||||
return false;
|
||||
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
|
||||
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
|
||||
|
||||
IType [] pArgs = createTypeArray( pInst.getArguments() );
|
||||
IType [] aArgs = createTypeArray( aInst.getArguments() );
|
||||
if( pArgs.length != aArgs.length )
|
||||
return false;
|
||||
for (int i = 0; i < pArgs.length; i++) {
|
||||
if( !deduceTemplateArgument( map, pArgs[i], aArgs[i] ) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return p.isSameType( a );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* transform a function template for use in partial ordering, as described in the
|
||||
* spec 14.5.5.2-3
|
||||
* @param template
|
||||
* @return
|
||||
* -for each type template parameter, synthesize a unique type and substitute that for each
|
||||
* occurence of that parameter in the function parameter list
|
||||
* -for each non-type template parameter, synthesize a unique value of the appropriate type and
|
||||
* susbstitute that for each occurence of that parameter in the function parameter list
|
||||
* for each template template parameter, synthesize a unique class template and substitute that
|
||||
* for each occurence of that parameter in the function parameter list
|
||||
* @throws DOMException
|
||||
*/
|
||||
|
||||
static private IType [] createArgsForFunctionTemplateOrdering( ICPPFunctionTemplate template ) throws DOMException{
|
||||
ICPPTemplateParameter [] paramList = template.getTemplateParameters();
|
||||
int size = paramList.length;
|
||||
IType [] args = new IType [ size ];
|
||||
for( int i = 0; i < size; i++ ){
|
||||
ICPPTemplateParameter param = paramList[i];
|
||||
if( param instanceof ICPPTemplateNonTypeParameter ){
|
||||
IType t = ((ICPPTemplateNonTypeParameter)param).getType();
|
||||
if( t instanceof CPPBasicType ){
|
||||
CPPASTLiteralExpression exp = new CPPASTLiteralExpression();
|
||||
exp.setValue( String.valueOf( i ) );
|
||||
CPPBasicType temp = (CPPBasicType) t.clone();
|
||||
temp.setValue( exp );
|
||||
args[i] = temp;
|
||||
}
|
||||
} else {
|
||||
args[i] = new CPPBasicType( -1, 0 );
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
static protected int orderTemplateFunctions( ICPPFunctionTemplate f1, ICPPFunctionTemplate f2 ) throws DOMException {
|
||||
//Using the transformed parameter list, perform argument deduction against the other
|
||||
//function template
|
||||
IType [] args = createArgsForFunctionTemplateOrdering( f1 );
|
||||
ICPPFunction function = (ICPPFunction) ((CPPTemplateDefinition)f1).instantiate( args );
|
||||
|
||||
ObjectMap m1 = deduceTemplateArguments( f2, function.getType().getParameterTypes() );
|
||||
|
||||
args = createArgsForFunctionTemplateOrdering( f2 );
|
||||
function = (ICPPFunction) ((CPPTemplateDefinition)f2).instantiate( args );
|
||||
|
||||
ObjectMap m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() );
|
||||
|
||||
//The transformed template is at least as specialized as the other iff the deduction
|
||||
//succeeds and the deduced parameter types are an exact match
|
||||
//A template is more specialized than another iff it is at least as specialized as the
|
||||
//other template and that template is not at least as specialized as the first.
|
||||
boolean d1 = ( m1 != null );
|
||||
boolean d2 = ( m2 != null );
|
||||
|
||||
if( d1 && d2 || !d1 && !d2 )
|
||||
return 0;
|
||||
else if( d1 && !d2 )
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
static protected ICPPTemplateDefinition matchTemplatePartialSpecialization( ICPPTemplateDefinition template, IType[] args ) throws DOMException{
|
||||
if( template == null ){
|
||||
return null;
|
||||
}
|
||||
|
||||
ICPPTemplateSpecialization[] specializations = template.getTemplateSpecializations();
|
||||
int size = ( specializations != null ) ? specializations.length : 0;
|
||||
if( size == 0 ){
|
||||
return template;
|
||||
}
|
||||
|
||||
ICPPTemplateSpecialization bestMatch = null, spec = null;
|
||||
boolean bestMatchIsBest = true;
|
||||
IType[] specArgs = null;
|
||||
for( int i = 0; i < size; i++ ){
|
||||
spec = specializations[i];
|
||||
specArgs = spec.getArguments();
|
||||
if( specArgs == null || specArgs.length != args.length ){
|
||||
continue;
|
||||
}
|
||||
|
||||
int specArgsSize = specArgs.length;
|
||||
ObjectMap map = new ObjectMap(specArgsSize);
|
||||
IType t1 = null, t2 = null;
|
||||
|
||||
boolean match = true;
|
||||
for( int j = 0; j < specArgsSize; j++ ){
|
||||
t1 = specArgs[j];
|
||||
t2 = args[j];
|
||||
|
||||
if( !deduceTemplateArgument( map, t1, t2 ) ){
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( match ){
|
||||
int compare = orderSpecializations( bestMatch, spec );
|
||||
if( compare == 0 ){
|
||||
bestMatchIsBest = false;
|
||||
} else if( compare < 0 ) {
|
||||
bestMatch = spec;
|
||||
bestMatchIsBest = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//14.5.4.1 If none of the specializations is more specialized than all the other matchnig
|
||||
//specializations, then the use of the class template is ambiguous and the program is ill-formed.
|
||||
if( !bestMatchIsBest ){
|
||||
//TODO problem
|
||||
return new CPPTemplateDefinition.CPPTemplateProblem( null, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, null);
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2
|
||||
* is more specialized, = 0 otherwise.
|
||||
* @param spec1
|
||||
* @param spec2
|
||||
* @return
|
||||
* @throws DOMException
|
||||
*/
|
||||
static private int orderSpecializations( ICPPTemplateSpecialization spec1, ICPPTemplateSpecialization spec2 ) throws DOMException {
|
||||
if( spec1 == null ){
|
||||
return -1;
|
||||
}
|
||||
|
||||
//to order class template specializations, we need to transform them into function templates
|
||||
ICPPFunctionTemplate template1 = null, template2 = null;
|
||||
|
||||
if( spec1 instanceof ICPPClassType ) {
|
||||
template1 = classTemplateSpecializationToFunctionTemplate( spec1 );
|
||||
template2 = classTemplateSpecializationToFunctionTemplate( spec2 );
|
||||
} else if( spec1 instanceof ICPPFunction ) {
|
||||
template1 = (ICPPFunctionTemplate) spec1;
|
||||
template2 = (ICPPFunctionTemplate) spec2;
|
||||
}
|
||||
|
||||
return orderTemplateFunctions( template1, template2);
|
||||
}
|
||||
|
||||
public static final class CPPImplicitFunctionTemplate extends CPPFunctionTemplate {
|
||||
IParameter [] functionParameters = null;
|
||||
ICPPTemplateParameter [] templateParameters = null;
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CPPImplicitFunctionTemplate( ICPPTemplateParameter [] templateParameters, IParameter [] functionParameters) {
|
||||
super( null );
|
||||
this.functionParameters = functionParameters;
|
||||
this.templateParameters = templateParameters;
|
||||
}
|
||||
public IParameter[] getParameters() {
|
||||
return functionParameters;
|
||||
}
|
||||
public ICPPTemplateParameter[] getTemplateParameters() {
|
||||
return templateParameters;
|
||||
}
|
||||
public IScope getScope() {
|
||||
return null;
|
||||
}
|
||||
public IFunctionType getType() {
|
||||
if( type == null ){
|
||||
type = CPPVisitor.createImplicitFunctionType( new CPPBasicType(IBasicType.t_void, 0 ), functionParameters );
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* transform the class template to a function template as described in the spec
|
||||
* 14.5.4.2-1
|
||||
* @param template
|
||||
* @return IParameterizedSymbol
|
||||
* the function template has the same template parameters as the partial specialization and
|
||||
* has a single function parameter whose type is a class template specialization with the template
|
||||
* arguments of the partial specialization
|
||||
*/
|
||||
static private ICPPFunctionTemplate classTemplateSpecializationToFunctionTemplate( ICPPTemplateSpecialization specialization ) {
|
||||
if( !(specialization instanceof ICPPClassType) )
|
||||
return null;
|
||||
|
||||
ICPPTemplateDefinition template = specialization;
|
||||
IType [] args = null;
|
||||
try {
|
||||
args = specialization.getArguments();
|
||||
} catch (DOMException e1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IType paramType = (IType) ((CPPTemplateDefinition)template).instantiate( args );
|
||||
IParameter [] functionParameters = new IParameter[] { new CPPParameter( paramType ) };
|
||||
|
||||
try {
|
||||
return new CPPImplicitFunctionTemplate( specialization.getTemplateParameters(), functionParameters );
|
||||
} catch (DOMException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static private boolean isValidArgument(ICPPTemplateParameter param, IType argument) {
|
||||
//TODO
|
||||
return true;
|
||||
}
|
||||
static protected boolean matchTemplateParameterAndArgument( ICPPTemplateParameter param, IType argument ){
|
||||
if( !isValidArgument(param, argument) ){
|
||||
return false;
|
||||
}
|
||||
if( param instanceof ICPPTemplateTypeParameter )
|
||||
return true;
|
||||
else if( param instanceof ICPPTemplateTemplateParameter ){
|
||||
if( !( argument instanceof ICPPTemplateDefinition ) )
|
||||
return false;
|
||||
|
||||
ICPPTemplateParameter [] pParams = null, aParams = null;
|
||||
try {
|
||||
pParams = ((ICPPTemplateTemplateParameter)param).getTemplateParameters();
|
||||
aParams = ((ICPPTemplateDefinition)argument).getTemplateParameters();
|
||||
} catch ( DOMException e ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int size = pParams.length;
|
||||
if( aParams.length != size){
|
||||
return false;
|
||||
}
|
||||
|
||||
for( int i = 0; i < size; i++){
|
||||
if( (pParams[i] instanceof ICPPTemplateTypeParameter && !(aParams[i] instanceof ICPPTemplateTypeParameter)) ||
|
||||
(pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) ||
|
||||
(pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter)) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
IType pType = ((ICPPTemplateNonTypeParameter)param).getType();
|
||||
Cost cost = CPPSemantics.checkStandardConversionSequence( argument, pType );
|
||||
|
||||
if( cost == null || cost.rank == Cost.NO_MATCH_RANK ){
|
||||
return false;
|
||||
}
|
||||
} catch( DOMException e ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException {
|
||||
IType [] args = null;
|
||||
if( template instanceof ICPPTemplateSpecialization ){
|
||||
args = ((ICPPTemplateSpecialization)template).getArguments();
|
||||
} else {
|
||||
ICPPTemplateParameter [] templateParameters = template.getTemplateParameters();
|
||||
args = new IType [ templateParameters.length ];
|
||||
for (int i = 0; i < templateParameters.length; i++) {
|
||||
if( templateParameters[i] instanceof IType ){
|
||||
args[i] = (IType) templateParameters[i];
|
||||
} else if( templateParameters[i] instanceof ICPPTemplateNonTypeParameter ){
|
||||
args[i] = ((ICPPTemplateNonTypeParameter)templateParameters[i]).getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( template instanceof CPPClassTemplate ){
|
||||
return ((CPPClassTemplate)template).instantiate( args );
|
||||
}
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
|
@ -110,6 +111,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
@ -286,7 +288,17 @@ public class CPPVisitor {
|
|||
if( mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName )
|
||||
return binding;
|
||||
|
||||
boolean template = false;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( name );
|
||||
if( scope instanceof ICPPTemplateScope ){
|
||||
ICPPScope parentScope = null;
|
||||
try {
|
||||
template = true;
|
||||
parentScope = (ICPPScope) scope.getParent();
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
scope = parentScope;
|
||||
}
|
||||
|
||||
if( mustBeSimple ){
|
||||
//3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
|
||||
|
@ -309,11 +321,14 @@ public class CPPVisitor {
|
|||
binding = scope.getBinding( elabType.getName(), false );
|
||||
if( binding == null || !(binding instanceof ICPPClassType) ){
|
||||
if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum ){
|
||||
binding = new CPPClassType( elabType.getName() );
|
||||
if( template )
|
||||
binding = new CPPClassTemplate( name );
|
||||
else
|
||||
binding = new CPPClassType( name );
|
||||
scope.addName( elabType.getName() );
|
||||
}
|
||||
} else if( binding instanceof ICPPClassType ){
|
||||
((CPPClassType)binding).addDeclaration( elabType );
|
||||
} else if( binding instanceof ICPPInternalBinding ){
|
||||
((ICPPInternalBinding)binding).addDeclaration( elabType );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
binding = e.getProblem();
|
||||
|
@ -343,12 +358,13 @@ public class CPPVisitor {
|
|||
return CPPTemplates.createClassPartialSpecialization( compType );
|
||||
}
|
||||
try {
|
||||
binding = scope.getBinding( name, false );
|
||||
binding = (scope != null ) ? scope.getBinding( name, false ) : null;
|
||||
if( binding == null || !(binding instanceof ICPPClassType) ){
|
||||
if( template )
|
||||
binding = new CPPClassTemplate( name );
|
||||
else
|
||||
binding = new CPPClassType( name );
|
||||
if( scope != null )
|
||||
scope.addName( compType.getName() );
|
||||
} else {
|
||||
if( binding instanceof ICPPInternalBinding ){
|
||||
|
@ -409,9 +425,9 @@ public class CPPVisitor {
|
|||
}
|
||||
private static IBinding createBinding( IASTDeclarator declarator ){
|
||||
IASTNode parent = declarator.getParent();
|
||||
|
||||
if( parent instanceof IASTTypeId )
|
||||
return CPPSemantics.resolveBinding( declarator.getName() );
|
||||
while( parent instanceof IASTDeclarator ){
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
while( declarator.getNestedDeclarator() != null )
|
||||
declarator = declarator.getNestedDeclarator();
|
||||
|
@ -422,8 +438,10 @@ public class CPPVisitor {
|
|||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
|
||||
while( parent instanceof IASTDeclarator ){
|
||||
parent = parent.getParent();
|
||||
if( parent instanceof IASTTypeId )
|
||||
return CPPSemantics.resolveBinding( name );
|
||||
else if( parent.getPropertyInParent() == ICPPASTTemplateSpecialization.OWNED_DECLARATION ){
|
||||
return CPPTemplates.createFunctionSpecialization( name );
|
||||
}
|
||||
|
||||
boolean template = false;
|
||||
|
@ -629,7 +647,9 @@ public class CPPVisitor {
|
|||
return dtor.getFunctionScope();
|
||||
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope();
|
||||
} //else if( node instanceof ICPPASTTemplateDeclaration )
|
||||
} else if( parent instanceof ICPPASTTemplateDeclaration ){
|
||||
return CPPTemplates.getContainingScope( node );
|
||||
}
|
||||
} else if( node instanceof IASTInitializerExpression ){
|
||||
IASTNode parent = node.getParent();
|
||||
while( !(parent instanceof IASTDeclarator) )
|
||||
|
@ -1350,6 +1370,8 @@ public class CPPVisitor {
|
|||
return getExpressionType( (IASTExpression) node );
|
||||
if( node instanceof IASTTypeId )
|
||||
return createType( ((IASTTypeId) node).getAbstractDeclarator() );
|
||||
if( node instanceof IASTParameterDeclaration )
|
||||
return createType( ((IASTParameterDeclaration)node).getDeclarator() );
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
|
@ -1420,6 +1442,14 @@ public class CPPVisitor {
|
|||
IBinding binding = name.resolveBinding();
|
||||
if( binding instanceof IType )
|
||||
type = (IType) binding;
|
||||
else if( binding instanceof ICPPTemplateNonTypeParameter ){
|
||||
//TODO workaround... is there anything better?
|
||||
try {
|
||||
type = ((ICPPTemplateNonTypeParameter)binding).getType();
|
||||
} catch (DOMException e) {
|
||||
type = e.getProblem();
|
||||
}
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
@ -1442,6 +1472,8 @@ public class CPPVisitor {
|
|||
return (IType) binding;
|
||||
} else if( binding instanceof IFunction ){
|
||||
return ((IFunction)binding).getType();
|
||||
} else if( binding instanceof ICPPTemplateNonTypeParameter ){
|
||||
return ((ICPPTemplateNonTypeParameter)binding).getType();
|
||||
}
|
||||
} catch ( DOMException e ){
|
||||
return e.getProblem();
|
||||
|
@ -1490,17 +1522,16 @@ public class CPPVisitor {
|
|||
}
|
||||
case ICPPASTLiteralExpression.lk_true :
|
||||
case ICPPASTLiteralExpression.lk_false:
|
||||
return new CPPBasicType( ICPPBasicType.t_bool, 0 );
|
||||
return new CPPBasicType( ICPPBasicType.t_bool, 0, expression );
|
||||
case IASTLiteralExpression.lk_char_constant:
|
||||
return new CPPBasicType( IBasicType.t_char, 0 );
|
||||
return new CPPBasicType( IBasicType.t_char, 0, expression );
|
||||
case IASTLiteralExpression.lk_float_constant:
|
||||
return new CPPBasicType( IBasicType.t_float, 0 );
|
||||
return new CPPBasicType( IBasicType.t_float, 0, expression );
|
||||
case IASTLiteralExpression.lk_integer_constant:
|
||||
return new CPPBasicType( IBasicType.t_int, 0 );
|
||||
return new CPPBasicType( IBasicType.t_int, 0, expression );
|
||||
case IASTLiteralExpression.lk_string_literal:
|
||||
IType type = new CPPBasicType( IBasicType.t_char, 0 );
|
||||
IType type = new CPPBasicType( IBasicType.t_char, 0, expression );
|
||||
type = new CPPQualifierType( type, true, false );
|
||||
((CPPQualifierType)type).setFromStringLiteral( true );
|
||||
return new CPPPointerType( type );
|
||||
}
|
||||
|
||||
|
@ -1526,6 +1557,20 @@ public class CPPVisitor {
|
|||
} catch( DOMException e ){
|
||||
return e.getProblem();
|
||||
}
|
||||
} else if( binding instanceof ITypedef ){
|
||||
try {
|
||||
IType type = ((ITypedef)binding).getType();
|
||||
while( type instanceof ITypedef )
|
||||
type = ((ITypedef)type).getType();
|
||||
if( type instanceof IFunctionType ){
|
||||
return ((IFunctionType)type).getReturnType();
|
||||
}
|
||||
return type;
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
} else if( binding instanceof IProblemBinding ){
|
||||
return (IType) binding;
|
||||
}
|
||||
} else if( expression instanceof IASTBinaryExpression ){
|
||||
IASTBinaryExpression binary = (IASTBinaryExpression) expression;
|
||||
|
@ -1541,6 +1586,8 @@ public class CPPVisitor {
|
|||
}
|
||||
}
|
||||
return new ProblemBinding( binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0] );
|
||||
} else if( type instanceof CPPBasicType ){
|
||||
((CPPBasicType)type).setValue( expression );
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
@ -1556,6 +1603,8 @@ public class CPPVisitor {
|
|||
}
|
||||
} else if( op == IASTUnaryExpression.op_amper ){
|
||||
return new CPPPointerType( type );
|
||||
} else if ( type instanceof CPPBasicType ){
|
||||
((CPPBasicType)type).setValue( expression );
|
||||
}
|
||||
return type;
|
||||
} else if( expression instanceof ICPPASTFieldReference ){
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -34,6 +34,19 @@ public class GPPPointerToMemberType extends CPPPointerToMemberType implements
|
|||
this.isRestrict = operator.isRestrict();
|
||||
}
|
||||
|
||||
public IType stripQualifiers(){
|
||||
GPPPointerToMemberType result = (GPPPointerToMemberType) super.stripQualifiers();
|
||||
|
||||
if( isRestrict ){
|
||||
if( result == this ){
|
||||
result = (GPPPointerToMemberType) clone();
|
||||
result.isRestrict = false;
|
||||
} else {
|
||||
result.isRestrict = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType#isRestrict()
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -44,6 +44,20 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType {
|
|||
this.isRestrict = isRestrict;
|
||||
}
|
||||
|
||||
public IType stripQualifiers(){
|
||||
GPPPointerType result = (GPPPointerType) super.stripQualifiers();
|
||||
|
||||
if( isRestrict ){
|
||||
if( result == this ){
|
||||
result = (GPPPointerType) clone();
|
||||
result.isRestrict = false;
|
||||
} else {
|
||||
result.isRestrict = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer#isRestrict()
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue