diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-12-05 22:20:54 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-12-05 22:20:54 +0100 |
commit | a01d09ca4730de4987d67e73a8ee895f77f57f9c (patch) | |
tree | e9f667f874572a51988225a45ab698ce079059a9 | |
parent | 6973d36261d8030c4836a8e25a0e95c19476978e (diff) | |
download | LPC-Projet-a01d09ca4730de4987d67e73a8ee895f77f57f9c.tar.gz LPC-Projet-a01d09ca4730de4987d67e73a8ee895f77f57f9c.zip |
Added tests, corrected two failed tests.
-rw-r--r-- | src/main.ml | 8 | ||||
-rw-r--r-- | src/parser.mly | 11 | ||||
-rw-r--r-- | src/pretty_typing.ml | 60 | ||||
-rwxr-xr-x | src/test.sh | 8 | ||||
-rw-r--r-- | src/typing.ml | 7 | ||||
-rw-r--r-- | tests/syntax/good/testfile-for-1.cpp | 1 | ||||
-rw-r--r-- | tests/typing/bad/testfile-arith-3.cpp | 2 | ||||
-rw-r--r-- | tests/typing/bad/testfile-arith-4.cpp | 2 | ||||
-rw-r--r-- | tests/typing/bad/testfile-arith-5.cpp | 3 | ||||
-rw-r--r-- | tests/typing/bad/testfile-redef-6.cpp | 1 | ||||
-rw-r--r-- | tests/typing/good/testfile-subtype-1.cpp | 1 |
11 files changed, 21 insertions, 83 deletions
diff --git a/src/main.ml b/src/main.ml index 9fb4e46..35bd6e0 100644 --- a/src/main.ml +++ b/src/main.ml @@ -47,11 +47,13 @@ let () = try let p = Parser.prog Lexer.token buf in - let t = Typing.prog p in close_in f; if !dump then Pretty.print_prog p; - if !dumpt then Pretty_typing.print_prog t; + if not !parse_only then begin + let t = Typing.prog p in + if !dumpt then Pretty_typing.print_prog t; + end with | Lexer.Lexing_error s -> localisation (Lexing.lexeme_start_p buf); @@ -63,7 +65,7 @@ let () = exit 1 | Typing.Error (loc, msg) -> localisation2 loc; - eprintf "%s" msg; + eprintf "%s@." msg; exit 1 | _ -> diff --git a/src/parser.mly b/src/parser.mly index 39fdf7d..a079886 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -109,12 +109,13 @@ member: ; cls_proto: -| ident = typed_var +| ident = typed_qvar LPAREN args = separated_list(COMMA, typed_var) RPAREN - { { - p_ret_type = Some(fst ident); - p_name = snd ident; - p_class = None; + { + let (vt, vc, vn) = ident in { + p_ret_type = Some(vt); + p_name = vn; + p_class = vc; p_args = args; p_loc = $startpos, $endpos } } | cls = TIDENT diff --git a/src/pretty_typing.ml b/src/pretty_typing.ml index 371b210..709611b 100644 --- a/src/pretty_typing.ml +++ b/src/pretty_typing.ml @@ -9,66 +9,6 @@ open Parser open Typing open Ast -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^"'" - | TIDENT(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 -> "}" - | COMMA -> "," - | COLON -> ":" - (* DATAZ *) - | INTVAL(i) -> "#" ^ (string_of_int i) - | STRVAL(s) -> "`" ^ s ^ "`" - (* STUPIDITIEZS *) - | STD_COUT -> "std::cout" - | INCLUDE_IOSTREAM -> "#include <iostream>" - | EOF -> "end." - -let print_tok t = - print_string ((token_str t) ^ "\n") - let csl f l = List.fold_left (fun x t -> (if x = "" then "" else x ^ ", ") ^ (f t)) "" l diff --git a/src/test.sh b/src/test.sh index fc241bf..603b404 100755 --- a/src/test.sh +++ b/src/test.sh @@ -4,14 +4,14 @@ echo "Testing SYNTAX/" for a in ../tests/syntax/good/*.cpp; do - if ./main.byte -parse-only $a; + if ./main.byte --parse-only $a; then echo "OK $a"; else echo "FAIL $a"; fi; done; for a in ../tests/syntax/bad/*.cpp; do - if ./main.byte -parse-only $a 2> /dev/null; + if ./main.byte --parse-only $a 2> /dev/null; then echo "FAIL $a"; else echo "OK $a"; fi; @@ -20,7 +20,7 @@ done; echo "---" echo "Testing TYPING/ only against parsing" for a in ../tests/typing/*/*.cpp; do - if ./main.byte -parse-only $a; + if ./main.byte --parse-only $a; then echo "OK $a"; else echo "FAIL $a"; fi; @@ -29,7 +29,7 @@ done; echo "---" echo "Testing EXEC/ only against parsing" for a in ../tests/exec/*.cpp; do - if ./main.byte -parse-only $a; + if ./main.byte --parse-only $a; then echo "OK $a"; else echo "FAIL $a"; fi; diff --git a/src/typing.ml b/src/typing.ml index 1a5e566..4d5b0c2 100644 --- a/src/typing.ml +++ b/src/typing.ml @@ -29,7 +29,7 @@ and texpr_desc = | TEIdent of ident | TEAssign of texpression * texpression | TECallFun of ident * texpression list (* changé : te -> ident *) -(* | TECallMeth of texpression * ident * texpression list *) (* changé : te -> ident *) +(* | TECallMethod of texpression * ident * texpression list *) (* changé : te -> ident *) | TEUnary of unop * texpression | TEBinary of texpression * binop * texpression | TEMember of texpression * ident @@ -67,11 +67,6 @@ and ts_desc = | TSWriteCout of tstr_expression list and tblock = tstatement list -(*and fun_type = { - f_args : type_ref list; - f_block : tblock; } -peut être effacé *) - and tproto = { tp_loc : loc; tp_name : ident; diff --git a/tests/syntax/good/testfile-for-1.cpp b/tests/syntax/good/testfile-for-1.cpp index 71f985d..170e303 100644 --- a/tests/syntax/good/testfile-for-1.cpp +++ b/tests/syntax/good/testfile-for-1.cpp @@ -1,2 +1 @@ int main() { for(;;); } - diff --git a/tests/typing/bad/testfile-arith-3.cpp b/tests/typing/bad/testfile-arith-3.cpp index ec4f877..9418b15 100644 --- a/tests/typing/bad/testfile-arith-3.cpp +++ b/tests/typing/bad/testfile-arith-3.cpp @@ -1,2 +1,2 @@ -int main() { char *p; p+p; } +int main() { int *p; p+p; } diff --git a/tests/typing/bad/testfile-arith-4.cpp b/tests/typing/bad/testfile-arith-4.cpp index f9ca567..fbb7e9a 100644 --- a/tests/typing/bad/testfile-arith-4.cpp +++ b/tests/typing/bad/testfile-arith-4.cpp @@ -1,3 +1,3 @@ class S { public: int a; }; -int main() { S s; char *p; p+s; } +int main() { S s; int *p; p+s; } diff --git a/tests/typing/bad/testfile-arith-5.cpp b/tests/typing/bad/testfile-arith-5.cpp index 2637ffc..f17d496 100644 --- a/tests/typing/bad/testfile-arith-5.cpp +++ b/tests/typing/bad/testfile-arith-5.cpp @@ -1,2 +1,3 @@ -int main() { char *p; 1-p; } +int main() { int *p; 1-p; } + diff --git a/tests/typing/bad/testfile-redef-6.cpp b/tests/typing/bad/testfile-redef-6.cpp index ae81bdc..32b0dfd 100644 --- a/tests/typing/bad/testfile-redef-6.cpp +++ b/tests/typing/bad/testfile-redef-6.cpp @@ -1,3 +1,2 @@ class S { public: int a; int a; }; -int main() {} diff --git a/tests/typing/good/testfile-subtype-1.cpp b/tests/typing/good/testfile-subtype-1.cpp index ee18b1e..67647d0 100644 --- a/tests/typing/good/testfile-subtype-1.cpp +++ b/tests/typing/good/testfile-subtype-1.cpp @@ -3,3 +3,4 @@ int main() { int *s; s = NULL; } + |