Browse Source

Update des tests + début production de code

Phyks (Lucas Verney) 5 years ago
parent
commit
cb6a632a77
100 changed files with 1423 additions and 13 deletions
  1. BIN
      .ast_typing.ml.swp
  2. BIN
      .hello.cpp.swp
  3. 15
    5
      compiler.ml
  4. 5
    0
      hello.cpp
  5. 4
    0
      hello.s
  6. BIN
      main.cmi
  7. BIN
      main.cmo
  8. BIN
      minic++
  9. 7
    0
      tests/exec/arith2.cpp
  10. 12
    0
      tests/exec/arith3.cpp
  11. 6
    0
      tests/exec/bool.cpp
  12. 26
    0
      tests/exec/bresenham.cpp
  13. 1
    1
      tests/exec/bst.cpp
  14. 16
    0
      tests/exec/constructor1.cpp
  15. 14
    0
      tests/exec/constructor2.cpp
  16. 15
    0
      tests/exec/constructor3.cpp
  17. 14
    0
      tests/exec/constructor4.cpp
  18. 11
    0
      tests/exec/fact_loop.cpp
  19. 10
    0
      tests/exec/fact_rec.cpp
  20. 21
    0
      tests/exec/fib_iter.cpp
  21. 22
    0
      tests/exec/field1.cpp
  22. 5
    0
      tests/exec/hello.cpp
  23. 8
    0
      tests/exec/ident1.cpp
  24. 13
    0
      tests/exec/if1.cpp
  25. 29
    0
      tests/exec/interval.cpp
  26. 9
    0
      tests/exec/lazy1.cpp
  27. 48
    0
      tests/exec/list.cpp
  28. 9
    0
      tests/exec/lvalue1.cpp
  29. 12
    0
      tests/exec/null.cpp
  30. 25
    0
      tests/exec/overload1.cpp
  31. 16
    0
      tests/exec/overload2.cpp
  32. 2
    2
      tests/exec/passing.cpp
  33. 23
    0
      tests/exec/pow_loop.cpp
  34. 22
    0
      tests/exec/pow_rec.cpp
  35. 11
    0
      tests/exec/prepost2.cpp
  36. 24
    0
      tests/exec/redef1.cpp
  37. 34
    0
      tests/exec/redef2.cpp
  38. 22
    0
      tests/exec/scope1.cpp
  39. 14
    0
      tests/exec/scope2.cpp
  40. 17
    0
      tests/exec/while.cpp
  41. 0
    1
      tests/syntax/good/testfile-for-1.cpp
  42. 2
    0
      tests/syntax/good/testfile-lexer_hack-1.cpp
  43. 3
    0
      tests/syntax/good/testfile-lexer_hack-2.cpp
  44. 1
    1
      tests/typing/bad/testfile-arith-3.cpp
  45. 1
    1
      tests/typing/bad/testfile-arith-4.cpp
  46. 2
    1
      tests/typing/bad/testfile-arith-5.cpp
  47. 4
    0
      tests/typing/bad/testfile-constructor-1.cpp
  48. 6
    0
      tests/typing/bad/testfile-extra_qualification-1.cpp
  49. 3
    0
      tests/typing/bad/testfile-incomplete_type-1.cpp
  50. 7
    0
      tests/typing/bad/testfile-overload-1.cpp
  51. 0
    1
      tests/typing/bad/testfile-redef-6.cpp
  52. 2
    0
      tests/typing/bad/testfile-reference_type-1.cpp
  53. 3
    0
      tests/typing/bad/testfile-reference_type-2.cpp
  54. 5
    0
      tests/typing/bad/testfile-subtyping-1.cpp
  55. 3
    0
      tests/typing/bad/testfile-this-1.cpp
  56. 2
    0
      tests/typing/good/testfile-not_incomplete_type-1.cpp
  57. 1
    0
      tests/typing/good/testfile-subtype-1.cpp
  58. 5
    0
      tests/typing/good/testfile-subtype-2.cpp
  59. 5
    0
      tests/typing/good/testfile-subtype-3.cpp
  60. 18
    0
      tests_old/LISEZMOI
  61. 60
    0
      tests_old/exec/ABR.cpp
  62. 0
    0
      tests_old/exec/Makefile
  63. 11
    0
      tests_old/exec/address1.cpp
  64. 12
    0
      tests_old/exec/address2.cpp
  65. 14
    0
      tests_old/exec/address3.cpp
  66. 12
    0
      tests_old/exec/affect.cpp
  67. 14
    0
      tests_old/exec/arith1.cpp
  68. 101
    0
      tests_old/exec/bst.cpp
  69. 7
    0
      tests_old/exec/for1.cpp
  70. 8
    0
      tests_old/exec/for2.cpp
  71. 11
    0
      tests_old/exec/for3.cpp
  72. 14
    0
      tests_old/exec/global.cpp
  73. 15
    0
      tests_old/exec/hexa.cpp
  74. 30
    0
      tests_old/exec/inheritance1.cpp
  75. 26
    0
      tests_old/exec/inheritance2.cpp
  76. 101
    0
      tests_old/exec/josephus.cpp
  77. 60
    0
      tests_old/exec/mandelbrot.cpp
  78. 13
    0
      tests_old/exec/octal.cpp
  79. 62
    0
      tests_old/exec/pascal.cpp
  80. 13
    0
      tests_old/exec/passing.cpp
  81. 14
    0
      tests_old/exec/prepost1.cpp
  82. 8
    0
      tests_old/exec/ref1.cpp
  83. 14
    0
      tests_old/exec/ref2.cpp
  84. 18
    0
      tests_old/exec/ref3.cpp
  85. 16
    0
      tests_old/exec/ref4.cpp
  86. 29
    0
      tests_old/exec/ref5.cpp
  87. 20
    0
      tests_old/exec/ref6.cpp
  88. 10
    0
      tests_old/exec/string.cpp
  89. 8
    0
      tests_old/exec/true_false.cpp
  90. 78
    0
      tests_old/exec/vehicles.cpp
  91. 1
    0
      tests_old/syntax/bad/testfile-bad_hexa-1.cpp
  92. 1
    0
      tests_old/syntax/bad/testfile-bad_ident1-1.cpp
  93. 1
    0
      tests_old/syntax/bad/testfile-bad_ident2-1.cpp
  94. 1
    0
      tests_old/syntax/bad/testfile-bad_octal-1.cpp
  95. 1
    0
      tests_old/syntax/bad/testfile-block1-1.cpp
  96. 1
    0
      tests_old/syntax/bad/testfile-block2-1.cpp
  97. 1
    0
      tests_old/syntax/bad/testfile-expr1-1.cpp
  98. 1
    0
      tests_old/syntax/bad/testfile-expr10-1.cpp
  99. 1
    0
      tests_old/syntax/bad/testfile-expr11-1.cpp
  100. 0
    0
      tests_old/syntax/bad/testfile-expr2-1.cpp

BIN
.main.ml.swp → .ast_typing.ml.swp View File


