Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-04-08 23:51:32 -0400
committerSergey Prigogin2012-04-09 01:33:39 -0400
commit64f529b3ecd2759678615d162d6214e6205e22d9 (patch)
tree83e10dd4f908b592294de0d7929f4f42ac269531
parent36442384d4c85bc34b77432175c735d52fda7d05 (diff)
downloadorg.eclipse.cdt-64f529b3ecd2759678615d162d6214e6205e22d9.tar.gz
org.eclipse.cdt-64f529b3ecd2759678615d162d6214e6205e22d9.tar.xz
org.eclipse.cdt-64f529b3ecd2759678615d162d6214e6205e22d9.zip
Replaced StringBuffer with StringBuilder.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java186
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java765
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java1370
3 files changed, 1159 insertions, 1162 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
index 5351512e02..974728e23d 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
@@ -32,7 +32,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test4s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -46,7 +46,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_1_3s2() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("char i;\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
@@ -61,7 +61,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char c1, c2;\n"); //$NON-NLS-1$
buffer.append("c1 = c1 + c2;\n"); //$NON-NLS-1$
@@ -79,7 +79,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("float f1, f2;\n"); //$NON-NLS-1$
buffer.append("double d;\n"); //$NON-NLS-1$
@@ -99,7 +99,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("double d1, d2;\n"); //$NON-NLS-1$
buffer.append("float f;\n"); //$NON-NLS-1$
@@ -121,7 +121,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("double x, y, z;\n"); //$NON-NLS-1$
buffer.append("x = (x * y) * z; // not equivalent tox *= y * z;\n"); //$NON-NLS-1$
@@ -145,7 +145,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int a, b;\n"); //$NON-NLS-1$
buffer.append("a = a + 32760 + b + 5;\n"); //$NON-NLS-1$
@@ -169,7 +169,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s15() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("//#include <stdio.h>\n"); //$NON-NLS-1$
buffer.append("int f() {");
buffer.append("int sum;\n"); //$NON-NLS-1$
@@ -186,7 +186,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_2_5s28() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct tag (* a[5])(float);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
}
@@ -199,7 +199,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_2_7s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -214,7 +214,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_4_4_4s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -234,7 +234,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_2s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f1() {}\n"); //$NON-NLS-1$
buffer.append("int f2() {}\n"); //$NON-NLS-1$
buffer.append("int f3() {}\n"); //$NON-NLS-1$
@@ -263,7 +263,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { int i; const int ci; };\n"); //$NON-NLS-1$
buffer.append("struct s s;\n"); //$NON-NLS-1$
buffer.append("const struct s cs;\n"); //$NON-NLS-1$
@@ -305,7 +305,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s8a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("union {\n"); //$NON-NLS-1$
buffer.append("struct {\n"); //$NON-NLS-1$
buffer.append("int alltypes;\n"); //$NON-NLS-1$
@@ -351,7 +351,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s8b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct t1 { int m; };\n"); //$NON-NLS-1$
buffer.append("struct t2 { int m; };\n"); //$NON-NLS-1$
buffer.append("int f(struct t1 * p1, struct t2 * p2)\n"); //$NON-NLS-1$
@@ -377,7 +377,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int *p = (int []){2, 4};\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 0);
}
@@ -392,7 +392,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(void)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int *p;\n"); //$NON-NLS-1$
@@ -412,7 +412,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(){\n"); //$NON-NLS-1$
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$
@@ -430,7 +430,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -447,7 +447,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("\"/tmp/fileXXXXXX\";\n"); //$NON-NLS-1$
buffer.append("(char []){\"/tmp/fileXXXXXX\"};\n"); //$NON-NLS-1$
@@ -464,7 +464,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("(const char []){\"abc\"} == \"abc\";\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
@@ -481,7 +481,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s15() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("struct int_list { int car; struct int_list *cdr; };\n"); //$NON-NLS-1$
buffer.append("struct int_list endless_zeros = {0, &endless_zeros};\n"); //$NON-NLS-1$
@@ -505,7 +505,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s16() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { int i; };\n"); //$NON-NLS-1$
buffer.append("int f (void)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -526,7 +526,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_3_4s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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, 0);
@@ -541,7 +541,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_3_4s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int array[5];\n"); //$NON-NLS-1$
buffer.append("int x = sizeof array / sizeof array[0];\n"); //$NON-NLS-1$
@@ -562,7 +562,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_6s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int n = 4, m = 3;\n"); //$NON-NLS-1$
buffer.append("int a[n][m];\n"); //$NON-NLS-1$
@@ -587,7 +587,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_15s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const void *c_vp;\n"); //$NON-NLS-1$
buffer.append("void *vp;\n"); //$NON-NLS-1$
@@ -610,7 +610,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_16_1s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char c;\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
@@ -633,7 +633,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_16_1s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const char **cpp;\n"); //$NON-NLS-1$
buffer.append("char *p;\n"); //$NON-NLS-1$
@@ -657,7 +657,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s17() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
// offsetoff is a macro defined in stddef.h, using GNU definition
buffer.append("#define offsetof(TYPE, MEMBER) ((size_t) (&((TYPE *)0)->MEMBER))\n");
@@ -682,7 +682,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s18a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("struct s *s1;\n"); //$NON-NLS-1$
buffer.append("struct s *s2;\n"); //$NON-NLS-1$
@@ -699,7 +699,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s18b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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, 0);
@@ -718,7 +718,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_2s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("enum hue { chartreuse, burgundy, claret=20, winedark };\n"); //$NON-NLS-1$
buffer.append("enum hue col, *cp;\n"); //$NON-NLS-1$
@@ -740,7 +740,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct tnode {\n"); //$NON-NLS-1$
buffer.append("int count;\n"); //$NON-NLS-1$
buffer.append("struct tnode *left, *right;\n"); //$NON-NLS-1$
@@ -760,7 +760,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef struct tnode TNODE;\n"); //$NON-NLS-1$
buffer.append("struct tnode {\n"); //$NON-NLS-1$
buffer.append("int count;\n"); //$NON-NLS-1$
@@ -778,7 +778,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -791,7 +791,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern const volatile int real_time_clock;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -815,7 +815,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const struct s { int mem; } cs = { 1 };\n"); //$NON-NLS-1$
buffer.append("struct s ncs; // the object ncs is modifiable\n"); //$NON-NLS-1$
@@ -841,7 +841,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -858,7 +858,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(int n, int * restrict p, int * restrict q)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("while (n-- > 0)\n"); //$NON-NLS-1$
@@ -883,7 +883,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(int n, int * restrict p, int * restrict q)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("while (n-- > 0)\n"); //$NON-NLS-1$
@@ -909,7 +909,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void h(int n, int * restrict p, int * restrict q, int * restrict r)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
@@ -936,7 +936,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int * restrict p1;\n"); //$NON-NLS-1$
@@ -965,7 +965,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef struct { int n; float * restrict v; } vector;\n"); //$NON-NLS-1$
buffer.append("vector new_vector(int n)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -995,7 +995,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_4s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("inline double fahr(double t)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("return (9.0 * t) / 5.0 + 32.0;\n"); //$NON-NLS-1$
@@ -1021,7 +1021,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("const int *ptr_to_constant;\n"); //$NON-NLS-1$
buffer.append("int *const constant_ptr1;\n"); //$NON-NLS-1$
buffer.append("typedef int *int_ptr;\n"); //$NON-NLS-1$
@@ -1035,7 +1035,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("float fa[11], *afp[17];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1047,7 +1047,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int *x;\n"); //$NON-NLS-1$
buffer.append("extern int y[];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -1070,7 +1070,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int n;\n"); //$NON-NLS-1$
buffer.append("extern int m;\n"); //$NON-NLS-1$
buffer.append("void fcompat(void)\n"); //$NON-NLS-1$
@@ -1110,7 +1110,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int n;\n"); //$NON-NLS-1$
buffer.append("int A[n]; // invalid: file scope VLA\n"); //$NON-NLS-1$
buffer.append("extern int (*p2)[n]; // invalid: file scope VM\n"); //$NON-NLS-1$
@@ -1139,7 +1139,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s16() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(void), *fip(), (*pfi)();\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1150,7 +1150,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s18() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int (*apfi[3])(int *x, int *y);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1161,7 +1161,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s19() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int (*fpfi(int (*)(long), int))(int, ...);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1187,7 +1187,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s20() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void addscalar(int n, int m,\n"); //$NON-NLS-1$
buffer.append("double a[n][n*m+300], double x);\n"); //$NON-NLS-1$
buffer.append("int main()\n"); //$NON-NLS-1$
@@ -1222,7 +1222,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s21() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("double maximum1(int n, int m, double a[n][m]);\n"); //$NON-NLS-1$
buffer.append("double maximum2(int n, int m, double a[*][*]);\n"); //$NON-NLS-1$
buffer.append("double maximum3(int n, int m, double a[ ][*]);\n"); //$NON-NLS-1$
@@ -1245,7 +1245,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef int MILES, KLICKSP();\n"); //$NON-NLS-1$
buffer.append("typedef struct { double hi, lo; } range;\n"); //$NON-NLS-1$
buffer.append("MILES distance;\n"); //$NON-NLS-1$
@@ -1262,7 +1262,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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, 0);
@@ -1277,7 +1277,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef void fv(int), (*pfv)(int);\n"); //$NON-NLS-1$
buffer.append("void (*signal(int, void (*)(int)))(int);\n"); //$NON-NLS-1$
buffer.append("fv *signal(int, fv *);\n"); //$NON-NLS-1$
@@ -1299,7 +1299,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void copyt(int n)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("typedef int B[n]; // B is n ints, n evaluated now\n"); //$NON-NLS-1$
@@ -1319,7 +1319,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s24() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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, 0);
@@ -1331,7 +1331,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s25() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int x[] = { 1, 3, 5 };\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1346,7 +1346,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s26a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int y[4][3] = {\n"); //$NON-NLS-1$
buffer.append("{ 1, 3, 5 },\n"); //$NON-NLS-1$
buffer.append("{ 2, 4, 6 },\n"); //$NON-NLS-1$
@@ -1363,7 +1363,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s26b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -1378,7 +1378,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s27() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -1391,7 +1391,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s28() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct { int a[3], b; } w[] = { { 1 }, 2 };\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1423,7 +1423,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s29() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("short q1[4][3][2] = {\n"); //$NON-NLS-1$
buffer.append("{ 1 },\n"); //$NON-NLS-1$
buffer.append("{ 2, 3 },\n"); //$NON-NLS-1$
@@ -1457,7 +1457,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s31() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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$
@@ -1475,7 +1475,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s32() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int foo() {\n"); //$NON-NLS-1$
buffer.append("char s1[] = \"abc\", t1[3] = \"abc\";\n"); //$NON-NLS-1$
buffer.append("char s2[] = { 'a', 'b', 'c', '\0' },\n"); //$NON-NLS-1$
@@ -1495,7 +1495,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s33() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("enum { member_one, member_two };\n"); //$NON-NLS-1$
buffer.append("const char *nm[] = {\n"); //$NON-NLS-1$
buffer.append("[member_two] = \"member two\",\n"); //$NON-NLS-1$
@@ -1510,7 +1510,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s34() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("div_t answer = { .quot = 2, .rem = -1 };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 1); // div_t (correctly) cannot be resolved
}
@@ -1522,7 +1522,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s35() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
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, 0);
@@ -1537,7 +1537,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s36() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int MAX=15;\n"); //$NON-NLS-1$
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$
@@ -1551,7 +1551,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s38() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("union { int any_member; } u = { .any_member = 42 };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 0);
}
@@ -1565,7 +1565,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int p(int);\n"); //$NON-NLS-1$
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("(void)p(0);\n"); //$NON-NLS-1$
@@ -1583,7 +1583,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char *s;\n"); //$NON-NLS-1$
buffer.append("while (*s++ != '\0')\n"); //$NON-NLS-1$
@@ -1608,7 +1608,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int i=1;\n"); //$NON-NLS-1$
buffer.append("while (i) {\n"); //$NON-NLS-1$
@@ -1640,7 +1640,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_4s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(int a) {}\n"); //$NON-NLS-1$
buffer.append("int g(int expr) {\n"); //$NON-NLS-1$
buffer.append("switch (expr)\n"); //$NON-NLS-1$
@@ -1674,7 +1674,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_1s3() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("goto first_time;\n"); //$NON-NLS-1$
buffer.append("for (;;) {\n"); //$NON-NLS-1$
@@ -1710,7 +1710,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("goto lab3; // invalid: going INTO scope of VLA.\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -1751,7 +1751,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_4s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { double i; } f(void);\n"); //$NON-NLS-1$
buffer.append("union {\n"); //$NON-NLS-1$
buffer.append("struct {\n"); //$NON-NLS-1$
@@ -1782,7 +1782,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_1s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int max(int a, int b)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("return a > b ? a : b;\n"); //$NON-NLS-1$
@@ -1800,7 +1800,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_1s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void g(int (*funcp)(void))\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("(*funcp)();\n"); //$NON-NLS-1$
@@ -1829,7 +1829,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_2s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int i1 = 1; // definition, external linkage\n"); //$NON-NLS-1$
buffer.append("static int i2 = 2; // definition, internal linkage\n"); //$NON-NLS-1$
buffer.append("extern int i3 = 3; // definition, external linkage\n"); //$NON-NLS-1$
@@ -1861,7 +1861,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int g() {}\n"); //$NON-NLS-1$
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("#if 'z' - 'a' == 25\n"); //$NON-NLS-1$
@@ -1884,7 +1884,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_3s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define hash_hash # ## #\n"); //$NON-NLS-1$
buffer.append("#define mkstr(a) # a\n"); //$NON-NLS-1$
buffer.append("#define in_between(a) mkstr(a)\n"); //$NON-NLS-1$
@@ -1901,7 +1901,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s3() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define TABSIZE 100\n"); //$NON-NLS-1$
buffer.append("int table[TABSIZE];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -1913,7 +1913,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define max(a, b) ((a) > (b) ? (a) : (b))\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1941,7 +1941,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define x 3\n"); //$NON-NLS-1$
buffer.append("#define f(a) f(x * (a))\n"); //$NON-NLS-1$
buffer.append("#undef x\n"); //$NON-NLS-1$
@@ -1985,7 +1985,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define str(s) # s \n"); //$NON-NLS-1$
buffer.append("#define xstr(s) str(s) \n"); //$NON-NLS-1$
buffer.append("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$
@@ -2017,7 +2017,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$
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$
@@ -2036,7 +2036,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define OBJ_LIKE1 (1-1)\n"); //$NON-NLS-1$
buffer.append("#define OBJ_LIKE2 \\n"); //$NON-NLS-1$
buffer.append(" (1-1) \\n"); //$NON-NLS-1$
@@ -2062,7 +2062,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define debug(...) fprintf(stderr, __VA_ARGS__)\n"); //$NON-NLS-1$
buffer.append("#define showlist(...) puts(#__VA_ARGS__)\n"); //$NON-NLS-1$
buffer.append("#define report(test, ...) ((test)?puts(#test):\\\n"); //$NON-NLS-1$
@@ -2095,7 +2095,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef signed int t;\n"); //$NON-NLS-1$
buffer.append("typedef int plain;\n"); //$NON-NLS-1$
buffer.append("struct tag {\n"); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
index 6044bae340..452ca0e7ec 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
@@ -69,161 +69,161 @@ public class AST2KnRTests extends AST2BaseTest {
}
public void testSimpleKRCTest1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(char x);\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(char x);\n"); //$NON-NLS-1$
+ buffer.append("int f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- IParameter x1 = (IParameter)((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName().resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x1 = (IParameter) ((IASTStandardFunctionDeclarator) f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName().resolveBinding();
- assertNotNull( x1 );
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x1, x2 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x1);
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x1, x2);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x1);
- assertEquals( decls.length, 2 );
- assertEquals( decls[0], ((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName() );
- assertEquals( decls[1], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
+ assertEquals(decls.length, 2);
+ assertEquals(decls[0], ((IASTStandardFunctionDeclarator) f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName());
+ assertEquals(decls[1], ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testSimpleKRCTest2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f();\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f();\n"); //$NON-NLS-1$
+ buffer.append("int f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x2);
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testSimpleKRCTest3() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int const *f();\n" ); //$NON-NLS-1$
- buffer.append( "int const *f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int const *f();\n"); //$NON-NLS-1$
+ buffer.append("int const *f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
}
public void testKRC_1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int isroot (x, y) /* comment */ \n" ); //$NON-NLS-1$
- buffer.append( "int x;\n" ); //$NON-NLS-1$
- buffer.append( "int y;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int isroot (x, y) /* comment */ \n"); //$NON-NLS-1$
+ buffer.append("int x;\n"); //$NON-NLS-1$
+ buffer.append("int y;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition isroot_def = (IASTFunctionDefinition) tu.getDeclarations()[0];
- IASTName ret_x = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+ IASTName ret_x = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
IASTDeclarator isroot_decltor = isroot_def.getDeclarator();
- assertTrue( isroot_decltor instanceof ICASTKnRFunctionDeclarator );
- IASTDeclarator x1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
- IASTDeclarator y1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
+ assertTrue(isroot_decltor instanceof ICASTKnRFunctionDeclarator);
+ IASTDeclarator x1 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
+ IASTDeclarator y1 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
- IParameter x_parm = (IParameter)x1.getName().resolveBinding();
- IParameter y_parm = (IParameter)y1.getName().resolveBinding();
- assertNotNull( x_parm );
- assertNotNull( y_parm );
+ IParameter x_parm = (IParameter) x1.getName().resolveBinding();
+ IParameter y_parm = (IParameter) y1.getName().resolveBinding();
+ assertNotNull(x_parm);
+ assertNotNull(y_parm);
- IASTDeclarator x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
- IASTDeclarator y2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
+ IASTDeclarator x2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
+ IASTDeclarator y2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
- IParameter x_parm2 = (IParameter)x2.getName().resolveBinding();
- IParameter y_parm2 = (IParameter)y2.getName().resolveBinding();
+ IParameter x_parm2 = (IParameter) x2.getName().resolveBinding();
+ IParameter y_parm2 = (IParameter) y2.getName().resolveBinding();
- assertNotNull( x_parm2 );
- assertNotNull( y_parm2 );
- assertNotNull( ret_x.resolveBinding() );
+ assertNotNull(x_parm2);
+ assertNotNull(y_parm2);
+ assertNotNull(ret_x.resolveBinding());
- assertEquals( x_parm, x_parm2 );
- assertEquals( y_parm, y_parm2 );
- assertEquals( ret_x.resolveBinding(), x_parm );
+ assertEquals(x_parm, x_parm2);
+ assertEquals(y_parm, y_parm2);
+ assertEquals(ret_x.resolveBinding(), x_parm);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(ret_x.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x1.getName() );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x1.getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
}
public void testKRCWithTypes() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef char c;\n" ); //$NON-NLS-1$
- buffer.append( "int isroot (c);\n" ); //$NON-NLS-1$
- buffer.append( "int isroot (x) \n" ); //$NON-NLS-1$
- buffer.append( "c x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTSimpleDeclaration c_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef char c;\n"); //$NON-NLS-1$
+ buffer.append("int isroot (c);\n"); //$NON-NLS-1$
+ buffer.append("int isroot (x) \n"); //$NON-NLS-1$
+ buffer.append("c x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+
+ IASTSimpleDeclaration c_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTFunctionDefinition isroot_def = (IASTFunctionDefinition) tu.getDeclarations()[2];
- //IASTName x0 = ((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
- IASTName x1 = ((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterNames()[0];
- IASTName x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+ //IASTName x0 = ((IASTStandardFunctionDeclarator) isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
+ IASTName x1 = ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterNames()[0];
+ IASTName x2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName x3 = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
- IParameter x1_var = (IParameter)x1.resolveBinding();
- IParameter x2_var = (IParameter)x2.resolveBinding();
- IParameter x3_var = (IParameter)x3.resolveBinding();
+ IParameter x1_var = (IParameter) x1.resolveBinding();
+ IParameter x2_var = (IParameter) x2.resolveBinding();
+ IParameter x3_var = (IParameter) x3.resolveBinding();
assertNotNull(x1_var);
assertNotNull(x2_var);
@@ -232,12 +232,12 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(x2_var, x3_var);
IASTName c1 = c_decl.getDeclarators()[0].getName();
- IASTName c2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
- IASTName c3 = ((IASTNamedTypeSpecifier)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
+ IASTName c2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
+ IASTName c3 = ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
- ITypedef c1_t = (ITypedef)c1.resolveBinding();
- ITypedef c2_t = (ITypedef)c2.resolveBinding();
- ITypedef c3_t = (ITypedef)c3.resolveBinding();
+ ITypedef c1_t = (ITypedef) c1.resolveBinding();
+ ITypedef c2_t = (ITypedef) c2.resolveBinding();
+ ITypedef c3_t = (ITypedef) c3.resolveBinding();
assertNotNull(c1_t);
assertNotNull(c2_t);
@@ -245,101 +245,101 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(c1_t, c2_t);
assertEquals(c2_t, c3_t);
assertTrue(c1_t.getType() instanceof IBasicType);
- assertEquals(((IBasicType)c1_t.getType()).getType(), IBasicType.t_char);
+ assertEquals(((IBasicType) c1_t.getType()).getType(), IBasicType.t_char);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x3.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testKRCProblem1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
IASTDeclaration[] decls= tu.getDeclarations();
assertTrue(CVisitor.getProblems(tu).length > 0);
}
public void testKRCProblem2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int i=0;\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) i++;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int i=0;\n"); //$NON-NLS-1$
+ buffer.append("int f(x) i++;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
IASTSimpleDeclaration sd= getDeclaration(tu, 0);
assertTrue(CVisitor.getProblems(tu).length > 0);
}
public void testKRCProblem3() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char y;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char y;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 0 );
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 0);
}
public void testKRCProblem4() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x,y,z) char x,y,z; int a;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x,y,z) char x,y,z; int a;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTSimpleDeclaration);
assertTrue(f_kr.getParameterDeclarations()[1] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// bindings should still be ok
IASTName x1 = f_kr.getParameterNames()[0];
IASTName y1 = f_kr.getParameterNames()[1];
IASTName z1 = f_kr.getParameterNames()[2];
- IASTName x2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName y2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[1].getName();
- IASTName z2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[2].getName();
- IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
-
- IParameter x1_parm = (IParameter)x1.resolveBinding();
- IParameter x2_parm = (IParameter)x2.resolveBinding();
- IParameter x3_parm = (IParameter)x3.resolveBinding();
- IParameter y1_parm = (IParameter)y1.resolveBinding();
- IParameter y2_parm = (IParameter)y2.resolveBinding();
- IParameter z1_parm = (IParameter)z1.resolveBinding();
- IParameter z2_parm = (IParameter)z2.resolveBinding();
+ IASTName x2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName y2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[1].getName();
+ IASTName z2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[2].getName();
+ IASTName x3 = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+
+ IParameter x1_parm = (IParameter) x1.resolveBinding();
+ IParameter x2_parm = (IParameter) x2.resolveBinding();
+ IParameter x3_parm = (IParameter) x3.resolveBinding();
+ IParameter y1_parm = (IParameter) y1.resolveBinding();
+ IParameter y2_parm = (IParameter) y2.resolveBinding();
+ IParameter z1_parm = (IParameter) z1.resolveBinding();
+ IParameter z2_parm = (IParameter) z2.resolveBinding();
assertEquals(x1_parm, x2_parm);
assertEquals(x2_parm, x3_parm);
@@ -347,267 +347,265 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(z1_parm, z2_parm);
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
-
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
}
public void testKRCProblem5() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char x,a;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char x,a;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 0 );
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 0);
}
public void testKRC_monop_cards1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "#ifdef __STDC__\n" ); //$NON-NLS-1$
- buffer.append( "#define __P(x) x\n" ); //$NON-NLS-1$
- buffer.append( "#else\n" ); //$NON-NLS-1$
- buffer.append( "#define __P(x) ()\n" ); //$NON-NLS-1$
- buffer.append( "#endif\n" ); //$NON-NLS-1$
- buffer.append( "struct A_struct {\n" ); //$NON-NLS-1$
- buffer.append( "int a;\n" ); //$NON-NLS-1$
- buffer.append( "long *c;\n" ); //$NON-NLS-1$
- buffer.append( "};\n" ); //$NON-NLS-1$
- buffer.append( "typedef struct A_struct A;\n" ); //$NON-NLS-1$
- buffer.append( "static void f __P((A *));\n" ); //$NON-NLS-1$
- buffer.append( "static void\n" ); //$NON-NLS-1$
- buffer.append( "f(x)\n" ); //$NON-NLS-1$
- buffer.append( "A *x; {\n" ); //$NON-NLS-1$
- buffer.append( "x->a = 0;\n" ); //$NON-NLS-1$
- buffer.append( "x->c[1]=x->c[2];\n" ); //$NON-NLS-1$
- buffer.append( "}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTSimpleDeclaration A_struct = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration A = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration)tu.getDeclarations()[2];
- IASTFunctionDefinition f_def = (IASTFunctionDefinition)tu.getDeclarations()[3];
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("#ifdef __STDC__\n"); //$NON-NLS-1$
+ buffer.append("#define __P(x) x\n"); //$NON-NLS-1$
+ buffer.append("#else\n"); //$NON-NLS-1$
+ buffer.append("#define __P(x) ()\n"); //$NON-NLS-1$
+ buffer.append("#endif\n"); //$NON-NLS-1$
+ buffer.append("struct A_struct {\n"); //$NON-NLS-1$
+ buffer.append("int a;\n"); //$NON-NLS-1$
+ buffer.append("long *c;\n"); //$NON-NLS-1$
+ buffer.append("};\n"); //$NON-NLS-1$
+ buffer.append("typedef struct A_struct A;\n"); //$NON-NLS-1$
+ buffer.append("static void f __P((A *));\n"); //$NON-NLS-1$
+ buffer.append("static void\n"); //$NON-NLS-1$
+ buffer.append("f(x)\n"); //$NON-NLS-1$
+ buffer.append("A *x; {\n"); //$NON-NLS-1$
+ buffer.append("x->a = 0;\n"); //$NON-NLS-1$
+ buffer.append("x->c[1]=x->c[2];\n"); //$NON-NLS-1$
+ buffer.append("}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+
+ IASTSimpleDeclaration A_struct = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration A = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
+ IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[3];
// check A_struct
- assertTrue( A_struct.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier );
- assertEquals( A_struct.getDeclarators().length, 0 );
+ assertTrue(A_struct.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier);
+ assertEquals(A_struct.getDeclarators().length, 0);
IASTName A_struct_name1 = ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName();
- assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$
+ assertEquals(A_struct_name1.toString(), "A_struct"); //$NON-NLS-1$
ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding();
- assertEquals( ((ICInternalBinding)A_struct_type1).getPhysicalNode(), ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName() );
+ assertEquals(((ICInternalBinding)A_struct_type1).getPhysicalNode(), ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName());
IField[] fields = A_struct_type1.getFields();
IField a1 = fields[0];
IField c1 = fields[1];
- assertEquals( a1.getName().toString(), "a" ); //$NON-NLS-1$
- assertEquals( c1.getName().toString(), "c" ); //$NON-NLS-1$
- IBasicType a1_t = (IBasicType)a1.getType();
- IPointerType c1_t = (IPointerType)c1.getType();
- assertEquals( a1_t.getType(), IBasicType.t_int );
- assertTrue( c1_t.getType() instanceof IBasicType );
- assertTrue( ((IBasicType)c1_t.getType()).isLong() );
+ assertEquals(a1.getName().toString(), "a"); //$NON-NLS-1$
+ assertEquals(c1.getName().toString(), "c"); //$NON-NLS-1$
+ IBasicType a1_t = (IBasicType) a1.getType();
+ IPointerType c1_t = (IPointerType) c1.getType();
+ assertEquals(a1_t.getType(), IBasicType.t_int);
+ assertTrue(c1_t.getType() instanceof IBasicType);
+ assertTrue(((IBasicType) c1_t.getType()).isLong());
// check A
IASTName A_name1 = A.getDeclarators()[0].getName();
- assertEquals( A_name1.toString(), "A" ); //$NON-NLS-1$
+ assertEquals(A_name1.toString(), "A"); //$NON-NLS-1$
ITypedef A_var1 = (ITypedef)A_name1.resolveBinding();
- assertTrue( A.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier );
+ assertTrue(A.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier);
IASTName A_struct_name_2 = ((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getName();
- assertEquals( A_struct_name_2.toString(), "A_struct" ); //$NON-NLS-1$
- assertEquals( ((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getStorageClass(), IASTDeclSpecifier.sc_typedef );
+ assertEquals(A_struct_name_2.toString(), "A_struct"); //$NON-NLS-1$
+ assertEquals(((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getStorageClass(), IASTDeclSpecifier.sc_typedef);
ICompositeType A_struct_type2 = (ICompositeType)A_struct_name_2.resolveBinding();
- assertEquals( A_struct_type2, A_struct_type1 );
+ assertEquals(A_struct_type2, A_struct_type1);
// check f_decl
- assertTrue( f_decl.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
- IASTStandardFunctionDeclarator f_decltor1 = ((IASTStandardFunctionDeclarator)f_decl.getDeclarators()[0]);
+ assertTrue(f_decl.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
+ IASTStandardFunctionDeclarator f_decltor1 = ((IASTStandardFunctionDeclarator) f_decl.getDeclarators()[0]);
IASTName f_name1 = f_decltor1.getName();
- IFunction f_fun1 = (IFunction)f_name1.resolveBinding();
- assertEquals( f_name1.toString(), "f" ); //$NON-NLS-1$
- assertEquals( f_decltor1.getParameters().length, 1 );
+ IFunction f_fun1 = (IFunction) f_name1.resolveBinding();
+ assertEquals(f_name1.toString(), "f"); //$NON-NLS-1$
+ assertEquals(f_decltor1.getParameters().length, 1);
//IASTName x0 = f_decltor1.getParameters()[0].getDeclarator().getName();
- IASTName A_name2 = ((ICASTTypedefNameSpecifier)f_decltor1.getParameters()[0].getDeclSpecifier()).getName();
- assertEquals( A_name2.toString(), "A" ); //$NON-NLS-1$
+ IASTName A_name2 = ((ICASTTypedefNameSpecifier) f_decltor1.getParameters()[0].getDeclSpecifier()).getName();
+ assertEquals(A_name2.toString(), "A"); //$NON-NLS-1$
ITypedef A_var2 = (ITypedef)A_name2.resolveBinding();
- assertEquals( A_var1, A_var2 );
+ assertEquals(A_var1, A_var2);
// check f_def
- assertTrue( f_def.getDeclarator() instanceof ICASTKnRFunctionDeclarator );
-
- ICASTKnRFunctionDeclarator f_decltor2 = (ICASTKnRFunctionDeclarator)f_def.getDeclarator();
- assertEquals( f_decltor2.getName().toString(), "f" ); //$NON-NLS-1$
- IFunction f_fun2 = (IFunction)f_decltor2.getName().resolveBinding();
- assertEquals( f_fun1, f_fun2 );
- ICBasicType f_ret_t = (ICBasicType)f_fun2.getType().getReturnType();
- assertEquals( f_ret_t.getType(), IBasicType.t_void );
+ assertTrue(f_def.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
+
+ ICASTKnRFunctionDeclarator f_decltor2 = (ICASTKnRFunctionDeclarator) f_def.getDeclarator();
+ assertEquals(f_decltor2.getName().toString(), "f"); //$NON-NLS-1$
+ IFunction f_fun2 = (IFunction) f_decltor2.getName().resolveBinding();
+ assertEquals(f_fun1, f_fun2);
+ ICBasicType f_ret_t = (ICBasicType) f_fun2.getType().getReturnType();
+ assertEquals(f_ret_t.getType(), IBasicType.t_void);
IASTName x1 = f_decltor2.getParameterNames()[0];
- assertEquals( x1.toString(), "x" ); //$NON-NLS-1$
- IASTSimpleDeclaration x_parm = (IASTSimpleDeclaration)f_decltor2.getParameterDeclarations()[0];
+ assertEquals(x1.toString(), "x"); //$NON-NLS-1$
+ IASTSimpleDeclaration x_parm = (IASTSimpleDeclaration) f_decltor2.getParameterDeclarations()[0];
IASTName x2 = x_parm.getDeclarators()[0].getName();
- assertEquals( x2.toString(), "x" ); //$NON-NLS-1$
- assertEquals( x_parm.getDeclarators()[0].getPointerOperators().length, 1 );
- IASTName A3 = ((IASTNamedTypeSpecifier)x_parm.getDeclSpecifier()).getName();
+ assertEquals(x2.toString(), "x"); //$NON-NLS-1$
+ assertEquals(x_parm.getDeclarators()[0].getPointerOperators().length, 1);
+ IASTName A3 = ((IASTNamedTypeSpecifier) x_parm.getDeclSpecifier()).getName();
ITypedef A_var3 = (ITypedef)A3.resolveBinding();
- assertEquals( A_var2, A_var3 );
- assertEquals( A3.toString(), "A" ); //$NON-NLS-1$;
- assertEquals( x1.resolveBinding(), x2.resolveBinding() );
+ assertEquals(A_var2, A_var3);
+ assertEquals(A3.toString(), "A"); //$NON-NLS-1$;
+ assertEquals(x1.resolveBinding(), x2.resolveBinding());
// check f_def body
- assertTrue( f_def.getBody() instanceof IASTCompoundStatement );
- IASTCompoundStatement f_def_body = (IASTCompoundStatement)f_def.getBody();
- IASTExpressionStatement stmt1 = (IASTExpressionStatement)f_def_body.getStatements()[0];
- IASTExpressionStatement stmt2 = (IASTExpressionStatement)f_def_body.getStatements()[1];
- IASTName a2 = ((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldName();
- assertEquals( ((IASTName)((ICInternalBinding)a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding() );
- IASTName x3 = ((IASTIdExpression)((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldOwner()).getName();
- assertEquals( x2.resolveBinding(), x3.resolveBinding() );
- assertEquals( ((IASTBinaryExpression)stmt1.getExpression()).getOperand2().toString(), "0" ); //$NON-NLS-1$
- assertTrue( ((IASTBinaryExpression)stmt2.getExpression()).getOperand1() instanceof IASTArraySubscriptExpression );
- assertTrue( ((IASTBinaryExpression)stmt2.getExpression()).getOperand2() instanceof IASTArraySubscriptExpression );
- IASTName c2 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldName();
- IASTName x4 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
- IASTName c3 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName();
- IASTName x5 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
- assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding() );
- assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding() );
- assertEquals( x3.resolveBinding(), x4.resolveBinding() );
- assertEquals( x4.resolveBinding(), x5.resolveBinding() );
+ assertTrue(f_def.getBody() instanceof IASTCompoundStatement);
+ IASTCompoundStatement f_def_body = (IASTCompoundStatement) f_def.getBody();
+ IASTExpressionStatement stmt1 = (IASTExpressionStatement) f_def_body.getStatements()[0];
+ IASTExpressionStatement stmt2 = (IASTExpressionStatement) f_def_body.getStatements()[1];
+ IASTName a2 = ((IASTFieldReference) ((IASTBinaryExpression) stmt1.getExpression()).getOperand1()).getFieldName();
+ assertEquals(((IASTName) ((ICInternalBinding) a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding());
+ IASTName x3 = ((IASTIdExpression) ((IASTFieldReference) ((IASTBinaryExpression) stmt1.getExpression()).getOperand1()).getFieldOwner()).getName();
+ assertEquals(x2.resolveBinding(), x3.resolveBinding());
+ assertEquals(((IASTBinaryExpression) stmt1.getExpression()).getOperand2().toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) stmt2.getExpression()).getOperand1() instanceof IASTArraySubscriptExpression);
+ assertTrue(((IASTBinaryExpression) stmt2.getExpression()).getOperand2() instanceof IASTArraySubscriptExpression);
+ IASTName c2 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldName();
+ IASTName x4 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
+ IASTName c3 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName();
+ IASTName x5 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
+ assertEquals(((IASTName) ((ICInternalBinding) c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding());
+ assertEquals(((IASTName) ((ICInternalBinding) c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding());
+ assertEquals(x3.resolveBinding(), x4.resolveBinding());
+ assertEquals(x4.resolveBinding(), x5.resolveBinding());
// test CFunction.getParameters size
IParameter[] f1_parms = f_fun1.getParameters();
- assertEquals( f1_parms.length, 1 );
+ assertEquals(f1_parms.length, 1);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x2.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testKRC_monop_cards2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int\n" ); //$NON-NLS-1$
- buffer.append( "getinp(prompt, list)\n" ); //$NON-NLS-1$
- buffer.append( " const char *prompt, *const list[];\n" ); //$NON-NLS-1$
- buffer.append( "{\n *list[1] = 'a';\n}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTFunctionDefinition getinp = (IASTFunctionDefinition)tu.getDeclarations()[0];
-
- IASTName prompt1 = ((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterNames()[0];
- IASTName list1 = ((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterNames()[1];
- IASTName prompt2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName list2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[1].getName();
- IASTName list3 = ((IASTIdExpression)((IASTArraySubscriptExpression)((IASTUnaryExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)getinp.getBody()).getStatements()[0]).getExpression()).getOperand1()).getOperand()).getArrayExpression()).getName();
-
- assertEquals( prompt1.resolveBinding(), prompt2.resolveBinding() );
- assertEquals( list1.resolveBinding(), list2.resolveBinding() );
- assertEquals( list2.resolveBinding(), list3.resolveBinding() );
-
- IASTSimpleDeclaration parm_decl = (IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0];
- assertTrue( ((IASTSimpleDeclSpecifier)parm_decl.getDeclSpecifier()).isConst() );
- assertEquals( ((IASTSimpleDeclSpecifier)parm_decl.getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_char );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int\n"); //$NON-NLS-1$
+ buffer.append("getinp(prompt, list)\n"); //$NON-NLS-1$
+ buffer.append(" const char *prompt, *const list[];\n"); //$NON-NLS-1$
+ buffer.append("{\n *list[1] = 'a';\n}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+
+ IASTFunctionDefinition getinp = (IASTFunctionDefinition) tu.getDeclarations()[0];
+
+ IASTName prompt1 = ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterNames()[0];
+ IASTName list1 = ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterNames()[1];
+ IASTName prompt2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName list2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[1].getName();
+ IASTName list3 = ((IASTIdExpression) ((IASTArraySubscriptExpression) ((IASTUnaryExpression) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) getinp.getBody()).getStatements()[0]).getExpression()).getOperand1()).getOperand()).getArrayExpression()).getName();
+
+ assertEquals(prompt1.resolveBinding(), prompt2.resolveBinding());
+ assertEquals(list1.resolveBinding(), list2.resolveBinding());
+ assertEquals(list2.resolveBinding(), list3.resolveBinding());
+
+ IASTSimpleDeclaration parm_decl = (IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0];
+ assertTrue(((IASTSimpleDeclSpecifier) parm_decl.getDeclSpecifier()).isConst());
+ assertEquals(((IASTSimpleDeclSpecifier) parm_decl.getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_char);
IASTDeclarator prompt = parm_decl.getDeclarators()[0];
- IASTArrayDeclarator list = (IASTArrayDeclarator)parm_decl.getDeclarators()[1];
- assertEquals( prompt.getName().toString(), "prompt" ); //$NON-NLS-1$
- assertEquals( prompt.getPointerOperators().length, 1 );
- assertEquals( list.getName().toString(), "list" ); //$NON-NLS-1$
- assertEquals( list.getArrayModifiers().length, 1 );
- assertNull( list.getArrayModifiers()[0].getConstantExpression() );
- assertEquals( list.getPointerOperators().length, 1 );
+ IASTArrayDeclarator list = (IASTArrayDeclarator) parm_decl.getDeclarators()[1];
+ assertEquals(prompt.getName().toString(), "prompt"); //$NON-NLS-1$
+ assertEquals(prompt.getPointerOperators().length, 1);
+ assertEquals(list.getName().toString(), "list"); //$NON-NLS-1$
+ assertEquals(list.getArrayModifiers().length, 1);
+ assertNull(list.getArrayModifiers()[0].getConstantExpression());
+ assertEquals(list.getPointerOperators().length, 1);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(list3.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], list2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], list2);
decls = tu.getDeclarationsInAST(prompt1.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], prompt2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], prompt2);
}
public void testKRC_getParametersOrder() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(a, b) int b,a;{}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
- ICASTKnRFunctionDeclarator f_decltor = (ICASTKnRFunctionDeclarator)f.getDeclarator();
- IFunction f_fun = (IFunction)f_decltor.getName().resolveBinding();
- IParameter [] f_parms = f_fun.getParameters();
- assertEquals( f_parms.length, 2 );
- assertEquals( ((CParameter)f_parms[0]).getName(), "a" ); //$NON-NLS-1$
- assertEquals( ((CParameter)f_parms[1]).getName(), "b" ); //$NON-NLS-1$
-
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(a, b) int b,a;{}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
+ ICASTKnRFunctionDeclarator f_decltor = (ICASTKnRFunctionDeclarator) f.getDeclarator();
+ IFunction f_fun = (IFunction) f_decltor.getName().resolveBinding();
+ IParameter[] f_parms = f_fun.getParameters();
+ assertEquals(f_parms.length, 2);
+ assertEquals(((CParameter) f_parms[0]).getName(), "a"); //$NON-NLS-1$
+ assertEquals(((CParameter) f_parms[1]).getName(), "b"); //$NON-NLS-1$
}
public void testKRC_Ethereal_1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct symbol {\n" ); //$NON-NLS-1$
- buffer.append( "int lambda;\n};\n" ); //$NON-NLS-1$
- buffer.append( "struct lemon {\n" ); //$NON-NLS-1$
- buffer.append( "struct symbol **symbols;\n" ); //$NON-NLS-1$
- buffer.append( "int errorcnt;\n};\n" ); //$NON-NLS-1$
- buffer.append( "void f(lemp)\n" ); //$NON-NLS-1$
- buffer.append( "struct lemon *lemp;\n{\n" ); //$NON-NLS-1$
- buffer.append( "lemp->symbols[1]->lambda = 1;\n" ); //$NON-NLS-1$
- buffer.append( "lemp->errorcnt++;}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTSimpleDeclaration symbol_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration lemon_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTFunctionDefinition f_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
-
- IASTName symbol_name1 = ((IASTCompositeTypeSpecifier)symbol_decl.getDeclSpecifier()).getName();
- IASTName lambda_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)symbol_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
- IASTName lemon_name1 = ((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getName();
- IASTName symbol_name2 = ((IASTElaboratedTypeSpecifier)((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclSpecifier()).getName();
- IASTName symbols_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
- IASTName errorcnt_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
- IASTName lemp_name1 = ((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterNames()[0];
- IASTName lemon_name2 = ((IASTElaboratedTypeSpecifier)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
- IASTName lemp_name2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName lemp_name3 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldOwner()).getName();
- IASTName symbols_name2 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldName();
- IASTName lambda_name2 = ((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldName();
-
- IASTName lemp_name4 = ((IASTIdExpression)((IASTFieldReference)((IASTUnaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldOwner()).getName();
- IASTName errorcnt_name2 = ((IASTFieldReference)((IASTUnaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldName();
-
- assertEquals( symbol_name1.resolveBinding(), symbol_name2.resolveBinding() );
- assertEquals( lambda_name1.resolveBinding(), lambda_name2.resolveBinding() );
- assertEquals( lemon_name1.resolveBinding(), lemon_name2.resolveBinding() );
- assertEquals( symbols_name1.resolveBinding(), symbols_name2.resolveBinding() );
- assertEquals( errorcnt_name1.resolveBinding(), errorcnt_name2.resolveBinding() );
- assertEquals( lemp_name1.resolveBinding(), lemp_name2.resolveBinding() );
- assertEquals( lemp_name2.resolveBinding(), lemp_name3.resolveBinding() );
- assertEquals( lemp_name3.resolveBinding(), lemp_name4.resolveBinding() );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct symbol {\n"); //$NON-NLS-1$
+ buffer.append("int lambda;\n};\n"); //$NON-NLS-1$
+ buffer.append("struct lemon {\n"); //$NON-NLS-1$
+ buffer.append("struct symbol **symbols;\n"); //$NON-NLS-1$
+ buffer.append("int errorcnt;\n};\n"); //$NON-NLS-1$
+ buffer.append("void f(lemp)\n"); //$NON-NLS-1$
+ buffer.append("struct lemon *lemp;\n{\n"); //$NON-NLS-1$
+ buffer.append("lemp->symbols[1]->lambda = 1;\n"); //$NON-NLS-1$
+ buffer.append("lemp->errorcnt++;}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+
+ IASTSimpleDeclaration symbol_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration lemon_decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[2];
+
+ IASTName symbol_name1 = ((IASTCompositeTypeSpecifier) symbol_decl.getDeclSpecifier()).getName();
+ IASTName lambda_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) symbol_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
+ IASTName lemon_name1 = ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getName();
+ IASTName symbol_name2 = ((IASTElaboratedTypeSpecifier) ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclSpecifier()).getName();
+ IASTName symbols_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
+ IASTName errorcnt_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
+ IASTName lemp_name1 = ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterNames()[0];
+ IASTName lemon_name2 = ((IASTElaboratedTypeSpecifier) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
+ IASTName lemp_name2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName lemp_name3 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldOwner()).getName();
+ IASTName symbols_name2 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldName();
+ IASTName lambda_name2 = ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldName();
+
+ IASTName lemp_name4 = ((IASTIdExpression) ((IASTFieldReference) ((IASTUnaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldOwner()).getName();
+ IASTName errorcnt_name2 = ((IASTFieldReference) ((IASTUnaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldName();
+
+ assertEquals(symbol_name1.resolveBinding(), symbol_name2.resolveBinding());
+ assertEquals(lambda_name1.resolveBinding(), lambda_name2.resolveBinding());
+ assertEquals(lemon_name1.resolveBinding(), lemon_name2.resolveBinding());
+ assertEquals(symbols_name1.resolveBinding(), symbols_name2.resolveBinding());
+ assertEquals(errorcnt_name1.resolveBinding(), errorcnt_name2.resolveBinding());
+ assertEquals(lemp_name1.resolveBinding(), lemp_name2.resolveBinding());
+ assertEquals(lemp_name2.resolveBinding(), lemp_name3.resolveBinding());
+ assertEquals(lemp_name3.resolveBinding(), lemp_name4.resolveBinding());
}
public void testBug97447() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("void f( a ) int a; {} \n"); //$NON-NLS-1$
- buffer.append("void f( int ); \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("void f(a) int a; {} \n"); //$NON-NLS-1$
+ buffer.append("void f(int); \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
CNameCollector col = new CNameCollector();
@@ -619,38 +617,38 @@ public class AST2KnRTests extends AST2BaseTest {
}
public void testBug100104() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef int ush;\n"); //$NON-NLS-1$
buffer.append("int f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int a=1;\n"); //$NON-NLS-1$
- buffer.append("((ush)(a)*(ush)(a) * a);\n"); //$NON-NLS-1$
+ buffer.append("((ush) (a)*(ush) (a) * a);\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
- assertTrue( tu.getDeclarations()[0] instanceof IASTSimpleDeclaration );
- assertTrue( tu.getDeclarations()[1] instanceof IASTFunctionDefinition );
- IASTStatement[] stmts = ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements();
- assertTrue( stmts[0] instanceof IASTDeclarationStatement );
- assertTrue( stmts[1] instanceof IASTExpressionStatement );
- assertTrue( stmts[2] instanceof IASTCompoundStatement );
- assertTrue( stmts[3] instanceof IASTNullStatement );
+ assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
+ assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
+ IASTStatement[] stmts = ((IASTCompoundStatement) ((IASTFunctionDefinition) tu.getDeclarations()[1]).getBody()).getStatements();
+ assertTrue(stmts[0] instanceof IASTDeclarationStatement);
+ assertTrue(stmts[1] instanceof IASTExpressionStatement);
+ assertTrue(stmts[2] instanceof IASTCompoundStatement);
+ assertTrue(stmts[3] instanceof IASTNullStatement);
}
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=203050
public void testBug203050() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef long time_t;\n" + //$NON-NLS-1$
"\n" + //$NON-NLS-1$
- "void (foo)(timep)\n" + //$NON-NLS-1$
+ "void (foo) (timep)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
" struct tm tmp;\n" + //$NON-NLS-1$
" bar(timep, &tmp);\n" + //$NON-NLS-1$
"}\n" + //$NON-NLS-1$
- "int (bar)(timep, tmp)\n" + //$NON-NLS-1$
+ "int (bar) (timep, tmp)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
" struct tm * tmp;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
@@ -658,23 +656,22 @@ public class AST2KnRTests extends AST2BaseTest {
"}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
- assertTrue( tu.getDeclarations()[0] instanceof IASTSimpleDeclaration );
- assertTrue( tu.getDeclarations()[1] instanceof IASTFunctionDefinition );
- assertTrue( tu.getDeclarations()[2] instanceof IASTFunctionDefinition );
- IASTStatement[] stmts = ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements();
- assertTrue( stmts[0] instanceof IASTDeclarationStatement );
- assertTrue( stmts[1] instanceof IASTExpressionStatement );
- IASTExpression expr= ((IASTExpressionStatement)stmts[1]).getExpression();
+ assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
+ assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
+ assertTrue(tu.getDeclarations()[2] instanceof IASTFunctionDefinition);
+ IASTStatement[] stmts = ((IASTCompoundStatement) ((IASTFunctionDefinition) tu.getDeclarations()[1]).getBody()).getStatements();
+ assertTrue(stmts[0] instanceof IASTDeclarationStatement);
+ assertTrue(stmts[1] instanceof IASTExpressionStatement);
+ IASTExpression expr= ((IASTExpressionStatement) stmts[1]).getExpression();
assertTrue(expr instanceof IASTFunctionCallExpression);
- IASTIdExpression fnameExpr= (IASTIdExpression)((IASTFunctionCallExpression)expr).getFunctionNameExpression();
+ IASTIdExpression fnameExpr= (IASTIdExpression) ((IASTFunctionCallExpression) expr).getFunctionNameExpression();
fnameExpr.getName().resolveBinding();
- IASTName fname= ((IASTFunctionDefinition)tu.getDeclarations()[2]).getDeclarator().getName();
+ IASTName fname= ((IASTFunctionDefinition) tu.getDeclarations()[2]).getDeclarator().getName();
try {
fname.resolveBinding();
} catch (StackOverflowError e) {
fail(e.getMessage());
}
}
-
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
index 46ee3cb7b6..a8ef3b40f4 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
@@ -39,795 +39,795 @@ public class GCCTests extends AST2BaseTest {
}
public void testGCC20000113() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct x { \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x1:1; \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x2:2; \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x3:3; \n" ); //$NON-NLS-1$
- buffer.append( "}; \n" ); //$NON-NLS-1$
- buffer.append( "foobar( int x, int y, int z ){ \n" ); //$NON-NLS-1$
- buffer.append( " struct x a = {x, y, z}; \n" ); //$NON-NLS-1$
- buffer.append( " struct x b = {x, y, z}; \n" ); //$NON-NLS-1$
- buffer.append( " struct x *c = &b; \n" ); //$NON-NLS-1$
- buffer.append( " c->x3 += ( a.x2 - a.x1) * c->x2; \n" ); //$NON-NLS-1$
- buffer.append( " if( a.x1 != 1 || c->x3 != 5 ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct x { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x1:1; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x2:2; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x3:3; \n"); //$NON-NLS-1$
+ buffer.append("}; \n"); //$NON-NLS-1$
+ buffer.append("foobar(int x, int y, int z) { \n"); //$NON-NLS-1$
+ buffer.append(" struct x a = {x, y, z}; \n"); //$NON-NLS-1$
+ buffer.append(" struct x b = {x, y, z}; \n"); //$NON-NLS-1$
+ buffer.append(" struct x *c = &b; \n"); //$NON-NLS-1$
+ buffer.append(" c->x3 += (a.x2 - a.x1) * c->x2; \n"); //$NON-NLS-1$
+ buffer.append(" if (a.x1 != 1 || c->x3 != 5) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 33 );
- ICompositeType x = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField x1 = (IField) collector.getName( 1 ).resolveBinding();
- IField x2 = (IField) collector.getName( 2 ).resolveBinding();
- IField x3 = (IField) collector.getName( 3 ).resolveBinding();
- IVariable vx = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable vy = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable vz = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 14 ).resolveBinding();
- IVariable c = (IVariable) collector.getName( 19 ).resolveBinding();
-
- assertInstances( collector, x, 4 );
- assertInstances( collector, x1, 3);
- assertInstances( collector, x2, 3);
- assertInstances( collector, x3, 3);
- assertInstances( collector, vx, 3);
- assertInstances( collector, vy, 3);
- assertInstances( collector, vz, 3);
- assertInstances( collector, a, 4);
- assertInstances( collector, b, 2);
- assertInstances( collector, c, 4);
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 33);
+ ICompositeType x = (ICompositeType) collector.getName(0).resolveBinding();
+ IField x1 = (IField) collector.getName(1).resolveBinding();
+ IField x2 = (IField) collector.getName(2).resolveBinding();
+ IField x3 = (IField) collector.getName(3).resolveBinding();
+ IVariable vx = (IVariable) collector.getName(5).resolveBinding();
+ IVariable vy = (IVariable) collector.getName(6).resolveBinding();
+ IVariable vz = (IVariable) collector.getName(7).resolveBinding();
+ IVariable a = (IVariable) collector.getName(9).resolveBinding();
+ IVariable b = (IVariable) collector.getName(14).resolveBinding();
+ IVariable c = (IVariable) collector.getName(19).resolveBinding();
+
+ assertInstances(collector, x, 4);
+ assertInstances(collector, x1, 3);
+ assertInstances(collector, x2, 3);
+ assertInstances(collector, x3, 3);
+ assertInstances(collector, vx, 3);
+ assertInstances(collector, vy, 3);
+ assertInstances(collector, vz, 3);
+ assertInstances(collector, a, 4);
+ assertInstances(collector, b, 2);
+ assertInstances(collector, c, 4);
}
public void testGCC20000205() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "static int f( int a ) { \n"); //$NON-NLS-1$
- buffer.append( " if( a == 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( " do \n"); //$NON-NLS-1$
- buffer.append( " if( a & 128 ) \n"); //$NON-NLS-1$
- buffer.append( " return 1; \n"); //$NON-NLS-1$
- buffer.append( " while( f(0) ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("static int f(int a) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a == 0) \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append(" do \n"); //$NON-NLS-1$
+ buffer.append(" if (a & 128) \n"); //$NON-NLS-1$
+ buffer.append(" return 1; \n"); //$NON-NLS-1$
+ buffer.append(" while (f(0)); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 5 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 5);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IVariable a = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, f, 2 );
- assertInstances( collector, a, 3 );
+ assertInstances(collector, f, 2);
+ assertInstances(collector, a, 3);
}
public void testGCC20000217() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "unsigned short int showbug( unsigned short int * a, \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int * b ) { \n"); //$NON-NLS-1$
- buffer.append( " *a += *b - 8; \n"); //$NON-NLS-1$
- buffer.append( " return (*a >= 8 ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main(){ \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int x = 0; \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int y = 10; \n"); //$NON-NLS-1$
- buffer.append( " if( showbug( &x, &y ) != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned short int showbug(unsigned short int * a, \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int * b) { \n"); //$NON-NLS-1$
+ buffer.append(" *a += *b - 8; \n"); //$NON-NLS-1$
+ buffer.append(" return (*a >= 8); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int x = 0; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int y = 10; \n"); //$NON-NLS-1$
+ buffer.append(" if (showbug(&x, &y) != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 12 );
+ assertEquals(collector.size(), 12);
- IFunction showBug = (IFunction) collector.getName( 0 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable y = (IVariable) collector.getName( 8 ).resolveBinding();
+ IFunction showBug = (IFunction) collector.getName(0).resolveBinding();
+ IVariable a = (IVariable) collector.getName(1).resolveBinding();
+ IVariable b = (IVariable) collector.getName(2).resolveBinding();
+ IVariable x = (IVariable) collector.getName(7).resolveBinding();
+ IVariable y = (IVariable) collector.getName(8).resolveBinding();
- assertInstances( collector, showBug, 2 );
- assertInstances( collector, a, 3 );
- assertInstances( collector, b, 2 );
- assertInstances( collector, x, 2 );
- assertInstances( collector, y, 2 );
+ assertInstances(collector, showBug, 2);
+ assertInstances(collector, a, 3);
+ assertInstances(collector, b, 2);
+ assertInstances(collector, x, 2);
+ assertInstances(collector, y, 2);
}
public void testGCC20000224() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int loop_1 = 100; \n"); //$NON-NLS-1$
- buffer.append( "int loop_2 = 7; \n"); //$NON-NLS-1$
- buffer.append( "int flag = 0; \n"); //$NON-NLS-1$
- buffer.append( "int test( void ) { \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " int counter = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( loop_1 > counter ) { \n"); //$NON-NLS-1$
- buffer.append( " if( flag & 1 ) { \n"); //$NON-NLS-1$
- buffer.append( " for( i = 0; i < loop_2; i++ ) { \n"); //$NON-NLS-1$
- buffer.append( " counter++; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " flag++; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " return 1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int loop_1 = 100; \n"); //$NON-NLS-1$
+ buffer.append("int loop_2 = 7; \n"); //$NON-NLS-1$
+ buffer.append("int flag = 0; \n"); //$NON-NLS-1$
+ buffer.append("int test(void) { \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" int counter = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (loop_1 > counter) { \n"); //$NON-NLS-1$
+ buffer.append(" if (flag & 1) { \n"); //$NON-NLS-1$
+ buffer.append(" for (i = 0; i < loop_2; i++) { \n"); //$NON-NLS-1$
+ buffer.append(" counter++; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" flag++; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" return 1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 16 );
- IVariable loop1 = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable loop2 = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable flag = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable counter = (IVariable) collector.getName( 6 ).resolveBinding();
-
- assertInstances( collector, loop1, 2 );
- assertInstances( collector, loop2, 2 );
- assertInstances( collector, flag, 3 );
- assertInstances( collector, i, 4 );
- assertInstances( collector, counter, 3 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 16);
+ IVariable loop1 = (IVariable) collector.getName(0).resolveBinding();
+ IVariable loop2 = (IVariable) collector.getName(1).resolveBinding();
+ IVariable flag = (IVariable) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(5).resolveBinding();
+ IVariable counter = (IVariable) collector.getName(6).resolveBinding();
+
+ assertInstances(collector, loop1, 2);
+ assertInstances(collector, loop2, 2);
+ assertInstances(collector, flag, 3);
+ assertInstances(collector, i, 4);
+ assertInstances(collector, counter, 3);
}
public void testGCC20000225() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int nResult, b = 0, i = -1; \n"); //$NON-NLS-1$
- buffer.append( " do { \n"); //$NON-NLS-1$
- buffer.append( " if( b != 0 ) { \n"); //$NON-NLS-1$
- buffer.append( " nResult = 1; \n"); //$NON-NLS-1$
- buffer.append( " } else { \n"); //$NON-NLS-1$
- buffer.append( " nResult = 0; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " i++; \n"); //$NON-NLS-1$
- buffer.append( " b = ( i + 2 ) * 4; \n"); //$NON-NLS-1$
- buffer.append( " } while ( i < 0 ); \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int nResult, b = 0, i = -1; \n"); //$NON-NLS-1$
+ buffer.append(" do { \n"); //$NON-NLS-1$
+ buffer.append(" if (b != 0) { \n"); //$NON-NLS-1$
+ buffer.append(" nResult = 1; \n"); //$NON-NLS-1$
+ buffer.append(" } else { \n"); //$NON-NLS-1$
+ buffer.append(" nResult = 0; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" i++; \n"); //$NON-NLS-1$
+ buffer.append(" b = (i + 2) * 4; \n"); //$NON-NLS-1$
+ buffer.append(" } while (i < 0); \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IVariable nResult = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 3 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IVariable nResult = (IVariable) collector.getName(1).resolveBinding();
+ IVariable b = (IVariable) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(3).resolveBinding();
- assertInstances( collector, nResult, 3 );
- assertInstances( collector, b, 3 );
- assertInstances( collector, i, 4 );
+ assertInstances(collector, nResult, 3);
+ assertInstances(collector, b, 3);
+ assertInstances(collector, i, 4);
}
public void testGCC20000227() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "static const unsigned char f[] = \"\\0\\377\"; \n"); //$NON-NLS-1$
- buffer.append( "static const unsigned char g[] = \"\\0y\"; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " if( sizeof f != 3 || sizeof g != 3 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( f[0] != g[0] ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( f[1] != g[1] || f[2] != g[2] ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("static const unsigned char f[] = \"\\0\\377\"; \n"); //$NON-NLS-1$
+ buffer.append("static const unsigned char g[] = \"\\0y\"; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (sizeof f != 3 || sizeof g != 3) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (f[0] != g[0]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (f[1] != g[1] || f[2] != g[2]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IVariable f = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable g = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IVariable f = (IVariable) collector.getName(0).resolveBinding();
+ IVariable g = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, f, 5 );
- assertInstances( collector, g, 5 );
+ assertInstances(collector, f, 5);
+ assertInstances(collector, g, 5);
}
public void testGCC20000313() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "unsigned int buggy( unsigned int *param ) { \n"); //$NON-NLS-1$
- buffer.append( " unsigned int accu, zero = 0, borrow; \n"); //$NON-NLS-1$
- buffer.append( " accu = - *param; \n"); //$NON-NLS-1$
- buffer.append( " borrow = - ( accu > zero ); \n"); //$NON-NLS-1$
- buffer.append( " return borrow; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main(void){ \n"); //$NON-NLS-1$
- buffer.append( " unsigned int param = 1; \n"); //$NON-NLS-1$
- buffer.append( " unsigned int borrow = buggy (&param); \n"); //$NON-NLS-1$
- buffer.append( " if( param != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( borrow +1 != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned int buggy(unsigned int *param) { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int accu, zero = 0, borrow; \n"); //$NON-NLS-1$
+ buffer.append(" accu = - *param; \n"); //$NON-NLS-1$
+ buffer.append(" borrow = - (accu > zero); \n"); //$NON-NLS-1$
+ buffer.append(" return borrow; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main(void) { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int param = 1; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int borrow = buggy (&param); \n"); //$NON-NLS-1$
+ buffer.append(" if (param != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (borrow +1 != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 19 );
+ assertEquals(collector.size(), 19);
IFunction buggy = (IFunction) collector.getName(0).resolveBinding();
IParameter param = (IParameter) collector.getName(1).resolveBinding();
- IVariable accu = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable zero = (IVariable) collector.getName( 3 ).resolveBinding();
- IVariable borrow = (IVariable) collector.getName( 4 ).resolveBinding();
- IVariable param2 = (IVariable) collector.getName( 13 ).resolveBinding();
- IVariable borrow2 = (IVariable) collector.getName( 14 ).resolveBinding();
-
- assertInstances( collector, buggy, 2 );
- assertInstances( collector, param, 2 );
- assertInstances( collector, accu, 3 );
- assertInstances( collector, zero, 2 );
- assertInstances( collector, borrow, 3 );
- assertInstances( collector, param2, 3 );
- assertInstances( collector, borrow2, 2 );
+ IVariable accu = (IVariable) collector.getName(2).resolveBinding();
+ IVariable zero = (IVariable) collector.getName(3).resolveBinding();
+ IVariable borrow = (IVariable) collector.getName(4).resolveBinding();
+ IVariable param2 = (IVariable) collector.getName(13).resolveBinding();
+ IVariable borrow2 = (IVariable) collector.getName(14).resolveBinding();
+
+ assertInstances(collector, buggy, 2);
+ assertInstances(collector, param, 2);
+ assertInstances(collector, accu, 3);
+ assertInstances(collector, zero, 2);
+ assertInstances(collector, borrow, 3);
+ assertInstances(collector, param2, 3);
+ assertInstances(collector, borrow2, 2);
}
public void testGCC20000314_1() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " long winds = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( winds != 0 ) { \n"); //$NON-NLS-1$
- buffer.append( " if( *(char*)winds ) \n"); //$NON-NLS-1$
- buffer.append( " break; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " if( winds == 0 || winds != 0 || *(char*)winds ) \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" long winds = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (winds != 0) { \n"); //$NON-NLS-1$
+ buffer.append(" if (*(char*)winds) \n"); //$NON-NLS-1$
+ buffer.append(" break; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" if (winds == 0 || winds != 0 || *(char*) winds) \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 7 );
- IVariable winds = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 7);
+ IVariable winds = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, winds, 6 );
+ assertInstances(collector, winds, 6);
}
public void testGCC20000314_2() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef unsigned long long uint64; \n" ); //$NON-NLS-1$
- buffer.append( "const uint64 bigconst = 1ULL << 34; \n" ); //$NON-NLS-1$
- buffer.append( "int a = 1; \n" ); //$NON-NLS-1$
- buffer.append( "static uint64 getmask(void) { \n" ); //$NON-NLS-1$
- buffer.append( " if(a) return bigconst; \n" ); //$NON-NLS-1$
- buffer.append( " else return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
- buffer.append( "main(){ \n" ); //$NON-NLS-1$
- buffer.append( " uint64 f = getmask(); \n" ); //$NON-NLS-1$
- buffer.append( " if( sizeof (long long) == 8 && f != bigconst ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef unsigned long long uint64; \n"); //$NON-NLS-1$
+ buffer.append("const uint64 bigconst = 1ULL << 34; \n"); //$NON-NLS-1$
+ buffer.append("int a = 1; \n"); //$NON-NLS-1$
+ buffer.append("static uint64 getmask(void) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a) return bigconst; \n"); //$NON-NLS-1$
+ buffer.append(" else return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" uint64 f = getmask(); \n"); //$NON-NLS-1$
+ buffer.append(" if (sizeof (long long) == 8 && f != bigconst) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 15 );
- ITypedef uint64 = (ITypedef) collector.getName( 0 ).resolveBinding();
- IVariable bigconst = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 3 ).resolveBinding();
- IFunction getmask = (IFunction) collector.getName( 5 ).resolveBinding();
- IVariable f = (IVariable) collector.getName( 11 ).resolveBinding();
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 15);
+ ITypedef uint64 = (ITypedef) collector.getName(0).resolveBinding();
+ IVariable bigconst = (IVariable) collector.getName(2).resolveBinding();
+ IVariable a = (IVariable) collector.getName(3).resolveBinding();
+ IFunction getmask = (IFunction) collector.getName(5).resolveBinding();
+ IVariable f = (IVariable) collector.getName(11).resolveBinding();
- assertInstances( collector, uint64, 4 );
- assertInstances( collector, bigconst, 3 );
- assertInstances( collector, a, 2 );
- assertInstances( collector, getmask, 2 );
- assertInstances( collector, f, 2 );
+ assertInstances(collector, uint64, 4);
+ assertInstances(collector, bigconst, 3);
+ assertInstances(collector, a, 2);
+ assertInstances(collector, getmask, 2);
+ assertInstances(collector, f, 2);
}
public void testGCC20000403() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "extern unsigned long aa[], bb[]; \n"); //$NON-NLS-1$
- buffer.append( "int seqgt( unsigned long a, unsigned short win, unsigned long b ); \n"); //$NON-NLS-1$
- buffer.append( "int seqgt2 ( unsigned long a, unsigned short win, unsigned long b ); \n"); //$NON-NLS-1$
- buffer.append( "main() { \n"); //$NON-NLS-1$
- buffer.append( " if( !seqgt( *aa, 0x1000, *bb) || !seqgt2( *aa, 0x1000, *bb) ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int seqgt( unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
- buffer.append( " return (long) ((a + win) - b) > 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int seqgt2( unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
- buffer.append( " long l = ((a + win) - b); \n"); //$NON-NLS-1$
- buffer.append( " return 1 > 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "unsigned long aa[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
- buffer.append( "unsigned long bb[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("extern unsigned long aa[], bb[]; \n"); //$NON-NLS-1$
+ buffer.append("int seqgt(unsigned long a, unsigned short win, unsigned long b); \n"); //$NON-NLS-1$
+ buffer.append("int seqgt2 (unsigned long a, unsigned short win, unsigned long b); \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (!seqgt(*aa, 0x1000, *bb) || !seqgt2(*aa, 0x1000, *bb)) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int seqgt(unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
+ buffer.append(" return (long) ((a + win) - b) > 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int seqgt2(unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
+ buffer.append(" long l = ((a + win) - b); \n"); //$NON-NLS-1$
+ buffer.append(" return 1 > 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("unsigned long aa[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
+ buffer.append("unsigned long bb[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 34 );
- IVariable aa = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable bb = (IVariable) collector.getName( 1 ).resolveBinding();
- IFunction seqgt = (IFunction) collector.getName( 2 ).resolveBinding();
- IParameter a1 = (IParameter) collector.getName( 3 ).resolveBinding();
- IParameter win1 = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter b1 = (IParameter) collector.getName( 5 ).resolveBinding();
- IFunction seqgt2 = (IFunction) collector.getName( 6 ).resolveBinding();
- IParameter a2 = (IParameter) collector.getName( 7 ).resolveBinding();
- IParameter win2 = (IParameter) collector.getName( 8 ).resolveBinding();
- IParameter b2 = (IParameter) collector.getName( 9 ).resolveBinding();
-
- assertInstances( collector, aa, 4 );
- assertInstances( collector, bb, 4 );
- assertInstances( collector, seqgt, 3 );
- assertInstances( collector, a1, 3 );
- assertInstances( collector, win1, 3 );
- assertInstances( collector, b1, 3 );
- assertInstances( collector, seqgt2, 3 );
- assertInstances( collector, a2, 3 );
- assertInstances( collector, win2, 3 );
- assertInstances( collector, b2, 3 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 34);
+ IVariable aa = (IVariable) collector.getName(0).resolveBinding();
+ IVariable bb = (IVariable) collector.getName(1).resolveBinding();
+ IFunction seqgt = (IFunction) collector.getName(2).resolveBinding();
+ IParameter a1 = (IParameter) collector.getName(3).resolveBinding();
+ IParameter win1 = (IParameter) collector.getName(4).resolveBinding();
+ IParameter b1 = (IParameter) collector.getName(5).resolveBinding();
+ IFunction seqgt2 = (IFunction) collector.getName(6).resolveBinding();
+ IParameter a2 = (IParameter) collector.getName(7).resolveBinding();
+ IParameter win2 = (IParameter) collector.getName(8).resolveBinding();
+ IParameter b2 = (IParameter) collector.getName(9).resolveBinding();
+
+ assertInstances(collector, aa, 4);
+ assertInstances(collector, bb, 4);
+ assertInstances(collector, seqgt, 3);
+ assertInstances(collector, a1, 3);
+ assertInstances(collector, win1, 3);
+ assertInstances(collector, b1, 3);
+ assertInstances(collector, seqgt2, 3);
+ assertInstances(collector, a2, 3);
+ assertInstances(collector, win2, 3);
+ assertInstances(collector, b2, 3);
}
public void testGCC20000412_1 () throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "short int i = -1; \n" ); //$NON-NLS-1$
- buffer.append( "const char * const wordlist[207]; \n" ); //$NON-NLS-1$
- buffer.append( "const char * const * foo( void ) { \n" ); //$NON-NLS-1$
- buffer.append( " register const char * const *wordptr = &wordlist[207u + i]; \n" ); //$NON-NLS-1$
- buffer.append( " return wordptr; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
- buffer.append( "int main() { \n" ); //$NON-NLS-1$
- buffer.append( " if( foo() != &wordlist[206] ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("short int i = -1; \n"); //$NON-NLS-1$
+ buffer.append("const char * const wordlist[207]; \n"); //$NON-NLS-1$
+ buffer.append("const char * const * foo(void) { \n"); //$NON-NLS-1$
+ buffer.append(" register const char * const *wordptr = &wordlist[207u + i]; \n"); //$NON-NLS-1$
+ buffer.append(" return wordptr; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (foo() != &wordlist[206]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 11 );
- IVariable i = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable wordlist = (IVariable) collector.getName( 1 ).resolveBinding();
- IFunction foo = (IFunction) collector.getName( 2 ).resolveBinding();
- IVariable wordptr = (IVariable) collector.getName( 4 ).resolveBinding();
-
- assertInstances( collector, i, 2 );
- assertInstances( collector, wordlist, 3 );
- assertInstances( collector, foo, 2 );
- assertInstances( collector, wordptr, 2 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 11);
+ IVariable i = (IVariable) collector.getName(0).resolveBinding();
+ IVariable wordlist = (IVariable) collector.getName(1).resolveBinding();
+ IFunction foo = (IFunction) collector.getName(2).resolveBinding();
+ IVariable wordptr = (IVariable) collector.getName(4).resolveBinding();
+
+ assertInstances(collector, i, 2);
+ assertInstances(collector, wordlist, 3);
+ assertInstances(collector, foo, 2);
+ assertInstances(collector, wordptr, 2);
}
public void testGCC20000412_2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f( int a, int *y ) { \n"); //$NON-NLS-1$
- buffer.append( " int x = a; \n"); //$NON-NLS-1$
- buffer.append( " if( a == 0 ) return *y; \n"); //$NON-NLS-1$
- buffer.append( " return f( a-1, &x ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main( int argc, char** argv){ \n"); //$NON-NLS-1$
- buffer.append( " if( f(100, (int *) 0 ) != 1) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(int a, int *y) { \n"); //$NON-NLS-1$
+ buffer.append(" int x = a; \n"); //$NON-NLS-1$
+ buffer.append(" if (a == 0) return *y; \n"); //$NON-NLS-1$
+ buffer.append(" return f(a-1, &x); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main(int argc, char** argv) { \n"); //$NON-NLS-1$
+ buffer.append(" if (f(100, (int *) 0) != 1) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 14 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter a = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter y = (IParameter) collector.getName( 2 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 3 ).resolveBinding();
-
- assertInstances( collector, f, 3 );
- assertInstances( collector, a, 4 );
- assertInstances( collector, y, 2 );
- assertInstances( collector, x, 2 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 14);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter a = (IParameter) collector.getName(1).resolveBinding();
+ IParameter y = (IParameter) collector.getName(2).resolveBinding();
+ IVariable x = (IVariable) collector.getName(3).resolveBinding();
+
+ assertInstances(collector, f, 3);
+ assertInstances(collector, a, 4);
+ assertInstances(collector, y, 2);
+ assertInstances(collector, x, 2);
}
public void testGCC20000412_3() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef struct { \n"); //$NON-NLS-1$
- buffer.append( " char y; \n"); //$NON-NLS-1$
- buffer.append( " char x[32]; \n"); //$NON-NLS-1$
- buffer.append( "} X; \n"); //$NON-NLS-1$
- buffer.append( "int z(void) { \n"); //$NON-NLS-1$
- buffer.append( " X xxx; \n"); //$NON-NLS-1$
- buffer.append( " xxx.x[0] = xxx.x[31] = '0'; \n"); //$NON-NLS-1$
- buffer.append( " xxx.y = 0xf; \n"); //$NON-NLS-1$
- buffer.append( " return f( xxx, xxx ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main (void) { \n"); //$NON-NLS-1$
- buffer.append( " int val; \n"); //$NON-NLS-1$
- buffer.append( " val = z(); \n"); //$NON-NLS-1$
- buffer.append( " if( val != 0x60 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int f( X x, X y ) { \n"); //$NON-NLS-1$
- buffer.append( " if( x.y != y.y ) \n"); //$NON-NLS-1$
- buffer.append( " return 'F'; \n"); //$NON-NLS-1$
- buffer.append( " return x.x[0] + y.x[0]; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef struct { \n"); //$NON-NLS-1$
+ buffer.append(" char y; \n"); //$NON-NLS-1$
+ buffer.append(" char x[32]; \n"); //$NON-NLS-1$
+ buffer.append("} X; \n"); //$NON-NLS-1$
+ buffer.append("int z(void) { \n"); //$NON-NLS-1$
+ buffer.append(" X xxx; \n"); //$NON-NLS-1$
+ buffer.append(" xxx.x[0] = xxx.x[31] = '0'; \n"); //$NON-NLS-1$
+ buffer.append(" xxx.y = 0xf; \n"); //$NON-NLS-1$
+ buffer.append(" return f(xxx, xxx); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main (void) { \n"); //$NON-NLS-1$
+ buffer.append(" int val; \n"); //$NON-NLS-1$
+ buffer.append(" val = z(); \n"); //$NON-NLS-1$
+ buffer.append(" if (val != 0x60) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int f(X x, X y) { \n"); //$NON-NLS-1$
+ buffer.append(" if (x.y != y.y) \n"); //$NON-NLS-1$
+ buffer.append(" return 'F'; \n"); //$NON-NLS-1$
+ buffer.append(" return x.x[0] + y.x[0]; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 36 );
- IField y = (IField) collector.getName( 1 ).resolveBinding();
- IField x = (IField) collector.getName( 2 ).resolveBinding();
- ITypedef X = (ITypedef) collector.getName( 3 ).resolveBinding();
- IFunction z = (IFunction) collector.getName( 4 ).resolveBinding();
- IVariable xxx = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable val = (IVariable) collector.getName( 19 ).resolveBinding();
- IParameter px = (IParameter) collector.getName( 25 ).resolveBinding();
- IParameter py = (IParameter) collector.getName( 27 ).resolveBinding();
-
- assertInstances( collector, y, 4 );
- assertInstances( collector, x, 5 );
- assertInstances( collector, X, 4 );
- assertInstances( collector, z, 2 );
- assertInstances( collector, xxx, 6 );
- assertInstances( collector, val, 3 );
- assertInstances( collector, px, 3 );
- assertInstances( collector, py, 3 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 36);
+ IField y = (IField) collector.getName(1).resolveBinding();
+ IField x = (IField) collector.getName(2).resolveBinding();
+ ITypedef X = (ITypedef) collector.getName(3).resolveBinding();
+ IFunction z = (IFunction) collector.getName(4).resolveBinding();
+ IVariable xxx = (IVariable) collector.getName(7).resolveBinding();
+ IVariable val = (IVariable) collector.getName(19).resolveBinding();
+ IParameter px = (IParameter) collector.getName(25).resolveBinding();
+ IParameter py = (IParameter) collector.getName(27).resolveBinding();
+
+ assertInstances(collector, y, 4);
+ assertInstances(collector, x, 5);
+ assertInstances(collector, X, 4);
+ assertInstances(collector, z, 2);
+ assertInstances(collector, xxx, 6);
+ assertInstances(collector, val, 3);
+ assertInstances(collector, px, 3);
+ assertInstances(collector, py, 3);
}
public void testGCC20000412_4() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "void f(int i, int j, int radius, int width, int N) { \n"); //$NON-NLS-1$
- buffer.append( " const int diff = i - radius; \n"); //$NON-NLS-1$
- buffer.append( " const int lowk = (diff > 0 ? diff : 0 ); \n"); //$NON-NLS-1$
- buffer.append( " int k; \n"); //$NON-NLS-1$
- buffer.append( " for( k = lowk; k <= 2; k++ ){ \n"); //$NON-NLS-1$
- buffer.append( " int idx = ((k-i+radius) * width - j + radius); \n"); //$NON-NLS-1$
- buffer.append( " if( idx < 0 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " for( k = lowk; k <= 2; k++ ) ; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main (int argc, char** argv ){ \n"); //$NON-NLS-1$
- buffer.append( " int exc_rad = 2; \n"); //$NON-NLS-1$
- buffer.append( " int N = 8; \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " for( i = 1; i < 4; i++ ) \n"); //$NON-NLS-1$
- buffer.append( " f( i, 1, exc_rad, 2*exc_rad + 1, N ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("void f(int i, int j, int radius, int width, int N) { \n"); //$NON-NLS-1$
+ buffer.append(" const int diff = i - radius; \n"); //$NON-NLS-1$
+ buffer.append(" const int lowk = (diff > 0 ? diff : 0); \n"); //$NON-NLS-1$
+ buffer.append(" int k; \n"); //$NON-NLS-1$
+ buffer.append(" for (k = lowk; k <= 2; k++) { \n"); //$NON-NLS-1$
+ buffer.append(" int idx = ((k-i+radius) * width - j + radius); \n"); //$NON-NLS-1$
+ buffer.append(" if (idx < 0) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" for (k = lowk; k <= 2; k++) ; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main (int argc, char** argv) { \n"); //$NON-NLS-1$
+ buffer.append(" int exc_rad = 2; \n"); //$NON-NLS-1$
+ buffer.append(" int N = 8; \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" for (i = 1; i < 4; i++) \n"); //$NON-NLS-1$
+ buffer.append(" f(i, 1, exc_rad, 2*exc_rad + 1, N); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 43 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter i1 = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter j = (IParameter) collector.getName( 2 ).resolveBinding();
- IParameter radius = (IParameter) collector.getName( 3 ).resolveBinding();
- IParameter width = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter N1 = (IParameter) collector.getName( 5 ).resolveBinding();
- IVariable diff = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable lowk = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable k = (IVariable) collector.getName( 12 ).resolveBinding();
- IVariable idx = (IVariable) collector.getName( 17 ).resolveBinding();
- IVariable exc_rad = (IVariable) collector.getName( 32 ).resolveBinding();
- IVariable N2 = (IVariable) collector.getName( 33 ).resolveBinding();
- IVariable i2 = (IVariable) collector.getName( 34 ).resolveBinding();
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 43);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter i1 = (IParameter) collector.getName(1).resolveBinding();
+ IParameter j = (IParameter) collector.getName(2).resolveBinding();
+ IParameter radius = (IParameter) collector.getName(3).resolveBinding();
+ IParameter width = (IParameter) collector.getName(4).resolveBinding();
+ IParameter N1 = (IParameter) collector.getName(5).resolveBinding();
+ IVariable diff = (IVariable) collector.getName(6).resolveBinding();
+ IVariable lowk = (IVariable) collector.getName(9).resolveBinding();
+ IVariable k = (IVariable) collector.getName(12).resolveBinding();
+ IVariable idx = (IVariable) collector.getName(17).resolveBinding();
+ IVariable exc_rad = (IVariable) collector.getName(32).resolveBinding();
+ IVariable N2 = (IVariable) collector.getName(33).resolveBinding();
+ IVariable i2 = (IVariable) collector.getName(34).resolveBinding();
- assertInstances( collector, f, 2 );
- assertInstances( collector, i1, 3 );
- assertInstances( collector, j, 2 );
- assertInstances( collector, radius, 4 );
- assertInstances( collector, width, 2 );
- assertInstances( collector, N1, 1 );
- assertInstances( collector, diff, 3 );
- assertInstances( collector, lowk, 3 );
- assertInstances( collector, k, 8 );
- assertInstances( collector, idx, 2 );
- assertInstances( collector, exc_rad, 3 );
- assertInstances( collector, N2, 2 );
- assertInstances( collector, i2, 5 );
+ assertInstances(collector, f, 2);
+ assertInstances(collector, i1, 3);
+ assertInstances(collector, j, 2);
+ assertInstances(collector, radius, 4);
+ assertInstances(collector, width, 2);
+ assertInstances(collector, N1, 1);
+ assertInstances(collector, diff, 3);
+ assertInstances(collector, lowk, 3);
+ assertInstances(collector, k, 8);
+ assertInstances(collector, idx, 2);
+ assertInstances(collector, exc_rad, 3);
+ assertInstances(collector, N2, 2);
+ assertInstances(collector, i2, 5);
}
public void testGCC20000412_5() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main( void ) { \n"); //$NON-NLS-1$
- buffer.append( " struct { \n"); //$NON-NLS-1$
- buffer.append( " int node; \n"); //$NON-NLS-1$
- buffer.append( " int type; \n"); //$NON-NLS-1$
- buffer.append( " } lastglob[1] = { { 0, 1 } }; \n"); //$NON-NLS-1$
- buffer.append( " if( lastglob[0].node != 0 || lastglob[0].type != 1 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main(void) { \n"); //$NON-NLS-1$
+ buffer.append(" struct { \n"); //$NON-NLS-1$
+ buffer.append(" int node; \n"); //$NON-NLS-1$
+ buffer.append(" int type; \n"); //$NON-NLS-1$
+ buffer.append(" } lastglob[1] = { { 0, 1 } }; \n"); //$NON-NLS-1$
+ buffer.append(" if (lastglob[0].node != 0 || lastglob[0].type != 1) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 10 );
- IField node = (IField) collector.getName( 3 ).resolveBinding();
- IField type = (IField) collector.getName( 4 ).resolveBinding();
- IVariable lastglob = (IVariable) collector.getName( 5 ).resolveBinding();
+ assertEquals(collector.size(), 10);
+ IField node = (IField) collector.getName(3).resolveBinding();
+ IField type = (IField) collector.getName(4).resolveBinding();
+ IVariable lastglob = (IVariable) collector.getName(5).resolveBinding();
- assertInstances( collector, node, 2 );
- assertInstances( collector, type, 2 );
- assertInstances( collector, lastglob, 3 );
+ assertInstances(collector, node, 2);
+ assertInstances(collector, type, 2);
+ assertInstances(collector, lastglob, 3);
}
public void testGCC20000419() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct foo { int a, b, c; }; \n"); //$NON-NLS-1$
- buffer.append( "void brother( int a, int b, int c ) { \n"); //$NON-NLS-1$
- buffer.append( " if( a ) return; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "void sister( struct foo f, int b, int c ) { \n"); //$NON-NLS-1$
- buffer.append( " brother( (f.b == b), b, c ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " struct foo f = { 7, 8, 9 }; \n"); //$NON-NLS-1$
- buffer.append( " sister( f, 1, 2 ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
- CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 25 );
- ICompositeType foo = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField fa = (IField) collector.getName( 1 ).resolveBinding();
- IField fb = (IField) collector.getName( 2 ).resolveBinding();
- IField fc = (IField) collector.getName( 3 ).resolveBinding();
- IFunction brother = (IFunction) collector.getName( 4 ).resolveBinding();
- IParameter pa = (IParameter) collector.getName( 5 ).resolveBinding();
- IParameter pb = (IParameter) collector.getName( 6 ).resolveBinding();
- IParameter pc = (IParameter) collector.getName( 7 ).resolveBinding();
- IFunction sister = (IFunction) collector.getName( 9 ).resolveBinding();
- IParameter sf = (IParameter) collector.getName( 11 ).resolveBinding();
- IParameter sb = (IParameter) collector.getName( 12 ).resolveBinding();
- IParameter sc = (IParameter) collector.getName( 13 ).resolveBinding();
- IVariable f = (IVariable) collector.getName( 22 ).resolveBinding();
-
- assertInstances( collector, foo, 3 );
- assertInstances( collector, fa, 1 );
- assertInstances( collector, fb, 2 );
- assertInstances( collector, fc, 1 );
- assertInstances( collector, brother, 2 );
- assertInstances( collector, pa, 2 );
- assertInstances( collector, pb, 1 );
- assertInstances( collector, pc, 1 );
- assertInstances( collector, sister, 2 );
- assertInstances( collector, sf, 2 );
- assertInstances( collector, sb, 3 );
- assertInstances( collector, sc, 2 );
- assertInstances( collector, f, 2 );
- }
- public void testGCC20000503() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("unsigned long sub( int a ) { \n"); //$NON-NLS-1$
- buffer.append(" return ((0 > a - 2) ? 0 : a - 2) * sizeof(long); \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct foo { int a, b, c; }; \n"); //$NON-NLS-1$
+ buffer.append("void brother(int a, int b, int c) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a) return; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("void sister(struct foo f, int b, int c) { \n"); //$NON-NLS-1$
+ buffer.append(" brother((f.b == b), b, c); \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
- buffer.append("main(){ \n"); //$NON-NLS-1$
- buffer.append(" return ( sub(0) != 0 ); \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct foo f = { 7, 8, 9 }; \n"); //$NON-NLS-1$
+ buffer.append(" sister(f, 1, 2); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 25);
+ ICompositeType foo = (ICompositeType) collector.getName(0).resolveBinding();
+ IField fa = (IField) collector.getName(1).resolveBinding();
+ IField fb = (IField) collector.getName(2).resolveBinding();
+ IField fc = (IField) collector.getName(3).resolveBinding();
+ IFunction brother = (IFunction) collector.getName(4).resolveBinding();
+ IParameter pa = (IParameter) collector.getName(5).resolveBinding();
+ IParameter pb = (IParameter) collector.getName(6).resolveBinding();
+ IParameter pc = (IParameter) collector.getName(7).resolveBinding();
+ IFunction sister = (IFunction) collector.getName(9).resolveBinding();
+ IParameter sf = (IParameter) collector.getName(11).resolveBinding();
+ IParameter sb = (IParameter) collector.getName(12).resolveBinding();
+ IParameter sc = (IParameter) collector.getName(13).resolveBinding();
+ IVariable f = (IVariable) collector.getName(22).resolveBinding();
+
+ assertInstances(collector, foo, 3);
+ assertInstances(collector, fa, 1);
+ assertInstances(collector, fb, 2);
+ assertInstances(collector, fc, 1);
+ assertInstances(collector, brother, 2);
+ assertInstances(collector, pa, 2);
+ assertInstances(collector, pb, 1);
+ assertInstances(collector, pc, 1);
+ assertInstances(collector, sister, 2);
+ assertInstances(collector, sf, 2);
+ assertInstances(collector, sb, 3);
+ assertInstances(collector, sc, 2);
+ assertInstances(collector, f, 2);
+ }
+ public void testGCC20000503() throws Exception {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned long sub(int a) { \n"); //$NON-NLS-1$
+ buffer.append(" return ((0 > a - 2) ? 0 : a - 2) * sizeof(long); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" return (sub(0) != 0); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
+ CNameCollector collector = new CNameCollector();
+ tu.accept(collector);
- assertEquals( collector.size(), 6 );
- IFunction sub = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter a = (IParameter) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 6);
+ IFunction sub = (IFunction) collector.getName(0).resolveBinding();
+ IParameter a = (IParameter) collector.getName(1).resolveBinding();
- assertInstances( collector, sub, 2 );
- assertInstances( collector, a, 3 );
+ assertInstances(collector, sub, 2);
+ assertInstances(collector, a, 3);
}
public void testGCC20000511() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("int f( int value, int expect ) { \n"); //$NON-NLS-1$
- buffer.append(" return ( value == expect ); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
- buffer.append("main(){ \n"); //$NON-NLS-1$
- buffer.append(" int a = 7, b = 6, c = 4, d = 7, e = 2; \n"); //$NON-NLS-1$
- buffer.append(" f( a || b % c, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a ? b % c : 0, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a = b % c, 2); \n"); //$NON-NLS-1$
- buffer.append(" f( a *= b % c, 4 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a /= b % c, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a %= b % c, 0 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a += b % c, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d || c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d ? c && e : 0, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d = c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d *= c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d %= c && e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d += c && e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d -= c && e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d || c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d ? c || e : 0, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d = c || e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d *= c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d %= c || e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d += c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d -= c || e, 0 ); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(int value, int expect) { \n"); //$NON-NLS-1$
+ buffer.append(" return (value == expect); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" int a = 7, b = 6, c = 4, d = 7, e = 2; \n"); //$NON-NLS-1$
+ buffer.append(" f(a || b % c, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(a ? b % c : 0, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a = b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a *= b % c, 4); \n"); //$NON-NLS-1$
+ buffer.append(" f(a /= b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a %= b % c, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(a += b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(d || c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d ? c && e : 0, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d = c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d *= c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d %= c && e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d += c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d -= c && e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d || c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d ? c || e : 0, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d = c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d *= c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d %= c || e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d += c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d -= c || e, 0); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 95 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter v = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter ex = (IParameter) collector.getName( 2 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable c = (IVariable) collector.getName( 8 ).resolveBinding();
- IVariable d = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable e = (IVariable) collector.getName( 10).resolveBinding();
-
-
- assertInstances( collector, f, 22 );
- assertInstances( collector, v, 2 );
- assertInstances( collector, ex, 2 );
- assertInstances( collector, a, 8 );
- assertInstances( collector, b, 8 );
- assertInstances( collector, c, 22 );
- assertInstances( collector, d, 15 );
- assertInstances( collector, e, 15 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 95);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter v = (IParameter) collector.getName(1).resolveBinding();
+ IParameter ex = (IParameter) collector.getName(2).resolveBinding();
+ IVariable a = (IVariable) collector.getName(6).resolveBinding();
+ IVariable b = (IVariable) collector.getName(7).resolveBinding();
+ IVariable c = (IVariable) collector.getName(8).resolveBinding();
+ IVariable d = (IVariable) collector.getName(9).resolveBinding();
+ IVariable e = (IVariable) collector.getName(10).resolveBinding();
+
+
+ assertInstances(collector, f, 22);
+ assertInstances(collector, v, 2);
+ assertInstances(collector, ex, 2);
+ assertInstances(collector, a, 8);
+ assertInstances(collector, b, 8);
+ assertInstances(collector, c, 22);
+ assertInstances(collector, d, 15);
+ assertInstances(collector, e, 15);
}
public void testGCC20000603() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct s1 { double d; }; \n"); //$NON-NLS-1$
- buffer.append( "struct s2 { double d; }; \n"); //$NON-NLS-1$
- buffer.append( "double f( struct s1 * a, struct s2 *b) { \n"); //$NON-NLS-1$
- buffer.append( " a->d = 1.0; \n"); //$NON-NLS-1$
- buffer.append( " return b->d + 1.0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " struct s1 a; \n"); //$NON-NLS-1$
- buffer.append( " a.d = 0.0; \n"); //$NON-NLS-1$
- buffer.append( " if( f( &a, (struct s2 *)&a ) != 2.0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct s1 { double d; }; \n"); //$NON-NLS-1$
+ buffer.append("struct s2 { double d; }; \n"); //$NON-NLS-1$
+ buffer.append("double f(struct s1 * a, struct s2 *b) { \n"); //$NON-NLS-1$
+ buffer.append(" a->d = 1.0; \n"); //$NON-NLS-1$
+ buffer.append(" return b->d + 1.0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct s1 a; \n"); //$NON-NLS-1$
+ buffer.append(" a.d = 0.0; \n"); //$NON-NLS-1$
+ buffer.append(" if (f(&a, (struct s2 *)&a) != 2.0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 22 );
- ICompositeType s1 = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField d1 = (IField) collector.getName( 1 ).resolveBinding();
- ICompositeType s2 = (ICompositeType) collector.getName( 2 ).resolveBinding();
- IField d2 = (IField) collector.getName( 3 ).resolveBinding();
- IFunction f = (IFunction) collector.getName( 4 ).resolveBinding();
- IParameter pa = (IParameter) collector.getName( 6 ).resolveBinding();
- IParameter pb = (IParameter) collector.getName( 8 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 15 ).resolveBinding();
-
- assertInstances( collector, s1, 3 );
- assertInstances( collector, s2, 3 );
- assertInstances( collector, d1, 3 );
- assertInstances( collector, d2, 2 );
- assertInstances( collector, f, 2 );
- assertInstances( collector, pa, 2 );
- assertInstances( collector, pb, 2 );
- assertInstances( collector, a, 4 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 22);
+ ICompositeType s1 = (ICompositeType) collector.getName(0).resolveBinding();
+ IField d1 = (IField) collector.getName(1).resolveBinding();
+ ICompositeType s2 = (ICompositeType) collector.getName(2).resolveBinding();
+ IField d2 = (IField) collector.getName(3).resolveBinding();
+ IFunction f = (IFunction) collector.getName(4).resolveBinding();
+ IParameter pa = (IParameter) collector.getName(6).resolveBinding();
+ IParameter pb = (IParameter) collector.getName(8).resolveBinding();
+ IVariable a = (IVariable) collector.getName(15).resolveBinding();
+
+ assertInstances(collector, s1, 3);
+ assertInstances(collector, s2, 3);
+ assertInstances(collector, d1, 3);
+ assertInstances(collector, d2, 2);
+ assertInstances(collector, f, 2);
+ assertInstances(collector, pa, 2);
+ assertInstances(collector, pb, 2);
+ assertInstances(collector, a, 4);
}
public void testGCC20000605_2() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct F { int i; }; \n"); //$NON-NLS-1$
- buffer.append( "void f1( struct F *x, struct F * y ) { \n"); //$NON-NLS-1$
- buffer.append( " int timeout = 0; \n"); //$NON-NLS-1$
- buffer.append( " for( ; ((const struct F*)x)->i < y->i; x->i++ ) \n"); //$NON-NLS-1$
- buffer.append( " if( ++timeout > 5 ) \n"); //$NON-NLS-1$
- buffer.append( " return; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "main() { \n"); //$NON-NLS-1$
- buffer.append( " struct F x, y; \n"); //$NON-NLS-1$
- buffer.append( " x.i = 0; y.i = 1; \n"); //$NON-NLS-1$
- buffer.append( " f1( &x, &y ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct F { int i; }; \n"); //$NON-NLS-1$
+ buffer.append("void f1(struct F *x, struct F * y) { \n"); //$NON-NLS-1$
+ buffer.append(" int timeout = 0; \n"); //$NON-NLS-1$
+ buffer.append(" for (; ((const struct F*)x)->i < y->i; x->i++) \n"); //$NON-NLS-1$
+ buffer.append(" if (++timeout > 5) \n"); //$NON-NLS-1$
+ buffer.append(" return; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct F x, y; \n"); //$NON-NLS-1$
+ buffer.append(" x.i = 0; y.i = 1; \n"); //$NON-NLS-1$
+ buffer.append(" f1(&x, &y); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 27 );
- ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField i = (IField) collector.getName( 1 ).resolveBinding();
- IFunction f1 = (IFunction) collector.getName( 2 ).resolveBinding();
- IParameter px = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter py = (IParameter) collector.getName( 6 ).resolveBinding();
- IVariable timeout = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 18 ).resolveBinding();
- IVariable y = (IVariable) collector.getName( 19 ).resolveBinding();
-
- assertInstances( collector, F, 5 );
- assertInstances( collector, i, 6 );
- assertInstances( collector, f1, 2 );
- assertInstances( collector, px, 3 );
- assertInstances( collector, py, 2 );
- assertInstances( collector, timeout, 2 );
- assertInstances( collector, x, 3 );
- assertInstances( collector, y, 3 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 27);
+ ICompositeType F = (ICompositeType) collector.getName(0).resolveBinding();
+ IField i = (IField) collector.getName(1).resolveBinding();
+ IFunction f1 = (IFunction) collector.getName(2).resolveBinding();
+ IParameter px = (IParameter) collector.getName(4).resolveBinding();
+ IParameter py = (IParameter) collector.getName(6).resolveBinding();
+ IVariable timeout = (IVariable) collector.getName(7).resolveBinding();
+ IVariable x = (IVariable) collector.getName(18).resolveBinding();
+ IVariable y = (IVariable) collector.getName(19).resolveBinding();
+
+ assertInstances(collector, F, 5);
+ assertInstances(collector, i, 6);
+ assertInstances(collector, f1, 2);
+ assertInstances(collector, px, 3);
+ assertInstances(collector, py, 2);
+ assertInstances(collector, timeout, 2);
+ assertInstances(collector, x, 3);
+ assertInstances(collector, y, 3);
}
public void testGCC20000605_3() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct F { int x; int y; }; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int timeout = 0, x = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( 1 ) { \n"); //$NON-NLS-1$
- buffer.append( " const struct F i = { x++, }; \n"); //$NON-NLS-1$
- buffer.append( " if( i.x > 0 ) \n"); //$NON-NLS-1$
- buffer.append( " break; \n"); //$NON-NLS-1$
- buffer.append( " if( ++timeout > 5 ) \n"); //$NON-NLS-1$
- buffer.append( " goto die; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " die: return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct F { int x; int y; }; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int timeout = 0, x = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (1) { \n"); //$NON-NLS-1$
+ buffer.append(" const struct F i = { x++, }; \n"); //$NON-NLS-1$
+ buffer.append(" if (i.x > 0) \n"); //$NON-NLS-1$
+ buffer.append(" break; \n"); //$NON-NLS-1$
+ buffer.append(" if (++timeout > 5) \n"); //$NON-NLS-1$
+ buffer.append(" goto die; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" die: return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
-
- assertEquals( collector.size(), 14 );
- ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField fx = (IField) collector.getName( 1 ).resolveBinding();
- IField fy = (IField) collector.getName( 2 ).resolveBinding();
- IVariable timeout = (IVariable) collector.getName( 4 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 7 ).resolveBinding();
- ILabel die = (ILabel) collector.getName( 13 ).resolveBinding();
-
- assertInstances( collector, F, 2 );
- assertInstances( collector, fx, 2 );
- assertInstances( collector, fy, 1 );
- assertInstances( collector, timeout, 2 );
- assertInstances( collector, x, 2 );
- assertInstances( collector, i, 2 );
- assertInstances( collector, die, 2 );
+ tu.accept(collector);
+
+ assertEquals(collector.size(), 14);
+ ICompositeType F = (ICompositeType) collector.getName(0).resolveBinding();
+ IField fx = (IField) collector.getName(1).resolveBinding();
+ IField fy = (IField) collector.getName(2).resolveBinding();
+ IVariable timeout = (IVariable) collector.getName(4).resolveBinding();
+ IVariable x = (IVariable) collector.getName(5).resolveBinding();
+ IVariable i = (IVariable) collector.getName(7).resolveBinding();
+ ILabel die = (ILabel) collector.getName(13).resolveBinding();
+
+ assertInstances(collector, F, 2);
+ assertInstances(collector, fx, 2);
+ assertInstances(collector, fy, 1);
+ assertInstances(collector, timeout, 2);
+ assertInstances(collector, x, 2);
+ assertInstances(collector, i, 2);
+ assertInstances(collector, die, 2);
}
public void testGCCenum_2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "enum foo { FOO, BAR }; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " for( i = BAR; i >= FOO; --i ) \n"); //$NON-NLS-1$
- buffer.append( " if( i == -1 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("enum foo { FOO, BAR }; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" for (i = BAR; i >= FOO; --i) \n"); //$NON-NLS-1$
+ buffer.append(" if (i == -1) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IEnumeration foo = (IEnumeration) collector.getName( 0 ).resolveBinding();
- IEnumerator FOO = (IEnumerator) collector.getName( 1 ).resolveBinding();
- IEnumerator BAR = (IEnumerator) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 4 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IEnumeration foo = (IEnumeration) collector.getName(0).resolveBinding();
+ IEnumerator FOO = (IEnumerator) collector.getName(1).resolveBinding();
+ IEnumerator BAR = (IEnumerator) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(4).resolveBinding();
- assertInstances( collector, foo, 1 );
- assertInstances( collector, FOO, 2 );
- assertInstances( collector, BAR, 2 );
- assertInstances( collector, i, 5 );
+ assertInstances(collector, foo, 1);
+ assertInstances(collector, FOO, 2);
+ assertInstances(collector, BAR, 2);
+ assertInstances(collector, i, 5);
}
}

Back to the top