From 8f1093f0e00f9b1df7ce343a879303fd56a95d08 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Tue, 29 Oct 2013 17:42:34 +0100 Subject: First commit. --- .gitignore | 3 + lexer.mll | 111 +++++++++++++++++++++ main.ml | 44 ++++++++ parser.mli | 53 ++++++++++ pretty.ml | 53 ++++++++++ tests/LISEZMOI | 18 ++++ tests/exec/ABR.cpp | 60 +++++++++++ tests/exec/ABR.out | 3 + tests/exec/Makefile | 6 ++ tests/exec/address1.cpp | 11 ++ tests/exec/address1.out | 3 + tests/exec/address2.cpp | 12 +++ tests/exec/address2.out | 2 + tests/exec/address3.cpp | 14 +++ tests/exec/address3.out | 3 + tests/exec/affect.cpp | 12 +++ tests/exec/affect.out | 2 + tests/exec/arith1.cpp | 14 +++ tests/exec/arith1.out | 5 + tests/exec/bst.cpp | 101 +++++++++++++++++++ tests/exec/bst.out | 4 + tests/exec/for1.cpp | 7 ++ tests/exec/for1.out | 10 ++ tests/exec/for2.cpp | 8 ++ tests/exec/for2.out | 11 ++ tests/exec/for3.cpp | 11 ++ tests/exec/for3.out | 27 +++++ tests/exec/global.cpp | 14 +++ tests/exec/global.out | 3 + tests/exec/hexa.cpp | 15 +++ tests/exec/hexa.out | 7 ++ tests/exec/inheritance1.cpp | 30 ++++++ tests/exec/inheritance1.out | 4 + tests/exec/inheritance2.cpp | 26 +++++ tests/exec/inheritance2.out | 2 + tests/exec/josephus.cpp | 101 +++++++++++++++++++ tests/exec/josephus.out | 6 ++ tests/exec/mandelbrot.cpp | 60 +++++++++++ tests/exec/mandelbrot.out | 30 ++++++ tests/exec/octal.cpp | 13 +++ tests/exec/octal.out | 6 ++ tests/exec/pascal.cpp | 62 ++++++++++++ tests/exec/pascal.out | 42 ++++++++ tests/exec/passing.cpp | 13 +++ tests/exec/passing.out | 2 + tests/exec/prepost1.cpp | 14 +++ tests/exec/prepost1.out | 5 + tests/exec/ref1.cpp | 8 ++ tests/exec/ref1.out | 1 + tests/exec/ref2.cpp | 14 +++ tests/exec/ref2.out | 3 + tests/exec/ref3.cpp | 18 ++++ tests/exec/ref3.out | 5 + tests/exec/ref4.cpp | 16 +++ tests/exec/ref4.out | 4 + tests/exec/ref5.cpp | 29 ++++++ tests/exec/ref5.out | 13 +++ tests/exec/ref6.cpp | 20 ++++ tests/exec/ref6.out | 8 ++ tests/exec/string.cpp | 10 ++ tests/exec/string.out | 7 ++ tests/exec/true_false.cpp | 8 ++ tests/exec/true_false.out | 2 + tests/exec/vehicles.cpp | 78 +++++++++++++++ tests/exec/vehicles.out | 10 ++ tests/syntax/bad/testfile-bad_hexa-1.cpp | 1 + tests/syntax/bad/testfile-bad_ident1-1.cpp | 1 + tests/syntax/bad/testfile-bad_ident2-1.cpp | 1 + tests/syntax/bad/testfile-bad_octal-1.cpp | 1 + tests/syntax/bad/testfile-block1-1.cpp | 1 + tests/syntax/bad/testfile-block2-1.cpp | 1 + tests/syntax/bad/testfile-expr1-1.cpp | 1 + tests/syntax/bad/testfile-expr10-1.cpp | 1 + tests/syntax/bad/testfile-expr11-1.cpp | 1 + tests/syntax/bad/testfile-expr2-1.cpp | 1 + tests/syntax/bad/testfile-expr3-1.cpp | 1 + tests/syntax/bad/testfile-expr4-1.cpp | 1 + tests/syntax/bad/testfile-expr6-1.cpp | 1 + tests/syntax/bad/testfile-expr7-1.cpp | 1 + tests/syntax/bad/testfile-expr8-1.cpp | 1 + tests/syntax/bad/testfile-expr9-1.cpp | 1 + tests/syntax/bad/testfile-for1-1.cpp | 1 + tests/syntax/bad/testfile-for2-1.cpp | 1 + tests/syntax/bad/testfile-for3-1.cpp | 1 + tests/syntax/bad/testfile-for4-1.cpp | 1 + tests/syntax/bad/testfile-for5-1.cpp | 1 + tests/syntax/bad/testfile-for6-1.cpp | 1 + tests/syntax/bad/testfile-for7-1.cpp | 1 + tests/syntax/bad/testfile-for8-1.cpp | 1 + tests/syntax/bad/testfile-if1-1.cpp | 1 + tests/syntax/bad/testfile-if2-1.cpp | 1 + tests/syntax/bad/testfile-if3-1.cpp | 1 + tests/syntax/bad/testfile-if_else-1.cpp | 1 + tests/syntax/bad/testfile-illegal_char-1.cpp | 1 + tests/syntax/bad/testfile-illegal_char-2.cpp | 2 + tests/syntax/bad/testfile-instr_decl1-1.cpp | 1 + tests/syntax/bad/testfile-instr_expr-1.cpp | 1 + tests/syntax/bad/testfile-keyword1-1.cpp | 1 + tests/syntax/bad/testfile-lexer_hack-1.cpp | 2 + tests/syntax/bad/testfile-lexer_hack-2.cpp | 3 + tests/syntax/bad/testfile-lexing1-1.cpp | 1 + tests/syntax/bad/testfile-lexing2-1.cpp | 2 + tests/syntax/bad/testfile-lexing3-1.cpp | 1 + tests/syntax/bad/testfile-lexing4-1.cpp | 1 + tests/syntax/bad/testfile-lexing5-1.cpp | 1 + tests/syntax/bad/testfile-lexing6-1.cpp | 1 + tests/syntax/bad/testfile-newline_in_string-1.cpp | 5 + tests/syntax/bad/testfile-parameters2-1.cpp | 1 + tests/syntax/bad/testfile-quotes_in_string-1.cpp | 3 + tests/syntax/bad/testfile-return1-1.cpp | 1 + tests/syntax/bad/testfile-unclosed_comment-1.cpp | 1 + .../bad/testfile-unclosed_escaped_string-1.cpp | 3 + tests/syntax/bad/testfile-unclosed_string-1.cpp | 4 + tests/syntax/bad/testfile-var2-1.cpp | 1 + tests/syntax/good/testfile-assign-1.cpp | 1 + tests/syntax/good/testfile-compare-1.cpp | 1 + tests/syntax/good/testfile-for-1.cpp | 2 + tests/typing/bad/testfile-ampersand-1.cpp | 1 + tests/typing/bad/testfile-ampersand-2.cpp | 2 + tests/typing/bad/testfile-ampersand-3.cpp | 4 + tests/typing/bad/testfile-arith-1.cpp | 2 + tests/typing/bad/testfile-arith-2.cpp | 3 + tests/typing/bad/testfile-arith-3.cpp | 2 + tests/typing/bad/testfile-arith-4.cpp | 3 + tests/typing/bad/testfile-arith-5.cpp | 2 + tests/typing/bad/testfile-arith-6.cpp | 3 + tests/typing/bad/testfile-arrow-1.cpp | 1 + tests/typing/bad/testfile-arrow-2.cpp | 2 + tests/typing/bad/testfile-arrow-3.cpp | 3 + tests/typing/bad/testfile-arrow-4.cpp | 3 + tests/typing/bad/testfile-arrow-5.cpp | 5 + tests/typing/bad/testfile-assign-1.cpp | 1 + tests/typing/bad/testfile-assign-10.cpp | 2 + tests/typing/bad/testfile-assign-11.cpp | 3 + tests/typing/bad/testfile-assign-12.cpp | 2 + tests/typing/bad/testfile-assign-13.cpp | 2 + tests/typing/bad/testfile-assign-14.cpp | 2 + tests/typing/bad/testfile-assign-15.cpp | 3 + tests/typing/bad/testfile-assign-16.cpp | 2 + tests/typing/bad/testfile-assign-17.cpp | 2 + tests/typing/bad/testfile-assign-18.cpp | 2 + tests/typing/bad/testfile-assign-19.cpp | 3 + tests/typing/bad/testfile-assign-2.cpp | 2 + tests/typing/bad/testfile-assign-20.cpp | 2 + tests/typing/bad/testfile-assign-21.cpp | 2 + tests/typing/bad/testfile-assign-22.cpp | 2 + tests/typing/bad/testfile-assign-23.cpp | 3 + tests/typing/bad/testfile-assign-24.cpp | 2 + tests/typing/bad/testfile-assign-25.cpp | 2 + tests/typing/bad/testfile-assign-26.cpp | 4 + tests/typing/bad/testfile-assign-27.cpp | 1 + tests/typing/bad/testfile-assign-28.cpp | 3 + tests/typing/bad/testfile-assign-29.cpp | 3 + tests/typing/bad/testfile-assign-3.cpp | 2 + tests/typing/bad/testfile-assign-30.cpp | 3 + tests/typing/bad/testfile-assign-31.cpp | 4 + tests/typing/bad/testfile-assign-4.cpp | 3 + tests/typing/bad/testfile-assign-5.cpp | 3 + tests/typing/bad/testfile-assign-6.cpp | 3 + tests/typing/bad/testfile-assign-7.cpp | 4 + tests/typing/bad/testfile-assign-8.cpp | 4 + tests/typing/bad/testfile-assign-9.cpp | 1 + tests/typing/bad/testfile-bang-1.cpp | 2 + tests/typing/bad/testfile-bang-2.cpp | 4 + tests/typing/bad/testfile-call-1.cpp | 2 + tests/typing/bad/testfile-call-2.cpp | 5 + tests/typing/bad/testfile-class-1.cpp | 1 + tests/typing/bad/testfile-class-2.cpp | 3 + tests/typing/bad/testfile-comparison-1.cpp | 2 + tests/typing/bad/testfile-comparison-2.cpp | 3 + tests/typing/bad/testfile-comparison-3.cpp | 3 + tests/typing/bad/testfile-comparison-4.cpp | 3 + tests/typing/bad/testfile-comparison-5.cpp | 3 + tests/typing/bad/testfile-comparison-6.cpp | 4 + tests/typing/bad/testfile-deref-1.cpp | 1 + tests/typing/bad/testfile-deref-2.cpp | 2 + tests/typing/bad/testfile-deref-3.cpp | 4 + tests/typing/bad/testfile-field-1.cpp | 1 + tests/typing/bad/testfile-field-2.cpp | 2 + tests/typing/bad/testfile-field-3.cpp | 3 + tests/typing/bad/testfile-field-4.cpp | 3 + tests/typing/bad/testfile-field-5.cpp | 3 + tests/typing/bad/testfile-field-6.cpp | 3 + tests/typing/bad/testfile-field-7.cpp | 5 + tests/typing/bad/testfile-for-1.cpp | 2 + tests/typing/bad/testfile-for-2.cpp | 4 + tests/typing/bad/testfile-global-1.cpp | 3 + tests/typing/bad/testfile-if-1.cpp | 2 + tests/typing/bad/testfile-if-2.cpp | 4 + tests/typing/bad/testfile-local-1.cpp | 2 + tests/typing/bad/testfile-redef-1.cpp | 2 + tests/typing/bad/testfile-redef-2.cpp | 4 + tests/typing/bad/testfile-redef-3.cpp | 4 + tests/typing/bad/testfile-redef-4.cpp | 4 + tests/typing/bad/testfile-redef-5.cpp | 2 + tests/typing/bad/testfile-redef-6.cpp | 3 + tests/typing/bad/testfile-ref-1.cpp | 1 + tests/typing/bad/testfile-ref-2.cpp | 3 + tests/typing/bad/testfile-return-1.cpp | 3 + tests/typing/bad/testfile-return-2.cpp | 4 + tests/typing/bad/testfile-return-3.cpp | 4 + tests/typing/bad/testfile-scope-1.cpp | 1 + tests/typing/bad/testfile-scope-2.cpp | 3 + tests/typing/bad/testfile-undef_var-1.cpp | 1 + tests/typing/bad/testfile-undef_var-2.cpp | 3 + tests/typing/bad/testfile-undef_var-3.cpp | 4 + tests/typing/bad/testfile-while-1.cpp | 2 + tests/typing/bad/testfile-while-2.cpp | 4 + tests/typing/good/testfile-subtype-1.cpp | 5 + 209 files changed, 1635 insertions(+) create mode 100644 .gitignore create mode 100644 lexer.mll create mode 100644 main.ml create mode 100644 parser.mli create mode 100644 pretty.ml create mode 100644 tests/LISEZMOI create mode 100644 tests/exec/ABR.cpp create mode 100644 tests/exec/ABR.out create mode 100644 tests/exec/Makefile create mode 100644 tests/exec/address1.cpp create mode 100644 tests/exec/address1.out create mode 100644 tests/exec/address2.cpp create mode 100644 tests/exec/address2.out create mode 100644 tests/exec/address3.cpp create mode 100644 tests/exec/address3.out create mode 100644 tests/exec/affect.cpp create mode 100644 tests/exec/affect.out create mode 100644 tests/exec/arith1.cpp create mode 100644 tests/exec/arith1.out create mode 100644 tests/exec/bst.cpp create mode 100644 tests/exec/bst.out create mode 100644 tests/exec/for1.cpp create mode 100644 tests/exec/for1.out create mode 100644 tests/exec/for2.cpp create mode 100644 tests/exec/for2.out create mode 100644 tests/exec/for3.cpp create mode 100644 tests/exec/for3.out create mode 100644 tests/exec/global.cpp create mode 100644 tests/exec/global.out create mode 100644 tests/exec/hexa.cpp create mode 100644 tests/exec/hexa.out create mode 100644 tests/exec/inheritance1.cpp create mode 100644 tests/exec/inheritance1.out create mode 100644 tests/exec/inheritance2.cpp create mode 100644 tests/exec/inheritance2.out create mode 100644 tests/exec/josephus.cpp create mode 100644 tests/exec/josephus.out create mode 100644 tests/exec/mandelbrot.cpp create mode 100644 tests/exec/mandelbrot.out create mode 100644 tests/exec/octal.cpp create mode 100644 tests/exec/octal.out create mode 100644 tests/exec/pascal.cpp create mode 100644 tests/exec/pascal.out create mode 100644 tests/exec/passing.cpp create mode 100644 tests/exec/passing.out create mode 100644 tests/exec/prepost1.cpp create mode 100644 tests/exec/prepost1.out create mode 100644 tests/exec/ref1.cpp create mode 100644 tests/exec/ref1.out create mode 100644 tests/exec/ref2.cpp create mode 100644 tests/exec/ref2.out create mode 100644 tests/exec/ref3.cpp create mode 100644 tests/exec/ref3.out create mode 100644 tests/exec/ref4.cpp create mode 100644 tests/exec/ref4.out create mode 100644 tests/exec/ref5.cpp create mode 100644 tests/exec/ref5.out create mode 100644 tests/exec/ref6.cpp create mode 100644 tests/exec/ref6.out create mode 100644 tests/exec/string.cpp create mode 100644 tests/exec/string.out create mode 100644 tests/exec/true_false.cpp create mode 100644 tests/exec/true_false.out create mode 100644 tests/exec/vehicles.cpp create mode 100644 tests/exec/vehicles.out create mode 100644 tests/syntax/bad/testfile-bad_hexa-1.cpp create mode 100644 tests/syntax/bad/testfile-bad_ident1-1.cpp create mode 100644 tests/syntax/bad/testfile-bad_ident2-1.cpp create mode 100644 tests/syntax/bad/testfile-bad_octal-1.cpp create mode 100644 tests/syntax/bad/testfile-block1-1.cpp create mode 100644 tests/syntax/bad/testfile-block2-1.cpp create mode 100644 tests/syntax/bad/testfile-expr1-1.cpp create mode 100644 tests/syntax/bad/testfile-expr10-1.cpp create mode 100644 tests/syntax/bad/testfile-expr11-1.cpp create mode 100644 tests/syntax/bad/testfile-expr2-1.cpp create mode 100644 tests/syntax/bad/testfile-expr3-1.cpp create mode 100644 tests/syntax/bad/testfile-expr4-1.cpp create mode 100644 tests/syntax/bad/testfile-expr6-1.cpp create mode 100644 tests/syntax/bad/testfile-expr7-1.cpp create mode 100644 tests/syntax/bad/testfile-expr8-1.cpp create mode 100644 tests/syntax/bad/testfile-expr9-1.cpp create mode 100644 tests/syntax/bad/testfile-for1-1.cpp create mode 100644 tests/syntax/bad/testfile-for2-1.cpp create mode 100644 tests/syntax/bad/testfile-for3-1.cpp create mode 100644 tests/syntax/bad/testfile-for4-1.cpp create mode 100644 tests/syntax/bad/testfile-for5-1.cpp create mode 100644 tests/syntax/bad/testfile-for6-1.cpp create mode 100644 tests/syntax/bad/testfile-for7-1.cpp create mode 100644 tests/syntax/bad/testfile-for8-1.cpp create mode 100644 tests/syntax/bad/testfile-if1-1.cpp create mode 100644 tests/syntax/bad/testfile-if2-1.cpp create mode 100644 tests/syntax/bad/testfile-if3-1.cpp create mode 100644 tests/syntax/bad/testfile-if_else-1.cpp create mode 100644 tests/syntax/bad/testfile-illegal_char-1.cpp create mode 100644 tests/syntax/bad/testfile-illegal_char-2.cpp create mode 100644 tests/syntax/bad/testfile-instr_decl1-1.cpp create mode 100644 tests/syntax/bad/testfile-instr_expr-1.cpp create mode 100644 tests/syntax/bad/testfile-keyword1-1.cpp create mode 100644 tests/syntax/bad/testfile-lexer_hack-1.cpp create mode 100644 tests/syntax/bad/testfile-lexer_hack-2.cpp create mode 100644 tests/syntax/bad/testfile-lexing1-1.cpp create mode 100644 tests/syntax/bad/testfile-lexing2-1.cpp create mode 100644 tests/syntax/bad/testfile-lexing3-1.cpp create mode 100644 tests/syntax/bad/testfile-lexing4-1.cpp create mode 100644 tests/syntax/bad/testfile-lexing5-1.cpp create mode 100644 tests/syntax/bad/testfile-lexing6-1.cpp create mode 100644 tests/syntax/bad/testfile-newline_in_string-1.cpp create mode 100644 tests/syntax/bad/testfile-parameters2-1.cpp create mode 100644 tests/syntax/bad/testfile-quotes_in_string-1.cpp create mode 100644 tests/syntax/bad/testfile-return1-1.cpp create mode 100644 tests/syntax/bad/testfile-unclosed_comment-1.cpp create mode 100644 tests/syntax/bad/testfile-unclosed_escaped_string-1.cpp create mode 100644 tests/syntax/bad/testfile-unclosed_string-1.cpp create mode 100644 tests/syntax/bad/testfile-var2-1.cpp create mode 100644 tests/syntax/good/testfile-assign-1.cpp create mode 100644 tests/syntax/good/testfile-compare-1.cpp create mode 100644 tests/syntax/good/testfile-for-1.cpp create mode 100644 tests/typing/bad/testfile-ampersand-1.cpp create mode 100644 tests/typing/bad/testfile-ampersand-2.cpp create mode 100644 tests/typing/bad/testfile-ampersand-3.cpp create mode 100644 tests/typing/bad/testfile-arith-1.cpp create mode 100644 tests/typing/bad/testfile-arith-2.cpp create mode 100644 tests/typing/bad/testfile-arith-3.cpp create mode 100644 tests/typing/bad/testfile-arith-4.cpp create mode 100644 tests/typing/bad/testfile-arith-5.cpp create mode 100644 tests/typing/bad/testfile-arith-6.cpp create mode 100644 tests/typing/bad/testfile-arrow-1.cpp create mode 100644 tests/typing/bad/testfile-arrow-2.cpp create mode 100644 tests/typing/bad/testfile-arrow-3.cpp create mode 100644 tests/typing/bad/testfile-arrow-4.cpp create mode 100644 tests/typing/bad/testfile-arrow-5.cpp create mode 100644 tests/typing/bad/testfile-assign-1.cpp create mode 100644 tests/typing/bad/testfile-assign-10.cpp create mode 100644 tests/typing/bad/testfile-assign-11.cpp create mode 100644 tests/typing/bad/testfile-assign-12.cpp create mode 100644 tests/typing/bad/testfile-assign-13.cpp create mode 100644 tests/typing/bad/testfile-assign-14.cpp create mode 100644 tests/typing/bad/testfile-assign-15.cpp create mode 100644 tests/typing/bad/testfile-assign-16.cpp create mode 100644 tests/typing/bad/testfile-assign-17.cpp create mode 100644 tests/typing/bad/testfile-assign-18.cpp create mode 100644 tests/typing/bad/testfile-assign-19.cpp create mode 100644 tests/typing/bad/testfile-assign-2.cpp create mode 100644 tests/typing/bad/testfile-assign-20.cpp create mode 100644 tests/typing/bad/testfile-assign-21.cpp create mode 100644 tests/typing/bad/testfile-assign-22.cpp create mode 100644 tests/typing/bad/testfile-assign-23.cpp create mode 100644 tests/typing/bad/testfile-assign-24.cpp create mode 100644 tests/typing/bad/testfile-assign-25.cpp create mode 100644 tests/typing/bad/testfile-assign-26.cpp create mode 100644 tests/typing/bad/testfile-assign-27.cpp create mode 100644 tests/typing/bad/testfile-assign-28.cpp create mode 100644 tests/typing/bad/testfile-assign-29.cpp create mode 100644 tests/typing/bad/testfile-assign-3.cpp create mode 100644 tests/typing/bad/testfile-assign-30.cpp create mode 100644 tests/typing/bad/testfile-assign-31.cpp create mode 100644 tests/typing/bad/testfile-assign-4.cpp create mode 100644 tests/typing/bad/testfile-assign-5.cpp create mode 100644 tests/typing/bad/testfile-assign-6.cpp create mode 100644 tests/typing/bad/testfile-assign-7.cpp create mode 100644 tests/typing/bad/testfile-assign-8.cpp create mode 100644 tests/typing/bad/testfile-assign-9.cpp create mode 100644 tests/typing/bad/testfile-bang-1.cpp create mode 100644 tests/typing/bad/testfile-bang-2.cpp create mode 100644 tests/typing/bad/testfile-call-1.cpp create mode 100644 tests/typing/bad/testfile-call-2.cpp create mode 100644 tests/typing/bad/testfile-class-1.cpp create mode 100644 tests/typing/bad/testfile-class-2.cpp create mode 100644 tests/typing/bad/testfile-comparison-1.cpp create mode 100644 tests/typing/bad/testfile-comparison-2.cpp create mode 100644 tests/typing/bad/testfile-comparison-3.cpp create mode 100644 tests/typing/bad/testfile-comparison-4.cpp create mode 100644 tests/typing/bad/testfile-comparison-5.cpp create mode 100644 tests/typing/bad/testfile-comparison-6.cpp create mode 100644 tests/typing/bad/testfile-deref-1.cpp create mode 100644 tests/typing/bad/testfile-deref-2.cpp create mode 100644 tests/typing/bad/testfile-deref-3.cpp create mode 100644 tests/typing/bad/testfile-field-1.cpp create mode 100644 tests/typing/bad/testfile-field-2.cpp create mode 100644 tests/typing/bad/testfile-field-3.cpp create mode 100644 tests/typing/bad/testfile-field-4.cpp create mode 100644 tests/typing/bad/testfile-field-5.cpp create mode 100644 tests/typing/bad/testfile-field-6.cpp create mode 100644 tests/typing/bad/testfile-field-7.cpp create mode 100644 tests/typing/bad/testfile-for-1.cpp create mode 100644 tests/typing/bad/testfile-for-2.cpp create mode 100644 tests/typing/bad/testfile-global-1.cpp create mode 100644 tests/typing/bad/testfile-if-1.cpp create mode 100644 tests/typing/bad/testfile-if-2.cpp create mode 100644 tests/typing/bad/testfile-local-1.cpp create mode 100644 tests/typing/bad/testfile-redef-1.cpp create mode 100644 tests/typing/bad/testfile-redef-2.cpp create mode 100644 tests/typing/bad/testfile-redef-3.cpp create mode 100644 tests/typing/bad/testfile-redef-4.cpp create mode 100644 tests/typing/bad/testfile-redef-5.cpp create mode 100644 tests/typing/bad/testfile-redef-6.cpp create mode 100644 tests/typing/bad/testfile-ref-1.cpp create mode 100644 tests/typing/bad/testfile-ref-2.cpp create mode 100644 tests/typing/bad/testfile-return-1.cpp create mode 100644 tests/typing/bad/testfile-return-2.cpp create mode 100644 tests/typing/bad/testfile-return-3.cpp create mode 100644 tests/typing/bad/testfile-scope-1.cpp create mode 100644 tests/typing/bad/testfile-scope-2.cpp create mode 100644 tests/typing/bad/testfile-undef_var-1.cpp create mode 100644 tests/typing/bad/testfile-undef_var-2.cpp create mode 100644 tests/typing/bad/testfile-undef_var-3.cpp create mode 100644 tests/typing/bad/testfile-while-1.cpp create mode 100644 tests/typing/bad/testfile-while-2.cpp create mode 100644 tests/typing/good/testfile-subtype-1.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e717cbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +_build +*.byte +.depend diff --git a/lexer.mll b/lexer.mll new file mode 100644 index 0000000..1a643eb --- /dev/null +++ b/lexer.mll @@ -0,0 +1,111 @@ + +(* + Analysateur lexicographiquep pour maxi-C++ +*) + +{ + open Lexing + open Parser + + exception Lexing_error of string + exception End_of_file + + let keywordz_l = [ + "class", CLASS; + "else", ELSE; + "false", FALSE; + "for", FOR; + "if", IF; + "int", INT; + "new", NEW; + "NULL", NULL; + "public", PUBLIC; + "return", RETURN; + "this", THIS; + "true", TRUE; + "virtual", VIRTUAL; + "void", VOID; + "while", WHILE; + ] + + let id_or_kwd = + let h = Hashtbl.create 20 in + List.iter (fun (s, t) -> Hashtbl.add h s t) keywordz_l; + fun s -> + try Hashtbl.find h s with _ -> IDENT s +} + +let digit = ['0'-'9'] +let alpha = ['a'-'z' 'A'-'Z'] +let ident = ('_' | alpha) ('_' | alpha | digit)* +let octal = ['0'-'7'] +let hexa = ['0'-'9' 'a'-'f' 'A'-'F'] + +rule token = parse + | ['\n' ' ' '\t']+ { token lexbuf } + | ident as id { id_or_kwd id } + | "//" { short_comment lexbuf; token lexbuf } + | "/*" { long_comment lexbuf; token lexbuf } + | "0x" (hexa+ as n) { INTVAL(int_of_string("0x" ^ n)) } + | ['1'-'9'] digit* as n { INTVAL(int_of_string(n)) } + | '0' (octal+ as n) { INTVAL(int_of_string("0o" ^ n)) } + | "0" { INTVAL(0) } + | digit ('_' | alpha | digit)+ + { raise (Lexing_error "Missing separators") } + | "\"" { STRVAL(strval "" lexbuf) } + | "=" { ASSIGN } + | "||" { LOR } + | "&&" { LAND } + | "==" { EQ } + | "!=" { NE } + | "<" { LT } + | "<=" { LE } + | ">" { GT } + | ">=" { GE } + | "+" { PLUS } + | "-" { MINUS } + | "*" { TIMES } + | "/" { DIV } + | "%" { MOD } + | "!" { NOT } + | "++" { INCR } + | "--" { DECR } + | "&" { REF } + | "(" { LPAREN } + | ")" { RPAREN } + | "->" { RARROW } + | "." { DOT } + | ";" { SEMICOLON } + | "::" { DOUBLECOLON } + | "<<" { LFLOW } + | "{" { LBRACE } + | "}" { RBRACE } + | eof { raise End_of_file } + | _ as c + { raise + (Lexing_error + ("illegal character: " ^ String.make 1 c)) } +and strval s = parse + | "\"" { s } + | "\\\\" { strval (s ^ "\\") lexbuf } + | "\\\"" { strval (s ^ "\"") lexbuf } + | "\\n" { strval (s ^ "\n") lexbuf } + | "\\t" { strval (s ^ "\t") lexbuf } + | "\\x" (hexa hexa as x) + { strval (s ^ + (String.make 1 (char_of_int (int_of_string("0x" ^ x))))) + lexbuf } + | "\\" + { raise (Lexing_error "Invalid escape sequence") } + | '\n' { raise (Lexing_error "Invalid character (newline) in string litteral.") } + | _ as c { strval (s ^ (String.make 1 c)) lexbuf } + | eof { raise (Lexing_error "Unfinished string") } +and short_comment = parse + | '\n' {} + | _ { short_comment lexbuf } + | eof {} +and long_comment = parse + | "*/" {} + | _ { long_comment lexbuf } + | eof { raise (Lexing_error "Unclosed comment") } + diff --git a/main.ml b/main.ml new file mode 100644 index 0000000..8d78987 --- /dev/null +++ b/main.ml @@ -0,0 +1,44 @@ +open Format +open Lexing + +let ifile = ref "" + +let set_var v s = v := s + +let usage = "usage: mini-cpp [options] file.cpp" + +let localisation pos = + let l = pos.pos_lnum in + let c = pos.pos_cnum - pos.pos_bol + 1 in + eprintf "File \"%s\", line %d, characters %d-%d:\n" + !ifile l (c-1) c + +let options = [] + +let () = + Arg.parse options (set_var ifile) usage; + + if !ifile = "" then ( + eprintf "No input file\n@?"; + exit 1); + + if not (Filename.check_suffix !ifile ".cpp") then ( + eprintf "Input files must have suffix .cpp\n@?"; + Arg.usage options usage; + exit 1); + + let f = open_in !ifile in + let buf = Lexing.from_channel f in + + try + while true do + print_string (Pretty.token_str (Lexer.token buf)); + print_string "\n" + done + with + | Lexer.End_of_file -> + exit 0 + | Lexer.Lexing_error s -> + localisation (Lexing.lexeme_start_p buf); + eprintf "Lexical analysis error: %s@." s; + exit 1 diff --git a/parser.mli b/parser.mli new file mode 100644 index 0000000..8309e8a --- /dev/null +++ b/parser.mli @@ -0,0 +1,53 @@ + +type token = + (* KEYWORDZ *) + | CLASS + | ELSE + | FALSE + | FOR + | IF + | INT + | NEW + | NULL + | PUBLIC + | RETURN + | THIS + | TRUE + | VIRTUAL + | VOID + | WHILE + (* IDENTZ *) + | IDENT of string + (* OPERATORZ, by precedence *) + | ASSIGN + | LOR + | LAND + | EQ + | NE + | LT + | LE + | GT + | GE + | PLUS + | MINUS + | TIMES + | DIV + | MOD + | NOT + | INCR + | DECR + | REF + (* and also : unary dereference, plus, minus *) + | LPAREN + | RPAREN + | RARROW + | DOT + (* OTHER SYMBOLZ *) + | SEMICOLON + | DOUBLECOLON + | LFLOW + | LBRACE + | RBRACE + (* DATAZ *) + | INTVAL of int + | STRVAL of string diff --git a/pretty.ml b/pretty.ml new file mode 100644 index 0000000..87cc383 --- /dev/null +++ b/pretty.ml @@ -0,0 +1,53 @@ +open Parser + +let token_str = function + | CLASS -> "class" + | ELSE -> "else" + | FALSE -> "false" + | FOR -> "for" + | IF -> "if" + | INT -> "int" + | NEW -> "new" + | NULL -> "NULL" + | PUBLIC -> "public" + | RETURN -> "return" + | THIS -> "this" + | TRUE -> "true" + | VIRTUAL -> "virtual" + | VOID -> "void" + | WHILE -> "while" + | IDENT(s) -> "'"^s^"'" + | ASSIGN -> "=" + | LOR -> "||" + | LAND -> "&&" + | EQ -> "==" + | NE -> "!=" + | LT -> "<" + | LE -> "<=" + | GT -> ">" + | GE -> ">=" + | PLUS -> "+" + | MINUS -> "-" + | TIMES -> "*" + | DIV -> "/" + | MOD -> "%" + | NOT -> "!" + | INCR -> "++" + | DECR -> "--" + | REF -> "&" + (* and also : unary dereference, plus, minus *) + | LPAREN -> "(" + | RPAREN -> ")" + | RARROW -> "->" + | DOT -> "." + (* OTHER SYMBOLZ *) + | SEMICOLON -> ";" + | DOUBLECOLON -> "::" + | LFLOW -> "<<" + | LBRACE -> "{" + | RBRACE -> "}" + (* DATAZ *) + | INTVAL(i) -> "#" ^ (string_of_int i) + | STRVAL(s) -> "`" ^ s ^ "`" + + diff --git a/tests/LISEZMOI b/tests/LISEZMOI new file mode 100644 index 0000000..6ee526d --- /dev/null +++ b/tests/LISEZMOI @@ -0,0 +1,18 @@ + +Les tests sont organisés en différentes catégories : + + syntax/bad/ refusés à l'analyse lexicale ou syntaxique + typing/bad/ refusés à l'analyse sémantique + typing/good/ acceptés à l'analyse sémantique + exec-fail/ compilés avec succès mais l'exécution du code MIPS doit échouer + exec/ compilés et exécutés avec succès, le résultat attendu étant + conforme au fichier .out + +Les tests sont cumulatifs i.e. + +- les fichiers de typing/bad/, exec-fail/ et exec/ peuvent être + utilisés pour la catégorie syntax/good/ + +- les fichiers de exec-fail/ et exec/ peuvent être + utilisés pour la catégorie typing/good/ + diff --git a/tests/exec/ABR.cpp b/tests/exec/ABR.cpp new file mode 100644 index 0000000..979ff4b --- /dev/null +++ b/tests/exec/ABR.cpp @@ -0,0 +1,60 @@ +#include + +/* arbres binaires de recherche */ + +class ABR { +public: + int valeur; + ABR *gauche; + ABR *droite; + ABR(ABR *g, int v, ABR *d); + void insere(int x); + int contient(int x); + void affiche(); +}; + +ABR::ABR(ABR *g, int v, ABR *d) { valeur = v; gauche = g; droite = d; } + +void ABR::insere(int x) { + if (x == valeur) return; + if (x < valeur) { + if (gauche == NULL) + gauche = new ABR(NULL, x, NULL); + else + gauche->insere(x); + } else + if (droite == NULL) + droite = new ABR(NULL, x, NULL); + else + droite->insere(x); +} + +int ABR::contient(int x) { + if (x == valeur) return true; + if (x < valeur && gauche != NULL) return gauche->contient(x); + if (droite != NULL) return droite->contient(x); + return false; +} + +void ABR::affiche() { + if (gauche != NULL) gauche->affiche(); + std::cout << "(" << valeur << ")"; + if (droite != NULL) droite->affiche(); +} + + +int main() { + ABR dico = ABR(NULL, 1, NULL); + dico.insere(17); + dico.insere(5); + dico.insere(8); + dico.affiche(); std::cout << "\n"; + + if (dico.contient(5) && + ! dico.contient(0) && + dico.contient(17) && + ! dico.contient(3)) + std::cout << "ok\n"; + + dico.affiche(); std::cout << "\n"; +} diff --git a/tests/exec/ABR.out b/tests/exec/ABR.out new file mode 100644 index 0000000..8855386 --- /dev/null +++ b/tests/exec/ABR.out @@ -0,0 +1,3 @@ +(1)(5)(8)(17) +ok +(1)(5)(8)(17) diff --git a/tests/exec/Makefile b/tests/exec/Makefile new file mode 100644 index 0000000..b260ba0 --- /dev/null +++ b/tests/exec/Makefile @@ -0,0 +1,6 @@ + +%: %.cpp + g++ -o $@ $^ + ./$@ + ./$@ > $*.out + diff --git a/tests/exec/address1.cpp b/tests/exec/address1.cpp new file mode 100644 index 0000000..fe70014 --- /dev/null +++ b/tests/exec/address1.cpp @@ -0,0 +1,11 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + int *y = &x; + *y = 42; + std::cout << "x = " << x << "\n"; + *y = *y + 1; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address1.out b/tests/exec/address1.out new file mode 100644 index 0000000..4202a65 --- /dev/null +++ b/tests/exec/address1.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 43 diff --git a/tests/exec/address2.cpp b/tests/exec/address2.cpp new file mode 100644 index 0000000..75c2c4f --- /dev/null +++ b/tests/exec/address2.cpp @@ -0,0 +1,12 @@ +#include + +void f(int *y) { + *y = 42; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address2.out b/tests/exec/address2.out new file mode 100644 index 0000000..8b53391 --- /dev/null +++ b/tests/exec/address2.out @@ -0,0 +1,2 @@ +x = 41 +x = 42 diff --git a/tests/exec/address3.cpp b/tests/exec/address3.cpp new file mode 100644 index 0000000..3917dc1 --- /dev/null +++ b/tests/exec/address3.cpp @@ -0,0 +1,14 @@ +#include + +void f(int *y) { + *y = *y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address3.out b/tests/exec/address3.out new file mode 100644 index 0000000..4202a65 --- /dev/null +++ b/tests/exec/address3.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 43 diff --git a/tests/exec/affect.cpp b/tests/exec/affect.cpp new file mode 100644 index 0000000..fd65fd1 --- /dev/null +++ b/tests/exec/affect.cpp @@ -0,0 +1,12 @@ +#include + +int main() { + int x = 0; + int y = 0; + x = ++y; + y = ++y + ++x; + y++; + x = --x + y; + std::cout << "x=" << x << "\n"; + std::cout << "y=" << y << "\n"; +} diff --git a/tests/exec/affect.out b/tests/exec/affect.out new file mode 100644 index 0000000..a6e2f7b --- /dev/null +++ b/tests/exec/affect.out @@ -0,0 +1,2 @@ +x=6 +y=5 diff --git a/tests/exec/arith1.cpp b/tests/exec/arith1.cpp new file mode 100644 index 0000000..2280f76 --- /dev/null +++ b/tests/exec/arith1.cpp @@ -0,0 +1,14 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + x = x+1; + std::cout << "x = " << x << "\n"; + x = 2*x; + std::cout << "x = " << x << "\n"; + x = 2*x + 3; + std::cout << "x = " << x << "\n"; + x = 1 - 2*x; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/arith1.out b/tests/exec/arith1.out new file mode 100644 index 0000000..a397f16 --- /dev/null +++ b/tests/exec/arith1.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 84 +x = 171 +x = -341 diff --git a/tests/exec/bst.cpp b/tests/exec/bst.cpp new file mode 100644 index 0000000..e5ccce8 --- /dev/null +++ b/tests/exec/bst.cpp @@ -0,0 +1,101 @@ + +#include + +// arbres binaires, où l'arbre vide est NULL + +class Node { +public: + int elt; + Node *left, *right; + Node(Node *left, int elt, Node *right); +}; + +Node::Node(Node *left, int elt, Node *right) { + this->left = left; + this->elt = elt; + this->right = right; +} + +int tree_size(Node *t) { + if (t == NULL) return 0; + return 1 + tree_size(t->left) + tree_size(t->right); +} + +Node *tree_add(Node *t, int x) { + if (t == NULL) return new Node(NULL, x, NULL); + if (x < t->elt) t->left = tree_add(t->left, x); + else if (x > t->elt) t->right = tree_add(t->right, x); + return t; +} + +void tree_add_ref(Node* &t, int x) { + if (t == NULL ) t = new Node(NULL, x, NULL); + else if (x < t->elt) tree_add_ref(t->left, x); + else if (x > t->elt) tree_add_ref(t->right, x); +} + +void tree_print(Node *t) { + if (t == NULL) return; + std::cout << "("; + tree_print(t->left); + std::cout << t->elt; + tree_print(t->right); + std::cout << ")"; +} + + +// encapsulation dans une classe + +class BST { +public: + Node *root; + BST(); + int size(); + void add1(int x); + void add2(int x); + void print(); +}; + +BST::BST() { + this->root = NULL; +} + +int BST::size() { + return tree_size(this->root); +} + +void BST::add1(int x) { + this->root = tree_add(this->root, x); +} + +void BST::add2(int x) { + tree_add_ref(this->root, x); +} + +void BST::print() { + tree_print(this->root); + std::cout << std::endl; +} + + +// tests + +int main() { + BST t; + t.add1(2); + t.add2(3); + t.add1(1); + t.print(); + t.add2(7); + t.add1(0); + t.print(); + BST *u = new BST(); + int i; + for (i = 0; i < 10; i++) + u->add1((31 * i) % 7); + u->print(); + for (i = 0; i < 10; i++) + u->add2((29 * i) % 13); + u->print(); + return 0; +} diff --git a/tests/exec/bst.out b/tests/exec/bst.out new file mode 100644 index 0000000..2795607 --- /dev/null +++ b/tests/exec/bst.out @@ -0,0 +1,4 @@ +((1)2(3)) +(((0)1)2(3(7))) +(0(((1)2)3(((4)5)6))) +(0(((1)2)3(((4)5)6((8)9((11)12))))) diff --git a/tests/exec/for1.cpp b/tests/exec/for1.cpp new file mode 100644 index 0000000..3ac56de --- /dev/null +++ b/tests/exec/for1.cpp @@ -0,0 +1,7 @@ +#include + +int main() { + int i; + for (i = 0; i < 10; i++) + std::cout << "i = " << i << "\n"; +} diff --git a/tests/exec/for1.out b/tests/exec/for1.out new file mode 100644 index 0000000..dc59d9b --- /dev/null +++ b/tests/exec/for1.out @@ -0,0 +1,10 @@ +i = 0 +i = 1 +i = 2 +i = 3 +i = 4 +i = 5 +i = 6 +i = 7 +i = 8 +i = 9 diff --git a/tests/exec/for2.cpp b/tests/exec/for2.cpp new file mode 100644 index 0000000..65ce735 --- /dev/null +++ b/tests/exec/for2.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int i; + for (i = 0; i < 10; i++) + std::cout << "i = " << i << "\n"; + std::cout << "i = " << i << "\n"; +} diff --git a/tests/exec/for2.out b/tests/exec/for2.out new file mode 100644 index 0000000..2bcca9c --- /dev/null +++ b/tests/exec/for2.out @@ -0,0 +1,11 @@ +i = 0 +i = 1 +i = 2 +i = 3 +i = 4 +i = 5 +i = 6 +i = 7 +i = 8 +i = 9 +i = 10 diff --git a/tests/exec/for3.cpp b/tests/exec/for3.cpp new file mode 100644 index 0000000..3df619c --- /dev/null +++ b/tests/exec/for3.cpp @@ -0,0 +1,11 @@ +#include + +int main() { + int i; + int j; + for (i = 0; i < 5; i++) + for (j = 0; j < 5; j++) + std::cout << "i*j = " << i*j << "\n"; + std::cout << "i = " << i << "\n"; + std::cout << "j = " << j << "\n"; +} diff --git a/tests/exec/for3.out b/tests/exec/for3.out new file mode 100644 index 0000000..6ed4dd6 --- /dev/null +++ b/tests/exec/for3.out @@ -0,0 +1,27 @@ +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 1 +i*j = 2 +i*j = 3 +i*j = 4 +i*j = 0 +i*j = 2 +i*j = 4 +i*j = 6 +i*j = 8 +i*j = 0 +i*j = 3 +i*j = 6 +i*j = 9 +i*j = 12 +i*j = 0 +i*j = 4 +i*j = 8 +i*j = 12 +i*j = 16 +i = 5 +j = 5 diff --git a/tests/exec/global.cpp b/tests/exec/global.cpp new file mode 100644 index 0000000..8a32a23 --- /dev/null +++ b/tests/exec/global.cpp @@ -0,0 +1,14 @@ +#include + +int x, *p; + +int main() { + x = 41; + std::cout << x << "\n"; + p = &x; + *p = *p + 1; + std::cout << x << "\n"; + int &r = x; + r = r + 1; + std::cout << x << "\n"; +} diff --git a/tests/exec/global.out b/tests/exec/global.out new file mode 100644 index 0000000..f91de27 --- /dev/null +++ b/tests/exec/global.out @@ -0,0 +1,3 @@ +41 +42 +43 diff --git a/tests/exec/hexa.cpp b/tests/exec/hexa.cpp new file mode 100644 index 0000000..70feac9 --- /dev/null +++ b/tests/exec/hexa.cpp @@ -0,0 +1,15 @@ +#include + +int main() { + std::cout << 0x100 << "\n"; + std::cout << 0xff << "\n"; + std::cout << 0xFF << "\n"; + int maxint = 0x7fffffff; + std::cout << maxint << "\n"; + int x = 0xDEADBEEF; + std::cout << x << "\n"; + x = 0xFFFFFFFF; + std::cout << x << "\n"; + x = 0x80000000; + std::cout << x << "\n"; +} diff --git a/tests/exec/hexa.out b/tests/exec/hexa.out new file mode 100644 index 0000000..2a5b25b --- /dev/null +++ b/tests/exec/hexa.out @@ -0,0 +1,7 @@ +256 +255 +255 +2147483647 +-559038737 +-1 +-2147483648 diff --git a/tests/exec/inheritance1.cpp b/tests/exec/inheritance1.cpp new file mode 100644 index 0000000..8a2c1e7 --- /dev/null +++ b/tests/exec/inheritance1.cpp @@ -0,0 +1,30 @@ +#include + +class A { +public: + virtual void f(); +}; + +class B : public A { +public: + void f(); +}; + +void A::f() { + std::cout << "this is A::f" << "\n"; +} + +void B::f() { + std::cout << "this is B::f" << "\n"; +} + +int main() { + A a; + a.f(); + B b; + b.f(); + A *x = &b; + x->f(); + x = &a; + x->f(); +} diff --git a/tests/exec/inheritance1.out b/tests/exec/inheritance1.out new file mode 100644 index 0000000..bb94fe2 --- /dev/null +++ b/tests/exec/inheritance1.out @@ -0,0 +1,4 @@ +this is A::f +this is B::f +this is B::f +this is A::f diff --git a/tests/exec/inheritance2.cpp b/tests/exec/inheritance2.cpp new file mode 100644 index 0000000..272b341 --- /dev/null +++ b/tests/exec/inheritance2.cpp @@ -0,0 +1,26 @@ +#include + +class A { +public: + virtual void f(); +}; + +class B : public A { +public: + void f(); +}; + +void A::f() { + std::cout << "this is A::f" << "\n"; +} + +void B::f() { + std::cout << "this is B::f" << "\n"; +} + +int main() { + A *a = new A(); + a->f(); + a = new B(); + a->f(); +} diff --git a/tests/exec/inheritance2.out b/tests/exec/inheritance2.out new file mode 100644 index 0000000..68820df --- /dev/null +++ b/tests/exec/inheritance2.out @@ -0,0 +1,2 @@ +this is A::f +this is B::f diff --git a/tests/exec/josephus.cpp b/tests/exec/josephus.cpp new file mode 100644 index 0000000..f43dac6 --- /dev/null +++ b/tests/exec/josephus.cpp @@ -0,0 +1,101 @@ +#include + +/*** listes circulaires doublement chaînées ***/ + +class ListeC { + public: + int valeur; + ListeC *suivant; + ListeC *precedent; + ListeC(int v); + void insererApres(int v); + void supprimer(); + void afficher(); +}; + +/* constructeur = liste réduite à un élément */ +ListeC::ListeC(int v) { + valeur = v; + suivant = precedent = this; +} + +/* insertion après un élément */ +void ListeC::insererApres(int v) { + ListeC *e = new ListeC(0); + e->valeur = v; + e->suivant = suivant; + suivant = e; + e->suivant->precedent = e; + e->precedent = this; +} + +/* suppression d'un élément */ +void ListeC::supprimer() { + precedent->suivant = suivant; + suivant->precedent = precedent; +} + +/* affichage */ +void ListeC::afficher() { + ListeC *c = this; + std::cout << c->valeur << " "; + c = c->suivant; + for (; c != this;) { + std::cout << c->valeur << " "; + c = c->suivant; + } + std::cout << "\n"; +} + +/*** problème de Josephus ***/ + +/* construction de la liste circulaire 1,2,...,n; + l'élément retourné est celui contenant 1 */ +ListeC *cercle(int n) { + ListeC *l = new ListeC(1); + int i; + for (i = n; i >= 2; i--) { + l->insererApres(i); + } + return l; +} + +/* jeu de Josephus */ +int josephus(int n, int p) { + /* c est le joueur courant, 1 au départ */ + ListeC *c = cercle(n); + + /* tant qu'il reste plus d'un joueur */ + for (; c != c->suivant;) { + /* on élimine un joueur */ + int i; + for (i = 1; i < p; i++) + c = c->suivant; + c->supprimer(); + // std::cout << c->valeur << " est éliminé"; + c = c->suivant; + } + // std::cout << "le gagnant est " << c->valeur; + return c->valeur; +} + +/*** Tests ***/ + +int main() { + ListeC l = ListeC(1); + l.afficher(); + l.insererApres(3); + l.afficher(); + l.insererApres(2); + l.afficher(); + l.suivant->supprimer(); + l.afficher(); + + ListeC *c = cercle(7); + c->afficher(); + + if (josephus(7, 5) == 6 && + josephus(5, 5) == 2 && + josephus(5, 17) == 4 && josephus(13, 2) == 11) + std::cout << "ok\n"; +} diff --git a/tests/exec/josephus.out b/tests/exec/josephus.out new file mode 100644 index 0000000..0506f80 --- /dev/null +++ b/tests/exec/josephus.out @@ -0,0 +1,6 @@ +1 +1 3 +1 2 3 +1 3 +1 2 3 4 5 6 7 +ok diff --git a/tests/exec/mandelbrot.cpp b/tests/exec/mandelbrot.cpp new file mode 100644 index 0000000..206b18b --- /dev/null +++ b/tests/exec/mandelbrot.cpp @@ -0,0 +1,60 @@ + +#include + +/* arithmetique de virgule fixe + precision q = 8192 i.e. 13 bits pour la partie decimale */ + +int add(int x, int y) { + return x + y; +} +int sub(int x, int y) { + return x - y; +} +int mul(int x, int y) { + int t = x * y; + return (t + 8192 / 2) / 8192; +} +int div(int x, int y) { + int t = x * 8192; + return (t + y / 2) / y; +} +int of_int(int x) { + return x * 8192; +} + +int iter(int n, int a, int b, int xn, int yn) { + if (n == 100) return true; + int xn2 = mul(xn, xn); + int yn2 = mul(yn, yn); + if (add(xn2, yn2) > of_int(4)) return false; + return iter(n+1, a, b, add(sub(xn2, yn2), a), + add(mul(of_int(2), mul(xn, yn)), b)); +} + +int inside(int x, int y) { + return iter(0, x, y, of_int(0), of_int(0)); +} + +int main() { + int steps = 30; + int xmin = of_int(-2); + int xmax = of_int(1); + int deltax = div(sub(xmax, xmin), of_int(2 * steps)); + int ymin = of_int(-1); + int ymax = of_int(1); + int deltay = div(sub(ymax, ymin), of_int(steps)); + int i; + for (i = 0; i < steps; i++) { + int y = add(ymin, mul(of_int(i), deltay)); + int j; + for (j = 0; j < 2 * steps; j++) { + int x = add(xmin, mul(of_int(j), deltax)); + if (inside(x, y)) + std::cout << "0"; + else + std::cout << "1"; + } + std::cout << "\n"; + } +} + diff --git a/tests/exec/mandelbrot.out b/tests/exec/mandelbrot.out new file mode 100644 index 0000000..11cc36c --- /dev/null +++ b/tests/exec/mandelbrot.out @@ -0,0 +1,30 @@ +111111111111111111111111111111111111111111111111111111111111 +111111111111111111111111111111111111111111111111111111111111 +111111111111111111111111111111111111110111111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111100111111111111111111111 +111111111111111111111111111111011000000000011111111111111111 +111111111111111111111111111110000000000000000001111111111111 +111111111111111111111111111110000000000000000011111111111111 +111111111111111111111111111100000000000000000001111111111111 +111111111111111111111111110000000000000000000000011111111111 +111111111111111110110111111000000000000000000000111111111111 +111111111111111110000000110000000000000000000000111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111100000000010000000000000000000001111111111111 +111110111100000000000000000000000000000000000111111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111110000000110000000000000000000000111111111111 +111111111111111110110111111000000000000000000000111111111111 +111111111111111111111111111000000000000000000000011111111111 +111111111111111111111111111100000000000000000001111111111111 +111111111111111111111111111110000000000000000011111111111111 +111111111111111111111111111111000000000000000001111111111111 +111111111111111111111111111111011000000000011111111111111111 +111111111111111111111111111111111111100111111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111110111111111111111111111 +111111111111111111111111111111111111111111111111111111111111 diff --git a/tests/exec/octal.cpp b/tests/exec/octal.cpp new file mode 100644 index 0000000..649ebde --- /dev/null +++ b/tests/exec/octal.cpp @@ -0,0 +1,13 @@ +#include + +int main() { + std::cout << 0100 << "\n"; + std::cout << 0777 << "\n"; + std::cout << 0644 << "\n"; + int maxint = 017777777777; + std::cout << maxint << "\n"; + int x = 037777777777; + std::cout << x << "\n"; + x = 020000000000; + std::cout << x << "\n"; +} diff --git a/tests/exec/octal.out b/tests/exec/octal.out new file mode 100644 index 0000000..ee77d8d --- /dev/null +++ b/tests/exec/octal.out @@ -0,0 +1,6 @@ +64 +511 +420 +2147483647 +-1 +-2147483648 diff --git a/tests/exec/pascal.cpp b/tests/exec/pascal.cpp new file mode 100644 index 0000000..a8a581e --- /dev/null +++ b/tests/exec/pascal.cpp @@ -0,0 +1,62 @@ + +// triangle de Pascal modulo 7 +// on n'a pas de tableaux, alors on utilise des listes chaînées + +#include + +class Array { +public: + int val; + Array *next; + Array(int n); // une liste à n éléments + int get(int i); + void set(int i, int v); +}; + +Array::Array(int n) { + if (n == 1) return; + next = new Array(n-1); +} + +int Array::get(int i) { + if (i == 0) return val; + return next->get(i-1); +} + +void Array::set(int i, int v) { + if (i == 0) val = v; + else next->set(i-1, v); +} + +void print_row(Array *r, int i) { + int j; + for (j = 0; j <= i; j++) { + if (r->get(j) != 0) + std::cout << "*"; + else + std::cout << "0"; + } + std::cout << "\n"; +} + +void compute_row(Array *r, int j) { + int v = 0; + if (j == 0) + v = 1; + else + v = (r->get(j) + r->get(j-1)) % 7; + r->set(j, v); + if (j > 0) + compute_row(r, j-1); +} + +int main() { + int h = 42; + Array *r = new Array(h+1); + int i; + for (i = 0; i < h; i++) { + r->set(i, 0); + compute_row(r, i); + print_row(r, i); + } +} diff --git a/tests/exec/pascal.out b/tests/exec/pascal.out new file mode 100644 index 0000000..58ca9bc --- /dev/null +++ b/tests/exec/pascal.out @@ -0,0 +1,42 @@ +* +** +*** +**** +***** +****** +******* +*000000* +**00000** +***0000*** +****000**** +*****00***** +******0****** +************** +*000000*000000* +**00000**00000** +***0000***0000*** +****000****000**** +*****00*****00***** +******0******0****** +********************* +*000000*000000*000000* +**00000**00000**00000** +***0000***0000***0000*** +****000****000****000**** +*****00*****00*****00***** +******0******0******0****** +**************************** +*000000*000000*000000*000000* +**00000**00000**00000**00000** +***0000***0000***0000***0000*** +****000****000****000****000**** +*****00*****00*****00*****00***** +******0******0******0******0****** +*********************************** +*000000*000000*000000*000000*000000* +**00000**00000**00000**00000**00000** +***0000***0000***0000***0000***0000*** +****000****000****000****000****000**** +*****00*****00*****00*****00*****00***** +******0******0******0******0******0****** +****************************************** diff --git a/tests/exec/passing.cpp b/tests/exec/passing.cpp new file mode 100644 index 0000000..6354fa5 --- /dev/null +++ b/tests/exec/passing.cpp @@ -0,0 +1,13 @@ +#include + +void incr(int &y) { + y = y+1; +} + +int main() { + int x = 5; + std::cout << "x = " << x << std::endl; + incr(x); + std::cout << "x = " << x << std::endl; +} + diff --git a/tests/exec/passing.out b/tests/exec/passing.out new file mode 100644 index 0000000..62226ae --- /dev/null +++ b/tests/exec/passing.out @@ -0,0 +1,2 @@ +x = 5 +x = 6 diff --git a/tests/exec/prepost1.cpp b/tests/exec/prepost1.cpp new file mode 100644 index 0000000..c536018 --- /dev/null +++ b/tests/exec/prepost1.cpp @@ -0,0 +1,14 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + x++; + std::cout << "x = " << x << "\n"; + x--; + std::cout << "x = " << x << "\n"; + ++x; + std::cout << "x = " << x << "\n"; + --x; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/prepost1.out b/tests/exec/prepost1.out new file mode 100644 index 0000000..12ad2b0 --- /dev/null +++ b/tests/exec/prepost1.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 41 +x = 42 +x = 41 diff --git a/tests/exec/ref1.cpp b/tests/exec/ref1.cpp new file mode 100644 index 0000000..f62d1f6 --- /dev/null +++ b/tests/exec/ref1.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int x = 41; + int &y = x; + y = 42; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref1.out b/tests/exec/ref1.out new file mode 100644 index 0000000..2d76aba --- /dev/null +++ b/tests/exec/ref1.out @@ -0,0 +1 @@ +x = 42 diff --git a/tests/exec/ref2.cpp b/tests/exec/ref2.cpp new file mode 100644 index 0000000..d4d2eb8 --- /dev/null +++ b/tests/exec/ref2.cpp @@ -0,0 +1,14 @@ +#include + +void f(int &y) { + y = 42; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + x = 41; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref2.out b/tests/exec/ref2.out new file mode 100644 index 0000000..26f06b0 --- /dev/null +++ b/tests/exec/ref2.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 41 diff --git a/tests/exec/ref3.cpp b/tests/exec/ref3.cpp new file mode 100644 index 0000000..ba58365 --- /dev/null +++ b/tests/exec/ref3.cpp @@ -0,0 +1,18 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + x = 0; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref3.out b/tests/exec/ref3.out new file mode 100644 index 0000000..65e2846 --- /dev/null +++ b/tests/exec/ref3.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 43 +x = 0 +x = 1 diff --git a/tests/exec/ref4.cpp b/tests/exec/ref4.cpp new file mode 100644 index 0000000..4f59ef4 --- /dev/null +++ b/tests/exec/ref4.cpp @@ -0,0 +1,16 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + int &z = x; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; +} diff --git a/tests/exec/ref4.out b/tests/exec/ref4.out new file mode 100644 index 0000000..771565f --- /dev/null +++ b/tests/exec/ref4.out @@ -0,0 +1,4 @@ +x = 41 +x = 42 +x = 43 +z = 43 diff --git a/tests/exec/ref5.cpp b/tests/exec/ref5.cpp new file mode 100644 index 0000000..1f9944b --- /dev/null +++ b/tests/exec/ref5.cpp @@ -0,0 +1,29 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + int &z = x; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + int &u = z; + f(u); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; +} diff --git a/tests/exec/ref5.out b/tests/exec/ref5.out new file mode 100644 index 0000000..d52026a --- /dev/null +++ b/tests/exec/ref5.out @@ -0,0 +1,13 @@ +x = 41 +x = 42 +x = 43 +z = 43 +x = 44 +z = 44 +u = 44 +x = 45 +z = 45 +u = 45 +x = 46 +z = 46 +u = 46 diff --git a/tests/exec/ref6.cpp b/tests/exec/ref6.cpp new file mode 100644 index 0000000..3737786 --- /dev/null +++ b/tests/exec/ref6.cpp @@ -0,0 +1,20 @@ +#include + +int &f(int b, int &x, int &y) { + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + if (b) return x; else return y; +} + +int main() { + int x = 42; + int y = 43; + int &r = f(1, x, y); + // now r is an alias for x + r = 12; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + f(0,x,y) = 13; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; +} diff --git a/tests/exec/ref6.out b/tests/exec/ref6.out new file mode 100644 index 0000000..cb5da25 --- /dev/null +++ b/tests/exec/ref6.out @@ -0,0 +1,8 @@ +x = 42 +y = 43 +x = 12 +y = 43 +x = 12 +y = 43 +x = 12 +y = 13 diff --git a/tests/exec/string.cpp b/tests/exec/string.cpp new file mode 100644 index 0000000..38183b8 --- /dev/null +++ b/tests/exec/string.cpp @@ -0,0 +1,10 @@ +#include + +int main() { + std::cout << "abc\n"; + std::cout << "a\nc\n"; + std::cout << "a\\c\n"; + std::cout << "a\tc\n"; + std::cout << "a\"c\n"; + std::cout << "\x41\x42\x43\n"; +} diff --git a/tests/exec/string.out b/tests/exec/string.out new file mode 100644 index 0000000..0772ea1 --- /dev/null +++ b/tests/exec/string.out @@ -0,0 +1,7 @@ +abc +a +c +a\c +a c +a"c +ABC diff --git a/tests/exec/true_false.cpp b/tests/exec/true_false.cpp new file mode 100644 index 0000000..42a4f65 --- /dev/null +++ b/tests/exec/true_false.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int b = true; + std::cout << "b = " << b << "\n"; + b = false; + std::cout << "b = " << b << "\n"; +} diff --git a/tests/exec/true_false.out b/tests/exec/true_false.out new file mode 100644 index 0000000..1748f7d --- /dev/null +++ b/tests/exec/true_false.out @@ -0,0 +1,2 @@ +b = 1 +b = 0 diff --git a/tests/exec/vehicles.cpp b/tests/exec/vehicles.cpp new file mode 100644 index 0000000..51ab55d --- /dev/null +++ b/tests/exec/vehicles.cpp @@ -0,0 +1,78 @@ +#include + +class Vehicle { +public: + int position; + Vehicle(); + virtual void move(int d); +}; + +Vehicle::Vehicle() { + position = 10; +} + +void Vehicle::move(int d) { + std::cout << "vehicle moves\n"; + position = position + d; +} + + +class Car : public Vehicle { +public: + // champ position hérité + int passengers; + Car(); + // methode move() héritée + void await(Vehicle &v); +}; + +Car::Car() { +} + +void Car::await(Vehicle &v) { + std::cout << "await: position = " << v.position << "\n"; + if (v.position < position) + v.move(position - v.position); + else + move(10); +} + +class Truck : public Vehicle { +public: + // champ position hérité + int load; + Truck(); + void move(int d); +}; + +Truck::Truck() { +} + +void Truck::move(int d) { // methode move redéfinie + std::cout << "truck moves\n"; + if (d <= 55) position = position + d; else position = position + 55; +} + +int main() { + Truck t; + std::cout << "t at " << t.position << "\n"; + Car c; + c.passengers = 2; + std::cout << "c at " << c.position << "\n"; + c.move(60); + std::cout << "c at " << c.position << "\n"; + Vehicle *v = &c; // alias + v->move(70); + std::cout << "c at " << c.position << "\n"; + c.await(t); + std::cout << "t at " << t.position << "\n"; + std::cout << "c at " << c.position << "\n"; + +} + +/* +Local Variables: +compile-command: "make vehicles" +End: +*/ + diff --git a/tests/exec/vehicles.out b/tests/exec/vehicles.out new file mode 100644 index 0000000..b5f6c21 --- /dev/null +++ b/tests/exec/vehicles.out @@ -0,0 +1,10 @@ +t at 10 +c at 10 +vehicle moves +c at 70 +vehicle moves +c at 140 +await: position = 10 +truck moves +t at 65 +c at 140 diff --git a/tests/syntax/bad/testfile-bad_hexa-1.cpp b/tests/syntax/bad/testfile-bad_hexa-1.cpp new file mode 100644 index 0000000..e0f8f14 --- /dev/null +++ b/tests/syntax/bad/testfile-bad_hexa-1.cpp @@ -0,0 +1 @@ +int main() { int x = 0xG; } diff --git a/tests/syntax/bad/testfile-bad_ident1-1.cpp b/tests/syntax/bad/testfile-bad_ident1-1.cpp new file mode 100644 index 0000000..823ff28 --- /dev/null +++ b/tests/syntax/bad/testfile-bad_ident1-1.cpp @@ -0,0 +1 @@ +void 1A() { } diff --git a/tests/syntax/bad/testfile-bad_ident2-1.cpp b/tests/syntax/bad/testfile-bad_ident2-1.cpp new file mode 100644 index 0000000..acc7054 --- /dev/null +++ b/tests/syntax/bad/testfile-bad_ident2-1.cpp @@ -0,0 +1 @@ +void A'A() { } diff --git a/tests/syntax/bad/testfile-bad_octal-1.cpp b/tests/syntax/bad/testfile-bad_octal-1.cpp new file mode 100644 index 0000000..f44401f --- /dev/null +++ b/tests/syntax/bad/testfile-bad_octal-1.cpp @@ -0,0 +1 @@ +int main() { int x = 08; } diff --git a/tests/syntax/bad/testfile-block1-1.cpp b/tests/syntax/bad/testfile-block1-1.cpp new file mode 100644 index 0000000..e5dc71d --- /dev/null +++ b/tests/syntax/bad/testfile-block1-1.cpp @@ -0,0 +1 @@ +void f() { { } diff --git a/tests/syntax/bad/testfile-block2-1.cpp b/tests/syntax/bad/testfile-block2-1.cpp new file mode 100644 index 0000000..3ce148d --- /dev/null +++ b/tests/syntax/bad/testfile-block2-1.cpp @@ -0,0 +1 @@ +void f() { { } } } diff --git a/tests/syntax/bad/testfile-expr1-1.cpp b/tests/syntax/bad/testfile-expr1-1.cpp new file mode 100644 index 0000000..fe82a74 --- /dev/null +++ b/tests/syntax/bad/testfile-expr1-1.cpp @@ -0,0 +1 @@ +void f() { ++ {}; } diff --git a/tests/syntax/bad/testfile-expr10-1.cpp b/tests/syntax/bad/testfile-expr10-1.cpp new file mode 100644 index 0000000..c2f97d8 --- /dev/null +++ b/tests/syntax/bad/testfile-expr10-1.cpp @@ -0,0 +1 @@ +void m() { a.x = ; } diff --git a/tests/syntax/bad/testfile-expr11-1.cpp b/tests/syntax/bad/testfile-expr11-1.cpp new file mode 100644 index 0000000..d0b2d79 --- /dev/null +++ b/tests/syntax/bad/testfile-expr11-1.cpp @@ -0,0 +1 @@ +void m() { a.x = {}; } diff --git a/tests/syntax/bad/testfile-expr2-1.cpp b/tests/syntax/bad/testfile-expr2-1.cpp new file mode 100644 index 0000000..1fda478 --- /dev/null +++ b/tests/syntax/bad/testfile-expr2-1.cpp @@ -0,0 +1 @@ +void f() { 0 ! 0; } diff --git a/tests/syntax/bad/testfile-expr3-1.cpp b/tests/syntax/bad/testfile-expr3-1.cpp new file mode 100644 index 0000000..0ff4a82 --- /dev/null +++ b/tests/syntax/bad/testfile-expr3-1.cpp @@ -0,0 +1 @@ +void f() { 0 <> 0; } diff --git a/tests/syntax/bad/testfile-expr4-1.cpp b/tests/syntax/bad/testfile-expr4-1.cpp new file mode 100644 index 0000000..e03ca37 --- /dev/null +++ b/tests/syntax/bad/testfile-expr4-1.cpp @@ -0,0 +1 @@ +void f() { 0 <== 0; } diff --git a/tests/syntax/bad/testfile-expr6-1.cpp b/tests/syntax/bad/testfile-expr6-1.cpp new file mode 100644 index 0000000..20d0013 --- /dev/null +++ b/tests/syntax/bad/testfile-expr6-1.cpp @@ -0,0 +1 @@ +void f() { (0)0; } diff --git a/tests/syntax/bad/testfile-expr7-1.cpp b/tests/syntax/bad/testfile-expr7-1.cpp new file mode 100644 index 0000000..573bbb9 --- /dev/null +++ b/tests/syntax/bad/testfile-expr7-1.cpp @@ -0,0 +1 @@ +void f() { j+ ; } diff --git a/tests/syntax/bad/testfile-expr8-1.cpp b/tests/syntax/bad/testfile-expr8-1.cpp new file mode 100644 index 0000000..95273c2 --- /dev/null +++ b/tests/syntax/bad/testfile-expr8-1.cpp @@ -0,0 +1 @@ +void f() { j ++ i ; } diff --git a/tests/syntax/bad/testfile-expr9-1.cpp b/tests/syntax/bad/testfile-expr9-1.cpp new file mode 100644 index 0000000..b400639 --- /dev/null +++ b/tests/syntax/bad/testfile-expr9-1.cpp @@ -0,0 +1 @@ +void f() { x = a.; } diff --git a/tests/syntax/bad/testfile-for1-1.cpp b/tests/syntax/bad/testfile-for1-1.cpp new file mode 100644 index 0000000..ca4f53e --- /dev/null +++ b/tests/syntax/bad/testfile-for1-1.cpp @@ -0,0 +1 @@ +void m() { int i; for( ; ; true; i++) ; } diff --git a/tests/syntax/bad/testfile-for2-1.cpp b/tests/syntax/bad/testfile-for2-1.cpp new file mode 100644 index 0000000..f600997 --- /dev/null +++ b/tests/syntax/bad/testfile-for2-1.cpp @@ -0,0 +1 @@ +void m() { int i; for( , i=0; true; i++) ; } diff --git a/tests/syntax/bad/testfile-for3-1.cpp b/tests/syntax/bad/testfile-for3-1.cpp new file mode 100644 index 0000000..be7aa4c --- /dev/null +++ b/tests/syntax/bad/testfile-for3-1.cpp @@ -0,0 +1 @@ +void m() { int i; for( i = 0, ; true; i++) ; } diff --git a/tests/syntax/bad/testfile-for4-1.cpp b/tests/syntax/bad/testfile-for4-1.cpp new file mode 100644 index 0000000..be2dfdf --- /dev/null +++ b/tests/syntax/bad/testfile-for4-1.cpp @@ -0,0 +1 @@ +void m() { for(int i = 0; ; ; i++) ; } diff --git a/tests/syntax/bad/testfile-for5-1.cpp b/tests/syntax/bad/testfile-for5-1.cpp new file mode 100644 index 0000000..303e843 --- /dev/null +++ b/tests/syntax/bad/testfile-for5-1.cpp @@ -0,0 +1 @@ +void m() { for(int i = 0; true; i = 0,) ; } diff --git a/tests/syntax/bad/testfile-for6-1.cpp b/tests/syntax/bad/testfile-for6-1.cpp new file mode 100644 index 0000000..85e1988 --- /dev/null +++ b/tests/syntax/bad/testfile-for6-1.cpp @@ -0,0 +1 @@ +void m() { for(int i = 0; true; i++) } diff --git a/tests/syntax/bad/testfile-for7-1.cpp b/tests/syntax/bad/testfile-for7-1.cpp new file mode 100644 index 0000000..41f8b51 --- /dev/null +++ b/tests/syntax/bad/testfile-for7-1.cpp @@ -0,0 +1 @@ +void m() { int i; for() ; } diff --git a/tests/syntax/bad/testfile-for8-1.cpp b/tests/syntax/bad/testfile-for8-1.cpp new file mode 100644 index 0000000..8b9040e --- /dev/null +++ b/tests/syntax/bad/testfile-for8-1.cpp @@ -0,0 +1 @@ +int main() { for(;;) } diff --git a/tests/syntax/bad/testfile-if1-1.cpp b/tests/syntax/bad/testfile-if1-1.cpp new file mode 100644 index 0000000..dad42a8 --- /dev/null +++ b/tests/syntax/bad/testfile-if1-1.cpp @@ -0,0 +1 @@ +void m() { if () ; } diff --git a/tests/syntax/bad/testfile-if2-1.cpp b/tests/syntax/bad/testfile-if2-1.cpp new file mode 100644 index 0000000..de75066 --- /dev/null +++ b/tests/syntax/bad/testfile-if2-1.cpp @@ -0,0 +1 @@ +void m() { if (;) ; } diff --git a/tests/syntax/bad/testfile-if3-1.cpp b/tests/syntax/bad/testfile-if3-1.cpp new file mode 100644 index 0000000..a32ebc5 --- /dev/null +++ b/tests/syntax/bad/testfile-if3-1.cpp @@ -0,0 +1 @@ +int m() { if (true) } diff --git a/tests/syntax/bad/testfile-if_else-1.cpp b/tests/syntax/bad/testfile-if_else-1.cpp new file mode 100644 index 0000000..afa1759 --- /dev/null +++ b/tests/syntax/bad/testfile-if_else-1.cpp @@ -0,0 +1 @@ +void m() { if (true) ; else } diff --git a/tests/syntax/bad/testfile-illegal_char-1.cpp b/tests/syntax/bad/testfile-illegal_char-1.cpp new file mode 100644 index 0000000..59c227c --- /dev/null +++ b/tests/syntax/bad/testfile-illegal_char-1.cpp @@ -0,0 +1 @@ +@ diff --git a/tests/syntax/bad/testfile-illegal_char-2.cpp b/tests/syntax/bad/testfile-illegal_char-2.cpp new file mode 100644 index 0000000..f13b8fe --- /dev/null +++ b/tests/syntax/bad/testfile-illegal_char-2.cpp @@ -0,0 +1,2 @@ + +int main() { @ int x = 1; } diff --git a/tests/syntax/bad/testfile-instr_decl1-1.cpp b/tests/syntax/bad/testfile-instr_decl1-1.cpp new file mode 100644 index 0000000..923e6c2 --- /dev/null +++ b/tests/syntax/bad/testfile-instr_decl1-1.cpp @@ -0,0 +1 @@ +void m() { int x = 0 } diff --git a/tests/syntax/bad/testfile-instr_expr-1.cpp b/tests/syntax/bad/testfile-instr_expr-1.cpp new file mode 100644 index 0000000..af42569 --- /dev/null +++ b/tests/syntax/bad/testfile-instr_expr-1.cpp @@ -0,0 +1 @@ +int m() { 0 } diff --git a/tests/syntax/bad/testfile-keyword1-1.cpp b/tests/syntax/bad/testfile-keyword1-1.cpp new file mode 100644 index 0000000..fd96c24 --- /dev/null +++ b/tests/syntax/bad/testfile-keyword1-1.cpp @@ -0,0 +1 @@ +void m() { fora (i = 0; 1; i++); } diff --git a/tests/syntax/bad/testfile-lexer_hack-1.cpp b/tests/syntax/bad/testfile-lexer_hack-1.cpp new file mode 100644 index 0000000..bfb6bb6 --- /dev/null +++ b/tests/syntax/bad/testfile-lexer_hack-1.cpp @@ -0,0 +1,2 @@ +S x; +int main() {} diff --git a/tests/syntax/bad/testfile-lexer_hack-2.cpp b/tests/syntax/bad/testfile-lexer_hack-2.cpp new file mode 100644 index 0000000..300ec96 --- /dev/null +++ b/tests/syntax/bad/testfile-lexer_hack-2.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +class S { public: int a; }; diff --git a/tests/syntax/bad/testfile-lexing1-1.cpp b/tests/syntax/bad/testfile-lexing1-1.cpp new file mode 100644 index 0000000..a1425a1 --- /dev/null +++ b/tests/syntax/bad/testfile-lexing1-1.cpp @@ -0,0 +1 @@ +int foo(int a, int b) { return a--b; } diff --git a/tests/syntax/bad/testfile-lexing2-1.cpp b/tests/syntax/bad/testfile-lexing2-1.cpp new file mode 100644 index 0000000..6c30d2e --- /dev/null +++ b/tests/syntax/bad/testfile-lexing2-1.cpp @@ -0,0 +1,2 @@ +void m() { int i = 1/// comment starts at first /, not second + 1; } diff --git a/tests/syntax/bad/testfile-lexing3-1.cpp b/tests/syntax/bad/testfile-lexing3-1.cpp new file mode 100644 index 0000000..8619b21 --- /dev/null +++ b/tests/syntax/bad/testfile-lexing3-1.cpp @@ -0,0 +1 @@ +void m() { int i = 1/**/0; } diff --git a/tests/syntax/bad/testfile-lexing4-1.cpp b/tests/syntax/bad/testfile-lexing4-1.cpp new file mode 100644 index 0000000..32ac816 --- /dev/null +++ b/tests/syntax/bad/testfile-lexing4-1.cpp @@ -0,0 +1 @@ +void m() { i/**/nt i = 10; } diff --git a/tests/syntax/bad/testfile-lexing5-1.cpp b/tests/syntax/bad/testfile-lexing5-1.cpp new file mode 100644 index 0000000..d935f8f --- /dev/null +++ b/tests/syntax/bad/testfile-lexing5-1.cpp @@ -0,0 +1 @@ + void m() { int i = 0; i +/**/= 10; } diff --git a/tests/syntax/bad/testfile-lexing6-1.cpp b/tests/syntax/bad/testfile-lexing6-1.cpp new file mode 100644 index 0000000..4989b51 --- /dev/null +++ b/tests/syntax/bad/testfile-lexing6-1.cpp @@ -0,0 +1 @@ + void m() { int i = 0; i + = 10; } diff --git a/tests/syntax/bad/testfile-newline_in_string-1.cpp b/tests/syntax/bad/testfile-newline_in_string-1.cpp new file mode 100644 index 0000000..92f9cc9 --- /dev/null +++ b/tests/syntax/bad/testfile-newline_in_string-1.cpp @@ -0,0 +1,5 @@ +void f() { + g(" + +"); +} diff --git a/tests/syntax/bad/testfile-parameters2-1.cpp b/tests/syntax/bad/testfile-parameters2-1.cpp new file mode 100644 index 0000000..f5e0bfe --- /dev/null +++ b/tests/syntax/bad/testfile-parameters2-1.cpp @@ -0,0 +1 @@ +void m(int x,) {} diff --git a/tests/syntax/bad/testfile-quotes_in_string-1.cpp b/tests/syntax/bad/testfile-quotes_in_string-1.cpp new file mode 100644 index 0000000..47a68d8 --- /dev/null +++ b/tests/syntax/bad/testfile-quotes_in_string-1.cpp @@ -0,0 +1,3 @@ +void f() { + g(" " "); +} diff --git a/tests/syntax/bad/testfile-return1-1.cpp b/tests/syntax/bad/testfile-return1-1.cpp new file mode 100644 index 0000000..135e57d --- /dev/null +++ b/tests/syntax/bad/testfile-return1-1.cpp @@ -0,0 +1 @@ +int m() { return diff --git a/tests/syntax/bad/testfile-unclosed_comment-1.cpp b/tests/syntax/bad/testfile-unclosed_comment-1.cpp new file mode 100644 index 0000000..33662f5 --- /dev/null +++ b/tests/syntax/bad/testfile-unclosed_comment-1.cpp @@ -0,0 +1 @@ +/* diff --git a/tests/syntax/bad/testfile-unclosed_escaped_string-1.cpp b/tests/syntax/bad/testfile-unclosed_escaped_string-1.cpp new file mode 100644 index 0000000..7d889f2 --- /dev/null +++ b/tests/syntax/bad/testfile-unclosed_escaped_string-1.cpp @@ -0,0 +1,3 @@ +void f() { + g("\"); +} diff --git a/tests/syntax/bad/testfile-unclosed_string-1.cpp b/tests/syntax/bad/testfile-unclosed_string-1.cpp new file mode 100644 index 0000000..0fce6a0 --- /dev/null +++ b/tests/syntax/bad/testfile-unclosed_string-1.cpp @@ -0,0 +1,4 @@ +void f() { + f("); + } + diff --git a/tests/syntax/bad/testfile-var2-1.cpp b/tests/syntax/bad/testfile-var2-1.cpp new file mode 100644 index 0000000..858665c --- /dev/null +++ b/tests/syntax/bad/testfile-var2-1.cpp @@ -0,0 +1 @@ +void f() { int } diff --git a/tests/syntax/good/testfile-assign-1.cpp b/tests/syntax/good/testfile-assign-1.cpp new file mode 100644 index 0000000..12cdbee --- /dev/null +++ b/tests/syntax/good/testfile-assign-1.cpp @@ -0,0 +1 @@ +void m() { int x; int y; y = x = 0; } diff --git a/tests/syntax/good/testfile-compare-1.cpp b/tests/syntax/good/testfile-compare-1.cpp new file mode 100644 index 0000000..81373c8 --- /dev/null +++ b/tests/syntax/good/testfile-compare-1.cpp @@ -0,0 +1 @@ +int m() { return 1==2 && 3==4 || !(5>=6); } diff --git a/tests/syntax/good/testfile-for-1.cpp b/tests/syntax/good/testfile-for-1.cpp new file mode 100644 index 0000000..71f985d --- /dev/null +++ b/tests/syntax/good/testfile-for-1.cpp @@ -0,0 +1,2 @@ +int main() { for(;;); } + diff --git a/tests/typing/bad/testfile-ampersand-1.cpp b/tests/typing/bad/testfile-ampersand-1.cpp new file mode 100644 index 0000000..065b3c5 --- /dev/null +++ b/tests/typing/bad/testfile-ampersand-1.cpp @@ -0,0 +1 @@ +int main() { &1; } diff --git a/tests/typing/bad/testfile-ampersand-2.cpp b/tests/typing/bad/testfile-ampersand-2.cpp new file mode 100644 index 0000000..ceffc1b --- /dev/null +++ b/tests/typing/bad/testfile-ampersand-2.cpp @@ -0,0 +1,2 @@ + +int main() { int x; int y; &(x+y); } diff --git a/tests/typing/bad/testfile-ampersand-3.cpp b/tests/typing/bad/testfile-ampersand-3.cpp new file mode 100644 index 0000000..7228085 --- /dev/null +++ b/tests/typing/bad/testfile-ampersand-3.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { &(foo()); } + diff --git a/tests/typing/bad/testfile-arith-1.cpp b/tests/typing/bad/testfile-arith-1.cpp new file mode 100644 index 0000000..8dde0c2 --- /dev/null +++ b/tests/typing/bad/testfile-arith-1.cpp @@ -0,0 +1,2 @@ +class S { public: int a; }; +int main() { S s; s+s; } diff --git a/tests/typing/bad/testfile-arith-2.cpp b/tests/typing/bad/testfile-arith-2.cpp new file mode 100644 index 0000000..30c56d4 --- /dev/null +++ b/tests/typing/bad/testfile-arith-2.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; s+1; } diff --git a/tests/typing/bad/testfile-arith-3.cpp b/tests/typing/bad/testfile-arith-3.cpp new file mode 100644 index 0000000..ec4f877 --- /dev/null +++ b/tests/typing/bad/testfile-arith-3.cpp @@ -0,0 +1,2 @@ + +int main() { char *p; p+p; } diff --git a/tests/typing/bad/testfile-arith-4.cpp b/tests/typing/bad/testfile-arith-4.cpp new file mode 100644 index 0000000..f9ca567 --- /dev/null +++ b/tests/typing/bad/testfile-arith-4.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; char *p; p+s; } diff --git a/tests/typing/bad/testfile-arith-5.cpp b/tests/typing/bad/testfile-arith-5.cpp new file mode 100644 index 0000000..2637ffc --- /dev/null +++ b/tests/typing/bad/testfile-arith-5.cpp @@ -0,0 +1,2 @@ + +int main() { char *p; 1-p; } diff --git a/tests/typing/bad/testfile-arith-6.cpp b/tests/typing/bad/testfile-arith-6.cpp new file mode 100644 index 0000000..0ef23c4 --- /dev/null +++ b/tests/typing/bad/testfile-arith-6.cpp @@ -0,0 +1,3 @@ + +int main() { int *p; char *q; putchar(p-q); } + diff --git a/tests/typing/bad/testfile-arrow-1.cpp b/tests/typing/bad/testfile-arrow-1.cpp new file mode 100644 index 0000000..d756d00 --- /dev/null +++ b/tests/typing/bad/testfile-arrow-1.cpp @@ -0,0 +1 @@ +int main() { 1->a; } diff --git a/tests/typing/bad/testfile-arrow-2.cpp b/tests/typing/bad/testfile-arrow-2.cpp new file mode 100644 index 0000000..379a9d0 --- /dev/null +++ b/tests/typing/bad/testfile-arrow-2.cpp @@ -0,0 +1,2 @@ + +int main() { int x; x->a; } diff --git a/tests/typing/bad/testfile-arrow-3.cpp b/tests/typing/bad/testfile-arrow-3.cpp new file mode 100644 index 0000000..4691f12 --- /dev/null +++ b/tests/typing/bad/testfile-arrow-3.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; x->a; } diff --git a/tests/typing/bad/testfile-arrow-4.cpp b/tests/typing/bad/testfile-arrow-4.cpp new file mode 100644 index 0000000..4691f12 --- /dev/null +++ b/tests/typing/bad/testfile-arrow-4.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; x->a; } diff --git a/tests/typing/bad/testfile-arrow-5.cpp b/tests/typing/bad/testfile-arrow-5.cpp new file mode 100644 index 0000000..c41b56d --- /dev/null +++ b/tests/typing/bad/testfile-arrow-5.cpp @@ -0,0 +1,5 @@ + +class S { public: int a; }; +void foo() {} +int main() { (foo())->a; } + diff --git a/tests/typing/bad/testfile-assign-1.cpp b/tests/typing/bad/testfile-assign-1.cpp new file mode 100644 index 0000000..5da9fdd --- /dev/null +++ b/tests/typing/bad/testfile-assign-1.cpp @@ -0,0 +1 @@ +int main() { 1 = 2; } diff --git a/tests/typing/bad/testfile-assign-10.cpp b/tests/typing/bad/testfile-assign-10.cpp new file mode 100644 index 0000000..24bf51e --- /dev/null +++ b/tests/typing/bad/testfile-assign-10.cpp @@ -0,0 +1,2 @@ + +int main() { 1++; } diff --git a/tests/typing/bad/testfile-assign-11.cpp b/tests/typing/bad/testfile-assign-11.cpp new file mode 100644 index 0000000..15716dd --- /dev/null +++ b/tests/typing/bad/testfile-assign-11.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; s++; } diff --git a/tests/typing/bad/testfile-assign-12.cpp b/tests/typing/bad/testfile-assign-12.cpp new file mode 100644 index 0000000..6440547 --- /dev/null +++ b/tests/typing/bad/testfile-assign-12.cpp @@ -0,0 +1,2 @@ + +int main() { int x; (x+1)++; } diff --git a/tests/typing/bad/testfile-assign-13.cpp b/tests/typing/bad/testfile-assign-13.cpp new file mode 100644 index 0000000..188b9c7 --- /dev/null +++ b/tests/typing/bad/testfile-assign-13.cpp @@ -0,0 +1,2 @@ + +int main() { 0--; } diff --git a/tests/typing/bad/testfile-assign-14.cpp b/tests/typing/bad/testfile-assign-14.cpp new file mode 100644 index 0000000..01a82c0 --- /dev/null +++ b/tests/typing/bad/testfile-assign-14.cpp @@ -0,0 +1,2 @@ + +int main() { 1--; } diff --git a/tests/typing/bad/testfile-assign-15.cpp b/tests/typing/bad/testfile-assign-15.cpp new file mode 100644 index 0000000..3c69dde --- /dev/null +++ b/tests/typing/bad/testfile-assign-15.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; s--; } diff --git a/tests/typing/bad/testfile-assign-16.cpp b/tests/typing/bad/testfile-assign-16.cpp new file mode 100644 index 0000000..a7c70f0 --- /dev/null +++ b/tests/typing/bad/testfile-assign-16.cpp @@ -0,0 +1,2 @@ + +int main() { int x; (x+1)--; } diff --git a/tests/typing/bad/testfile-assign-17.cpp b/tests/typing/bad/testfile-assign-17.cpp new file mode 100644 index 0000000..e65c23e --- /dev/null +++ b/tests/typing/bad/testfile-assign-17.cpp @@ -0,0 +1,2 @@ + +int main() { ++0; } diff --git a/tests/typing/bad/testfile-assign-18.cpp b/tests/typing/bad/testfile-assign-18.cpp new file mode 100644 index 0000000..2294f48 --- /dev/null +++ b/tests/typing/bad/testfile-assign-18.cpp @@ -0,0 +1,2 @@ + +int main() { ++1; } diff --git a/tests/typing/bad/testfile-assign-19.cpp b/tests/typing/bad/testfile-assign-19.cpp new file mode 100644 index 0000000..ae01145 --- /dev/null +++ b/tests/typing/bad/testfile-assign-19.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; ++s; } diff --git a/tests/typing/bad/testfile-assign-2.cpp b/tests/typing/bad/testfile-assign-2.cpp new file mode 100644 index 0000000..74969d8 --- /dev/null +++ b/tests/typing/bad/testfile-assign-2.cpp @@ -0,0 +1,2 @@ + +int main() { 0 = 1; } diff --git a/tests/typing/bad/testfile-assign-20.cpp b/tests/typing/bad/testfile-assign-20.cpp new file mode 100644 index 0000000..b60dafb --- /dev/null +++ b/tests/typing/bad/testfile-assign-20.cpp @@ -0,0 +1,2 @@ + +int main() { int x; ++(x+1); } diff --git a/tests/typing/bad/testfile-assign-21.cpp b/tests/typing/bad/testfile-assign-21.cpp new file mode 100644 index 0000000..0eeee1f --- /dev/null +++ b/tests/typing/bad/testfile-assign-21.cpp @@ -0,0 +1,2 @@ + +int main() { --0; } diff --git a/tests/typing/bad/testfile-assign-22.cpp b/tests/typing/bad/testfile-assign-22.cpp new file mode 100644 index 0000000..36b8226 --- /dev/null +++ b/tests/typing/bad/testfile-assign-22.cpp @@ -0,0 +1,2 @@ + +int main() { --1; } diff --git a/tests/typing/bad/testfile-assign-23.cpp b/tests/typing/bad/testfile-assign-23.cpp new file mode 100644 index 0000000..8a07de0 --- /dev/null +++ b/tests/typing/bad/testfile-assign-23.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; --s; } diff --git a/tests/typing/bad/testfile-assign-24.cpp b/tests/typing/bad/testfile-assign-24.cpp new file mode 100644 index 0000000..4189d96 --- /dev/null +++ b/tests/typing/bad/testfile-assign-24.cpp @@ -0,0 +1,2 @@ + +int main() { int x; --(x+1); } diff --git a/tests/typing/bad/testfile-assign-25.cpp b/tests/typing/bad/testfile-assign-25.cpp new file mode 100644 index 0000000..7bb02d2 --- /dev/null +++ b/tests/typing/bad/testfile-assign-25.cpp @@ -0,0 +1,2 @@ + +int main() { int x; x = --x--; } diff --git a/tests/typing/bad/testfile-assign-26.cpp b/tests/typing/bad/testfile-assign-26.cpp new file mode 100644 index 0000000..7ce0ded --- /dev/null +++ b/tests/typing/bad/testfile-assign-26.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { ++(foo()); } + diff --git a/tests/typing/bad/testfile-assign-27.cpp b/tests/typing/bad/testfile-assign-27.cpp new file mode 100644 index 0000000..66e5295 --- /dev/null +++ b/tests/typing/bad/testfile-assign-27.cpp @@ -0,0 +1 @@ +int main() { int *p; -p; } diff --git a/tests/typing/bad/testfile-assign-28.cpp b/tests/typing/bad/testfile-assign-28.cpp new file mode 100644 index 0000000..3d20c1b --- /dev/null +++ b/tests/typing/bad/testfile-assign-28.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; +s; } diff --git a/tests/typing/bad/testfile-assign-29.cpp b/tests/typing/bad/testfile-assign-29.cpp new file mode 100644 index 0000000..dc6e3e6 --- /dev/null +++ b/tests/typing/bad/testfile-assign-29.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; -s; } diff --git a/tests/typing/bad/testfile-assign-3.cpp b/tests/typing/bad/testfile-assign-3.cpp new file mode 100644 index 0000000..4926a21 --- /dev/null +++ b/tests/typing/bad/testfile-assign-3.cpp @@ -0,0 +1,2 @@ + +int main() { int x; int y; (x+y) = 2; } diff --git a/tests/typing/bad/testfile-assign-30.cpp b/tests/typing/bad/testfile-assign-30.cpp new file mode 100644 index 0000000..1d650eb --- /dev/null +++ b/tests/typing/bad/testfile-assign-30.cpp @@ -0,0 +1,3 @@ + +void foo() {} +int main() { +(foo()); } diff --git a/tests/typing/bad/testfile-assign-31.cpp b/tests/typing/bad/testfile-assign-31.cpp new file mode 100644 index 0000000..b31ee49 --- /dev/null +++ b/tests/typing/bad/testfile-assign-31.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { -(foo()); } + diff --git a/tests/typing/bad/testfile-assign-4.cpp b/tests/typing/bad/testfile-assign-4.cpp new file mode 100644 index 0000000..c71cddc --- /dev/null +++ b/tests/typing/bad/testfile-assign-4.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; S s; x = s; } diff --git a/tests/typing/bad/testfile-assign-5.cpp b/tests/typing/bad/testfile-assign-5.cpp new file mode 100644 index 0000000..6d42d60 --- /dev/null +++ b/tests/typing/bad/testfile-assign-5.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s; s = 0; } diff --git a/tests/typing/bad/testfile-assign-6.cpp b/tests/typing/bad/testfile-assign-6.cpp new file mode 100644 index 0000000..12c2f37 --- /dev/null +++ b/tests/typing/bad/testfile-assign-6.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; S s; s = x; } diff --git a/tests/typing/bad/testfile-assign-7.cpp b/tests/typing/bad/testfile-assign-7.cpp new file mode 100644 index 0000000..2e12f3a --- /dev/null +++ b/tests/typing/bad/testfile-assign-7.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +class T { public: int b; }; +int main() { S s; T t; s = t; } diff --git a/tests/typing/bad/testfile-assign-8.cpp b/tests/typing/bad/testfile-assign-8.cpp new file mode 100644 index 0000000..1c104db --- /dev/null +++ b/tests/typing/bad/testfile-assign-8.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { int x; x = foo(); } + diff --git a/tests/typing/bad/testfile-assign-9.cpp b/tests/typing/bad/testfile-assign-9.cpp new file mode 100644 index 0000000..7cfcff7 --- /dev/null +++ b/tests/typing/bad/testfile-assign-9.cpp @@ -0,0 +1 @@ +int main() { 0++; } diff --git a/tests/typing/bad/testfile-bang-1.cpp b/tests/typing/bad/testfile-bang-1.cpp new file mode 100644 index 0000000..2c45d1c --- /dev/null +++ b/tests/typing/bad/testfile-bang-1.cpp @@ -0,0 +1,2 @@ +class S { public: int a; }; +int main() { S s; !s; } diff --git a/tests/typing/bad/testfile-bang-2.cpp b/tests/typing/bad/testfile-bang-2.cpp new file mode 100644 index 0000000..1cecc76 --- /dev/null +++ b/tests/typing/bad/testfile-bang-2.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { !(foo()); } + diff --git a/tests/typing/bad/testfile-call-1.cpp b/tests/typing/bad/testfile-call-1.cpp new file mode 100644 index 0000000..2de8346 --- /dev/null +++ b/tests/typing/bad/testfile-call-1.cpp @@ -0,0 +1,2 @@ +void f(int x) {} +int main() { f(); } diff --git a/tests/typing/bad/testfile-call-2.cpp b/tests/typing/bad/testfile-call-2.cpp new file mode 100644 index 0000000..ddf482c --- /dev/null +++ b/tests/typing/bad/testfile-call-2.cpp @@ -0,0 +1,5 @@ + +class S { public: int a; }; +void f(int x) {} +int main() { S s; f(s); } + diff --git a/tests/typing/bad/testfile-class-1.cpp b/tests/typing/bad/testfile-class-1.cpp new file mode 100644 index 0000000..cb39856 --- /dev/null +++ b/tests/typing/bad/testfile-class-1.cpp @@ -0,0 +1 @@ +class S { public: S a; }; diff --git a/tests/typing/bad/testfile-class-2.cpp b/tests/typing/bad/testfile-class-2.cpp new file mode 100644 index 0000000..27a630c --- /dev/null +++ b/tests/typing/bad/testfile-class-2.cpp @@ -0,0 +1,3 @@ + +class S { public: void v; }; + diff --git a/tests/typing/bad/testfile-comparison-1.cpp b/tests/typing/bad/testfile-comparison-1.cpp new file mode 100644 index 0000000..2466fe4 --- /dev/null +++ b/tests/typing/bad/testfile-comparison-1.cpp @@ -0,0 +1,2 @@ +class S { public: int a; }; +int main() { int x; S s; 1 < s; } diff --git a/tests/typing/bad/testfile-comparison-2.cpp b/tests/typing/bad/testfile-comparison-2.cpp new file mode 100644 index 0000000..fc24f6a --- /dev/null +++ b/tests/typing/bad/testfile-comparison-2.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; S s; 1 != s; } diff --git a/tests/typing/bad/testfile-comparison-3.cpp b/tests/typing/bad/testfile-comparison-3.cpp new file mode 100644 index 0000000..bdbb44b --- /dev/null +++ b/tests/typing/bad/testfile-comparison-3.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s1; S s2; s1 < s2; } diff --git a/tests/typing/bad/testfile-comparison-4.cpp b/tests/typing/bad/testfile-comparison-4.cpp new file mode 100644 index 0000000..6d7a48f --- /dev/null +++ b/tests/typing/bad/testfile-comparison-4.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S s1; S s2; s1 != s2; } diff --git a/tests/typing/bad/testfile-comparison-5.cpp b/tests/typing/bad/testfile-comparison-5.cpp new file mode 100644 index 0000000..61d826c --- /dev/null +++ b/tests/typing/bad/testfile-comparison-5.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; S s; 1 == s; } diff --git a/tests/typing/bad/testfile-comparison-6.cpp b/tests/typing/bad/testfile-comparison-6.cpp new file mode 100644 index 0000000..f081f6a --- /dev/null +++ b/tests/typing/bad/testfile-comparison-6.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { 1 < foo(); } + diff --git a/tests/typing/bad/testfile-deref-1.cpp b/tests/typing/bad/testfile-deref-1.cpp new file mode 100644 index 0000000..7854300 --- /dev/null +++ b/tests/typing/bad/testfile-deref-1.cpp @@ -0,0 +1 @@ +int main() { *1; } diff --git a/tests/typing/bad/testfile-deref-2.cpp b/tests/typing/bad/testfile-deref-2.cpp new file mode 100644 index 0000000..d3a1318 --- /dev/null +++ b/tests/typing/bad/testfile-deref-2.cpp @@ -0,0 +1,2 @@ + +int main() { int x; *x; } diff --git a/tests/typing/bad/testfile-deref-3.cpp b/tests/typing/bad/testfile-deref-3.cpp new file mode 100644 index 0000000..622fa8b --- /dev/null +++ b/tests/typing/bad/testfile-deref-3.cpp @@ -0,0 +1,4 @@ + +void foo() {} +int main() { *(foo()); } + diff --git a/tests/typing/bad/testfile-field-1.cpp b/tests/typing/bad/testfile-field-1.cpp new file mode 100644 index 0000000..785c97d --- /dev/null +++ b/tests/typing/bad/testfile-field-1.cpp @@ -0,0 +1 @@ +int main() { 1.a; } diff --git a/tests/typing/bad/testfile-field-2.cpp b/tests/typing/bad/testfile-field-2.cpp new file mode 100644 index 0000000..e64aded --- /dev/null +++ b/tests/typing/bad/testfile-field-2.cpp @@ -0,0 +1,2 @@ + +int main() { int x; x.a; } diff --git a/tests/typing/bad/testfile-field-3.cpp b/tests/typing/bad/testfile-field-3.cpp new file mode 100644 index 0000000..382e124 --- /dev/null +++ b/tests/typing/bad/testfile-field-3.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; x.a; } diff --git a/tests/typing/bad/testfile-field-4.cpp b/tests/typing/bad/testfile-field-4.cpp new file mode 100644 index 0000000..4a2cf19 --- /dev/null +++ b/tests/typing/bad/testfile-field-4.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S *s; s.a; } diff --git a/tests/typing/bad/testfile-field-5.cpp b/tests/typing/bad/testfile-field-5.cpp new file mode 100644 index 0000000..382e124 --- /dev/null +++ b/tests/typing/bad/testfile-field-5.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { int x; x.a; } diff --git a/tests/typing/bad/testfile-field-6.cpp b/tests/typing/bad/testfile-field-6.cpp new file mode 100644 index 0000000..4a2cf19 --- /dev/null +++ b/tests/typing/bad/testfile-field-6.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; }; +int main() { S *s; s.a; } diff --git a/tests/typing/bad/testfile-field-7.cpp b/tests/typing/bad/testfile-field-7.cpp new file mode 100644 index 0000000..3ab70cb --- /dev/null +++ b/tests/typing/bad/testfile-field-7.cpp @@ -0,0 +1,5 @@ + +class S { public: int a; }; +void foo() {} +int main() { (foo()).a; } + diff --git a/tests/typing/bad/testfile-for-1.cpp b/tests/typing/bad/testfile-for-1.cpp new file mode 100644 index 0000000..bd1cf8e --- /dev/null +++ b/tests/typing/bad/testfile-for-1.cpp @@ -0,0 +1,2 @@ +void foo() {} +int main() { for( ; foo(); ); } diff --git a/tests/typing/bad/testfile-for-2.cpp b/tests/typing/bad/testfile-for-2.cpp new file mode 100644 index 0000000..91dae25 --- /dev/null +++ b/tests/typing/bad/testfile-for-2.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +int main() { S s; for( ; s; ); } + diff --git a/tests/typing/bad/testfile-global-1.cpp b/tests/typing/bad/testfile-global-1.cpp new file mode 100644 index 0000000..860c09d --- /dev/null +++ b/tests/typing/bad/testfile-global-1.cpp @@ -0,0 +1,3 @@ +void v; +int main() { } + diff --git a/tests/typing/bad/testfile-if-1.cpp b/tests/typing/bad/testfile-if-1.cpp new file mode 100644 index 0000000..2a96643 --- /dev/null +++ b/tests/typing/bad/testfile-if-1.cpp @@ -0,0 +1,2 @@ +void foo() {} +int main() { if(foo()); } diff --git a/tests/typing/bad/testfile-if-2.cpp b/tests/typing/bad/testfile-if-2.cpp new file mode 100644 index 0000000..fa8aa4d --- /dev/null +++ b/tests/typing/bad/testfile-if-2.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +int main() { S s; if(s); } + diff --git a/tests/typing/bad/testfile-local-1.cpp b/tests/typing/bad/testfile-local-1.cpp new file mode 100644 index 0000000..850e678 --- /dev/null +++ b/tests/typing/bad/testfile-local-1.cpp @@ -0,0 +1,2 @@ +int main() { void v; } + diff --git a/tests/typing/bad/testfile-redef-1.cpp b/tests/typing/bad/testfile-redef-1.cpp new file mode 100644 index 0000000..db8446b --- /dev/null +++ b/tests/typing/bad/testfile-redef-1.cpp @@ -0,0 +1,2 @@ +int main() {} +int main() {} diff --git a/tests/typing/bad/testfile-redef-2.cpp b/tests/typing/bad/testfile-redef-2.cpp new file mode 100644 index 0000000..4518185 --- /dev/null +++ b/tests/typing/bad/testfile-redef-2.cpp @@ -0,0 +1,4 @@ + +void f() {} +void f() {} +int main() {} diff --git a/tests/typing/bad/testfile-redef-3.cpp b/tests/typing/bad/testfile-redef-3.cpp new file mode 100644 index 0000000..5e5d141 --- /dev/null +++ b/tests/typing/bad/testfile-redef-3.cpp @@ -0,0 +1,4 @@ + +int f; +void f() {} +int main() {} diff --git a/tests/typing/bad/testfile-redef-4.cpp b/tests/typing/bad/testfile-redef-4.cpp new file mode 100644 index 0000000..fa82b3d --- /dev/null +++ b/tests/typing/bad/testfile-redef-4.cpp @@ -0,0 +1,4 @@ + +void f() {} +int f; +int main() {} diff --git a/tests/typing/bad/testfile-redef-5.cpp b/tests/typing/bad/testfile-redef-5.cpp new file mode 100644 index 0000000..503a592 --- /dev/null +++ b/tests/typing/bad/testfile-redef-5.cpp @@ -0,0 +1,2 @@ + +int main() { int x; int x; } diff --git a/tests/typing/bad/testfile-redef-6.cpp b/tests/typing/bad/testfile-redef-6.cpp new file mode 100644 index 0000000..ae81bdc --- /dev/null +++ b/tests/typing/bad/testfile-redef-6.cpp @@ -0,0 +1,3 @@ + +class S { public: int a; int a; }; +int main() {} diff --git a/tests/typing/bad/testfile-ref-1.cpp b/tests/typing/bad/testfile-ref-1.cpp new file mode 100644 index 0000000..34b913a --- /dev/null +++ b/tests/typing/bad/testfile-ref-1.cpp @@ -0,0 +1 @@ +int main() { int &x = 42; } diff --git a/tests/typing/bad/testfile-ref-2.cpp b/tests/typing/bad/testfile-ref-2.cpp new file mode 100644 index 0000000..4997202 --- /dev/null +++ b/tests/typing/bad/testfile-ref-2.cpp @@ -0,0 +1,3 @@ + +int main() { int x; int &y = &x; } + diff --git a/tests/typing/bad/testfile-return-1.cpp b/tests/typing/bad/testfile-return-1.cpp new file mode 100644 index 0000000..5eb3571 --- /dev/null +++ b/tests/typing/bad/testfile-return-1.cpp @@ -0,0 +1,3 @@ +class S { public: int a; }; +S f() { return 1; } +int main() { } diff --git a/tests/typing/bad/testfile-return-2.cpp b/tests/typing/bad/testfile-return-2.cpp new file mode 100644 index 0000000..b14902c --- /dev/null +++ b/tests/typing/bad/testfile-return-2.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +int f() { S s; return s; } +int main() { } diff --git a/tests/typing/bad/testfile-return-3.cpp b/tests/typing/bad/testfile-return-3.cpp new file mode 100644 index 0000000..f13c7a3 --- /dev/null +++ b/tests/typing/bad/testfile-return-3.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +int main() { S s; return s; } + diff --git a/tests/typing/bad/testfile-scope-1.cpp b/tests/typing/bad/testfile-scope-1.cpp new file mode 100644 index 0000000..cc6caa9 --- /dev/null +++ b/tests/typing/bad/testfile-scope-1.cpp @@ -0,0 +1 @@ +int main() { { int x; } x; } diff --git a/tests/typing/bad/testfile-scope-2.cpp b/tests/typing/bad/testfile-scope-2.cpp new file mode 100644 index 0000000..13135ba --- /dev/null +++ b/tests/typing/bad/testfile-scope-2.cpp @@ -0,0 +1,3 @@ + +int main() { int x; if(x) { int y; } else y; } + diff --git a/tests/typing/bad/testfile-undef_var-1.cpp b/tests/typing/bad/testfile-undef_var-1.cpp new file mode 100644 index 0000000..d6d1769 --- /dev/null +++ b/tests/typing/bad/testfile-undef_var-1.cpp @@ -0,0 +1 @@ +int main() { x; } diff --git a/tests/typing/bad/testfile-undef_var-2.cpp b/tests/typing/bad/testfile-undef_var-2.cpp new file mode 100644 index 0000000..03922a3 --- /dev/null +++ b/tests/typing/bad/testfile-undef_var-2.cpp @@ -0,0 +1,3 @@ + +int main() { int x; } +void n() { x; } diff --git a/tests/typing/bad/testfile-undef_var-3.cpp b/tests/typing/bad/testfile-undef_var-3.cpp new file mode 100644 index 0000000..9831eb2 --- /dev/null +++ b/tests/typing/bad/testfile-undef_var-3.cpp @@ -0,0 +1,4 @@ + +int main(int x) { } +void n() { x; } + diff --git a/tests/typing/bad/testfile-while-1.cpp b/tests/typing/bad/testfile-while-1.cpp new file mode 100644 index 0000000..1cadb41 --- /dev/null +++ b/tests/typing/bad/testfile-while-1.cpp @@ -0,0 +1,2 @@ +void foo() {} +int main() { while(foo()); } diff --git a/tests/typing/bad/testfile-while-2.cpp b/tests/typing/bad/testfile-while-2.cpp new file mode 100644 index 0000000..3814d87 --- /dev/null +++ b/tests/typing/bad/testfile-while-2.cpp @@ -0,0 +1,4 @@ + +class S { public: int a; }; +int main() { S s; while(s); } + diff --git a/tests/typing/good/testfile-subtype-1.cpp b/tests/typing/good/testfile-subtype-1.cpp new file mode 100644 index 0000000..ee18b1e --- /dev/null +++ b/tests/typing/good/testfile-subtype-1.cpp @@ -0,0 +1,5 @@ +#include +int main() { + int *s; + s = NULL; +} -- cgit v1.2.3