BIN
.Makefile.swp → .hello.cpp.swp View File


+ 15
- 5
compiler.ml View File

@@ -2,9 +2,19 @@
2 2
 
3 3
 open Mips
4 4
 
5
+let mips_fonction f =
6
+    let content = f.fonction_content in
7
+
8
+let mips_decl x y = match x with
9
+    | AT_Fonction f ->
10
+            let generated_mips = mips_fonction f in
11
+            {
12
+                text = generated_mips.text ++ y.text;
13
+                data = generated_mips.data ++ y.data;
14
+            }
15
+    | _ -> assert false
16
+    (* TODO *)
17
+
5 18
 let program x = 
6
-    {
7
-        text = nop;
8
-        data = label "newline"
9
-               ++ asciiz "\n";
10
-    }
19
+    let mips = List.fold_left mips_decl x.program in
20
+    mips

+ 5
- 0
hello.cpp View File

@@ -0,0 +1,5 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << "hello world\n";
5
+}

+ 4
- 0
hello.s View File

@@ -0,0 +1,4 @@
1
+.text
2
+.data
3
+newline:
4
+	.asciiz "\n"

BIN
main.cmi View File


BIN
main.cmo View File


BIN
minic++ View File


+ 7
- 0
tests/exec/arith2.cpp View File

@@ -0,0 +1,7 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << (1 < 2 && 2 <= 3 || (1 + 3)  == (4 + 0)) << "\n";
5
+  std::cout << (2 > 1 && (2 >= 3 || 3 != 3)  == ! (3 == 4)) << "\n";
6
+  std::cout << (- 2 * - 5 ==  2 && 1 == 2 && 0 == 0) << "\n";
7
+}

+ 12
- 0
tests/exec/arith3.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int expr1 =- 7 + 6 * 5 - 4 / 3 - 2;     // 20
5
+  std::cout << expr1 << "\n";
6
+  int expr2 = (7 + 6) * (5 - 4) / 3 - 2; // 2
7
+  std::cout << expr2 << "\n";
8
+  int expr3 = 7 + 6 * (5 - 4 / (3 - 2));  // 13
9
+  std::cout << expr3 << "\n";
10
+  int sum = expr1 % 8 + expr2 + expr3;    // 19
11
+  std::cout << sum << "\n";
12
+}

+ 6
- 0
tests/exec/bool.cpp View File

@@ -0,0 +1,6 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << true << "\n";
5
+  std::cout << false << "\n";
6
+}

+ 26
- 0
tests/exec/bresenham.cpp View File

@@ -0,0 +1,26 @@
1
+#include <iostream>
2
+
3
+void plot(int y) {
4
+  while (y-- > 0) std::cout << " ";
5
+  std::cout << "X\n";
6
+}
7
+
8
+// suppose 0 <= y2 <= x2 (premier octant)
9
+void bresenham(int x2, int y2) {
10
+  int x = 0;
11
+  int y = 0;
12
+  int e = 2 * y2 - x2;
13
+  for (x = 0; x <= x2; x++) {
14
+    plot (y);
15
+    if (e < 0)
16
+      e = e + 2* y2;
17
+    else {
18
+      y++;
19
+      e = e + 2 * (y2 - x2);
20
+    }
21
+  }
22
+}
23
+
24
+int main() {
25
+  bresenham(10, 6);
26
+}

+ 1
- 1
tests/exec/bst.cpp View File

@@ -74,7 +74,7 @@ void BST::add2(int x) {
74 74
 
75 75
 void BST::print() {
76 76
   tree_print(this->root);
77
-  std::cout << std::endl;
77
+  std::cout << "\n";
78 78
 }
79 79
 
80 80
 

+ 16
- 0
tests/exec/constructor1.cpp View File

@@ -0,0 +1,16 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  int x;
6
+  int y;
7
+  A (int x, int y);
8
+};
9
+
10
+A::A(int x, int y) { this->x = x; this->y =y; }
11
+
12
+int main() {
13
+  A a = A(17, 42);
14
+  std::cout << a.x << "\n";
15
+  std::cout << a.y << "\n";
16
+}

+ 14
- 0
tests/exec/constructor2.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  A();
6
+};
7
+
8
+A::A() {
9
+  std::cout << "hello world\n";
10
+}
11
+
12
+int main() {
13
+  A a;
14
+}

+ 15
- 0
tests/exec/constructor3.cpp View File

@@ -0,0 +1,15 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  A();
6
+};
7
+
8
+A::A() {
9
+  std::cout << "hello world\n";
10
+}
11
+
12
+int main() {
13
+  A *a;
14
+  std::cout << "no hello world\n";
15
+}

+ 14
- 0
tests/exec/constructor4.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  A();
6
+};
7
+
8
+A::A() {
9
+  std::cout << "brand new world\n";
10
+}
11
+
12
+int main() {
13
+  A *a = new A();
14
+}

+ 11
- 0
tests/exec/fact_loop.cpp View File

@@ -0,0 +1,11 @@
1
+#include <iostream>
2
+
3
+int fact_loop(int n) {
4
+  int r = 1;
5
+  while (n > 1) r = r * n--;
6
+  return r;
7
+}
8
+
9
+int main() {
10
+  std::cout << fact_loop(5) << "\n";
11
+}

+ 10
- 0
tests/exec/fact_rec.cpp View File

@@ -0,0 +1,10 @@
1
+#include <iostream>
2
+
3
+int fact_rec(int n) {
4
+  if (n <= 1) return 1;
5
+  return n * fact_rec(n - 1);
6
+}
7
+
8
+int main() {
9
+  std::cout << fact_rec(5) << "\n";
10
+}

+ 21
- 0
tests/exec/fib_iter.cpp View File

@@ -0,0 +1,21 @@
1
+#include <iostream>
2
+
3
+class fib {
4
+public:
5
+  int prev, cur;
6
+  fib();
7
+  int next();
8
+};
9
+
10
+fib::fib() {
11
+  prev = 1; cur = 0;
12
+}
13
+
14
+int fib::next() { int i = cur; cur = prev + cur; prev = i; return i; }
15
+
16
+int main() {
17
+  fib s;
18
+  int f;
19
+  while((f = s.next()) <= 100)
20
+    std::cout << f << "\n";
21
+}

+ 22
- 0
tests/exec/field1.cpp View File

@@ -0,0 +1,22 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  int x;
6
+};
7
+
8
+class B : public A {
9
+public:
10
+  int x;
11
+};
12
+
13
+int main() {
14
+  A *a = new A();
15
+  a->x = 0;
16
+  std::cout << a->x << "\n";
17
+  B *b = new B();
18
+  b->x = 1;
19
+  std::cout << b->x << "\n";
20
+  a = b;
21
+  std::cout << a->x << "\n";
22
+}

+ 5
- 0
tests/exec/hello.cpp View File

@@ -0,0 +1,5 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << "hello world\n";
5
+}

+ 8
- 0
tests/exec/ident1.cpp View File

