X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/993936c04d73e4c97d0dc0910dbbef5f2c684c15..abad11c5570b7b9bbae5ff92b3050cf68fe3fd14:/parsing_c/parser_c.mly diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 4c0c5e4..0318137 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -69,7 +69,7 @@ let addStorageD = function let addInlineD = function | ((true,ii), ({inlineD = (false,[])} as v)) -> { v with inlineD=(true,[ii])} | ((true,ii), ({inlineD = (true, ii2)} as v)) -> warning "duplicate inline" v - | _ -> raise Impossible + | _ -> raise (Impossible 86) let addTypeD = function @@ -98,8 +98,8 @@ let addTypeD = function | ((Middle3 x,ii), ({typeD = ((a,None,c),ii2)} as v)) -> {v with typeD = (a, Some x,c),ii++ii2} - | ((Right3 t,ii), ({typeD = ((a,b,Some _),ii2)} as _v)) -> - raise (Semantic ("two or more data types", fake_pi)) + | ((Right3 t,ii), ({typeD = ((a,b,Some x),ii2)} as _v)) -> + raise (Semantic ((Printf.sprintf "two or more data types: t %s ii %s\ntypeD %s ii2 %s\n" (Dumper.dump t) (Dumper.dump ii) (Dumper.dump x) (Dumper.dump ii2)), fake_pi)) | ((Right3 t,ii), ({typeD = ((a,b,None),ii2)} as v)) -> {v with typeD = (a,b, Some t),ii++ii2} @@ -231,7 +231,7 @@ let (fixOldCDecl: fullType -> fullType) = fun ty -> | BaseType Void -> ty | _ -> - pr2 ("SEMANTIC:parameter name omitted, but I continue"); + pr2_once ("SEMANTIC:parameter name omitted, but I continue"); ty ) @@ -240,7 +240,7 @@ let (fixOldCDecl: fullType -> fullType) = fun ty -> match param with | {p_namei = None} -> (* if majuscule, then certainly macro-parameter *) - pr2 ("SEMANTIC:parameter name omitted, but I continue"); + pr2_once ("SEMANTIC:parameter name omitted, but I continue"); | _ -> () )); ty @@ -400,6 +400,7 @@ let mk_string_wrap (s,info) = (s, [info]) %token <(string * Ast_c.isWchar) * Ast_c.info> TString %token TIdent +%token TKRParam %token Tconstructorname /* parsing_hack for c++ */ /*(* appears mostly after some fix_xxx in parsing_hack *)*/ %token TypedefIdent @@ -663,7 +664,7 @@ ident_extra_cpp: { CppConcatenatedName ( match $3 with - | [] -> raise Impossible + | [] -> raise (Impossible 87) | (x,concatnull)::xs -> assert(null concatnull); (mk_string_wrap $1, [])::(x,[$2])::xs @@ -768,7 +769,7 @@ new_argument: let fty = mk_ty (Array (Some $3, ty.Ast_c.p_type)) [$2;$4] in let pty = { ty with p_type = fty } in Right(ArgType pty) - | _ -> raise Impossible + | _ -> raise (Impossible 88) } unary_op: @@ -797,9 +798,9 @@ postfix_expr: /*(* gccext: also called compound literals *)*/ | topar2 type_name tcpar2 TOBrace TCBrace - { mk_e(Constructor ($2, [])) [$1;$3;$4;$5] } + { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] } | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt TCBrace - { mk_e(Constructor ($2, List.rev $5)) ([$1;$3;$4;$7] ++ $6) } + { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7]++$6))) [$1;$3] } primary_expr: @@ -981,15 +982,14 @@ iteration: | Tdo statement Twhile TOPar expr TCPar TPtVirg { DoWhile ($2,$5), [$1;$3;$4;$6;$7] } | Tfor TOPar expr_statement expr_statement TCPar statement - { For ($3,$4,(None, []),$6), [$1;$2;$5]} + { For (ForExp $3,$4,(None, []),$6), [$1;$2;$5]} | Tfor TOPar expr_statement expr_statement expr TCPar statement - { For ($3,$4,(Some $5, []),$7), [$1;$2;$6] } + { For (ForExp $3,$4,(Some $5, []),$7), [$1;$2;$6] } /*(* c++ext: for(int i = 0; i < n; i++)*)*/ - | Tfor TOPar decl expr_statement expr_opt TCPar statement - { - (* pr2 "DECL in for"; *) - MacroIteration ("toto", [], $7),[$1;$2;$6] (* TODOfake ast, TODO need decl2 ? *) - } + | Tfor TOPar decl expr_statement TCPar statement + { For (ForDecl ($3 Ast_c.LocalDecl),$4,(None, []),$6), [$1;$2;$5]} + | Tfor TOPar decl expr_statement expr TCPar statement + { For (ForDecl ($3 Ast_c.LocalDecl),$4,(Some $5, []),$7), [$1;$2;$6] } /*(* cppext: *)*/ | TMacroIterator TOPar argument_list_ne TCPar statement { MacroIteration (fst $1, $3, $5), [snd $1;$2;$4] } @@ -1219,6 +1219,14 @@ parameter_type_list: parameter_decl2: + TKRParam { + let name = RegularName (mk_string_wrap $1) in + LP.add_ident (str_of_name name); + { p_namei = Some name; + p_type = mk_ty NoType []; + p_register = (false, []); + } + } | decl_spec declaratorp { let ((returnType,hasreg),iihasreg) = fixDeclSpecForParam $1 in let (name, ftyp) = $2 in @@ -1353,6 +1361,19 @@ decl2: MacroDecl ((fst $3, $5, true), [snd $3;$4;$6;$7;fakeInfo();$1;$2])} + | TMacroDecl TOPar argument_list TCPar teq initialize TPtVirg + { function _ -> + MacroDeclInit ((fst $1, $3, $6), [snd $1;$2;$4;$5;$7;fakeInfo()]) } + | Tstatic TMacroDecl TOPar argument_list TCPar teq initialize TPtVirg + { function _ -> + MacroDeclInit ((fst $2, $4, $7),[snd $2;$3;$5;$6;$8;fakeInfo();$1]) } + | Tstatic TMacroDeclConst TMacroDecl TOPar argument_list TCPar + teq initialize TPtVirg + { function _ -> + MacroDeclInit + ((fst $3, $5, $8), [snd $3;$4;$6;$7;$9;fakeInfo();$1;$2])} + + /*(*-----------------------------------------------------------------------*)*/ decl_spec2: | storage_class_spec { {nullDecl with storageD = (fst $1, [snd $1]) } } @@ -1551,7 +1572,7 @@ field_declaration: *) } - | spec_qualif_list TPtVirg + | spec_qualif_list TPtVirg { (* gccext: allow empty elements if it is a structdef or enumdef *) let (returnType,storage) = fixDeclSpecForDecl $1 in @@ -1768,18 +1789,23 @@ define_val: DefineType typ } -/* can be in conflict with decl_spec, maybe change fixDeclSpecForMacro +/*(* can be in conflict with decl_spec, maybe change fixDeclSpecForMacro * to also allow storage ? | storage_class_spec { DefineTodo } | Tinline { DefineTodo } -*/ +*)*/ - /*(* a few special cases *)*/ - | stat_or_decl stat_or_decl_list { DefineTodo } -/* + | stat_or_decl stat_or_decl_list + { DefineMulti + (List.map + (function + StmtElem e -> e + | _ -> failwith "unexpected statement for DefineMulti") + ($1 :: $2)) } +/*(* | statement statement { DefineTodo } | decl function_definition { DefineTodo } -*/ +*)*/ @@ -2079,7 +2105,3 @@ opt_ptvirg: *)*/ -expr_opt: - | expr { Some $1 } - | /*(* empty *)*/ { None } -