@@ -0,0 +1,8 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int ___________ = 1;
5
+  int ____1_____023__ = 0;
6
+  if (___________ && ____1_____023__ == 0)
7
+    std::cout << "non, tous les programmes n'affichent pas hello world\n";
8
+}

+ 13
- 0
tests/exec/if1.cpp View File

@@ -0,0 +1,13 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  if (1)
5
+    if (0)
6
+      ;
7
+    else {
8
+      if (1 == 2)
9
+        std::cout << (0/0);
10
+      else
11
+        std::cout << "hello world\n";
12
+    }
13
+}

+ 29
- 0
tests/exec/interval.cpp View File

@@ -0,0 +1,29 @@
1
+#include <iostream>
2
+
3
+class interval {
4
+public:
5
+  int low, hi;
6
+  interval(int low, int hi);
7
+  void iterate(int& i);
8
+  int ok(int& i);
9
+  int next(int& i);
10
+};
11
+
12
+interval::interval(int low, int hi) {
13
+  this->low = low;
14
+  this->hi  = hi;
15
+}
16
+
17
+void interval::iterate(int& i) { i = low; }
18
+
19
+int interval::ok(int& i) { return i <= hi; }
20
+
21
+int interval::next(int& i) { return i++; }
22
+
23
+int main() {
24
+  interval s = interval(3, 10);
25
+  int i;
26
+  s.iterate(i);
27
+  while(s.ok(i))
28
+    std::cout << s.next(i) << "\n";
29
+}

+ 9
- 0
tests/exec/lazy1.cpp View File

@@ -0,0 +1,9 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << (42 || (1/0)) << "\n";
5
+  std::cout << (0  && (2/0)) << "\n";
6
+  int *p = NULL;
7
+  if (1 || *p)
8
+    std::cout << "ok\n";
9
+}

+ 48
- 0
tests/exec/list.cpp View File

@@ -0,0 +1,48 @@
1
+#include <iostream>
2
+
3
+// liste simplement chaînée
4
+
5
+class cell {
6
+public:
7
+  int v;
8
+  cell *next;
9
+  cell(int v, cell* next);
10
+};
11
+
12
+cell::cell(int v, cell* next) {
13
+  this->v = v;
14
+  this->next = next;
15
+}
16
+
17
+// liste chaînée de size éléments, avec accès à l'élément i (en temps O(i))
18
+
19
+class list {
20
+public:
21
+  cell *head;
22
+  list(int size);
23
+  int& get(int i);
24
+};
25
+
26
+list::list(int size) {
27
+  this->head = NULL;
28
+  while (size-- > 0) this->head = new cell(0, this->head);
29
+}
30
+
31
+int& list::get(int i) {
32
+  cell *c = this->head;
33
+  while (i-- > 0) c = c->next;
34
+  return c->v;
35
+}
36
+
37
+// on s'en sert comme un tableau pour calculer les premiers nombres
38
+// de Fibonacci (en temps quadratique, donc)
39
+
40
+int main() {
41
+  list l = list(11);
42
+  l.get(1) = 1;
43
+  int i;
44
+  for (i = 2; i < 11; i++) {
45
+    l.get(i) = l.get(i-2) + l.get(i-1);
46
+    std::cout << "F(" << i << ") = " << l.get(i) << "\n";
47
+  }
48
+}

+ 9
- 0
tests/exec/lvalue1.cpp View File

@@ -0,0 +1,9 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x;
5
+  int y;
6
+  int z;
7
+  x = y = z = 1;
8
+  std::cout << x << " " << y << " " << z << "\n";
9
+}

+ 12
- 0
tests/exec/null.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+
3
+class A { public: };
4
+
5
+int main() {
6
+  int *p = NULL;
7
+  std::cout << (p == NULL) << "\n";
8
+  int x = 1;
9
+  std::cout << (&x == NULL) << "\n";
10
+  A a;
11
+  std::cout << (&a == NULL) << "\n";
12
+}

+ 25
- 0
tests/exec/overload1.cpp View File

@@ -0,0 +1,25 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+    int a;
6
+  A();
7
+  void set_a();
8
+  void set_a(int a);
9
+};
10
+
11
+A::A() { }
12
+void A::set_a() { a = 1; }
13
+void A::set_a(int a) { this->a = a; }
14
+
15
+int main() {
16
+  A a;
17
+  int b;
18
+  a.set_a();
19
+  b = a.a == 1;
20
+  a.set_a(2);
21
+  b = b && a.a == 2;
22
+  if (b)
23
+    std::cout << "ok\n";
24
+}
25
+

+ 16
- 0
tests/exec/overload2.cpp View File

@@ -0,0 +1,16 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  int a;
6
+  A();
7
+  A(int a_param);
8
+};
9
+
10
+A::A() { a = 1; }
11
+A::A(int a_param) { a = a_param; }
12
+
13
+int main() {
14
+  if ((new A())->a == 1 && (new A(2))->a == 2)
15
+    std::cout << "ok\n";
16
+}

+ 2
- 2
tests/exec/passing.cpp View File

@@ -6,8 +6,8 @@ void incr(int &y) {
6 6
 
7 7
 int main() {
8 8
   int x = 5;
9
-  std::cout << "x = " << x << std::endl;
9
+  std::cout << "x = " << x << "\n";
10 10
   incr(x);
11
-  std::cout << "x = " << x << std::endl;
11
+  std::cout << "x = " << x << "\n";
12 12
 }
13 13
 

+ 23
- 0
tests/exec/pow_loop.cpp View File

@@ -0,0 +1,23 @@
1
+#include <iostream>
2
+
3
+class Puiss {
4
+public:
5
+  int pow(int a, int n);
6
+};
7
+
8
+int Puiss::pow(int a, int n) {
9
+  int r = 1;
10
+  int i;
11
+  for(i = 0; i < n / 2; i++)
12
+    r = r * a;
13
+  r = r * r;
14
+  if (n % 2 != 0)
15
+    r = r * a;
16
+  return r;
17
+}
18
+
19
+int main() {
20
+  Puiss p;
21
+  std::cout << p.pow(2, 4) << "\n";
22
+  std::cout << p.pow(6, 3) << "\n";
23
+}

+ 22
- 0
tests/exec/pow_rec.cpp View File

@@ -0,0 +1,22 @@
1
+#include <iostream>
2
+
3
+class Puiss {
4
+public:
5
+  int pow(int a, int n);
6
+};
7
+
8
+int Puiss::pow(int a, int n) {
9
+  if (n <= 0)
10
+    return 1;
11
+  int r = pow(a, n / 2);
12
+  r = r * r;
13
+  if (n % 2 == 0)
14
+    return r;
15
+  return r * a;
16
+}
17
+
18
+int main() {
19
+  Puiss p;
20
+  std::cout << p.pow(2, 4) << "\n";
21
+  std::cout << p.pow(6, 3) << "\n";
22
+}

+ 11
- 0
tests/exec/prepost2.cpp View File

@@ -0,0 +1,11 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 41;
5
+  std::cout << "x = " << x << "\n";
6
+  std::cout << "x = " << x++ << "\n";
7
+  std::cout << "x = " << ++x << "\n";
8
+  std::cout << "x = " << x-- << "\n";
9
+  std::cout << "x = " << --x << "\n";
10
+  std::cout << "x = " << x << "\n";
11
+}

+ 24
- 0
tests/exec/redef1.cpp View File

@@ -0,0 +1,24 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  virtual int f(int x);
6
+};
7
+
8
+int A::f(int x) { return x; }
9
+
10
+class B : public A {
11
+public:
12
+  virtual int f(int x);
13
+};
14
+
15
+int B::f(int x) { return 2*x; }
16
+
17
+int main() {
18
+  A *a = new A();
19
+  std::cout << a->f(1) << "\n";
20
+  B *b = new B();
21
+  std::cout << b->f(1) << "\n";
22
+  a = b;
23
+  std::cout << a->f(1) << "\n"; // c'est B::f qui est appelée
24
+}

+ 34
- 0
tests/exec/redef2.cpp View File

@@ -0,0 +1,34 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  virtual int f(int x);
6
+};
7
+
8
+int A::f(int x) { return x; }
9
+
10
+class B : public A {
11
+public:
12
+};
13
+
14
+class C : public B {
15
+public:
16
+  virtual int f(int x);
17
+};
18
+
19
+int C::f(int x) { return 3*x; }
20
+
21
+int main() {
22
+  A *a = new A();
23
+  std::cout << a->f(1) << "\n";
24
+  B *b = new B();
25
+  std::cout << b->f(1) << "\n";
26
+  C *c = new C();
27
+  std::cout << c->f(1) << "\n";
28
+  a = b;
29
+  std::cout << a->f(1) << "\n";
30
+  a = c;
31
+  std::cout << a->f(1) << "\n";
32
+  b = c;
33
+  std::cout << b->f(1) << "\n";
34
+}

+ 22
- 0
tests/exec/scope1.cpp View File

@@ -0,0 +1,22 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  int x;
6
+  int f();
7
+  int g(int x);
8
+};
9
+
10
+int A::f() { int x = 0; x++; return x; }
11
+
12
+int A::g(int x) { x++; return x; }
13
+
14
+int main() {
15
+  A a;
16
+  a.x = 0;
17
+  std::cout << a.x << "\n";
18
+  std::cout << a.f() << "\n";
19
+  std::cout << a.x << "\n";
20
+  std::cout << a.g(1) << "\n";
21
+  std::cout << a.x << "\n";
22
+}

+ 14
- 0
tests/exec/scope2.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int i = 42;
5
+  std::cout << i << "\n";
6
+  if (1) {
7
+    int j = 1;
8
+    std::cout << j << "\n";
9
+  } else {
10
+    int j = 2;
11
+    std::cout << j << "\n";
12
+  }
13
+  std::cout << i << "\n";
14
+}

+ 17
- 0
tests/exec/while.cpp View File

@@ -0,0 +1,17 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int i = 0;
5
+  int cpt = 0;
6
+  for( ; i < 10; ) {
7
+    int j;
8
+    j = 10;
9
+    for ( ; j > 0; ) {
10
+      ++cpt;
11
+      --j;
12
+    }
13
+    i++;
14
+  }
15
+  if (cpt == 100)
16
+    std::cout << "ok\n";
17
+}

+ 0
- 1
tests/syntax/good/testfile-for-1.cpp View File

@@ -1,2 +1 @@
1 1
 int main() { for(;;); }
2
-

+ 2
- 0
tests/syntax/good/testfile-lexer_hack-1.cpp View File

@@ -0,0 +1,2 @@
1
+class
2
+S { public: int a; };

+ 3
- 0
tests/syntax/good/testfile-lexer_hack-2.cpp View File

@@ -0,0 +1,3 @@
1
+
2
+class /* oups */ S { public: int a; };
3
+

+ 1
- 1
tests/typing/bad/testfile-arith-3.cpp View File

@@ -1,2 +1,2 @@
1 1
 
2
-int main() { char *p; p+p; }
2
+int main() { int *p; p+p; }

+ 1
- 1
tests/typing/bad/testfile-arith-4.cpp View File

@@ -1,3 +1,3 @@
1 1
 
2 2
 class S { public: int a; };
3
-int main() { S s; char *p; p+s; }
3
+int main() { S s; int *p; p+s; }

+ 2
- 1
tests/typing/bad/testfile-arith-5.cpp View File

@@ -1,2 +1,3 @@
1 1
 
2
-int main() { char *p; 1-p; }
2
+int main() { int *p; 1-p; }
3
+

+ 4
- 0
tests/typing/bad/testfile-constructor-1.cpp View File

@@ -0,0 +1,4 @@
1
+class A { public: };
2
+class B { public: A(); };
3
+int main() {}
4
+

+ 6
- 0
tests/typing/bad/testfile-extra_qualification-1.cpp View File

@@ -0,0 +1,6 @@
1
+class A {
2
+public:
3
+  void A::f();
4
+};
5
+int main() {}
6
+

+ 3
- 0
tests/typing/bad/testfile-incomplete_type-1.cpp View File

@@ -0,0 +1,3 @@
1
+class A { public: A a; };
2
+int main() {}
3
+

+ 7
- 0
tests/typing/bad/testfile-overload-1.cpp View File

@@ -0,0 +1,7 @@
1
+class A {
2
+public:
3
+  void A::f();
4
+  void A::f();
5
+};
6
+int main() {}
7
+

+ 0
- 1
tests/typing/bad/testfile-redef-6.cpp View File

@@ -1,3 +1,2 @@
1 1
 
2 2
 class S { public: int a; int a; };
3
-int main() {}

+ 2
- 0
tests/typing/bad/testfile-reference_type-1.cpp View File

@@ -0,0 +1,2 @@
1
+int& f() { return 0; }
2
+int main() {}

+ 3
- 0
tests/typing/bad/testfile-reference_type-2.cpp View File

@@ -0,0 +1,3 @@
1
+
2
+int main() { int &y = 42; }
3
+

+ 5
- 0
tests/typing/bad/testfile-subtyping-1.cpp View File

@@ -0,0 +1,5 @@
1
+class A { public: };
2
+class B : public A { public: };
3
+
4
+int main() { B *x = new A(); }
5
+

+ 3
- 0
tests/typing/bad/testfile-this-1.cpp View File

@@ -0,0 +1,3 @@
1
+void f() { std::cout << this << "\n"; }
2
+int main() {}
3
+

+ 2
- 0
tests/typing/good/testfile-not_incomplete_type-1.cpp View File

@@ -0,0 +1,2 @@
1
+class A { public: A *a; };
2
+int main() {}

+ 1
- 0
tests/typing/good/testfile-subtype-1.cpp View File

@@ -3,3 +3,4 @@ int main() {
3 3
   int *s;
4 4
   s = NULL;
5 5
 }
6
+

+ 5
- 0
tests/typing/good/testfile-subtype-2.cpp View File

@@ -0,0 +1,5 @@
1
+
2
+#include <iostream>
3
+class A { public: };
4
+int main() { A *x = NULL; }
5
+

+ 5
- 0
tests/typing/good/testfile-subtype-3.cpp View File

@@ -0,0 +1,5 @@
1
+
2
+class A { public: };
3
+class B : public A { public: };
4
+int main() { A *x = new B(); }
5
+

+ 18
- 0
tests_old/LISEZMOI View File

@@ -0,0 +1,18 @@
1
+
2
+Les tests sont organisés en différentes catégories :
3
+
4
+  syntax/bad/    refusés à l'analyse lexicale ou syntaxique
5
+  typing/bad/    refusés à l'analyse sémantique
6
+  typing/good/   acceptés à l'analyse sémantique
7
+  exec-fail/     compilés avec succès mais l'exécution du code MIPS doit échouer
8
+  exec/          compilés et exécutés avec succès, le résultat attendu étant
9
+                 conforme au fichier .out
10
+
11
+Les tests sont cumulatifs i.e.
12
+
13
+- les fichiers de typing/bad/, exec-fail/ et exec/ peuvent être
14
+  utilisés pour la catégorie syntax/good/
15
+
16
+- les fichiers de exec-fail/ et exec/ peuvent être
17
+  utilisés pour la catégorie typing/good/
18
+

+ 60
- 0
tests_old/exec/ABR.cpp View File

@@ -0,0 +1,60 @@
1
+#include <iostream>
2
+
3
+/* arbres binaires de recherche */
4
+
5
+class ABR {
6
+public:
7
+  int valeur;
8
+  ABR *gauche;
9
+  ABR *droite;
10
+  ABR(ABR *g, int v, ABR *d);
11
+  void insere(int x);
12
+  int contient(int x);
13
+  void affiche();
14
+};
15
+
16
+ABR::ABR(ABR *g, int v, ABR *d) { valeur = v; gauche = g; droite = d; }
17
+
18
+void ABR::insere(int x) {
19
+  if (x == valeur) return;
20
+  if (x < valeur) {
21
+    if (gauche == NULL)
22
+      gauche = new ABR(NULL, x, NULL);
23
+    else
24
+      gauche->insere(x);
25
+  } else
26
+    if (droite == NULL)
27
+      droite = new ABR(NULL, x, NULL);
28
+    else
29
+      droite->insere(x);
30
+}
31
+
32
+int ABR::contient(int x) {
33
+  if (x == valeur) return true;
34
+  if (x < valeur && gauche != NULL) return gauche->contient(x);
35
+  if (droite != NULL) return droite->contient(x);
36
+  return false;
37
+}
38
+
39
+void ABR::affiche() {
40
+  if (gauche != NULL) gauche->affiche();
41
+  std::cout << "(" << valeur << ")";
42
+  if (droite != NULL) droite->affiche();
43
+}
44
+
45
+
46
+int main() {
47
+  ABR dico = ABR(NULL, 1, NULL);
48
+  dico.insere(17);
49
+  dico.insere(5);
50
+  dico.insere(8);
51
+  dico.affiche(); std::cout << "\n";
52
+
53
+  if (dico.contient(5) &&
54
+      ! dico.contient(0) &&
55
+      dico.contient(17) &&
56
+      ! dico.contient(3))
57
+    std::cout << "ok\n";
58
+
59
+  dico.affiche(); std::cout << "\n";
60
+}

tests/exec/Makefile → tests_old/exec/Makefile View File


+ 11
- 0
tests_old/exec/address1.cpp View File

@@ -0,0 +1,11 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 41;
5
+  std::cout << "x = " << x << "\n";
6
+  int *y = &x;
7
+  *y = 42;
8
+  std::cout << "x = " << x << "\n";
9
+  *y = *y + 1;
10
+  std::cout << "x = " << x << "\n";
11
+}

+ 12
- 0
tests_old/exec/address2.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+
3
+void f(int *y) {
4
+  *y = 42;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(&x);
11
+  std::cout << "x = " << x << "\n";
12
+}

+ 14
- 0
tests_old/exec/address3.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+void f(int *y) {
4
+  *y = *y + 1;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(&x);
11
+  std::cout << "x = " << x << "\n";
12
+  f(&x);
13
+  std::cout << "x = " << x << "\n";
14
+}

+ 12
- 0
tests_old/exec/affect.cpp View File

@@ -0,0 +1,12 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 0;
5
+  int y = 0;
6
+  x = ++y;
7
+  y = ++y + ++x;
8
+  y++;
9
+  x = --x + y;
10
+  std::cout << "x=" << x << "\n";
11
+  std::cout << "y=" << y << "\n";
12
+}

+ 14
- 0
tests_old/exec/arith1.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 41;
5
+  std::cout << "x = " << x << "\n";
6
+  x = x+1;
7
+  std::cout << "x = " << x << "\n";
8
+  x = 2*x;
9
+  std::cout << "x = " << x << "\n";
10
+  x = 2*x + 3;
11
+  std::cout << "x = " << x << "\n";
12
+  x = 1 - 2*x;
13
+  std::cout << "x = " << x << "\n";
14
+}

+ 101
- 0
tests_old/exec/bst.cpp View File

@@ -0,0 +1,101 @@
1
+
2
+#include <iostream>
3
+
4
+// arbres binaires, où l'arbre vide est NULL
5
+
6
+class Node {
7
+public:
8
+  int elt;
9
+  Node *left, *right;
10
+  Node(Node *left, int elt, Node *right);
11
+};
12
+
13
+Node::Node(Node *left, int elt, Node *right) {
14
+  this->left = left;
15
+  this->elt = elt;
16
+  this->right = right;
17
+}
18
+
19
+int tree_size(Node *t) {
20
+  if (t == NULL) return 0;
21
+  return 1 + tree_size(t->left) + tree_size(t->right);
22
+}
23
+
24
+Node *tree_add(Node *t, int x) {
25
+  if (t == NULL) return new Node(NULL, x, NULL);
26
+  if      (x < t->elt) t->left  = tree_add(t->left,  x);
27
+  else if (x > t->elt) t->right = tree_add(t->right, x);
28
+  return t;
29
+}
30
+
31
+void tree_add_ref(Node* &t, int x) {
32
+  if      (t == NULL ) t = new Node(NULL, x, NULL);
33
+  else if (x < t->elt) tree_add_ref(t->left,  x);
34
+  else if (x > t->elt) tree_add_ref(t->right, x);
35
+}
36
+
37
+void tree_print(Node *t) {
38
+  if (t == NULL) return;
39
+  std::cout << "(";
40
+  tree_print(t->left);
41
+  std::cout << t->elt;
42
+  tree_print(t->right);
43
+  std::cout << ")";
44
+}
45
+
46
+
47
+// encapsulation dans une classe
48
+
49
+class BST {
50
+public:
51
+  Node *root;
52
+  BST();
53
+  int size();
54
+  void add1(int x);
55
+  void add2(int x);
56
+  void print();
57
+};
58
+
59
+BST::BST() {
60
+  this->root = NULL;
61
+}
62
+
63
+int BST::size() {
64
+  return tree_size(this->root);
65
+}
66
+
67
+void BST::add1(int x) {
68
+  this->root = tree_add(this->root, x);
69
+}
70
+
71
+void BST::add2(int x) {
72
+  tree_add_ref(this->root, x);
73
+}
74
+
75
+void BST::print() {
76
+  tree_print(this->root);
77
+  std::cout << std::endl;
78
+}
79
+
80
+
81
+// tests
82
+
83
+int main() {
84
+  BST t;
85
+  t.add1(2);
86
+  t.add2(3);
87
+  t.add1(1);
88
+  t.print();
89
+  t.add2(7);
90
+  t.add1(0);
91
+  t.print();
92
+  BST *u = new BST();
93
+  int i;
94
+  for (i = 0; i < 10; i++)
95
+    u->add1((31 * i) % 7);
96
+  u->print();
97
+  for (i = 0; i < 10; i++)
98
+    u->add2((29 * i) % 13);
99
+  u->print();
100
+  return 0;
101
+}

+ 7
- 0
tests_old/exec/for1.cpp View File

@@ -0,0 +1,7 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int i;
5
+  for (i = 0; i < 10; i++)
6
+    std::cout << "i = " << i << "\n";
7
+}

+ 8
- 0
tests_old/exec/for2.cpp View File

@@ -0,0 +1,8 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int i;
5
+  for (i = 0; i < 10; i++)
6
+    std::cout << "i = " << i << "\n";
7
+  std::cout << "i = " << i << "\n";
8
+}

+ 11
- 0
tests_old/exec/for3.cpp View File

@@ -0,0 +1,11 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int i;
5
+  int j;
6
+  for (i = 0; i < 5; i++)
7
+    for (j = 0; j < 5; j++)
8
+      std::cout << "i*j = " << i*j << "\n";
9
+  std::cout << "i = " << i << "\n";
10
+  std::cout << "j = " << j << "\n";
11
+}

+ 14
- 0
tests_old/exec/global.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+int x, *p;
4
+
5
+int main() {
6
+  x = 41;
7
+  std::cout << x << "\n";
8
+  p = &x;
9
+  *p = *p + 1;
10
+  std::cout << x << "\n";
11
+  int &r = x;
12
+  r = r + 1;
13
+  std::cout << x << "\n";
14
+}

+ 15
- 0
tests_old/exec/hexa.cpp View File

@@ -0,0 +1,15 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << 0x100 << "\n";
5
+  std::cout << 0xff << "\n";
6
+  std::cout << 0xFF << "\n";
7
+  int maxint = 0x7fffffff;
8
+  std::cout << maxint << "\n";
9
+  int x = 0xDEADBEEF;
10
+  std::cout << x << "\n";
11
+  x = 0xFFFFFFFF;
12
+  std::cout << x << "\n";
13
+  x = 0x80000000;
14
+  std::cout << x << "\n";
15
+}

+ 30
- 0
tests_old/exec/inheritance1.cpp View File

@@ -0,0 +1,30 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  virtual void f();
6
+};
7
+
8
+class B : public A {
9
+public:
10
+  void f();
11
+};
12
+
13
+void A::f() {
14
+  std::cout << "this is A::f" << "\n";
15
+}
16
+
17
+void B::f() {
18
+  std::cout << "this is B::f" << "\n";
19
+}
20
+
21
+int main() {
22
+  A a;
23
+  a.f();
24
+  B b;
25
+  b.f();
26
+  A *x = &b;
27
+  x->f();
28
+  x = &a;
29
+  x->f();
30
+}

+ 26
- 0
tests_old/exec/inheritance2.cpp View File

@@ -0,0 +1,26 @@
1
+#include <iostream>
2
+
3
+class A {
4
+public:
5
+  virtual void f();
6
+};
7
+
8
+class B : public A {
9
+public:
10
+  void f();
11
+};
12
+
13
+void A::f() {
14
+  std::cout << "this is A::f" << "\n";
15
+}
16
+
17
+void B::f() {
18
+  std::cout << "this is B::f" << "\n";
19
+}
20
+
21
+int main() {
22
+  A *a = new A();
23
+  a->f();
24
+  a = new B();
25
+  a->f();
26
+}

+ 101
- 0
tests_old/exec/josephus.cpp View File

@@ -0,0 +1,101 @@
1
+#include <iostream>
2
+
3
+/*** listes circulaires doublement chaînées ***/
4
+
5
+class ListeC {
6
+  public:
7
+  int valeur;
8
+  ListeC *suivant;
9
+  ListeC *precedent;
10
+  ListeC(int v);
11
+  void insererApres(int v);
12
+  void supprimer();
13
+  void afficher();
14
+};
15
+
16
+/* constructeur = liste réduite à un élément */
17
+ListeC::ListeC(int v) {
18
+  valeur = v;
19
+  suivant = precedent = this;
20
+}
21
+
22
+/* insertion après un élément */
23
+void ListeC::insererApres(int v) {
24
+  ListeC *e = new ListeC(0);
25
+  e->valeur = v;
26
+  e->suivant = suivant;
27
+  suivant = e;
28
+  e->suivant->precedent = e;
29
+  e->precedent = this;
30
+}
31
+
32
+/* suppression d'un élément */
33
+void ListeC::supprimer() {
34
+  precedent->suivant = suivant;
35
+  suivant->precedent = precedent;
36
+}
37
+
38
+/* affichage */
39
+void ListeC::afficher() {
40
+  ListeC *c = this;
41
+  std::cout << c->valeur << " ";
42
+  c = c->suivant;
43
+  for (; c != this;) {
44
+    std::cout << c->valeur << " ";
45
+    c = c->suivant;
46
+  }
47
+  std::cout << "\n";
48
+}
49
+
50
+/*** problème de Josephus ***/
51
+
52
+/* construction de la liste circulaire 1,2,...,n;
53
+   l'élément retourné est celui contenant 1 */
54
+ListeC *cercle(int n) {
55
+  ListeC *l = new ListeC(1);
56
+  int i;
57
+  for (i = n; i >= 2; i--) {
58
+    l->insererApres(i);
59
+  }
60
+  return l;
61
+}
62
+
63
+/* jeu de Josephus */
64
+int josephus(int n, int p) {
65
+  /* c est le joueur courant, 1 au départ */
66
+  ListeC *c = cercle(n);
67
+
68
+  /* tant qu'il reste plus d'un joueur */
69
+  for (; c != c->suivant;) {
70
+    /* on élimine un joueur */
71
+    int i;
72
+    for (i = 1; i < p; i++)
73
+      c = c->suivant;
74
+    c->supprimer();
75
+    // std::cout << c->valeur << " est éliminé";
76
+    c = c->suivant;
77
+  }
78
+  // std::cout << "le gagnant est " << c->valeur;
79
+  return c->valeur;
80
+}
81
+
82
+/*** Tests ***/
83
+
84
+int main() {
85
+  ListeC l = ListeC(1);
86
+  l.afficher();
87
+  l.insererApres(3);
88
+  l.afficher();
89
+  l.insererApres(2);
90
+  l.afficher();
91
+  l.suivant->supprimer();
92
+  l.afficher();
93
+
94
+  ListeC *c = cercle(7);
95
+  c->afficher();
96
+
97
+  if (josephus(7, 5) == 6 &&
98
+      josephus(5, 5) == 2 &&
99
+      josephus(5, 17) == 4 && josephus(13, 2) == 11)
100
+    std::cout << "ok\n";
101
+}

+ 60
- 0
tests_old/exec/mandelbrot.cpp View File

@@ -0,0 +1,60 @@
1
+
2
+#include <iostream>
3
+
4
+/* arithmetique de virgule fixe
5
+   precision q = 8192 i.e. 13 bits pour la partie decimale */
6
+
7
+int add(int x, int y) {
8
+  return x + y;
9
+}
10
+int sub(int x, int y) {
11
+  return x - y;
12
+}
13
+int mul(int x, int y) {
14
+  int t = x * y;
15
+  return (t + 8192 / 2) / 8192;
16
+}
17
+int div(int x, int y) {
18
+  int t = x * 8192;
19
+  return (t + y / 2) / y;
20
+}
21
+int of_int(int x) {
22
+  return x * 8192;
23
+}
24
+
25
+int iter(int n, int a, int b, int xn, int yn) {
26
+  if (n == 100) return true;
27
+  int xn2 = mul(xn, xn);
28
+  int yn2 = mul(yn, yn);
29
+  if (add(xn2, yn2) > of_int(4)) return false;
30
+  return iter(n+1, a, b, add(sub(xn2, yn2), a),
31
+              add(mul(of_int(2), mul(xn, yn)), b));
32
+}
33
+
34
+int inside(int x, int y) {
35
+  return iter(0, x, y, of_int(0), of_int(0));
36
+}
37
+
38
+int main() {
39
+  int steps = 30;
40
+  int xmin = of_int(-2);
41
+  int xmax = of_int(1);
42
+  int deltax = div(sub(xmax, xmin), of_int(2 * steps));
43
+  int ymin = of_int(-1);
44
+  int ymax = of_int(1);
45
+  int deltay = div(sub(ymax, ymin), of_int(steps));
46
+  int i;
47
+  for (i = 0; i < steps; i++) {
48
+    int y = add(ymin, mul(of_int(i), deltay));
49
+    int j;
50
+    for (j = 0; j < 2 * steps; j++) {
51
+      int x = add(xmin, mul(of_int(j), deltax));
52
+      if (inside(x, y))
53
+        std::cout << "0";
54
+      else
55
+        std::cout << "1";
56
+    }
57
+    std::cout << "\n";
58
+  }
59
+}
60
+

+ 13
- 0
tests_old/exec/octal.cpp View File

@@ -0,0 +1,13 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << 0100 << "\n";
5
+  std::cout << 0777 << "\n";
6
+  std::cout << 0644 << "\n";
7
+  int maxint = 017777777777;
8
+  std::cout << maxint << "\n";
9
+  int x = 037777777777;
10
+  std::cout << x << "\n";
11
+  x = 020000000000;
12
+  std::cout << x << "\n";
13
+}

+ 62
- 0
tests_old/exec/pascal.cpp View File

@@ -0,0 +1,62 @@
1
+
2
+// triangle de Pascal modulo 7
3
+// on n'a pas de tableaux, alors on utilise des listes chaînées
4
+
5
+#include <iostream>
6
+
7
+class Array {
8
+public:
9
+  int val;
10
+  Array *next;
11
+  Array(int n);    // une liste à n éléments
12
+  int get(int i);
13
+  void set(int i, int v);
14
+};
15
+
16
+Array::Array(int n) {
17
+  if (n == 1) return;
18
+  next = new Array(n-1);
19
+}
20
+
21
+int Array::get(int i) {
22
+  if (i == 0) return val;
23
+  return next->get(i-1);
24
+}
25
+
26
+void Array::set(int i, int v) {
27
+  if (i == 0) val = v;
28
+  else next->set(i-1, v);
29
+}
30
+
31
+void print_row(Array *r, int i) {
32
+  int j;
33
+  for (j = 0; j <= i; j++) {
34
+    if (r->get(j) != 0)
35
+      std::cout << "*";
36
+    else
37
+      std::cout << "0";
38
+  }
39
+  std::cout << "\n";
40
+}
41
+
42
+void compute_row(Array *r, int j) {
43
+  int v = 0;
44
+  if (j == 0)
45
+    v = 1;
46
+  else
47
+    v = (r->get(j) + r->get(j-1)) % 7;
48
+  r->set(j, v);
49
+  if (j > 0)
50
+    compute_row(r, j-1);
51
+}
52
+
53
+int main() {
54
+  int h = 42;
55
+  Array *r = new Array(h+1);
56
+  int i;
57
+  for (i = 0; i < h; i++) {
58
+    r->set(i, 0);
59
+    compute_row(r, i);
60
+    print_row(r, i);
61
+  }
62
+}

+ 13
- 0
tests_old/exec/passing.cpp View File

@@ -0,0 +1,13 @@
1
+#include <iostream>
2
+
3
+void incr(int &y) {
4
+  y = y+1;
5
+}
6
+
7
+int main() {
8
+  int x = 5;
9
+  std::cout << "x = " << x << std::endl;
10
+  incr(x);
11
+  std::cout << "x = " << x << std::endl;
12
+}
13
+

+ 14
- 0
tests_old/exec/prepost1.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 41;
5
+  std::cout << "x = " << x << "\n";
6
+  x++;
7
+  std::cout << "x = " << x << "\n";
8
+  x--;
9
+  std::cout << "x = " << x << "\n";
10
+  ++x;
11
+  std::cout << "x = " << x << "\n";
12
+  --x;
13
+  std::cout << "x = " << x << "\n";
14
+}

+ 8
- 0
tests_old/exec/ref1.cpp View File

@@ -0,0 +1,8 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int x = 41;
5
+  int &y = x;
6
+  y = 42;
7
+  std::cout << "x = " << x << "\n";
8
+}

+ 14
- 0
tests_old/exec/ref2.cpp View File

@@ -0,0 +1,14 @@
1
+#include <iostream>
2
+
3
+void f(int &y) {
4
+  y = 42;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(x);
11
+  std::cout << "x = " << x << "\n";
12
+  x = 41;
13
+  std::cout << "x = " << x << "\n";
14
+}

+ 18
- 0
tests_old/exec/ref3.cpp View File

@@ -0,0 +1,18 @@
1
+#include <iostream>
2
+
3
+void f(int &y) {
4
+  y = y + 1;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(x);
11
+  std::cout << "x = " << x << "\n";
12
+  f(x);
13
+  std::cout << "x = " << x << "\n";
14
+  x = 0;
15
+  std::cout << "x = " << x << "\n";
16
+  f(x);
17
+  std::cout << "x = " << x << "\n";
18
+}

+ 16
- 0
tests_old/exec/ref4.cpp View File

@@ -0,0 +1,16 @@
1
+#include <iostream>
2
+
3
+void f(int &y) {
4
+  y = y + 1;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(x);
11
+  std::cout << "x = " << x << "\n";
12
+  int &z = x;
13
+  f(z);
14
+  std::cout << "x = " << x << "\n";
15
+  std::cout << "z = " << z << "\n";
16
+}

+ 29
- 0
tests_old/exec/ref5.cpp View File

@@ -0,0 +1,29 @@
1
+#include <iostream>
2
+
3
+void f(int &y) {
4
+  y = y + 1;
5
+}
6
+
7
+int main() {
8
+  int x = 41;
9
+  std::cout << "x = " << x << "\n";
10
+  f(x);
11
+  std::cout << "x = " << x << "\n";
12
+  int &z = x;
13
+  f(z);
14
+  std::cout << "x = " << x << "\n";
15
+  std::cout << "z = " << z << "\n";
16
+  int &u = z;
17
+  f(u);
18
+  std::cout << "x = " << x << "\n";
19
+  std::cout << "z = " << z << "\n";
20
+  std::cout << "u = " << u << "\n";
21
+  f(z);
22
+  std::cout << "x = " << x << "\n";
23
+  std::cout << "z = " << z << "\n";
24
+  std::cout << "u = " << u << "\n";
25
+  f(x);
26
+  std::cout << "x = " << x << "\n";
27
+  std::cout << "z = " << z << "\n";
28
+  std::cout << "u = " << u << "\n";
29
+}

+ 20
- 0
tests_old/exec/ref6.cpp View File

@@ -0,0 +1,20 @@
1
+#include <iostream>
2
+
3
+int &f(int b, int &x, int &y) {
4
+  std::cout << "x = " << x << "\n";
5
+  std::cout << "y = " << y << "\n";
6
+  if (b) return x; else return y;
7
+}
8
+
9
+int main() {
10
+  int x = 42;
11
+  int y = 43;
12
+  int &r = f(1, x, y);
13
+  // now r is an alias for x
14
+  r = 12;
15
+  std::cout << "x = " << x << "\n";
16
+  std::cout << "y = " << y << "\n";
17
+  f(0,x,y) = 13;
18
+  std::cout << "x = " << x << "\n";
19
+  std::cout << "y = " << y << "\n";
20
+}

+ 10
- 0
tests_old/exec/string.cpp View File

@@ -0,0 +1,10 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  std::cout << "abc\n";
5
+  std::cout << "a\nc\n";
6
+  std::cout << "a\\c\n";
7
+  std::cout << "a\tc\n";
8
+  std::cout << "a\"c\n";
9
+  std::cout << "\x41\x42\x43\n";
10
+}

+ 8
- 0
tests_old/exec/true_false.cpp View File

@@ -0,0 +1,8 @@
1
+#include <iostream>
2
+
3
+int main() {
4
+  int b = true;
5
+  std::cout << "b = " << b << "\n";
6
+  b = false;
7
+  std::cout << "b = " << b << "\n";
8
+}

+ 78
- 0
tests_old/exec/vehicles.cpp View File

@@ -0,0 +1,78 @@
1
+#include <iostream>
2
+
3
+class Vehicle {
4
+public:
5
+  int position;
6
+  Vehicle();
7
+  virtual void move(int d);
8
+};
9
+
10
+Vehicle::Vehicle() {
11
+  position = 10;
12
+}
13
+
14
+void Vehicle::move(int d) {
15
+  std::cout << "vehicle moves\n";
16
+  position = position + d;
17
+}
18
+
19
+
20
+class Car : public Vehicle {
21
+public:
22
+  // champ position hérité
23
+  int passengers;
24
+  Car();
25
+  // methode move() héritée
26
+  void await(Vehicle &v);
27
+};
28
+
29
+Car::Car() {
30
+}
31
+
32
+void Car::await(Vehicle &v) {
33
+  std::cout << "await: position = " << v.position << "\n";
34
+  if (v.position < position)
35
+    v.move(position - v.position);
36
+  else
37
+    move(10);
38
+}
39
+
40
+class Truck : public Vehicle {
41
+public:
42
+  // champ position hérité
43
+  int load;
44
+  Truck();
45
+  void move(int d);
46
+};
47
+
48
+Truck::Truck() {
49
+}
50
+
51
+void Truck::move(int d) { // methode move redéfinie
52
+  std::cout << "truck moves\n";
53
+  if (d <= 55) position = position + d; else position = position + 55;
54
+}
55
+
56
+int main() {
57
+  Truck t;
58
+  std::cout << "t at " << t.position << "\n";
59
+  Car c;
60
+  c.passengers = 2;
61
+  std::cout << "c at " << c.position << "\n";
62
+  c.move(60);
63
+  std::cout << "c at " << c.position << "\n";
64
+  Vehicle *v = &c; // alias
65
+  v->move(70);
66
+  std::cout << "c at " << c.position << "\n";
67
+  c.await(t);
68
+  std::cout << "t at " << t.position << "\n";
69
+  std::cout << "c at " << c.position << "\n";
70
+
71
+}
72
+
73
+/*
74
+Local Variables:
75
+compile-command: "make vehicles"
76
+End:
77
+*/
78
+

+ 1
- 0
tests_old/syntax/bad/testfile-bad_hexa-1.cpp View File

@@ -0,0 +1 @@
1
+int main() { int x = 0xG; }

+ 1
- 0
tests_old/syntax/bad/testfile-bad_ident1-1.cpp View File

@@ -0,0 +1 @@
1
+void 1A() { }

+ 1
- 0
tests_old/syntax/bad/testfile-bad_ident2-1.cpp View File

@@ -0,0 +1 @@
1
+void  A'A() { }

+ 1
- 0
tests_old/syntax/bad/testfile-bad_octal-1.cpp View File

@@ -0,0 +1 @@
1
+int main() { int x = 08; }

+ 1
- 0
tests_old/syntax/bad/testfile-block1-1.cpp View File

@@ -0,0 +1 @@
1
+void f() { { }

+ 1
- 0
tests_old/syntax/bad/testfile-block2-1.cpp View File

@@ -0,0 +1 @@
1
+void f() { { } } }

+ 1
- 0
tests_old/syntax/bad/testfile-expr1-1.cpp View File

@@ -0,0 +1 @@
1
+void f() { ++ {}; }

+ 1
- 0
tests_old/syntax/bad/testfile-expr10-1.cpp View File

@@ -0,0 +1 @@
1
+void m() { a.x = ; }

+ 1
- 0
tests_old/syntax/bad/testfile-expr11-1.cpp View File

@@ -0,0 +1 @@
1
+void m() { a.x = {}; }

+ 0
- 0
tests_old/syntax/bad/testfile-expr2-1.cpp View File


Some files were not shown because too many files changed in this diff