From f6b0c4a078929406eed19853fafe6b8d39e20dd7 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Sat, 14 May 2022 22:17:29 +0530 Subject: [PATCH 01/24] Added `new (type) (initializer)` and branched all_basic_types in parser_cocci_menhir.mly into all_basic_types and all_basic_types_without_braces Signed-off-by : Tathagata Roy --- ocaml/coccilib.mli | 4 + parsing_cocci/arity.ml | 11 ++ parsing_cocci/ast0_cocci.ml | 3 + parsing_cocci/ast0_cocci.mli | 5 +- parsing_cocci/ast0toast.ml | 10 ++ parsing_cocci/ast_cocci.ml | 2 + parsing_cocci/ast_cocci.mli | 3 + parsing_cocci/check_meta.ml | 3 + parsing_cocci/compute_lines.ml | 9 ++ parsing_cocci/context_neg.ml | 3 + parsing_cocci/disjdistr.ml | 4 + parsing_cocci/get_constants.ml | 2 + parsing_cocci/get_constants2.ml | 1 + parsing_cocci/index.ml | 5 +- parsing_cocci/iso_pattern.ml | 6 ++ parsing_cocci/menhir_output | 2 + parsing_cocci/parse_cocci.ml | 12 ++- parsing_cocci/parser_cocci_menhir.conflicts | 114 ++++++++++++++++++++ parsing_cocci/parser_cocci_menhir.mly | 99 +++++++++++++---- parsing_cocci/pretty_print_cocci.ml | 10 ++ parsing_cocci/single_statement.ml | 1 + parsing_cocci/type_infer.ml | 1 + parsing_cocci/unify_ast.ml | 3 + parsing_cocci/unparse_ast0.ml | 10 ++ parsing_cocci/visitor_ast.ml | 18 ++++ parsing_cocci/visitor_ast0.ml | 9 ++ 26 files changed, 319 insertions(+), 31 deletions(-) create mode 100644 parsing_cocci/menhir_output create mode 100644 parsing_cocci/parser_cocci_menhir.conflicts diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 36f2fe5b..cea8a343 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -2613,6 +2613,8 @@ module Ast_cocci : | Cast of string mcode * fullType * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * fullType * string mcode + | NewPar of string mcode * string mcode * fullType * string mcode * string mcode * expression dots * + string mcode | TypeExp of fullType | Paren of string mcode * expression * string mcode | Constructor of string mcode * fullType * string mcode * initialiser @@ -3363,6 +3365,8 @@ module Ast0_cocci : | Cast of string mcode * typeC * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * typeC * string mcode + | NewPar of string mcode * string mcode * typeC * string mcode * string mcode * expression dots * + string mcode | TypeExp of typeC | Constructor of string mcode * typeC * string mcode * initialiser | MetaErr of Ast_cocci.meta_name mcode * constraints * pure diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 8113c3f3..936c4155 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -276,6 +276,17 @@ let rec top_expression opt_allowed tgt expr = let ty = typeC arity ty in let rp = mcode rp in make_exp expr tgt arity (Ast0.SizeOfType(szf,lp,ty,rp)) + | Ast0.NewPar(nw,lp,ty,rp,lpb,exp,rpb) -> + let arity = + exp_same (mcode2line nw) (List.map mcode2arity [nw;lp;rp;lpb;rpb]) in + let nw = mcode nw in + let lp = mcode lp in + let ty = typeC arity ty in + let rp = mcode rp in + let lpb = mcode lpb in + let exp = dots (expression arity) exp in + let rpb = mcode rpb in + make_exp expr tgt arity (Ast0.NewPar(nw,lp,ty,rp,lpb,exp,rpb)) | Ast0.TypeExp(ty) -> Ast0.rewrap expr (Ast0.TypeExp(typeC tgt ty)) | Ast0.MetaErr(name,constraints,pure) -> let arity = exp_same (mcode2line name) [mcode2arity name] in diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 8b773328..71d7ec54 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -128,6 +128,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * typeC * string mcode (* ) *) + | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * + string mcode (* ) *) * string mcode (* (|{ *) * expression dots * + string mcode (* )|} *) | TypeExp of typeC (* type name used as an expression, only in args *) | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index a852ffc5..d22577bc 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -118,7 +118,10 @@ and base_expression = string mcode (* ) *) * expression | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * - typeC * string mcode (* ) *) + typeC * string mcode (* ) *) + | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * + string mcode (* ) *) * string mcode (* (|{ *) * expression dots * + string mcode (* )|} *) | TypeExp of typeC | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index c9915fa7..8bb9a785 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -448,6 +448,16 @@ and expression e = | Ast0.SizeOfType(szf,lp,ty,rp) -> let allminus = check_allminus.VT0.combiner_rec_expression e in Ast.SizeOfType(mcode szf, mcode lp,typeC allminus ty,mcode rp) + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + let allminus = check_allminus.VT0.combiner_rec_expression e in + let nw = mcode nw in + let lp = mcode lp in + let ty = typeC allminus ty in + let rp = mcode rp in + let lpb = mcode lpb in + let expr = dots expression expr in + let rpb = mcode rpb in + Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) | Ast0.TypeExp(ty) -> let allminus = check_allminus.VT0.combiner_rec_expression e in Ast.TypeExp(typeC allminus ty) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index 9af4aedc..d188af13 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -200,6 +200,8 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * string mcode (* ) *) + | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * string mcode (* ) *) * + string mcode (* (|{ *) * expression dots * string mcode (* )|} *) | TypeExp of fullType (*type name used as an expression, only in arg or #define*) diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 97e424c6..bfb8745f 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -185,6 +185,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * string mcode (* ) *) + | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * + string mcode (* ) *) * string mcode (* (|{ *) * expression dots * + string mcode (* )|} *) | TypeExp of fullType | Paren of string mcode (* ( *) * expression * diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 8179b7d3..445fd745 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -202,6 +202,9 @@ and expression context old_metas table minus e = expression ID old_metas table minus exp | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + typeC old_metas table minus ty; + dots (expression ID old_metas table minus) expr | Ast0.TypeExp(ty) -> typeC old_metas table minus ty | Ast0.Constructor(lp,ty,rp,init) -> typeC old_metas table minus ty; initialiser old_metas table minus init diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 5204258b..a52b1c75 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -441,6 +441,15 @@ let rec expression e = let rp = normal_mcode rp in mkres e (Ast0.SizeOfType(szf,lp,typeC ty,rp)) (promote_mcode szf) (promote_mcode rp) + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + let nw = normal_mcode nw in + let lp = normal_mcode lp in + let rp = normal_mcode rp in + let lpb = normal_mcode lpb in + let expr = dots is_exp_dots (Some(promote_mcode lpb)) expression expr in + let rpb = normal_mcode rpb in + mkres e (Ast0.NewPar(nw,lp,typeC ty,rp,lpb,expr,rpb)) (promote_mcode nw) + (promote_mcode rpb) | Ast0.TypeExp(ty) -> let ty = typeC ty in mkres e (Ast0.TypeExp(ty)) ty ty | Ast0.Constructor(lp,ty,rp,init) -> diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index 81453bed..206094c8 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -682,6 +682,9 @@ let rec equal_expression e1 e2 = equal_mcode szf1 szf2 | (Ast0.SizeOfType(szf1,lp1,_,rp1),Ast0.SizeOfType(szf2,lp2,_,rp2)) -> equal_mcode szf1 szf2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 + | (Ast0.NewPar(new1,lp1,_,rp1,lpb1,_,rpb1), Ast0.NewPar(new2,lp2,_,rp2,lpb2,_,rpb2)) -> + equal_mcode new1 new2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && + equal_mcode lpb1 lpb2 && equal_mcode rpb1 rpb2 | (Ast0.TypeExp(_),Ast0.TypeExp(_)) -> true | (Ast0.Constructor(lp1,_,rp1,_),Ast0.Constructor(lp2,_,rp2,_)) -> equal_mcode lp1 lp2 && equal_mcode rp1 rp2 diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index b30f19af..f3a72e89 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -230,6 +230,10 @@ and disjexp e = let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.SizeOfType(szf,lp,ty,rp))) ty + | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + disjmult2 (disjty ty) (disjdots disjexp expr) + (function ty -> function exp -> + Ast.rewrap e (Ast.NewPar(nw,lp,ty,rp,lpb,exp,rpb))) | Ast.TypeExp(ty) -> let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.TypeExp(ty))) ty diff --git a/parsing_cocci/get_constants.ml b/parsing_cocci/get_constants.ml index ebab2487..94b2c27c 100644 --- a/parsing_cocci/get_constants.ml +++ b/parsing_cocci/get_constants.ml @@ -53,6 +53,8 @@ let get_minus_constants bind orbind = (r.V.combiner_expression exp) | Ast.SizeOfExpr(sizeof,_) | Ast.SizeOfType(sizeof,_,_,_) -> bind (k e) [Ast.unwrap_mcode sizeof] + | Ast.NewPar(new,_,_,_,_,_,_) -> + bind (k e) [Ast.unwrap_mcode new] | Ast.DisjExpr(exps) -> disj_union_all (List.map r.V.combiner_expression exps) | Ast.Edots(_,_) | Ast.Ecircles(_,_) | Ast.Estars(_,_) -> [] diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index 39ddbd1e..dfd5bc7a 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -489,6 +489,7 @@ let do_get_constants constants keywords env (neg_pos,_) = | Ast.MetaExprList(name,_,_,_,_) -> minherited name | Ast.SizeOfExpr(sizeof,exp) -> bind (keywords "sizeof") (k e) | Ast.SizeOfType(sizeof,lp,ty,rp) -> bind (keywords "sizeof") (k e) + | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> bind (keywords "new") (k e) | Ast.NestExpr(starter,expr_dots,ender,wc,false) -> option_default | Ast.NestExpr(starter,expr_dots,ender,wc,true) -> r.V.combiner_expression_dots expr_dots diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index abff93d1..068e3b0d 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -5,8 +5,8 @@ *) (* create an index for each constructor *) -(* current max is 193, also unused: 8-9, 15, 42, 46, 57, 65, 85-86, - 113-115 *) +(* current max is 193, also unused: 8-9, 15, 42, 46, 57, +*) (* doesn't really work - requires that identical terms with no token subterms (eg dots) not appear on the same line *) @@ -64,6 +64,7 @@ let expression e = | Ast0.Cast(lp,ty,attr,rp,exp) -> [30] | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *) | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *) + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> [65] | Ast0.TypeExp(ty) -> [123] (* added after *) | Ast0.Constructor(lp,ty,rp,init) -> [155] | Ast0.MetaErr(name,_,_) -> [32] diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index f0a514f2..6d3990b7 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -782,6 +782,12 @@ let match_maker checks_needed context_required whencode_allowed = conjunct_many_bindings [check_mcode lp1 lp; check_mcode rp1 rp; check_mcode szf1 szf; match_typeC tya tyb] + | (Ast0.NewPar(nw1,lp1,ty1,rp1,lpb1,expr1,rpb1), + Ast0.NewPar(nw2,lp2,ty2,rp2,lpb2,expr2,rpb2)) -> + conjunct_many_bindings + [check_mcode lp1 lp2; check_mcode rp1 rp2; check_mcode nw1 nw2; + match_typeC ty1 ty2; check_mcode lpb1 lpb2; check_mcode rpb1 rpb2; + match_dots match_expr is_elist_matcher do_elist_match expr1 expr2] | (Ast0.Constructor(lp1,tya,rp1,inita), Ast0.Constructor(lp,tyb,rp,initb)) -> conjunct_many_bindings diff --git a/parsing_cocci/menhir_output b/parsing_cocci/menhir_output new file mode 100644 index 00000000..4e6d37e3 --- /dev/null +++ b/parsing_cocci/menhir_output @@ -0,0 +1,2 @@ +File "parser_cocci_menhir.mly", line 238, characters 7-15: +Error: Unbound module Data diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index dbbca37c..b2aa431b 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -178,7 +178,8 @@ let token2c (tok,_) add_clt = | PC.TSizeof(clt) -> add_clt "sizeof" clt | PC.TTypeof(clt) -> add_clt "typeof" clt - + | PC.TNew(clt) -> add_clt "new" clt + | PC.TString(x,_,clt) -> add_clt (Printf.sprintf "\"%s\"" x) clt | PC.TChar(x,_,clt) -> add_clt x clt | PC.TFloat(x,clt) -> add_clt x clt @@ -352,7 +353,7 @@ let plus_attachable only_plus (tok,_) = | PC.TSymId(_,clt) | PC.TTypeId(_,clt) | PC.TDeclarerId(_,clt) | PC.TIteratorId(_,clt) - | PC.TSizeof(clt) | PC.TTypeof(clt) + | PC.TSizeof(clt) | PC.TTypeof(clt) | PC.TNew(clt) | PC.TString(_,_,clt) | PC.TChar(_,_,clt) | PC.TFloat(_,clt) | PC.TInt(_,clt) | PC.TDecimalCst(_,_,_,clt) @@ -442,7 +443,7 @@ let get_clt (tok,_) = | PC.TTypeId(_,clt) | PC.TSymId(_,clt) | PC.TDeclarerId(_,clt) | PC.TIteratorId(_,clt) - | PC.TSizeof(clt) | PC.TTypeof(clt) + | PC.TSizeof(clt) | PC.TTypeof(clt) | PC.TNew(clt) | PC.TString(_,_,clt) | PC.TChar(_,_,clt) | PC.TFloat(_,clt) | PC.TInt(_,clt) | PC.TDecimalCst(_,_,_,clt) @@ -637,6 +638,7 @@ let update_clt (tok,x) clt = | PC.TSizeof(_) -> (PC.TSizeof(clt),x) | PC.TTypeof(_) -> (PC.TTypeof(clt),x) + | PC.TNew(_) -> (PC.TNew(clt),x) | PC.TString(s,sz,_) -> (PC.TString(s,sz,clt),x) | PC.TChar(s,sz,_) -> (PC.TChar(s,sz,clt),x) @@ -919,7 +921,7 @@ let split_token ((tok,_) as t) = | PC.TIf(clt) | PC.TElse(clt) | PC.TWhile(clt) | PC.TFor(clt) | PC.TDo(clt) | PC.TSwitch(clt) | PC.TCase(clt) | PC.TDefault(clt) - | PC.TSizeof(clt) | PC.TTypeof(clt) + | PC.TSizeof(clt) | PC.TTypeof(clt) | PC.TNew(clt) | PC.TReturn(clt) | PC.TBreak(clt) | PC.TContinue(clt) | PC.TGoto(clt) | PC.TIdent(_,clt) | PC.TTypeId(_,clt) | PC.TDeclarerId(_,clt) | PC.TIteratorId(_,clt) @@ -1345,7 +1347,7 @@ let token2line (tok,_) = | PC.TIf(clt) | PC.TElse(clt) | PC.TWhile(clt) | PC.TFor(clt) | PC.TDo(clt) | PC.TSwitch (clt) | PC.TCase (clt) | PC.TDefault (clt) - | PC.TSizeof (clt) | PC.TTypeof (clt) + | PC.TSizeof (clt) | PC.TTypeof (clt) | PC.TNew(clt) | PC.TReturn(clt) | PC.TBreak(clt) | PC.TContinue(clt) | PC.TGoto(clt) | PC.TIdent(_,clt) | PC.TTypeId(_,clt) | PC.TDeclarerId(_,clt) | PC.TIteratorId(_,clt) diff --git a/parsing_cocci/parser_cocci_menhir.conflicts b/parsing_cocci/parser_cocci_menhir.conflicts new file mode 100644 index 00000000..0c89c8a2 --- /dev/null +++ b/parsing_cocci/parser_cocci_menhir.conflicts @@ -0,0 +1,114 @@ + +** Conflict (shift/reduce) in state 905. +** Token involved: TOBrace +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew struct_or_union type_ident + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + unary_expr(expr,invalid) TOpAssign assign_expr_bis + (?) + +** In state 905, looking ahead at TOBrace, reducing production +** non_signable_types_no_ident -> struct_or_union type_ident +** is permitted because of the following sub-derivation: + +TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace + all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish + non_signable_types // lookahead token is inherited + non_signable_types_no_ident // lookahead token is inherited + struct_or_union type_ident . + +** In state 905, looking ahead at TOBrace, shifting is permitted +** because of the following sub-derivation: + +TNew ctype cpp_initialiser + all_basic_types list(mul) + non_signable_types + non_signable_types_no_ident + struct_or_union type_ident . TOBrace struct_decl_list TCBrace + +** Conflict (shift/reduce) in state 142. +** Token involved: TOBrace +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew TMetaType + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + unary_expr(expr,invalid) TOpAssign assign_expr_bis + (?) + +** In state 142, looking ahead at TOBrace, shifting is permitted +** because of the following sub-derivation: + +TNew ctype cpp_initialiser + all_basic_types list(mul) + non_signable_types + non_signable_types_no_ident + TMetaType . TOBrace struct_decl_list TCBrace + +** In state 142, looking ahead at TOBrace, reducing production +** signable_types_no_ident -> TMetaType +** is permitted because of the following sub-derivation: + +TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace + all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish + signable_types // lookahead token is inherited + signable_types_no_ident // lookahead token is inherited + TMetaType . + +** Conflict (shift/reduce) in state 108. +** Token involved: TOBrace +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew Tenum ident + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + unary_expr(expr,invalid) TOpAssign assign_expr_bis + (?) + +** In state 108, looking ahead at TOBrace, reducing production +** non_signable_types_no_ident -> Tenum ident +** is permitted because of the following sub-derivation: + +TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace + all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish + non_signable_types // lookahead token is inherited + non_signable_types_no_ident // lookahead token is inherited + Tenum ident . + +** In state 108, looking ahead at TOBrace, shifting is permitted +** because of the following sub-derivation: + +TNew ctype cpp_initialiser + all_basic_types list(mul) + non_signable_types + non_signable_types_no_ident + Tenum ident . TOBrace enum_decl_list TCBrace diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 0148113c..d32e7205 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -240,7 +240,7 @@ let inline_id aft = function %token TVAEllipsis %token TIf TElse TWhile TFor TDo TSwitch TCase TDefault TReturn -%token TBreak TContinue TGoto TSizeof TTypeof TFunDecl TFunProto +%token TBreak TContinue TGoto TSizeof TTypeof TFunDecl TFunProto TNew %token Tdecimal Texec %token TIdent TTypeId TDeclarerId TIteratorId TSymId %token TDirective @@ -967,7 +967,25 @@ signable_types: Ast0_cocci.wrap(Ast0_cocci.MetaType(Parse_aux.clt2mcode nm (Parse_aux.id2clt p),Ast_cocci.CstrTrue, Ast0_cocci.Impure (*will be ignored*))) } -non_signable_types_no_ident: +non_signable_types_no_ident_with_braces: + s=Tenum i=ioption(ident) l=TOBrace ids=enum_decl_list r=TCBrace + { (if i = None && !Data.in_iso + then failwith "enums must be named in the iso file"); + Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, i)), + Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } + | s=struct_or_union i=ioption(type_ident) + l=TOBrace d=struct_decl_list r=TCBrace + { (if i = None && !Data.in_iso + then failwith "structures must be named in the iso file"); + Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, i)), + Parse_aux.clt2mcode "{" l, + d, Parse_aux.clt2mcode "}" r)) } + | s=TMetaType l=TOBrace d=struct_decl_list r=TCBrace + { let (nm,cstr,pure,clt) = s in + let ty = Ast0_cocci.wrap(Ast0_cocci.MetaType(Parse_aux.clt2mcode nm clt,cstr,pure)) in + Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(ty,Parse_aux.clt2mcode "{" l,d,Parse_aux.clt2mcode "}" r)) } + +non_signable_types_no_ident_without_braces: ty=Tvoid { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.VoidType,[Parse_aux.clt2mcode "void" ty])) } | ty1=Tlong ty2=Tdouble @@ -1003,24 +1021,8 @@ non_signable_types_no_ident: { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.PtrDiffType,[Parse_aux.clt2mcode "ptrdiff_t" ty])) } | s=Tenum i=ident { Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, Some i)) } -| s=Tenum i=ioption(ident) l=TOBrace ids=enum_decl_list r=TCBrace - { (if i = None && !Data.in_iso - then failwith "enums must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, i)), - Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } | s=struct_or_union i=type_ident // allow typedef name { Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, Some i)) } -| s=struct_or_union i=ioption(type_ident) - l=TOBrace d=struct_decl_list r=TCBrace - { (if i = None && !Data.in_iso - then failwith "structures must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, i)), - Parse_aux.clt2mcode "{" l, - d, Parse_aux.clt2mcode "}" r)) } -| s=TMetaType l=TOBrace d=struct_decl_list r=TCBrace - { let (nm,cstr,pure,clt) = s in - let ty = Ast0_cocci.wrap(Ast0_cocci.MetaType(Parse_aux.clt2mcode nm clt,cstr,pure)) in - Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(ty,Parse_aux.clt2mcode "{" l,d,Parse_aux.clt2mcode "}" r)) } | Tdecimal TOPar enum_val TComma enum_val TCPar { Ast0_cocci.wrap(Ast0_cocci.Decimal(Parse_aux.clt2mcode "decimal" $1, Parse_aux.clt2mcode "(" $2,$3, @@ -1054,8 +1056,14 @@ non_signable_types_no_ident: (Semantic_cocci.Semantic "auto is not a valid C type, try using the --c++ option") } +non_signable_types_without_braces: + ty=non_signable_types_no_ident_without_braces { ty } +| p=TTypeId + { Ast0_cocci.wrap(Ast0_cocci.TypeName(Parse_aux.id2mcode p)) } + non_signable_types: - ty=non_signable_types_no_ident { ty } + ty=non_signable_types_no_ident_without_braces { ty } +| ty=non_signable_types_no_ident_with_braces { ty } | p=TTypeId { Ast0_cocci.wrap(Ast0_cocci.TypeName(Parse_aux.id2mcode p)) } @@ -1065,6 +1073,11 @@ signed_basic_types: | r=Tunsigned ty=signable_types { Ast0_cocci.wrap(Ast0_cocci.Signed(Parse_aux.clt2mcode Ast_cocci.Unsigned r,Some ty)) } +all_basic_types_without_braces: + ty=signed_basic_types { ty } +| ty=signable_types { ty } +| ty=non_signable_types_without_braces { ty } + all_basic_types: ty=signed_basic_types { ty } | ty=signable_types { ty } @@ -1082,6 +1095,28 @@ signed_or_unsigned: top_ctype: ctype { Ast0_cocci.wrap(Ast0_cocci.OTHER(Ast0_cocci.wrap(Ast0_cocci.Ty($1)))) } +ctype_without_braces: + cv1=ioption(const_vol) ty=all_basic_types_without_braces cv2=ioption(const_vol) m=list(mul) +| cv1=ioption(const_vol) ty=signed_or_unsigned cv2=ioption(const_vol) m=list(mul) + { let cv = match cv1,cv2 with + None, None -> None + | Some _, Some _ -> raise (Semantic_cocci.Semantic "duplicate const/volatile") + | Some x, None -> Some x + | None, Some x -> Some x in + List.fold_left + (function prev -> + function (star,cv) -> + Parse_aux.make_cv cv (Parse_aux.pointerify prev [star])) + (Parse_aux.make_cv cv ty) m } +| lp=TOPar0 t=midzero_list(ctype,ctype) rp=TCPar0 + { let (mids,code) = t in + Ast0_cocci.wrap + (Ast0_cocci.DisjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } +| lp=TOPar0 t=andzero_list(ctype,ctype) rp=TCPar0 + { let (mids,code) = t in + Ast0_cocci.wrap + (Ast0_cocci.ConjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } + ctype: cv1=ioption(const_vol) ty=all_basic_types cv2=ioption(const_vol) m=list(mul) | cv1=ioption(const_vol) ty=signed_or_unsigned cv2=ioption(const_vol) m=list(mul) @@ -2245,8 +2280,20 @@ unary_expr(r,pe): { Ast0_cocci.wrap(Ast0_cocci.SizeOfExpr (Parse_aux.clt2mcode "sizeof" $1, $2)) } | s=TSizeof lp=TOPar t=ctype rp=TCPar { Ast0_cocci.wrap(Ast0_cocci.SizeOfType (Parse_aux.clt2mcode "sizeof" s, - Parse_aux.clt2mcode "(" lp,t, - Parse_aux.clt2mcode ")" rp)) } + Parse_aux.clt2mcode "(" lp,t, + Parse_aux.clt2mcode ")" rp)) } + | n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser + { let (lpb2, args, rpb2) = args in + Ast0_cocci.wrap(Ast0_cocci.NewPar ( Parse_aux.clt2mcode "new" n, + Parse_aux.clt2mcode "(" lp1, t, Parse_aux.clt2mcode ")" rp1, + lpb2, args, rpb2)) } + | n=TNew t=ctype_without_braces args=cpp_initialiser + { let (lpb2, args, rpb2) = args in + Ast0_cocci.wrap(Ast0_cocci.NewNoPar ( Parse_aux.clt2mcode "new" n, t, lpb2, args, rpb2)) } + +cpp_initialiser: + lp=TOPar args=eexpr_list_option rp=TCPar { (Parse_aux.clt2mcode "(" lp, args, Parse_aux.clt2mcode ")" rp) } + | lb=TOBrace args=eexpr_list_option rb=TCBrace { (Parse_aux.clt2mcode "{" lb, args, Parse_aux.clt2mcode "}" rb) } // version that allows dots unary_expr_bis: @@ -2261,8 +2308,13 @@ unary_expr_bis: { Ast0_cocci.wrap(Ast0_cocci.SizeOfExpr (Parse_aux.clt2mcode "sizeof" $1, $2)) } | s=TSizeof lp=TOPar t=ctype rp=TCPar { Ast0_cocci.wrap(Ast0_cocci.SizeOfType (Parse_aux.clt2mcode "sizeof" s, - Parse_aux.clt2mcode "(" lp,t, - Parse_aux.clt2mcode ")" rp)) } + Parse_aux.clt2mcode "(" lp,t, + Parse_aux.clt2mcode ")" rp)) } + | n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser + { let (lpb2, args, rpb2) = args in + Ast0_cocci.wrap(Ast0_cocci.NewPar ( Parse_aux.clt2mcode "new" n, + Parse_aux.clt2mcode "(" lp1, t, Parse_aux.clt2mcode ")" rp1, + lpb2, args, rpb2)) } unary_op: TAnd { Parse_aux.clt2mcode Ast_cocci.GetRef $1 } | TMul { Parse_aux.clt2mcode Ast_cocci.DeRef $1 } @@ -3408,6 +3460,7 @@ anything: /* used for script code */ | TContinue { "continue" } | TGoto { "goto" } | TSizeof { "sizeof" } + | TNew { "new" } | Tdecimal { "decimal" } | Texec { "EXEC" } | TIdent { fst $1 } diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index cdab9706..fac20f56 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -259,6 +259,16 @@ let rec expression e = mcode print_string sizeof; mcode print_string_box lp; fullType ty; close_box(); mcode print_string rp + | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + mcode print_string nw; + print_string " "; + mcode print_string lp; + fullType ty; + mcode print_string rp; + print_string " "; + mcode print_string lpb; + dots (function _ -> ()) expression expr; + mcode print_string rpb | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; fullType ty; close_box(); diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 4c1ae0c5..5feb13c4 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -141,6 +141,7 @@ let rec left_expression e = | Ast0.Cast(lp,ty,attr,rp,exp) -> modif_before_mcode lp | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> modif_before_mcode nw | Ast0.TypeExp(ty) -> left_typeC ty | Ast0.Constructor(lp,ty,rp,init) -> modif_before_mcode lp | Ast0.MetaErr(name,_,_) -> modif_before_mcode name diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml index d20d963b..51bf4219 100644 --- a/parsing_cocci/type_infer.ml +++ b/parsing_cocci/type_infer.ml @@ -294,6 +294,7 @@ let rec propagate_types env = | Ast0.Cast(lp,ty,attr,rp,exp) -> Some ty | Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type) | Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type) + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> Some ty | Ast0.TypeExp(ty) -> None | Ast0.Constructor(lp,ty,rp,init) -> Some ty | Ast0.MetaErr(name,_,_) -> None diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 28650a0c..7a02ffce 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -229,6 +229,9 @@ and unify_expression e1 e2 = unify_expression e1 e2 | (Ast.SizeOfType(szf1,lp1,ty1,rp1),Ast.SizeOfType(szf2,lp2,ty2,rp2)) -> unify_fullType ty1 ty2 + | (Ast.NewPar(new1,lp1,ty1,rp1,lpb1,expr1,rpb1), Ast.NewPar(new2,lp2,ty2,rp2,lpb2,expr2,rpb2)) -> + unify_fullType ty1 ty2 && + unify_dots unify_expression edots expr1 expr2 | (Ast.TypeExp(ty1),Ast.TypeExp(ty2)) -> unify_fullType ty1 ty2 | (Ast.Constructor(lp1,ty1,rp1,i1),Ast.Constructor(lp2,ty2,rp2,i2)) -> unify_fullType ty1 ty2 && unify_initialiser i1 i2 diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index 3075832e..66bdd00b 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -231,6 +231,16 @@ let rec expression e = mcode print_string szf; mcode print_string_box lp; typeC ty; close_box(); mcode print_string rp + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + mcode print_string nw; + print_string " "; + mcode print_string lp; + typeC ty; + mcode print_string rp; + print_string " "; + mcode print_string lpb; + expression_dots expr; + mcode print_string rpb | Ast0.TypeExp(ty) -> typeC ty | Ast0.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; typeC ty; close_box(); diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index d9a49971..9f0c8964 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -217,6 +217,15 @@ let combiner bind option_default let lty = fullType ty in let lrp = string_mcode rp in multibind [lszf; llp; lty; lrp] + | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + let lnw = string_mcode nw in + let llp = string_mcode lp in + let lty = fullType ty in + let lrp = string_mcode rp in + let llpb = string_mcode lpb in + let lexpr = expression_dots expr in + let lrpb = string_mcode rpb in + multibind [lnw; llp; lty; lrp; llpb; lexpr; lrpb] | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in @@ -1254,6 +1263,15 @@ let rebuilder let lty = fullType ty in let lrp = string_mcode rp in Ast.SizeOfType(lszf, llp, lty, lrp) + | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + let lnw = string_mcode nw in + let llp = string_mcode lp in + let lty = fullType ty in + let lrp = string_mcode rp in + let llpb = string_mcode lpb in + let lexpr = expression_dots expr in + let lrpb = string_mcode rpb in + Ast.NewPar(lnw,llp,lty,lrp,llpb,lexpr,lrpb) | Ast.TypeExp(ty) -> Ast.TypeExp(fullType ty) | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index 89a0f63b..13252225 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -202,6 +202,15 @@ let visitor mode bind option_default let (ty_n,ty) = typeC ty in let (rp_n,rp) = string_mcode rp in (multibind [szf_n;lp_n;ty_n;rp_n], Ast0.SizeOfType(szf,lp,ty,rp)) + | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + let (nw_n,nw) = string_mcode nw in + let (lp_n,lp) = string_mcode lp in + let (ty_n,ty) = typeC ty in + let (rp_n,rp) = string_mcode rp in + let (lpb_n,lpb) = string_mcode lpb in + let (expr_n,expr) = expression_dots expr in + let (rpb_n,rpb) = string_mcode rpb in + (multibind [nw_n;lp_n;ty_n;rp_n;lpb_n;expr_n;rpb_n], Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb)) | Ast0.TypeExp(ty) -> let (ty_n,ty) = typeC ty in (ty_n,Ast0.TypeExp(ty)) -- GitLab From 9aa3eb2bacf626b626aa437596a679d1e7876612 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Sun, 15 May 2022 19:21:46 +0530 Subject: [PATCH 02/24] Added support for NewNoPar for the expression `new new-type initializer` in SmPL Signed-off-by: Tathagata Roy --- ocaml/coccilib.mli | 2 + parsing_cocci/arity.ml | 9 ++ parsing_cocci/ast0_cocci.ml | 2 + parsing_cocci/ast0_cocci.mli | 2 + parsing_cocci/ast0toast.ml | 8 ++ parsing_cocci/ast_cocci.ml | 1 + parsing_cocci/ast_cocci.mli | 2 + parsing_cocci/check_meta.ml | 3 + parsing_cocci/compute_lines.ml | 7 ++ parsing_cocci/context_neg.ml | 2 + parsing_cocci/disjdistr.ml | 4 + parsing_cocci/get_constants.ml | 4 +- parsing_cocci/get_constants2.ml | 1 + parsing_cocci/iso_pattern.ml | 5 + parsing_cocci/parser_cocci_menhir.conflicts | 114 -------------------- parsing_cocci/pretty_print_cocci.ml | 8 ++ parsing_cocci/single_statement.ml | 1 + parsing_cocci/type_infer.ml | 1 + parsing_cocci/unify_ast.ml | 3 + parsing_cocci/unparse_ast0.ml | 8 ++ parsing_cocci/visitor_ast.ml | 14 +++ parsing_cocci/visitor_ast0.ml | 7 ++ 22 files changed, 93 insertions(+), 115 deletions(-) diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index cea8a343..4177cd6c 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -2615,6 +2615,7 @@ module Ast_cocci : | SizeOfType of string mcode * string mcode * fullType * string mcode | NewPar of string mcode * string mcode * fullType * string mcode * string mcode * expression dots * string mcode + | NewNoPar of string mcode * fullType * string mcode * expression dots * string mcode | TypeExp of fullType | Paren of string mcode * expression * string mcode | Constructor of string mcode * fullType * string mcode * initialiser @@ -3367,6 +3368,7 @@ module Ast0_cocci : | SizeOfType of string mcode * string mcode * typeC * string mcode | NewPar of string mcode * string mcode * typeC * string mcode * string mcode * expression dots * string mcode + | NewNoPar of string mcode * typeC * string mcode * expression dots * string mcode | TypeExp of typeC | Constructor of string mcode * typeC * string mcode * initialiser | MetaErr of Ast_cocci.meta_name mcode * constraints * pure diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 936c4155..08b91c4f 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -287,6 +287,15 @@ let rec top_expression opt_allowed tgt expr = let exp = dots (expression arity) exp in let rpb = mcode rpb in make_exp expr tgt arity (Ast0.NewPar(nw,lp,ty,rp,lpb,exp,rpb)) + | Ast0.NewNoPar(nw,ty,lpb,exp,rpb) -> + let arity = + exp_same (mcode2line nw) (List.map mcode2arity [nw;lpb;rpb]) in + let nw = mcode nw in + let ty = typeC arity ty in + let lpb = mcode lpb in + let exp = dots (expression arity) exp in + let rpb = mcode rpb in + make_exp expr tgt arity (Ast0.NewNoPar(nw,ty,lpb,exp,rpb)) | Ast0.TypeExp(ty) -> Ast0.rewrap expr (Ast0.TypeExp(typeC tgt ty)) | Ast0.MetaErr(name,constraints,pure) -> let arity = exp_same (mcode2line name) [mcode2arity name] in diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 71d7ec54..13657b6b 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -131,6 +131,8 @@ and base_expression = | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * string mcode (* ) *) * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) + | NewNoPar of string mcode (* new *) * typeC * string mcode (* (|{ *) * expression dots * + string mcode (* )|} *) | TypeExp of typeC (* type name used as an expression, only in args *) | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index d22577bc..2efeb929 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -122,6 +122,8 @@ and base_expression = | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * string mcode (* ) *) * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) + | NewNoPar of string mcode (* new *) * typeC * string mcode (* (|{ *) * + expression dots * string mcode (* )|} *) | TypeExp of typeC | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index 8bb9a785..78b85d0d 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -458,6 +458,14 @@ and expression e = let expr = dots expression expr in let rpb = mcode rpb in Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + let allminus = check_allminus.VT0.combiner_rec_expression e in + let nw = mcode nw in + let ty = typeC allminus ty in + let lpb = mcode lpb in + let expr = dots expression expr in + let rpb = mcode rpb in + Ast.NewNoPar(nw,ty,lpb,expr,rpb) | Ast0.TypeExp(ty) -> let allminus = check_allminus.VT0.combiner_rec_expression e in Ast.TypeExp(typeC allminus ty) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index d188af13..64222d69 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -202,6 +202,7 @@ and base_expression = fullType * string mcode (* ) *) | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * string mcode (* ) *) * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) + | NewNoPar of string mcode (* new *) * fullType * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) | TypeExp of fullType (*type name used as an expression, only in arg or #define*) diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index bfb8745f..5e84e5dd 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -188,6 +188,8 @@ and base_expression = | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * string mcode (* ) *) * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) + | NewNoPar of string mcode (* new *) * fullType * string mcode (* (|{ *) * expression dots * + string mcode (* )|} *) | TypeExp of fullType | Paren of string mcode (* ( *) * expression * diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 445fd745..c08724ad 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -205,6 +205,9 @@ and expression context old_metas table minus e = | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> typeC old_metas table minus ty; dots (expression ID old_metas table minus) expr + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + typeC old_metas table minus ty; + dots (expression ID old_metas table minus) expr | Ast0.TypeExp(ty) -> typeC old_metas table minus ty | Ast0.Constructor(lp,ty,rp,init) -> typeC old_metas table minus ty; initialiser old_metas table minus init diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index a52b1c75..1400a773 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -450,6 +450,13 @@ let rec expression e = let rpb = normal_mcode rpb in mkres e (Ast0.NewPar(nw,lp,typeC ty,rp,lpb,expr,rpb)) (promote_mcode nw) (promote_mcode rpb) + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + let nw = normal_mcode nw in + let lpb = normal_mcode lpb in + let expr = dots is_exp_dots ( Some(promote_mcode lpb)) expression expr in + let rpb = normal_mcode rpb in + mkres e (Ast0.NewNoPar(nw,typeC ty,lpb,expr,rpb)) (promote_mcode nw) + (promote_mcode rpb) | Ast0.TypeExp(ty) -> let ty = typeC ty in mkres e (Ast0.TypeExp(ty)) ty ty | Ast0.Constructor(lp,ty,rp,init) -> diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index 206094c8..86601e2a 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -685,6 +685,8 @@ let rec equal_expression e1 e2 = | (Ast0.NewPar(new1,lp1,_,rp1,lpb1,_,rpb1), Ast0.NewPar(new2,lp2,_,rp2,lpb2,_,rpb2)) -> equal_mcode new1 new2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && equal_mcode lpb1 lpb2 && equal_mcode rpb1 rpb2 + | (Ast0.NewNoPar(new1,_,lpb1,_,rpb1), Ast0.NewNoPar(new2,_,lpb2,_,rpb2)) -> + equal_mcode new1 new2 && equal_mcode lpb1 lpb2 && equal_mcode rpb1 rpb2 | (Ast0.TypeExp(_),Ast0.TypeExp(_)) -> true | (Ast0.Constructor(lp1,_,rp1,_),Ast0.Constructor(lp2,_,rp2,_)) -> equal_mcode lp1 lp2 && equal_mcode rp1 rp2 diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index f3a72e89..dc8327dd 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -234,6 +234,10 @@ and disjexp e = disjmult2 (disjty ty) (disjdots disjexp expr) (function ty -> function exp -> Ast.rewrap e (Ast.NewPar(nw,lp,ty,rp,lpb,exp,rpb))) + | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> + disjmult2 (disjty ty) (disjdots disjexp expr) + (function ty -> function exp -> + Ast.rewrap e (Ast.NewNoPar(nw,ty,lpb,exp,rpb))) | Ast.TypeExp(ty) -> let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.TypeExp(ty))) ty diff --git a/parsing_cocci/get_constants.ml b/parsing_cocci/get_constants.ml index 94b2c27c..85a746a5 100644 --- a/parsing_cocci/get_constants.ml +++ b/parsing_cocci/get_constants.ml @@ -53,7 +53,9 @@ let get_minus_constants bind orbind = (r.V.combiner_expression exp) | Ast.SizeOfExpr(sizeof,_) | Ast.SizeOfType(sizeof,_,_,_) -> bind (k e) [Ast.unwrap_mcode sizeof] - | Ast.NewPar(new,_,_,_,_,_,_) -> + | Ast.NewPar(nw,_,_,_,_,_,_) -> + bind (k e) [Ast.unwrap_mcode new] + | Ast.NewNoPar(nw,_,_,_,_,_,_) -> bind (k e) [Ast.unwrap_mcode new] | Ast.DisjExpr(exps) -> disj_union_all (List.map r.V.combiner_expression exps) diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index dfd5bc7a..a13b5c35 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -490,6 +490,7 @@ let do_get_constants constants keywords env (neg_pos,_) = | Ast.SizeOfExpr(sizeof,exp) -> bind (keywords "sizeof") (k e) | Ast.SizeOfType(sizeof,lp,ty,rp) -> bind (keywords "sizeof") (k e) | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> bind (keywords "new") (k e) + | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> bind (keywords "new") (k e) | Ast.NestExpr(starter,expr_dots,ender,wc,false) -> option_default | Ast.NestExpr(starter,expr_dots,ender,wc,true) -> r.V.combiner_expression_dots expr_dots diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 6d3990b7..6d3eb3d7 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -788,6 +788,11 @@ let match_maker checks_needed context_required whencode_allowed = [check_mcode lp1 lp2; check_mcode rp1 rp2; check_mcode nw1 nw2; match_typeC ty1 ty2; check_mcode lpb1 lpb2; check_mcode rpb1 rpb2; match_dots match_expr is_elist_matcher do_elist_match expr1 expr2] + | (Ast0.NewNoPar(nw1,ty1,lpb1,expr1,rpb1), + Ast0.NewNoPar(nw2,ty2,lpb2,expr2,rpb2)) -> + conjunct_many_bindings + [check_mcode nw1 nw2; match_typeC ty1 ty2; check_mcode lpb1 lpb2; check_mcode rpb1 rpb2; + match_dots match_expr is_elist_matcher do_elist_match expr1 expr2] | (Ast0.Constructor(lp1,tya,rp1,inita), Ast0.Constructor(lp,tyb,rp,initb)) -> conjunct_many_bindings diff --git a/parsing_cocci/parser_cocci_menhir.conflicts b/parsing_cocci/parser_cocci_menhir.conflicts index 0c89c8a2..e69de29b 100644 --- a/parsing_cocci/parser_cocci_menhir.conflicts +++ b/parsing_cocci/parser_cocci_menhir.conflicts @@ -1,114 +0,0 @@ - -** Conflict (shift/reduce) in state 905. -** Token involved: TOBrace -** This state is reached from iso_main after reading: - -TIsoTopLevel TNew struct_or_union type_ident - -** The derivations that appear below have the following common factor: -** (The question mark symbol (?) represents the spot where the derivations begin to differ.) - -iso_main -TIsoTopLevel nest_start list(iso(nest_start)) EOF - nest_after_dots - expr nest_after_exp - pre_basic_expr(expr,invalid) - basic_expr(expr,invalid) - assign_expr(expr,invalid) - unary_expr(expr,invalid) TOpAssign assign_expr_bis - (?) - -** In state 905, looking ahead at TOBrace, reducing production -** non_signable_types_no_ident -> struct_or_union type_ident -** is permitted because of the following sub-derivation: - -TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace - all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish - non_signable_types // lookahead token is inherited - non_signable_types_no_ident // lookahead token is inherited - struct_or_union type_ident . - -** In state 905, looking ahead at TOBrace, shifting is permitted -** because of the following sub-derivation: - -TNew ctype cpp_initialiser - all_basic_types list(mul) - non_signable_types - non_signable_types_no_ident - struct_or_union type_ident . TOBrace struct_decl_list TCBrace - -** Conflict (shift/reduce) in state 142. -** Token involved: TOBrace -** This state is reached from iso_main after reading: - -TIsoTopLevel TNew TMetaType - -** The derivations that appear below have the following common factor: -** (The question mark symbol (?) represents the spot where the derivations begin to differ.) - -iso_main -TIsoTopLevel nest_start list(iso(nest_start)) EOF - nest_after_dots - expr nest_after_exp - pre_basic_expr(expr,invalid) - basic_expr(expr,invalid) - assign_expr(expr,invalid) - unary_expr(expr,invalid) TOpAssign assign_expr_bis - (?) - -** In state 142, looking ahead at TOBrace, shifting is permitted -** because of the following sub-derivation: - -TNew ctype cpp_initialiser - all_basic_types list(mul) - non_signable_types - non_signable_types_no_ident - TMetaType . TOBrace struct_decl_list TCBrace - -** In state 142, looking ahead at TOBrace, reducing production -** signable_types_no_ident -> TMetaType -** is permitted because of the following sub-derivation: - -TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace - all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish - signable_types // lookahead token is inherited - signable_types_no_ident // lookahead token is inherited - TMetaType . - -** Conflict (shift/reduce) in state 108. -** Token involved: TOBrace -** This state is reached from iso_main after reading: - -TIsoTopLevel TNew Tenum ident - -** The derivations that appear below have the following common factor: -** (The question mark symbol (?) represents the spot where the derivations begin to differ.) - -iso_main -TIsoTopLevel nest_start list(iso(nest_start)) EOF - nest_after_dots - expr nest_after_exp - pre_basic_expr(expr,invalid) - basic_expr(expr,invalid) - assign_expr(expr,invalid) - unary_expr(expr,invalid) TOpAssign assign_expr_bis - (?) - -** In state 108, looking ahead at TOBrace, reducing production -** non_signable_types_no_ident -> Tenum ident -** is permitted because of the following sub-derivation: - -TNew ctype cpp_initialiser // lookahead token appears because cpp_initialiser can begin with TOBrace - all_basic_types list(mul) // lookahead token is inherited because list(mul) can vanish - non_signable_types // lookahead token is inherited - non_signable_types_no_ident // lookahead token is inherited - Tenum ident . - -** In state 108, looking ahead at TOBrace, shifting is permitted -** because of the following sub-derivation: - -TNew ctype cpp_initialiser - all_basic_types list(mul) - non_signable_types - non_signable_types_no_ident - Tenum ident . TOBrace enum_decl_list TCBrace diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index fac20f56..9f60aefc 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -269,6 +269,14 @@ let rec expression e = mcode print_string lpb; dots (function _ -> ()) expression expr; mcode print_string rpb + | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> + mcode print_string nw; + print_string " "; + fullType ty; + print_string " "; + mcode print_string lpb; + dots (function _ -> ()) expression expr; + mcode print_string rpb | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; fullType ty; close_box(); diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 5feb13c4..4fd8cc98 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -142,6 +142,7 @@ let rec left_expression e = | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> modif_before_mcode nw + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> modif_before_mcode nw | Ast0.TypeExp(ty) -> left_typeC ty | Ast0.Constructor(lp,ty,rp,init) -> modif_before_mcode lp | Ast0.MetaErr(name,_,_) -> modif_before_mcode name diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml index 51bf4219..fec8ae8d 100644 --- a/parsing_cocci/type_infer.ml +++ b/parsing_cocci/type_infer.ml @@ -295,6 +295,7 @@ let rec propagate_types env = | Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type) | Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type) | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> Some ty + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> Some ty | Ast0.TypeExp(ty) -> None | Ast0.Constructor(lp,ty,rp,init) -> Some ty | Ast0.MetaErr(name,_,_) -> None diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 7a02ffce..fd2510fe 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -232,6 +232,9 @@ and unify_expression e1 e2 = | (Ast.NewPar(new1,lp1,ty1,rp1,lpb1,expr1,rpb1), Ast.NewPar(new2,lp2,ty2,rp2,lpb2,expr2,rpb2)) -> unify_fullType ty1 ty2 && unify_dots unify_expression edots expr1 expr2 + | (Ast.NewNoPar(new1,ty1,lpb1,expr1,rpb1), Ast.NewNoPar(new2,ty2,lpb2,expr2,rpb2)) -> + unify_fullType ty1 ty2 && + unify_dots unify_expression edots expr1 expr2 | (Ast.TypeExp(ty1),Ast.TypeExp(ty2)) -> unify_fullType ty1 ty2 | (Ast.Constructor(lp1,ty1,rp1,i1),Ast.Constructor(lp2,ty2,rp2,i2)) -> unify_fullType ty1 ty2 && unify_initialiser i1 i2 diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index 66bdd00b..db2ffc54 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -241,6 +241,14 @@ let rec expression e = mcode print_string lpb; expression_dots expr; mcode print_string rpb + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + mcode print_string nw; + print_string " "; + typeC ty; + print_string " "; + mcode print_string lpb; + expression_dots expr; + mcode print_string rpb | Ast0.TypeExp(ty) -> typeC ty | Ast0.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; typeC ty; close_box(); diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 9f0c8964..05ad3f3b 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -226,6 +226,13 @@ let combiner bind option_default let lexpr = expression_dots expr in let lrpb = string_mcode rpb in multibind [lnw; llp; lty; lrp; llpb; lexpr; lrpb] + | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> + let lnw = string_mcode nw in + let lty = fullType ty in + let llpb = string_mcode lpb in + let lexpr = expression_dots expr in + let lrpb = string_mcode rpb in + multibind [lnw; lty; llpb; lexpr; lrpb] | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in @@ -1272,6 +1279,13 @@ let rebuilder let lexpr = expression_dots expr in let lrpb = string_mcode rpb in Ast.NewPar(lnw,llp,lty,lrp,llpb,lexpr,lrpb) + | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> + let lnw = string_mcode nw in + let lty = fullType ty in + let llpb = string_mcode lpb in + let lexpr = expression_dots expr in + let lrpb = string_mcode rpb in + Ast.NewNoPar(lnw,lty,llpb,lexpr,lrpb) | Ast.TypeExp(ty) -> Ast.TypeExp(fullType ty) | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index 13252225..deb9ad81 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -211,6 +211,13 @@ let visitor mode bind option_default let (expr_n,expr) = expression_dots expr in let (rpb_n,rpb) = string_mcode rpb in (multibind [nw_n;lp_n;ty_n;rp_n;lpb_n;expr_n;rpb_n], Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb)) + | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + let (nw_n,nw) = string_mcode nw in + let (ty_n,ty) = typeC ty in + let (lpb_n,lpb) = string_mcode lpb in + let (expr_n,expr) = expression_dots expr in + let (rpb_n,rpb) = string_mcode rpb in + (multibind [nw_n;ty_n;lpb_n;expr_n;rpb_n], Ast0.NewNoPar(nw,ty,lpb,expr,rpb)) | Ast0.TypeExp(ty) -> let (ty_n,ty) = typeC ty in (ty_n,Ast0.TypeExp(ty)) -- GitLab From 5831d204dfc3ead91759ce21d3caea3421519a55 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Thu, 26 May 2022 20:05:47 +0530 Subject: [PATCH 03/24] Integrated 8 variations of new in SmPL --- parsing_cocci/#parser_cocci_menhir.conflicts# | 1023 +++++++++++++++++ parsing_cocci/arity.ml | 46 +- parsing_cocci/ast0_cocci.ml | 10 +- parsing_cocci/ast0_cocci.mli | 10 +- parsing_cocci/ast0toast.ml | 27 +- parsing_cocci/ast_cocci.ml | 8 +- parsing_cocci/ast_cocci.mli | 10 +- parsing_cocci/check_meta.ml | 10 +- parsing_cocci/compute_lines.ml | 32 +- parsing_cocci/context_neg.ml | 17 +- parsing_cocci/disjdistr.ml | 16 +- parsing_cocci/get_constants2.ml | 3 +- parsing_cocci/index.ml | 4 +- parsing_cocci/iso_pattern.ml | 24 +- parsing_cocci/parser_cocci_menhir.mly | 92 +- parsing_cocci/pretty_print_cocci.ml | 25 +- parsing_cocci/single_statement.ml | 3 +- parsing_cocci/type_infer.ml | 3 +- parsing_cocci/unify_ast.ml | 12 +- parsing_cocci/unparse_ast0.ml | 26 +- parsing_cocci/visitor_ast.ml | 52 +- parsing_cocci/visitor_ast0.ml | 26 +- 22 files changed, 1277 insertions(+), 202 deletions(-) create mode 100644 parsing_cocci/#parser_cocci_menhir.conflicts# diff --git a/parsing_cocci/#parser_cocci_menhir.conflicts# b/parsing_cocci/#parser_cocci_menhir.conflicts# new file mode 100644 index 00000000..2b84b440 --- /dev/null +++ b/parsing_cocci/#parser_cocci_menhir.conflicts# @@ -0,0 +1,1023 @@ + +** Conflict (reduce/reduce) in state 999. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDotDot TDmOp TDefault TComma TCase TCPar0 TCPar TCEllipsis TCCro TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TNew ctype_without_braces cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + cond_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,dot_expressions) // lookahead token is inherited + unary_expr(eexpr,dot_expressions) // lookahead token is inherited + (?) + +** In state 999, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** In state 999, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** Conflict (reduce/reduce) in state 997. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDotDot TDmOp TDefault TComma TCase TCPar0 TCPar TCEllipsis TCCro TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TNew placement_params ctype_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + cond_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,dot_expressions) // lookahead token is inherited + unary_expr(eexpr,dot_expressions) // lookahead token is inherited + (?) + +** In state 997, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** In state 997, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** Conflict (reduce/reduce) in state 996. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDotDot TDmOp TDefault TComma TCase TCPar0 TCPar TCEllipsis TCCro TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TNew placement_params TOPar ctype TCPar cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + cond_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) + arith_expr(eexpr,dot_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,dot_expressions) // lookahead token is inherited + unary_expr(eexpr,dot_expressions) // lookahead token is inherited + (?) + +** In state 996, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** In state 996, looking ahead at TXor, reducing production +** unary_expr(eexpr,dot_expressions) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** Conflict (shift/reduce) in state 989. +** Token involved: TCPar +** This state is reached from iso_main after reading: + +TIsoToTestExpression TNew TOPar ctype + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + unary_expr(eexpr,dot_expressions) TOpAssign assign_expr_bis + (?) + +** In state 989, looking ahead at TCPar, reducing production +** aexpr -> ctype +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser + TOPar eexpr_list_option TCPar // lookahead token appears + empty_list_start(aexpr,TEllipsis) // lookahead token is inherited + nonempty_list_start(aexpr,TEllipsis) // lookahead token is inherited + aexpr // lookahead token is inherited + ctype . + +** In state 989, looking ahead at TCPar, shifting is permitted +** because of the following sub-derivation: + +TNew TOPar ctype . TCPar cpp_initialiser + +** Conflict (reduce/reduce) in state 835. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDmOp TDefault TComma TCase TCPar0 TCEllipsis TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew ctype_without_braces cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + cond_expr(expr,invalid) + arith_expr(expr,invalid) + arith_expr(expr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(expr,invalid) // lookahead token is inherited + unary_expr(expr,invalid) // lookahead token is inherited + (?) + +** In state 835, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** In state 835, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** Conflict (reduce/reduce) in state 833. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDmOp TDefault TComma TCase TCPar0 TCEllipsis TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew placement_params ctype_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + cond_expr(expr,invalid) + arith_expr(expr,invalid) + arith_expr(expr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(expr,invalid) // lookahead token is inherited + unary_expr(expr,invalid) // lookahead token is inherited + (?) + +** In state 833, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** In state 833, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** Conflict (reduce/reduce) in state 832. +** Tokens involved: TXor TWhy TShROp TShLOp TRightIso TPtVirg TPlus TPOEllipsis TPCEllipsis TOrLog TOr TOpAssign TOEllipsis TNotEq TMul TMinus TMid0 TMetaBinaryOp TMetaAssignOp TLogOp TLineEnd TIso TEqEq TEq TEllipsis TDmOp TDefault TComma TCase TCPar0 TCEllipsis TCBrace TArobArob TArob TAndLog TAnd0 TAnd EOF +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew placement_params TOPar ctype TCPar cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + cond_expr(expr,invalid) + arith_expr(expr,invalid) + arith_expr(expr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(expr,invalid) // lookahead token is inherited + unary_expr(expr,invalid) // lookahead token is inherited + (?) + +** In state 832, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** In state 832, looking ahead at TXor, reducing production +** unary_expr(expr,invalid) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** Conflict (shift/reduce) in state 825. +** Token involved: TCPar +** This state is reached from iso_main after reading: + +TIsoTopLevel TNew TOPar ctype + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + unary_expr(expr,invalid) TOpAssign assign_expr_bis + (?) + +** In state 825, looking ahead at TCPar, reducing production +** aexpr -> ctype +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser + TOPar eexpr_list_option TCPar // lookahead token appears + empty_list_start(aexpr,TEllipsis) // lookahead token is inherited + nonempty_list_start(aexpr,TEllipsis) // lookahead token is inherited + aexpr // lookahead token is inherited + ctype . + +** In state 825, looking ahead at TCPar, shifting is permitted +** because of the following sub-derivation: + +TNew TOPar ctype . TCPar cpp_initialiser + +** Conflict (shift/reduce) in state 737. +** Token involved: TCPar +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew TOPar ctype + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + unary_expr(expr,invalid) TOpAssign assign_expr_bis + TSizeof unary_expr_bis + (?) + +** In state 737, looking ahead at TCPar, reducing production +** aexpr -> ctype +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser + TOPar eexpr_list_option TCPar // lookahead token appears + empty_list_start(aexpr,TEllipsis) // lookahead token is inherited + nonempty_list_start(aexpr,TEllipsis) // lookahead token is inherited + aexpr // lookahead token is inherited + ctype . + +** In state 737, looking ahead at TCPar, shifting is permitted +** because of the following sub-derivation: + +TNew TOPar ctype . TCPar cpp_initialiser + +** Conflict (reduce/reduce) in state 588. +** Tokens involved: TXor TShROp TShLOp TPlus TOrLog TOr TNotEq TMul TMinus TMetaBinaryOp TLogOp TEqEq TDmOp TComma TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from minus_main after reading: + +loption(filespec) TOInit TNew ctype_without_braces cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +minus_main +minus_body EOF +loption(filespec) loption(minus_start) + minus_start + top_init + TOInit initialize_list TCBrace + empty_list_start(initialize2,edots_when(TEllipsis,initialize)) + nonempty_list_start(initialize2,edots_when(TEllipsis,initialize)) + initialize2 + arith_expr(eexpr,invalid) + arith_expr(eexpr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,invalid) // lookahead token is inherited + unary_expr(eexpr,invalid) // lookahead token is inherited + (?) + +** In state 588, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** In state 588, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** Conflict (reduce/reduce) in state 586. +** Tokens involved: TXor TShROp TShLOp TPlus TOrLog TOr TNotEq TMul TMinus TMetaBinaryOp TLogOp TEqEq TDmOp TComma TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from minus_main after reading: + +loption(filespec) TOInit TNew placement_params ctype_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +minus_main +minus_body EOF +loption(filespec) loption(minus_start) + minus_start + top_init + TOInit initialize_list TCBrace + empty_list_start(initialize2,edots_when(TEllipsis,initialize)) + nonempty_list_start(initialize2,edots_when(TEllipsis,initialize)) + initialize2 + arith_expr(eexpr,invalid) + arith_expr(eexpr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,invalid) // lookahead token is inherited + unary_expr(eexpr,invalid) // lookahead token is inherited + (?) + +** In state 586, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** In state 586, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** Conflict (reduce/reduce) in state 585. +** Tokens involved: TXor TShROp TShLOp TPlus TOrLog TOr TNotEq TMul TMinus TMetaBinaryOp TLogOp TEqEq TDmOp TComma TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from minus_main after reading: + +loption(filespec) TOInit TNew placement_params TOPar ctype TCPar cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +minus_main +minus_body EOF +loption(filespec) loption(minus_start) + minus_start + top_init + TOInit initialize_list TCBrace + empty_list_start(initialize2,edots_when(TEllipsis,initialize)) + nonempty_list_start(initialize2,edots_when(TEllipsis,initialize)) + initialize2 + arith_expr(eexpr,invalid) + arith_expr(eexpr,invalid) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,invalid) // lookahead token is inherited + unary_expr(eexpr,invalid) // lookahead token is inherited + (?) + +** In state 585, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** In state 585, looking ahead at TXor, reducing production +** unary_expr(eexpr,invalid) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** Conflict (shift/reduce) in state 578. +** Token involved: TCPar +** This state is reached from minus_main after reading: + +loption(filespec) TOInit TNew TOPar ctype + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +minus_main +minus_body EOF +loption(filespec) loption(minus_start) + minus_start + top_init + TOInit initialize_list TCBrace + empty_list_start(initialize2,edots_when(TEllipsis,initialize)) + nonempty_list_start(initialize2,edots_when(TEllipsis,initialize)) + initialize2 + arith_expr(eexpr,invalid) + cast_expr(eexpr,invalid) + unary_expr(eexpr,invalid) + (?) + +** In state 578, looking ahead at TCPar, reducing production +** aexpr -> ctype +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser + TOPar eexpr_list_option TCPar // lookahead token appears + empty_list_start(aexpr,TEllipsis) // lookahead token is inherited + nonempty_list_start(aexpr,TEllipsis) // lookahead token is inherited + aexpr // lookahead token is inherited + ctype . + +** In state 578, looking ahead at TCPar, shifting is permitted +** because of the following sub-derivation: + +TNew TOPar ctype . TCPar cpp_initialiser + +** Conflict (reduce/reduce) in state 491. +** Tokens involved: TXor TWhy TShROp TShLOp TPlus TPCEllipsis TOrLog TOr TOpAssign TNotEq TMul TMinus TMetaBinaryOp TMetaAssignOp TLogOp TEqEq TEq TEllipsis TDmOp TComma TCPar TCEllipsis TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TPOEllipsis TNew ctype_without_braces cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + unary_expr(eexpr,dot_expressions) TOpAssign assign_expr_bis + postfix_expr(eexpr,dot_expressions) + primary_expr(eexpr,dot_expressions) + dot_expressions + nest_expressions + TPOEllipsis expr_dots(TEllipsis) TPCEllipsis + no_dot_start_end(dexpr,edots_when(TEllipsis,eexpr)) + dexpr list(pair(edots_when(TEllipsis,eexpr),dexpr)) + pre_basic_expr(eexpr,nest_expressions) + basic_expr(eexpr,nest_expressions) + assign_expr(eexpr,nest_expressions) + cond_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,nest_expressions) // lookahead token is inherited + unary_expr(eexpr,nest_expressions) // lookahead token is inherited + (?) + +** In state 491, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** In state 491, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew ctype_without_braces cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew ctype_without_braces cpp_initialiser . + +** Conflict (shift/reduce) in state 488. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew all_basic_types_without_braces const_vol + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 488, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + all_basic_types_without_braces const_vol list(mul) // lookahead token is inherited + . + +** In state 488, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + all_basic_types_without_braces const_vol list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 486. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew all_basic_types_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 486, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + all_basic_types_without_braces list(mul) // lookahead token is inherited + . + +** In state 486, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + all_basic_types_without_braces list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 484. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew const_vol all_basic_types_without_braces const_vol + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 484, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + const_vol all_basic_types_without_braces const_vol list(mul) // lookahead token is inherited + . + +** In state 484, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + const_vol all_basic_types_without_braces const_vol list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 482. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew const_vol all_basic_types_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 482, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + const_vol all_basic_types_without_braces list(mul) // lookahead token is inherited + . + +** In state 482, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + const_vol all_basic_types_without_braces list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 480. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew const_vol signed_or_unsigned const_vol + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 480, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + const_vol signed_or_unsigned const_vol list(mul) // lookahead token is inherited + . + +** In state 480, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + const_vol signed_or_unsigned const_vol list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 478. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew const_vol signed_or_unsigned + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 478, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + const_vol signed_or_unsigned list(mul) // lookahead token is inherited + . + +** In state 478, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + const_vol signed_or_unsigned list(mul) + mul list(mul) + . TMul + +** Conflict (reduce/reduce) in state 476. +** Tokens involved: TXor TWhy TShROp TShLOp TPlus TPCEllipsis TOrLog TOr TOpAssign TNotEq TMul TMinus TMetaBinaryOp TMetaAssignOp TLogOp TEqEq TEq TEllipsis TDmOp TComma TCPar TCEllipsis TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TPOEllipsis TNew placement_params ctype_without_braces + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + unary_expr(eexpr,dot_expressions) TOpAssign assign_expr_bis + postfix_expr(eexpr,dot_expressions) + primary_expr(eexpr,dot_expressions) + dot_expressions + nest_expressions + TPOEllipsis expr_dots(TEllipsis) TPCEllipsis + no_dot_start_end(dexpr,edots_when(TEllipsis,eexpr)) + dexpr list(pair(edots_when(TEllipsis,eexpr),dexpr)) + pre_basic_expr(eexpr,nest_expressions) + basic_expr(eexpr,nest_expressions) + assign_expr(eexpr,nest_expressions) + cond_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,nest_expressions) // lookahead token is inherited + unary_expr(eexpr,nest_expressions) // lookahead token is inherited + (?) + +** In state 476, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** In state 476, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew placement_params ctype_without_braces +** is permitted because of the following sub-derivation: + +TNew placement_params ctype_without_braces . + +** Conflict (reduce/reduce) in state 473. +** Tokens involved: TXor TWhy TShROp TShLOp TPlus TPCEllipsis TOrLog TOr TOpAssign TNotEq TMul TMinus TMetaBinaryOp TMetaAssignOp TLogOp TEqEq TEq TEllipsis TDmOp TComma TCPar TCEllipsis TCBrace TAndLog TAnd +** The following explanations concentrate on token TXor. +** This state is reached from iso_main after reading: + +TIsoToTestExpression TPOEllipsis TNew placement_params TOPar ctype TCPar cpp_initialiser + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + unary_expr(eexpr,dot_expressions) TOpAssign assign_expr_bis + postfix_expr(eexpr,dot_expressions) + primary_expr(eexpr,dot_expressions) + dot_expressions + nest_expressions + TPOEllipsis expr_dots(TEllipsis) TPCEllipsis + no_dot_start_end(dexpr,edots_when(TEllipsis,eexpr)) + dexpr list(pair(edots_when(TEllipsis,eexpr),dexpr)) + pre_basic_expr(eexpr,nest_expressions) + basic_expr(eexpr,nest_expressions) + assign_expr(eexpr,nest_expressions) + cond_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) + arith_expr(eexpr,nest_expressions) TXor arith_expr_bis // lookahead token appears + cast_expr(eexpr,nest_expressions) // lookahead token is inherited + unary_expr(eexpr,nest_expressions) // lookahead token is inherited + (?) + +** In state 473, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** In state 473, looking ahead at TXor, reducing production +** unary_expr(eexpr,nest_expressions) -> TNew placement_params TOPar ctype TCPar cpp_initialiser +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser . + +** Conflict (shift/reduce) in state 465. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew signed_or_unsigned const_vol + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 465, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + signed_or_unsigned const_vol list(mul) // lookahead token is inherited + . + +** In state 465, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + signed_or_unsigned const_vol list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 463. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew signed_or_unsigned + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 463, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + signed_or_unsigned list(mul) // lookahead token is inherited + . + +** In state 463, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + signed_or_unsigned list(mul) + mul list(mul) + . TMul + +** Conflict (shift/reduce) in state 452. +** Token involved: TCPar +** This state is reached from iso_main after reading: + +TIsoToTestExpression TPOEllipsis TNew TOPar ctype + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoToTestExpression eexpr list(iso(eexpr)) EOF + pre_basic_expr(eexpr,dot_expressions) + basic_expr(eexpr,dot_expressions) + assign_expr(eexpr,dot_expressions) + unary_expr(eexpr,dot_expressions) TOpAssign assign_expr_bis + postfix_expr(eexpr,dot_expressions) + primary_expr(eexpr,dot_expressions) + dot_expressions + nest_expressions + TPOEllipsis expr_dots(TEllipsis) TPCEllipsis + no_dot_start_end(dexpr,edots_when(TEllipsis,eexpr)) + dexpr list(pair(edots_when(TEllipsis,eexpr),dexpr)) + pre_basic_expr(eexpr,nest_expressions) + basic_expr(eexpr,nest_expressions) + assign_expr(eexpr,nest_expressions) + unary_expr(eexpr,nest_expressions) TOpAssign assign_expr_bis + (?) + +** In state 452, looking ahead at TCPar, reducing production +** aexpr -> ctype +** is permitted because of the following sub-derivation: + +TNew placement_params TOPar ctype TCPar cpp_initialiser + TOPar eexpr_list_option TCPar // lookahead token appears + empty_list_start(aexpr,TEllipsis) // lookahead token is inherited + nonempty_list_start(aexpr,TEllipsis) // lookahead token is inherited + aexpr // lookahead token is inherited + ctype . + +** In state 452, looking ahead at TCPar, shifting is permitted +** because of the following sub-derivation: + +TNew TOPar ctype . TCPar cpp_initialiser + +** Conflict (shift/reduce) in state 165. +** Token involved: TMul +** This state is reached from iso_main after reading: + +TIsoTopLevel TSizeof TNew signed_or_unsigned mul + +** The derivations that appear below have the following common factor: +** (The question mark symbol (?) represents the spot where the derivations begin to differ.) + +iso_main +TIsoTopLevel nest_start list(iso(nest_start)) EOF + nest_after_dots + expr nest_after_exp + pre_basic_expr(expr,invalid) + basic_expr(expr,invalid) + assign_expr(expr,invalid) + (?) + +** In state 165, looking ahead at TMul, reducing production +** list(mul) -> +** is permitted because of the following sub-derivation: + +cond_expr(expr,invalid) +arith_expr(expr,invalid) +arith_expr(expr,invalid) TMul arith_expr_bis // lookahead token appears +cast_expr(expr,invalid) // lookahead token is inherited +unary_expr(expr,invalid) // lookahead token is inherited +TSizeof unary_expr_bis // lookahead token is inherited + TNew ctype_without_braces // lookahead token is inherited + signed_or_unsigned list(mul) // lookahead token is inherited + mul list(mul) // lookahead token is inherited + . + +** In state 165, looking ahead at TMul, shifting is permitted +** because of the following sub-derivation: + +unary_expr(expr,invalid) TOpAssign assign_expr_bis +TSizeof unary_expr_bis + TNew ctype_without_braces cpp_initialiser + signed_or_unsigned list(mul) + mul list(mul) + mul list(mul) + . TMul diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 08b91c4f..1e4111c5 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -90,6 +90,7 @@ let mcodebinaryOp2arity op = match Ast0.unwrap op with let mcode x = x (* nothing to do ... *) + (* --------------------------------------------------------------------- *) (* Dots *) @@ -179,13 +180,10 @@ let rec top_expression opt_allowed tgt expr = let str = dots (string_fragment arity) str in let rq = mcode rq in make_exp expr tgt arity (Ast0.StringConstant(lq,str,rq,isWchar)) - | Ast0.FunCall(fn,lp,args,rp) -> - let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in - let fn = expression arity fn in - let lp = mcode lp in - let args = dots (expression arity) args in - let rp = mcode rp in - make_exp expr tgt arity (Ast0.FunCall(fn,lp,args,rp)) + | Ast0.FunCall(fn,lp,args,rp) -> (* TODO FunCall(fn,args) *) + let fn = expression tgt fn in + let (lp,args,rp) = arg_list tgt (lp,args,rp) in + make_exp expr tgt tgt (Ast0.FunCall(fn,lp,args,rp)) | Ast0.Assignment(left,op,right,simple) -> let arity = exp_same (mcodeassignOp2line op) [mcodeassignOp2arity op] in let left = expression arity left in @@ -276,26 +274,19 @@ let rec top_expression opt_allowed tgt expr = let ty = typeC arity ty in let rp = mcode rp in make_exp expr tgt arity (Ast0.SizeOfType(szf,lp,ty,rp)) - | Ast0.NewPar(nw,lp,ty,rp,lpb,exp,rpb) -> + | Ast0.New(nw,pp_opt,lp2_opt,ty,rp2_opt,args_opt) -> let arity = - exp_same (mcode2line nw) (List.map mcode2arity [nw;lp;rp;lpb;rpb]) in + match (lp2_opt,rp2_opt) with + | (Some lp, Some rp) -> exp_same (mcode2line nw) (List.map mcode2arity [nw;lp;rp]) + | (None, None) -> exp_same (mcode2line nw) [mcode2arity nw] + | _ -> failwith "impossible" in let nw = mcode nw in - let lp = mcode lp in + let pp_opt = get_option (arg_list arity) pp_opt in + let lp2_opt = get_option mcode lp2_opt in let ty = typeC arity ty in - let rp = mcode rp in - let lpb = mcode lpb in - let exp = dots (expression arity) exp in - let rpb = mcode rpb in - make_exp expr tgt arity (Ast0.NewPar(nw,lp,ty,rp,lpb,exp,rpb)) - | Ast0.NewNoPar(nw,ty,lpb,exp,rpb) -> - let arity = - exp_same (mcode2line nw) (List.map mcode2arity [nw;lpb;rpb]) in - let nw = mcode nw in - let ty = typeC arity ty in - let lpb = mcode lpb in - let exp = dots (expression arity) exp in - let rpb = mcode rpb in - make_exp expr tgt arity (Ast0.NewNoPar(nw,ty,lpb,exp,rpb)) + let rp2_opt = get_option mcode rp2_opt in + let args_opt = get_option (arg_list arity) args_opt in + make_exp expr tgt arity (Ast0.New(nw,pp_opt,lp2_opt,ty,rp2_opt,args_opt)) | Ast0.TypeExp(ty) -> Ast0.rewrap expr (Ast0.TypeExp(typeC tgt ty)) | Ast0.MetaErr(name,constraints,pure) -> let arity = exp_same (mcode2line name) [mcode2arity name] in @@ -358,6 +349,13 @@ let rec top_expression opt_allowed tgt expr = and expression tgt exp = top_expression false tgt exp +and arg_list tgt (lp,exp,rp) = + let arity = all_same false tgt (mcode2line lp) [mcode2arity lp; mcode2arity rp] in + let lp = mcode lp in + let exp = dots (expression arity) exp in + let rp = mcode rp in + (lp,exp,rp) + and make_fragment = make_opt (function x -> failwith "opt not allowed for string fragment") diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 13657b6b..228a853e 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -128,11 +128,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * typeC * string mcode (* ) *) - | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * - string mcode (* ) *) * string mcode (* (|{ *) * expression dots * - string mcode (* )|} *) - | NewNoPar of string mcode (* new *) * typeC * string mcode (* (|{ *) * expression dots * - string mcode (* )|} *) + | New of string mcode (* new *) * arguments option * + string mcode (* ( *) option * typeC * + string mcode (* ) *) option * arguments option (* argument list *) | TypeExp of typeC (* type name used as an expression, only in args *) | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser @@ -160,6 +158,8 @@ and base_expression = and expression = base_expression wrap +and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) + and constraints = expression Ast.generic_constraints and listlen = diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index 2efeb929..fdce084e 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -119,11 +119,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * typeC * string mcode (* ) *) - | NewPar of string mcode (* new *) * string mcode (* ( *) * typeC * - string mcode (* ) *) * string mcode (* (|{ *) * expression dots * - string mcode (* )|} *) - | NewNoPar of string mcode (* new *) * typeC * string mcode (* (|{ *) * - expression dots * string mcode (* )|} *) + | New of string mcode (* new *) * arguments option * + string mcode (* ( *) option * typeC * + string mcode (* ) *) option * arguments option | TypeExp of typeC | Constructor of string mcode (* ( *) * typeC * string mcode (* ) *) * initialiser @@ -149,6 +147,8 @@ and base_expression = and expression = base_expression wrap +and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) + and constraints = expression Ast_cocci.generic_constraints and listlen = diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index 78b85d0d..32669ad5 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -448,24 +448,15 @@ and expression e = | Ast0.SizeOfType(szf,lp,ty,rp) -> let allminus = check_allminus.VT0.combiner_rec_expression e in Ast.SizeOfType(mcode szf, mcode lp,typeC allminus ty,mcode rp) - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> - let allminus = check_allminus.VT0.combiner_rec_expression e in - let nw = mcode nw in - let lp = mcode lp in - let ty = typeC allminus ty in - let rp = mcode rp in - let lpb = mcode lpb in - let expr = dots expression expr in - let rpb = mcode rpb in - Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> let allminus = check_allminus.VT0.combiner_rec_expression e in let nw = mcode nw in + let pp_opt = get_option argslist pp_opt in + let lp2 = get_option mcode lp_opt in let ty = typeC allminus ty in - let lpb = mcode lpb in - let expr = dots expression expr in - let rpb = mcode rpb in - Ast.NewNoPar(nw,ty,lpb,expr,rpb) + let rp2 = get_option mcode rp_opt in + let args_opt = get_option argslist args_opt in + Ast.New(nw,pp_opt,lp2,ty,rp2,args_opt) | Ast0.TypeExp(ty) -> let allminus = check_allminus.VT0.combiner_rec_expression e in Ast.TypeExp(typeC allminus ty) @@ -507,6 +498,12 @@ and expression e = | Ast0.OptExp(exp) -> Ast.OptExp(expression exp)) in if Ast0.get_test_exp e then Ast.set_test_exp e1 else e1 +and argslist (lp,args,rp) = + let lp = mcode lp in + let args = dots expression args in + let rp = mcode rp in + (lp,args,rp) + and assignOp op = rewrap op no_isos (match Ast0.unwrap op with diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index 64222d69..7794fdc4 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -200,9 +200,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * string mcode (* ) *) - | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * string mcode (* ) *) * - string mcode (* (|{ *) * expression dots * string mcode (* )|} *) - | NewNoPar of string mcode (* new *) * fullType * string mcode (* (|{ *) * expression dots * string mcode (* )|} *) + | New of string mcode (* new *) * arguments option * + string mcode (* ( *) option * fullType * + string mcode (* ) *) option * arguments option | TypeExp of fullType (*type name used as an expression, only in arg or #define*) @@ -279,6 +279,8 @@ and form = ANY | ID | LocalID | GlobalID | CONST (* form for MetaExp *) and expression = base_expression wrap +and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) + and listlen = MetaListLen of meta_name mcode * constraints * keep_binding * inherited | CstListLen of int diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 5e84e5dd..eff292d4 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -185,11 +185,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * string mcode (* ) *) - | NewPar of string mcode (* new *) * string mcode (* ( *) * fullType * - string mcode (* ) *) * string mcode (* (|{ *) * expression dots * - string mcode (* )|} *) - | NewNoPar of string mcode (* new *) * fullType * string mcode (* (|{ *) * expression dots * - string mcode (* )|} *) + | New of string mcode (* new *) * arguments option * + string mcode (* ( *) option * fullType * + string mcode (* ) *) option * arguments option | TypeExp of fullType | Paren of string mcode (* ( *) * expression * @@ -264,6 +262,8 @@ and form = ANY | ID | LocalID| GlobalID | CONST (* form for MetaExp *) and expression = base_expression wrap +and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) + and listlen = MetaListLen of meta_name mcode * constraints * keep_binding * inherited | CstListLen of int diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index c08724ad..de1c67cb 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -202,12 +202,10 @@ and expression context old_metas table minus e = expression ID old_metas table minus exp | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> typeC old_metas table minus ty; - dots (expression ID old_metas table minus) expr - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> - typeC old_metas table minus ty; - dots (expression ID old_metas table minus) expr + get_opt (check_args (expression ID old_metas table minus)) pp_opt; + get_opt (check_args (expression ID old_metas table minus)) args_opt; | Ast0.TypeExp(ty) -> typeC old_metas table minus ty | Ast0.Constructor(lp,ty,rp,init) -> typeC old_metas table minus ty; initialiser old_metas table minus init @@ -249,6 +247,8 @@ and check_len table minus len = constraints table minus cstr | _ -> () +and check_args fn (_,args,_) = + dots fn args (* --------------------------------------------------------------------- *) (* Types *) diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 1400a773..b7fde029 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -441,22 +441,18 @@ let rec expression e = let rp = normal_mcode rp in mkres e (Ast0.SizeOfType(szf,lp,typeC ty,rp)) (promote_mcode szf) (promote_mcode rp) - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> (* HIGH doubts in this one *) let nw = normal_mcode nw in - let lp = normal_mcode lp in - let rp = normal_mcode rp in - let lpb = normal_mcode lpb in - let expr = dots is_exp_dots (Some(promote_mcode lpb)) expression expr in - let rpb = normal_mcode rpb in - mkres e (Ast0.NewPar(nw,lp,typeC ty,rp,lpb,expr,rpb)) (promote_mcode nw) - (promote_mcode rpb) - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> - let nw = normal_mcode nw in - let lpb = normal_mcode lpb in - let expr = dots is_exp_dots ( Some(promote_mcode lpb)) expression expr in - let rpb = normal_mcode rpb in - mkres e (Ast0.NewNoPar(nw,typeC ty,lpb,expr,rpb)) (promote_mcode nw) - (promote_mcode rpb) + let pp_opt = get_option normal_args pp_opt in + let lp_opt = get_option normal_mcode lp_opt in + let ty = typeC ty in + let rp_opt = get_option normal_mcode rp_opt in + let args_opt = get_option normal_args args_opt in + let tmp = Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) in + (match (args_opt,rp_opt) with + | (None,None) -> mkres e tmp (promote_mcode nw) ty + | (None,Some x) -> mkres e tmp (promote_mcode nw) (promote_mcode x) + | (Some (lp,args,rp),_) -> mkres e tmp (promote_mcode nw) (promote_mcode rp)) | Ast0.TypeExp(ty) -> let ty = typeC ty in mkres e (Ast0.TypeExp(ty)) ty ty | Ast0.Constructor(lp,ty,rp,init) -> @@ -516,6 +512,12 @@ let rec expression e = let exp = expression exp in mkres e (Ast0.AsSExpr(exp,asexp)) exp exp +and normal_args (lp,args,rp) = + let lp = normal_mcode lp in + let args = dots is_exp_dots (Some(promote_mcode lp)) expression args in + let rp = normal_mcode rp in + (lp,args,rp) + and expression_dots x = dots is_exp_dots None expression x and string_fragment e = diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index 86601e2a..8f7d8232 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -604,6 +604,15 @@ let equal_option e1 e2 = | (None, None) -> true | _ -> false +let equal_args args1 args2= + match (args1, args2) with + | (Some args1, Some args2) -> + let (lp1,_,rp1) = args1 in + let (lp2,_,rp2) = args2 in + equal_mcode lp1 lp2 && equal_mcode rp1 rp2 + | (None, None) -> true + | _ -> false + let dots fn d1 d2 = List.length (Ast0.unwrap d1) = List.length (Ast0.unwrap d2) @@ -682,11 +691,9 @@ let rec equal_expression e1 e2 = equal_mcode szf1 szf2 | (Ast0.SizeOfType(szf1,lp1,_,rp1),Ast0.SizeOfType(szf2,lp2,_,rp2)) -> equal_mcode szf1 szf2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 - | (Ast0.NewPar(new1,lp1,_,rp1,lpb1,_,rpb1), Ast0.NewPar(new2,lp2,_,rp2,lpb2,_,rpb2)) -> - equal_mcode new1 new2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && - equal_mcode lpb1 lpb2 && equal_mcode rpb1 rpb2 - | (Ast0.NewNoPar(new1,_,lpb1,_,rpb1), Ast0.NewNoPar(new2,_,lpb2,_,rpb2)) -> - equal_mcode new1 new2 && equal_mcode lpb1 lpb2 && equal_mcode rpb1 rpb2 + | (Ast0.New(new1,pp1_opt,lp1,_,rp1,args1_opt), Ast0.New(new2,pp2_opt,lp2,_,rp2,args2_opt)) -> + equal_mcode new1 new2 && equal_args pp1_opt pp2_opt && + equal_option lp1 lp2 && equal_option rp1 rp2 && equal_args args1_opt args2_opt | (Ast0.TypeExp(_),Ast0.TypeExp(_)) -> true | (Ast0.Constructor(lp1,_,rp1,_),Ast0.Constructor(lp2,_,rp2,_)) -> equal_mcode lp1 lp2 && equal_mcode rp1 rp2 diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index dc8327dd..81ac5ecf 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -230,14 +230,10 @@ and disjexp e = let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.SizeOfType(szf,lp,ty,rp))) ty - | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> - disjmult2 (disjty ty) (disjdots disjexp expr) - (function ty -> function exp -> - Ast.rewrap e (Ast.NewPar(nw,lp,ty,rp,lpb,exp,rpb))) - | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> - disjmult2 (disjty ty) (disjdots disjexp expr) - (function ty -> function exp -> - Ast.rewrap e (Ast.NewNoPar(nw,ty,lpb,exp,rpb))) + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> + disjmult3 (disjoption disjargs pp_opt) (disjty ty) (disjoption disjargs args_opt) + (fun pp_opt ty args_opt -> + Ast.rewrap e (Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt))) | Ast.TypeExp(ty) -> let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.TypeExp(ty))) ty @@ -266,6 +262,10 @@ and disjexp e = let exp = disjexp exp in List.map (function exp -> Ast.rewrap e (Ast.OptExp(exp))) exp +and disjargs (lp,args,rp) = + let args = disjdots disjexp args in + List.map (function args -> (lp,args,rp)) args + and disjparam p = match Ast.unwrap p with Ast.VoidParam(ty,attr) -> [p] (* void is the only possible value *) diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index a13b5c35..cfb86ba2 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -489,8 +489,7 @@ let do_get_constants constants keywords env (neg_pos,_) = | Ast.MetaExprList(name,_,_,_,_) -> minherited name | Ast.SizeOfExpr(sizeof,exp) -> bind (keywords "sizeof") (k e) | Ast.SizeOfType(sizeof,lp,ty,rp) -> bind (keywords "sizeof") (k e) - | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> bind (keywords "new") (k e) - | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> bind (keywords "new") (k e) + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> bind (keywords "new") (k e) | Ast.NestExpr(starter,expr_dots,ender,wc,false) -> option_default | Ast.NestExpr(starter,expr_dots,ender,wc,true) -> r.V.combiner_expression_dots expr_dots diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index 068e3b0d..cc4f5a34 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -5,7 +5,7 @@ *) (* create an index for each constructor *) -(* current max is 193, also unused: 8-9, 15, 42, 46, 57, +(* current max is 193, also unused: 8-9, 15, 42, 46, 65 *) (* doesn't really work - requires that identical terms with no token @@ -64,7 +64,7 @@ let expression e = | Ast0.Cast(lp,ty,attr,rp,exp) -> [30] | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *) | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *) - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> [65] + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args) -> [57] | Ast0.TypeExp(ty) -> [123] (* added after *) | Ast0.Constructor(lp,ty,rp,init) -> [155] | Ast0.MetaErr(name,_,_) -> [32] diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 6d3eb3d7..86cb7240 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -782,17 +782,11 @@ let match_maker checks_needed context_required whencode_allowed = conjunct_many_bindings [check_mcode lp1 lp; check_mcode rp1 rp; check_mcode szf1 szf; match_typeC tya tyb] - | (Ast0.NewPar(nw1,lp1,ty1,rp1,lpb1,expr1,rpb1), - Ast0.NewPar(nw2,lp2,ty2,rp2,lpb2,expr2,rpb2)) -> - conjunct_many_bindings - [check_mcode lp1 lp2; check_mcode rp1 rp2; check_mcode nw1 nw2; - match_typeC ty1 ty2; check_mcode lpb1 lpb2; check_mcode rpb1 rpb2; - match_dots match_expr is_elist_matcher do_elist_match expr1 expr2] - | (Ast0.NewNoPar(nw1,ty1,lpb1,expr1,rpb1), - Ast0.NewNoPar(nw2,ty2,lpb2,expr2,rpb2)) -> - conjunct_many_bindings - [check_mcode nw1 nw2; match_typeC ty1 ty2; check_mcode lpb1 lpb2; check_mcode rpb1 rpb2; - match_dots match_expr is_elist_matcher do_elist_match expr1 expr2] + | (Ast0.New(nw1,pp1_opt,lp1_opt,ty1,rp1_opt,args1_opt), + Ast0.New(nw2,pp2_opt,lp2_opt,ty2,rp2_opt,args2_opt)) -> + conjunct_many_bindings + [check_mcode nw1 nw2; match_option check_args pp1_opt pp2_opt; match_option check_mcode lp1_opt lp2_opt; + match_typeC ty1 ty2; match_option check_mcode rp1_opt rp2_opt; match_option check_args args1_opt args2_opt] | (Ast0.Constructor(lp1,tya,rp1,inita), Ast0.Constructor(lp,tyb,rp,initb)) -> conjunct_many_bindings @@ -852,6 +846,14 @@ let match_maker checks_needed context_required whencode_allowed = (* the special case for function types prevents the eg T X; -> T X = E; iso from applying, which doesn't seem very relevant, but it also avoids a mysterious bug that is obtained with eg int attach(...); *) + + (* For checking if arguments sorrounded by braces/brackets/paranthesis match *) + and check_args args1 args2 = + let (lp1,args1,rp1) = args1 in + let (lp2,args2,rp2) = args2 in + conjunct_many_bindings + [ check_mcode lp1 lp2; match_dots match_expr is_elist_matcher do_elist_match args1 args2; check_mcode rp1 rp2 ] + and varargs_equal (comma1, ellipsis1) (comma2, ellipsis2) = let c1 = Ast0_cocci.unwrap_mcode comma1 and e1 = Ast0_cocci.unwrap_mcode ellipsis1 diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index d32e7205..e86fd156 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -2188,6 +2188,7 @@ cond_expr(r,pe): dd=TDotDot r=cond_expr(r, pe) { Ast0_cocci.wrap(Ast0_cocci.CondExpr (l, Parse_aux.clt2mcode "?" w, t, Parse_aux.clt2mcode ":" dd, r)) } + | cppnew { $1 } arith_expr(r,pe): cast_expr(r,pe) { $1 } @@ -2282,18 +2283,41 @@ unary_expr(r,pe): { Ast0_cocci.wrap(Ast0_cocci.SizeOfType (Parse_aux.clt2mcode "sizeof" s, Parse_aux.clt2mcode "(" lp,t, Parse_aux.clt2mcode ")" rp)) } - | n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser - { let (lpb2, args, rpb2) = args in - Ast0_cocci.wrap(Ast0_cocci.NewPar ( Parse_aux.clt2mcode "new" n, - Parse_aux.clt2mcode "(" lp1, t, Parse_aux.clt2mcode ")" rp1, - lpb2, args, rpb2)) } +cppnew: + (* There are a total of 8 variations of New, because of three independant binary possibilities, + that is, new (placement params)|None (type)|type initilizer|None *) + n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, + Some (Parse_aux.clt2mcode "(" lp1), t, Some (Parse_aux.clt2mcode ")" rp1), args )) } | n=TNew t=ctype_without_braces args=cpp_initialiser - { let (lpb2, args, rpb2) = args in - Ast0_cocci.wrap(Ast0_cocci.NewNoPar ( Parse_aux.clt2mcode "new" n, t, lpb2, args, rpb2)) } + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, None, t, None, args )) } + | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), + args )) } + | n=TNew pp=placement_params t=ctype_without_braces + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + None, t, None, None )) } + + | n=TNew lp1=TOPar t=ctype rp1=TCPar + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, + Some (Parse_aux.clt2mcode "(" lp1), t, Some (Parse_aux.clt2mcode ")" rp1), + None )) } + | n=TNew t=ctype_without_braces + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, None, t, None, None )) } + | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), None )) } + | n=TNew pp=placement_params t=ctype_without_braces args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, None, t, None, args )) } + cpp_initialiser: - lp=TOPar args=eexpr_list_option rp=TCPar { (Parse_aux.clt2mcode "(" lp, args, Parse_aux.clt2mcode ")" rp) } - | lb=TOBrace args=eexpr_list_option rb=TCBrace { (Parse_aux.clt2mcode "{" lb, args, Parse_aux.clt2mcode "}" rb) } + lp=TOPar args=eexpr_list_option rp=TCPar { Some (Parse_aux.clt2mcode "(" lp, args, Parse_aux.clt2mcode ")" rp) } + | lb=TOBrace args=eexpr_list_option rb=TCBrace { Some (Parse_aux.clt2mcode "{" lb, args, Parse_aux.clt2mcode "}" rb) } + +placement_params: + lp=TOPar args=eexpr_list_option_without_ctype rp=TCPar { Some (Parse_aux.clt2mcode "(" lp, args, Parse_aux.clt2mcode ")" rp) } // version that allows dots unary_expr_bis: @@ -2310,12 +2334,35 @@ unary_expr_bis: { Ast0_cocci.wrap(Ast0_cocci.SizeOfType (Parse_aux.clt2mcode "sizeof" s, Parse_aux.clt2mcode "(" lp,t, Parse_aux.clt2mcode ")" rp)) } - | n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser - { let (lpb2, args, rpb2) = args in - Ast0_cocci.wrap(Ast0_cocci.NewPar ( Parse_aux.clt2mcode "new" n, - Parse_aux.clt2mcode "(" lp1, t, Parse_aux.clt2mcode ")" rp1, - lpb2, args, rpb2)) } - +/* | n=TNew lp1=TOPar t=ctype rp1=TCPar args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, + Some (Parse_aux.clt2mcode "(" lp1), t, Some (Parse_aux.clt2mcode ")" rp1), args )) } + | n=TNew t=ctype_without_braces args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, + None, t, None, args )) } + | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), + args )) } + | n=TNew pp=placement_params t=ctype_without_braces args=cpp_initialiser + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + None, t, None, args )) } + + + | n=TNew lp1=TOPar t=ctype rp1=TCPar + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, + Some (Parse_aux.clt2mcode "(" lp1), t, Some (Parse_aux.clt2mcode ")" rp1), + None )) } + | n=TNew t=ctype_without_braces + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, None, t, None, None )) } + | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), + None )) } + | n=TNew pp=placement_params t=ctype_without_braces + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, + None, t, None, None )) } +*/ unary_op: TAnd { Parse_aux.clt2mcode Ast_cocci.GetRef $1 } | TMul { Parse_aux.clt2mcode Ast_cocci.DeRef $1 } | TPlus { Parse_aux.clt2mcode Ast_cocci.UnPlus $1 } @@ -3083,14 +3130,17 @@ when_start: /* arg expr. may contain a type or a explist metavariable */ aexpr: + aexpr_without_ctype { $1 } + | ctype + { Ast0_cocci.set_arg_exp(Ast0_cocci.wrap(Ast0_cocci.TypeExp($1))) } + +aexpr_without_ctype: dargexpr { Ast0_cocci.set_arg_exp $1 } | TMetaExpList { let (nm,lenname,constraints,pure,clt) = $1 in let nm = Parse_aux.clt2mcode nm clt in let lenname = Parse_aux.dolen clt lenname in Ast0_cocci.wrap(Ast0_cocci.MetaExprList(nm,lenname,constraints,pure)) } - | ctype - { Ast0_cocci.set_arg_exp(Ast0_cocci.wrap(Ast0_cocci.TypeExp($1))) } eexpr_list_option: empty_list_start(aexpr,TEllipsis) @@ -3099,6 +3149,14 @@ eexpr_list_option: (fun _ d -> Ast0_cocci.wrap(Ast0_cocci.Edots(Parse_aux.clt2mcode "..." d,None))) (fun c -> Ast0_cocci.EComma c)) } +eexpr_list_option_without_ctype: + empty_list_start(aexpr_without_ctype,TEllipsis) + { Ast0_cocci.wrap + ($1 + (fun _ d -> Ast0_cocci.wrap(Ast0_cocci.Edots(Parse_aux.clt2mcode "..." d,None))) + (fun c -> Ast0_cocci.EComma c)) } + + /****************************************************************************/ // IBM C only diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 9f60aefc..ac2f085c 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -259,24 +259,15 @@ let rec expression e = mcode print_string sizeof; mcode print_string_box lp; fullType ty; close_box(); mcode print_string rp - | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> - mcode print_string nw; - print_string " "; - mcode print_string lp; - fullType ty; - mcode print_string rp; - print_string " "; - mcode print_string lpb; - dots (function _ -> ()) expression expr; - mcode print_string rpb - | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> mcode print_string nw; print_string " "; + print_option print_args pp_opt; + print_option (function e -> mcode print_string e) lp_opt; fullType ty; + print_option (function e -> mcode print_string e) rp_opt; print_string " "; - mcode print_string lpb; - dots (function _ -> ()) expression expr; - mcode print_string rpb + print_option print_args args_opt; | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; fullType ty; close_box(); @@ -303,6 +294,12 @@ let rec expression e = | Ast.Edots(dots,None) -> mcode print_string dots | Ast.OptExp(exp) -> print_string "?"; expression exp +and print_args (lp,args,rp) = + mcode print_string lp; + dots (function _ -> ()) expression args; + mcode print_string rp; + print_string " "; + and string_fragment e = match Ast.unwrap e with Ast.ConstantFragment(str) -> mcode print_string str diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 4fd8cc98..9206a77c 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -141,8 +141,7 @@ let rec left_expression e = | Ast0.Cast(lp,ty,attr,rp,exp) -> modif_before_mcode lp | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> modif_before_mcode nw - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> modif_before_mcode nw + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> modif_before_mcode nw | Ast0.TypeExp(ty) -> left_typeC ty | Ast0.Constructor(lp,ty,rp,init) -> modif_before_mcode lp | Ast0.MetaErr(name,_,_) -> modif_before_mcode name diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml index fec8ae8d..1be5ad6d 100644 --- a/parsing_cocci/type_infer.ml +++ b/parsing_cocci/type_infer.ml @@ -294,8 +294,7 @@ let rec propagate_types env = | Ast0.Cast(lp,ty,attr,rp,exp) -> Some ty | Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type) | Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type) - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> Some ty - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> Some ty + | Ast0.New(nw,pp,lp_opt,ty,rp_opt,args) -> Some ty | Ast0.TypeExp(ty) -> None | Ast0.Constructor(lp,ty,rp,init) -> Some ty | Ast0.MetaErr(name,_,_) -> None diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index fd2510fe..307fc68e 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -229,12 +229,10 @@ and unify_expression e1 e2 = unify_expression e1 e2 | (Ast.SizeOfType(szf1,lp1,ty1,rp1),Ast.SizeOfType(szf2,lp2,ty2,rp2)) -> unify_fullType ty1 ty2 - | (Ast.NewPar(new1,lp1,ty1,rp1,lpb1,expr1,rpb1), Ast.NewPar(new2,lp2,ty2,rp2,lpb2,expr2,rpb2)) -> + | (Ast.New(new1,pp1_opt,lp1_opt,ty1,rp1_opt,args1_opt), Ast.New(new2,pp2_opt,lp2_opt,ty2,rp2_opt,args2_opt)) -> unify_fullType ty1 ty2 && - unify_dots unify_expression edots expr1 expr2 - | (Ast.NewNoPar(new1,ty1,lpb1,expr1,rpb1), Ast.NewNoPar(new2,ty2,lpb2,expr2,rpb2)) -> - unify_fullType ty1 ty2 && - unify_dots unify_expression edots expr1 expr2 + unify_option unify_args pp1_opt pp2_opt && + unify_option unify_args args1_opt args2_opt | (Ast.TypeExp(ty1),Ast.TypeExp(ty2)) -> unify_fullType ty1 ty2 | (Ast.Constructor(lp1,ty1,rp1,i1),Ast.Constructor(lp2,ty2,rp2,i2)) -> unify_fullType ty1 ty2 && unify_initialiser i1 i2 @@ -279,6 +277,10 @@ and unify_expression e1 e2 = | (_,Ast.OptExp(_)) -> failwith "unsupported expression" | _ -> false +(* Used for the nonterminal arguments *) +and unify_args (_,args1,_) (_,args2,_) = + unify_dots unify_expression edots args1 args2 + (* --------------------------------------------------------------------- *) (* Strings *) diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index db2ffc54..d65a1b64 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -231,24 +231,15 @@ let rec expression e = mcode print_string szf; mcode print_string_box lp; typeC ty; close_box(); mcode print_string rp - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> - mcode print_string nw; - print_string " "; - mcode print_string lp; - typeC ty; - mcode print_string rp; - print_string " "; - mcode print_string lpb; - expression_dots expr; - mcode print_string rpb - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + | Ast0.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> mcode print_string nw; print_string " "; + print_option (print_args true) pp_opt; + print_option (function e -> mcode print_string e) lp_opt; typeC ty; + print_option (function e -> mcode print_string e) rp_opt; print_string " "; - mcode print_string lpb; - expression_dots expr; - mcode print_string rpb + print_option (print_args false) args_opt; | Ast0.TypeExp(ty) -> typeC ty | Ast0.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; typeC ty; close_box(); @@ -287,6 +278,13 @@ let rec expression e = and expression_dots x = dots (function _ -> ()) expression x +and print_args putspace (lp,args,rp) = + mcode print_string lp; + expression_dots args; + mcode print_string rp; + if putspace then + print_string " " + and string_fragment e = match Ast0.unwrap e with Ast0.ConstantFragment(str) -> mcode print_string str diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 05ad3f3b..17204ab1 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -217,22 +217,14 @@ let combiner bind option_default let lty = fullType ty in let lrp = string_mcode rp in multibind [lszf; llp; lty; lrp] - | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> let lnw = string_mcode nw in - let llp = string_mcode lp in + let lpp_opt = get_option argslist pp_opt in + let llp = get_option string_mcode lp_opt in let lty = fullType ty in - let lrp = string_mcode rp in - let llpb = string_mcode lpb in - let lexpr = expression_dots expr in - let lrpb = string_mcode rpb in - multibind [lnw; llp; lty; lrp; llpb; lexpr; lrpb] - | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> - let lnw = string_mcode nw in - let lty = fullType ty in - let llpb = string_mcode lpb in - let lexpr = expression_dots expr in - let lrpb = string_mcode rpb in - multibind [lnw; lty; llpb; lexpr; lrpb] + let lrp = get_option string_mcode rp_opt in + let largs_opt = get_option argslist args_opt in + multibind [lnw; lpp_opt; llp; lty; lrp; largs_opt] | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in @@ -267,6 +259,12 @@ let combiner bind option_default | Ast.OptExp(exp) -> expression exp in exprfn all_functions k e + and argslist (lp,args,rp) = + let lp = string_mcode lp in + let args = expression_dots args in + let rp = string_mcode rp in + multibind [lp; args; rp] + and assignOp op = let k e = match Ast.unwrap e with @@ -1270,22 +1268,14 @@ let rebuilder let lty = fullType ty in let lrp = string_mcode rp in Ast.SizeOfType(lszf, llp, lty, lrp) - | Ast.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> let lnw = string_mcode nw in - let llp = string_mcode lp in + let lpp_opt = get_option argslist pp_opt in + let llp_opt = get_option string_mcode lp_opt in let lty = fullType ty in - let lrp = string_mcode rp in - let llpb = string_mcode lpb in - let lexpr = expression_dots expr in - let lrpb = string_mcode rpb in - Ast.NewPar(lnw,llp,lty,lrp,llpb,lexpr,lrpb) - | Ast.NewNoPar(nw,ty,lpb,expr,rpb) -> - let lnw = string_mcode nw in - let lty = fullType ty in - let llpb = string_mcode lpb in - let lexpr = expression_dots expr in - let lrpb = string_mcode rpb in - Ast.NewNoPar(lnw,lty,llpb,lexpr,lrpb) + let lrp_opt = get_option string_mcode rp_opt in + let largs_opt = get_option argslist args_opt in + Ast.New(lnw,lpp_opt,llp_opt,lty,lrp_opt,largs_opt) | Ast.TypeExp(ty) -> Ast.TypeExp(fullType ty) | Ast.Constructor(lp,ty,rp,init) -> let llp = string_mcode lp in @@ -1325,6 +1315,12 @@ let rebuilder | Ast.OptExp(exp) -> Ast.OptExp(expression exp)) in exprfn all_functions k e + and argslist (lp,args,rp) = + let lp = string_mcode lp in + let args = expression_dots args in + let rp = string_mcode rp in + (lp,args,rp) + and string_fragment e = let k e = Ast.rewrap e diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index deb9ad81..385e9de0 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -202,22 +202,14 @@ let visitor mode bind option_default let (ty_n,ty) = typeC ty in let (rp_n,rp) = string_mcode rp in (multibind [szf_n;lp_n;ty_n;rp_n], Ast0.SizeOfType(szf,lp,ty,rp)) - | Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb) -> - let (nw_n,nw) = string_mcode nw in - let (lp_n,lp) = string_mcode lp in - let (ty_n,ty) = typeC ty in - let (rp_n,rp) = string_mcode rp in - let (lpb_n,lpb) = string_mcode lpb in - let (expr_n,expr) = expression_dots expr in - let (rpb_n,rpb) = string_mcode rpb in - (multibind [nw_n;lp_n;ty_n;rp_n;lpb_n;expr_n;rpb_n], Ast0.NewPar(nw,lp,ty,rp,lpb,expr,rpb)) - | Ast0.NewNoPar(nw,ty,lpb,expr,rpb) -> + | Ast0.New(nw,pp_opt,lp2_opt,ty,rp2_opt,args_opt) -> let (nw_n,nw) = string_mcode nw in + let (pp_opt_n, pp_opt) = get_option argslist pp_opt in + let (lp2_n,lp2) = get_option string_mcode lp2_opt in let (ty_n,ty) = typeC ty in - let (lpb_n,lpb) = string_mcode lpb in - let (expr_n,expr) = expression_dots expr in - let (rpb_n,rpb) = string_mcode rpb in - (multibind [nw_n;ty_n;lpb_n;expr_n;rpb_n], Ast0.NewNoPar(nw,ty,lpb,expr,rpb)) + let (rp2_n,rp2) = get_option string_mcode rp2_opt in + let (args_n, args) = get_option argslist args_opt in + (multibind [nw_n;pp_opt_n;lp2_n;ty_n;rp2_n;args_n], Ast0.New(nw,pp_opt,lp2,ty,rp2,args_opt)) | Ast0.TypeExp(ty) -> let (ty_n,ty) = typeC ty in (ty_n,Ast0.TypeExp(ty)) @@ -269,7 +261,11 @@ let visitor mode bind option_default let (asstm_n,asstm) = statement asstm in (bind exp_n asstm_n, Ast0.AsSExpr(exp,asstm))) in exprfn all_functions k e - + and argslist (lp,args,rp) = + let (lp_n,lp) = string_mcode lp in + let (args_n, args) = expression_dots args in + let (rp_n,rp) = string_mcode rp in + (multibind [lp_n; args_n; rp_n], (lp,args,rp)) and string_fragment e = let k e = rewrap e -- GitLab From 66d401a95e603f6a623907642ec59920ed0b08de Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Wed, 8 Jun 2022 21:19:53 +0530 Subject: [PATCH 04/24] Added new functionality in parsing_c/ --- engine/cocci_vs_c.ml | 14 ++++ ocaml/coccilib.mli | 12 ++-- parsing_c/ast_c.ml | 3 +- parsing_c/ast_c.mli | 2 +- parsing_c/parser_c.mly | 99 ++++++++++++++++++++++++--- parsing_c/pretty_print_c.ml | 33 ++++++++- parsing_c/type_annoter_c.ml | 2 +- parsing_c/unparse_cocci.ml | 2 +- parsing_c/unparse_hrule.ml | 8 +-- parsing_c/visitor_c.ml | 19 ++--- parsing_cocci/parser_cocci_menhir.mly | 7 -- 11 files changed, 160 insertions(+), 41 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 8b40b3a0..bf1dc141 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -1587,6 +1587,20 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = ((B.SizeOfType (typb),typ),[ib1;ib2;ib3]) ))))) + | A.New (ia1, pp_opt,ia2_opt,typa,ia3_opt,argsa), ((B.New (pp_opt,typb,init_opt), typ), ib1::ii) -> + tokenf ia1 ib1 >>= (fun ia1 ib1 -> + fullType tpya typb >>= (fun typa typb -> + let rest = + default ii + (function x -> + match rest with + ib2::ib3::rest -> + let (ia2, pp, ia3) = pp_opt in + option tokenf ia2_opt (Some ib2) >>= ( fun ia2_opt (Some ib2) -> + option tokenf ia3_opt (Some + + ) + pp in (* todo? iso ? allow all the combinations ? *) | A.Paren (ia1, ea, ia2), ((B.ParenExpr (eb), typ),ii) -> diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 4177cd6c..8bd545a4 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -2613,9 +2613,8 @@ module Ast_cocci : | Cast of string mcode * fullType * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * fullType * string mcode - | NewPar of string mcode * string mcode * fullType * string mcode * string mcode * expression dots * - string mcode - | NewNoPar of string mcode * fullType * string mcode * expression dots * string mcode + | New of string mcode * arguments option * string mcode option * fullType * string mcode option * + arguments option | TypeExp of fullType | Paren of string mcode * expression * string mcode | Constructor of string mcode * fullType * string mcode * initialiser @@ -2633,6 +2632,7 @@ module Ast_cocci : expression option * multi | Edots of string mcode * expression option | OptExp of expression + and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) and 'a generic_constraints = 'a Ast_cocci.generic_constraints = CstrFalse @@ -3366,9 +3366,8 @@ module Ast0_cocci : | Cast of string mcode * typeC * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * typeC * string mcode - | NewPar of string mcode * string mcode * typeC * string mcode * string mcode * expression dots * - string mcode - | NewNoPar of string mcode * typeC * string mcode * expression dots * string mcode + | New of string mcode * arguments option * string mcode option * typeC * string mcode option * + arguments option | TypeExp of typeC | Constructor of string mcode * typeC * string mcode * initialiser | MetaErr of Ast_cocci.meta_name mcode * constraints * pure @@ -3389,6 +3388,7 @@ module Ast0_cocci : (string mcode * string mcode * expression) option | OptExp of expression and expression = base_expression wrap + and arguments = string mcode (* ( *) * expression dots * string mcode (* ) *) and constraints = expression Ast_cocci.generic_constraints and listlen = Ast0_cocci.listlen = diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml index 76568e74..2892363b 100644 --- a/parsing_c/ast_c.ml +++ b/parsing_c/ast_c.ml @@ -368,14 +368,13 @@ and expression = (expressionbis * exp_info ref (* semantic: *)) wrap3 | ParenExpr of expression (* for C++: *) - | New of (argument wrap2 (* , *) list) option * argument + | New of (argument wrap2 (* , *) list) option * fullType * (argument wrap2 (* , *) list) option | Delete of bool (* true if [] *) * expression (* CPP [defined] operator, e.g. #if defined(A) *) | Defined of name (* cppext: IfdefExpr TODO *) - (* cppext: normally just expression *) and argument = (expression, weird_argument) Common.either and weird_argument = diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli index c7a012de..44d62838 100644 --- a/parsing_c/ast_c.mli +++ b/parsing_c/ast_c.mli @@ -118,7 +118,7 @@ and expressionbis = | StatementExpr of compound wrap | Constructor of fullType * initialiser | ParenExpr of expression - | New of argument wrap2 list option * argument + | New of (argument wrap2 list) option * fullType * (argument wrap2 list) option | Delete of bool (* true if [] *) * expression | Defined of name and argument = (expression, weird_argument) Common.either diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 581379e1..0da55e44 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -814,9 +814,77 @@ cond_expr: { $1 } | arith_expr TWhy gcc_opt_expr TDotDot cond_expr { mk_e (CondExpr ($1,$3,$5)) [$2;$4] } - | Tnew new_argument { mk_e(New (None, $2)) [$1] } - | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5)) [$1; $2; $4] } - + | Tnew cpp_type /*ask about using a Tnull*/ + /* does cpp_type support class names and nested-specifiers */ + cpp_initialiser_opt + { + let (ty,par2) = $2 in + let (init,par3) = $3 in + mk_e (New (None, ty, init)) ($1 :: par2 @ par3) } + | Tnew placement_params_opt + cpp_type + cpp_initialiser_opt + { + let (pp,par1) = $2 in + let (ty,par2) = $3 in + let (init,par3) = $4 in + mk_e (New (pp, ty, init)) ($1 :: par1 @ par2 @ par3) + } + +placement_params_opt: + TOPar argument_list_ne_without_paramdecl TCPar { (Some $2, [$1;$3] ) } + +cpp_initialiser_opt: + | TOPar argument_list_ne TCPar { (Some $2, [$1;$3] ) } + | TOBrace argument_list_ne TCBrace { (Some $2, [$1;$3] ) } + | /*(* empty *)*/ { (None, []) } + +cpp_type: + TOPar simple_type TCPar + { let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); $2),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + ((snd ret), [$1;$3]) + } + | simple_type + { + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); $1),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + ((snd ret), []) + } + | TOPar TIdent TCPar { + let name = RegularName (mk_string_wrap $2) in + let st = (Right3 (TypeName (name, Ast_c.noTypedefDef())),[]) in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); st),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + ((snd ret), [$1;$3]) +} + | TIdent { + let name = RegularName (mk_string_wrap $1) in + let st = (Right3 (TypeName (name, Ast_c.noTypedefDef())),[]) in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); st),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + ((snd ret), []) +} arith_expr: | cast_expr { $1 } @@ -988,6 +1056,9 @@ argument_ne: | parameter_decl_arg { Right (ArgType $1) } | action_higherordermacro_ne { Right (ArgAction $1) } +argument_ne_without_paramdecl: + | assign_expr { Left $1 } + | action_higherordermacro_ne { Right (ArgAction $1) } argument: | assign_expr { Left $1 } @@ -1341,8 +1412,9 @@ simple_type: [] -> ret | _ -> warning "attributes found in typeof(...), dropping" ret } -type_spec2: +type_spec2_without_braces: simple_type { $1 } +type_spec2_with_braces: | struct_or_union_spec { Right3 (fst $1), snd $1 } | enum_spec { Right3 (fst $1), snd $1 } @@ -1350,7 +1422,9 @@ type_spec2: /*(* workarounds *)*/ /*(*----------------------------*)*/ -type_spec: type_spec2 { dt "type" (); $1 } +type_spec: + type_spec2_without_braces { dt "type" (); $1 } + | type_spec2_with_braces { dt "type" (); $1 } /*(*-----------------------------------------------------------------------*)*/ /*(* Qualifiers *)*/ @@ -1693,7 +1767,6 @@ spec_qualif_list2: spec_qualif_list: spec_qualif_list2 { dt "spec_qualif" (); $1 } - /*(* for pointers in direct_declarator and abstract_declarator *)*/ type_qualif_list: | type_qualif { (Ast_c.noattr,{nullDecl with qualifD = (fst $1,[snd $1])}) } @@ -1715,8 +1788,6 @@ type_name: let (returnType, _) = fixDeclSpecForDecl ds in (attrs1@attrs2, fn returnType) } - - abstract_declaratort: | abstract_declarator { $1 } /*(* gccext: *)*/ @@ -2736,6 +2807,10 @@ argument_list_ne: | argument_ne { [$1, []] } | argument_list_ne TComma argument { $1 @ [$3, [$2]] } +argument_list_ne_without_paramdecl: + | argument_ne_without_paramdecl { [$1, []] } + | argument_list_ne TComma argument_ne_without_paramdecl { $1 @ [$3, [$2]] } + argument_list: | argument { [$1, []] } | argument_list TComma argument { $1 @ [$3, [$2]] } @@ -2837,6 +2912,14 @@ comma_opt: | TComma { [$1] } | /*(* empty *)*/ { [] } +TOPar_opt: + | TOPar { [$1] } + | /*(* empty *)*/ { [] } + +TCPar_opt: + | TCPar { [$1] } + | /*(* empty *)*/ { [] } + /*(* gcc_opt_virg: | TPtVirg { } diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index dc94fc56..02a694ff 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -167,9 +167,30 @@ let mk_pretty_printers | ParenExpr (e), [i1;i2] -> pr_elem i1; pp_expression e; pr_elem i2; - | New (None, t), [i1] -> pr_elem i1; pp_argument t - | New (Some ts, t), [i1; i2; i3] -> - pr_elem i1; pr_elem i2; pp_arg_list ts; pr_elem i3; pp_argument t + | New (pp, t, init), i1::rest -> + pr_elem i1; pr_space(); + let rest = + default rest + (function x -> + match rest with + i2::i3::rest -> + pr_arg_list_with_par (i2,x,i3); + rest + | _ -> failwith "impossible") + pp in + (match init with + None -> + (match rest with + [i4;i5] -> pr_elem i4; pp_type t; pr_elem i5 + | [] -> pp_type t + | _ -> failwith "impossible") + | Some init -> + (match rest with + [i4;i5;i6;i7] -> + pr_elem i4; pp_type t; pr_elem i5; + pr_arg_list_with_par (i6, init, i7) + | [i6;i7] -> pp_type t; pr_arg_list_with_par (i6,init,i7) + | _ -> failwith "impossible")) | Delete(false,t), [i1] -> pr_elem i1; pr_space(); pp_expression t | Delete(true,t), [i1;i2;i3] -> pr_elem i1; pr_space(); pr_elem i2; pr_elem i3; pr_space(); @@ -212,6 +233,12 @@ let mk_pretty_printers let i = Common.tuple_of_list1 ii in pr_elem i + and pr_arg_list_with_par (i1, args, i2) = + pr_elem i1; + pp_arg_list args; + pr_elem i2; + pr_space() + and pr_binaryOp (_,ii) = let i = Common.tuple_of_list1 ii in pr_elem i diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml index 1dbb89aa..6d1332f9 100644 --- a/parsing_c/type_annoter_c.ml +++ b/parsing_c/type_annoter_c.ml @@ -1151,7 +1151,7 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr -> | _ -> k expr; Type_c.noTypeHere *) - | New (_, ty) -> + | New (_, ty, _) -> k expr; pr2_once "Type annotater:not handling New"; Type_c.noTypeHere (* TODO *) diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 37265e2e..de8d4598 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -459,7 +459,7 @@ let rec expression e = | Ast_c.StatementExpr (statxs, _) -> top | Ast_c.Constructor (t, init) -> unary | Ast_c.ParenExpr (e) -> primary - | Ast_c.New (_, t) -> unary + | Ast_c.New (_, t, _) -> unary | Ast_c.Delete(_,t) -> unary | Ast_c.Defined _ -> primary in diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml index ffa2268b..4a95a859 100644 --- a/parsing_c/unparse_hrule.ml +++ b/parsing_c/unparse_hrule.ml @@ -200,11 +200,11 @@ let print_metavar pr = function print_typedef pr ty; Pretty_print_c.pp_param_gen - (function x -> + ~pr_elem:(function x -> let str = Ast_c.str_of_info x in if not (List.mem str ["const";"volatile"]) then pr str) - (function _ -> pr " ") + ~pr_space:(function _ -> pr " ") {Ast_c.p_register = (false,[]); p_namei = Some name'; p_type = (({Ast_c.const = false; Ast_c.volatile = false},[]),ty); @@ -338,8 +338,8 @@ let print_one_type pr env ty = match List.assoc name env with Ast_c.MetaTypeVal ty -> Pretty_print_c.pp_type_gen - (function x -> pr (Ast_c.str_of_info x)) - (function _ -> pr " ") + ~pr_elem:(function x -> pr (Ast_c.str_of_info x)) + ~pr_space:(function _ -> pr " ") ty | _ -> failwith "impossible" with Not_found -> pr (Ast_cocci.string_of_fullType ty)) diff --git a/parsing_c/visitor_c.ml b/parsing_c/visitor_c.ml index 47a27ece..b5a00331 100644 --- a/parsing_c/visitor_c.ml +++ b/parsing_c/visitor_c.ml @@ -341,10 +341,10 @@ let rec vk_expr = fun bigf expr -> | ParenExpr (e) -> exprf e - | New (None, t) -> vk_argument bigf t - | New (Some ts, t) -> - vk_argument_list bigf ts; - vk_argument bigf t + | New (pp, t, init) -> + do_option (vk_argument_list bigf) pp; + vk_type bigf t; + do_option (vk_argument_list bigf) init | Delete (_,e) -> vk_expr bigf e | Defined name -> vk_name bigf name @@ -1248,10 +1248,13 @@ let rec vk_expr_s = fun bigf expr -> | ParenExpr (e) -> ParenExpr (exprf e) - | New (None, t) -> New (None, vk_argument_s bigf t) - | New (Some ts, t) -> - New (Some (ts +> List.map (fun (e,ii) -> - vk_argument_s bigf e, iif ii)), vk_argument_s bigf t) + | New (pp, t, init) -> + New ( + fmap (function pp -> pp +> List.map (fun (e,ii) -> + vk_argument_s bigf e, iif ii)) pp, + vk_type_s bigf t, + fmap (function init -> init +> List.map (fun (e,ii) -> + vk_argument_s bigf e, iif ii)) init) | Delete (box,e) -> Delete (box,vk_expr_s bigf e) | Defined name -> Defined (vk_name_s bigf name) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index e86fd156..be589eca 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -2291,10 +2291,6 @@ cppnew: Some (Parse_aux.clt2mcode "(" lp1), t, Some (Parse_aux.clt2mcode ")" rp1), args )) } | n=TNew t=ctype_without_braces args=cpp_initialiser { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, None, t, None, args )) } - | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar args=cpp_initialiser - { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, - Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), - args )) } | n=TNew pp=placement_params t=ctype_without_braces { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, None, t, None, None )) } @@ -2308,9 +2304,6 @@ cppnew: | n=TNew pp=placement_params lp2=TOPar t=ctype rp2=TCPar { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, Some (Parse_aux.clt2mcode "(" lp2), t, Some (Parse_aux.clt2mcode ")" rp2), None )) } - | n=TNew pp=placement_params t=ctype_without_braces args=cpp_initialiser - { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, pp, None, t, None, args )) } - cpp_initialiser: lp=TOPar args=eexpr_list_option rp=TCPar { Some (Parse_aux.clt2mcode "(" lp, args, Parse_aux.clt2mcode ")" rp) } -- GitLab From 66db7f4aed95ccd4706cce19d5942086d183cb85 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Sun, 12 Jun 2022 10:50:44 +0530 Subject: [PATCH 05/24] Modified engine/cocci_vs_c.ml to support New --- engine/cocci_vs_c.ml | 76 ++++++++++++++++++++++++++++++++++++-------- ocaml/coccilib.mli | 2 +- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index bf1dc141..2f618d68 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -1587,20 +1587,70 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = ((B.SizeOfType (typb),typ),[ib1;ib2;ib3]) ))))) - | A.New (ia1, pp_opt,ia2_opt,typa,ia3_opt,argsa), ((B.New (pp_opt,typb,init_opt), typ), ib1::ii) -> + | A.New (ia1, pp_opta,ia4_opt,typa,ia5_opt,init_opta), ((B.New (pp_optb,typb,init_optb), typ), ib1::ii) -> tokenf ia1 ib1 >>= (fun ia1 ib1 -> - fullType tpya typb >>= (fun typa typb -> - let rest = - default ii - (function x -> - match rest with - ib2::ib3::rest -> - let (ia2, pp, ia3) = pp_opt in - option tokenf ia2_opt (Some ib2) >>= ( fun ia2_opt (Some ib2) -> - option tokenf ia3_opt (Some - - ) - pp in + option (fun (ia2, x, ia3) (_,y,_,_) -> + arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> + let x = A.rewrap x xunwrap in + match ii with + ib2::ib3::ii -> + tokenf ia2 ib2 >>= (fun ia2 ib2 -> + tokenf ia3 ib3 >>= (fun ia3 ib3 -> + return ((ia2, x, ia3), (ib2, y, ib3, ii)) + )) + |_ -> failwith "impossible")) + pp_opta (match pp_optb with + None -> None + | Some pp_optb -> Some (ib1, pp_optb, ib1, []) ) >>= (fun pp_opta pp_optb -> + let (ib23,pp_optb,ii) = + match pp_optb with + None -> ([],None, ii) + | Some (ib2, pp_optb, ib3, ii) -> ([ib2;ib3],Some pp_optb,ii) in + option (fun ia4 _ -> + match ii with + ib4::ii -> + tokenf ia4 ib4 >>= (fun ia4 ib4-> + return (ia4, (ib4, ii))) + | _ -> fail) + ia4_opt (if ia4_opt=None then None else Some (ib1, [])) >>= + (fun ia4_opt ib4_opt -> + let (ib4, ii) = + match ib4_opt with + None -> ([], ii) + | Some (ib4, ii) -> ([ib4], ii) in + fullType typa typb >>= (fun typa typb -> + option ( fun ia5 _ -> + match ii with + ib5::ii -> tokenf ia5 ib5 >>= (fun ia5 ib5 -> + return (ia5, (ib5, ii))) + | _ -> fail) + ia5_opt (if ia5_opt=None then None else Some (ib1, [])) >>= (*EXPLAIN WHY I MADE THE CODE SO WEIRD*) + (fun ia5_opt ib5_opt -> + let (ib5, ii) = + match ib5_opt with + None -> ([], ii) + | Some (ib5, ii) -> ([ib5], ii) in + option (fun (ia6, x, ia7) (_, y, _) -> + arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> + let x = A.rewrap x xunwrap in + match ii with + [ib6;ib7] -> + tokenf ia6 ib6 >>= (fun ia6 ib6 -> + tokenf ia7 ib7 >>= (fun ia7 ib7 -> + return ((ia6, x, ia7), (ib6, y, ib7)))) + | ib5::ib6::l -> fail (* EXPLAIN TO MADAM WHY THIS IS NOT failwith*) + | _ -> failwith "impossible")) + init_opta (match init_optb with + None -> None + | Some init_optb -> Some (ib1, init_optb, ib1)) >>= (fun init_opta init_optb -> + let (ib67, init_optb) = match init_optb with + None -> ([], None) + | Some (ib6, init_optb, ib7) -> ([ib6;ib7], Some init_optb) in + return ( + ((A.New(ia1, pp_opta, ia4_opt, typa, ia5_opt ,init_opta))) +> wa, + ((B.New(pp_optb, typb, init_optb), typ), [ib1]@ib23@ib4@ib5@ib67) + ))))))) + (* todo? iso ? allow all the combinations ? *) | A.Paren (ia1, ea, ia2), ((B.ParenExpr (eb), typ),ii) -> diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 8bd545a4..03c58275 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -162,7 +162,7 @@ module Ast_c : | StatementExpr of compound wrap | Constructor of fullType * initialiser | ParenExpr of expression - | New of argument wrap2 list option * argument + | New of argument wrap2 list option * fullType * argument wrap2 list option | Delete of bool * expression | Defined of name and argument = (expression, weird_argument) Common.either -- GitLab From b94bd73d551a96d46e5db76b5c8c94a87e686800 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 14 Jun 2022 11:27:03 +0530 Subject: [PATCH 06/24] Fixed Bugs in New checker Signed-off-by: Tathagata Roy --- engine/cocci_vs_c.ml | 68 +++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 2f618d68..50d88c88 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -1589,31 +1589,35 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = | A.New (ia1, pp_opta,ia4_opt,typa,ia5_opt,init_opta), ((B.New (pp_optb,typb,init_optb), typ), ib1::ii) -> tokenf ia1 ib1 >>= (fun ia1 ib1 -> - option (fun (ia2, x, ia3) (_,y,_,_) -> + (* for checking pp_opt *) + option (fun (ia2, x, ia3) (ib2,y,ib3,ii) -> arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> let x = A.rewrap x xunwrap in - match ii with - ib2::ib3::ii -> tokenf ia2 ib2 >>= (fun ia2 ib2 -> tokenf ia3 ib3 >>= (fun ia3 ib3 -> return ((ia2, x, ia3), (ib2, y, ib3, ii)) )) - |_ -> failwith "impossible")) - pp_opta (match pp_optb with - None -> None - | Some pp_optb -> Some (ib1, pp_optb, ib1, []) ) >>= (fun pp_opta pp_optb -> + )) + pp_opta + (match (pp_optb,ii) with + (None,_) -> None + | (Some pp_optb, ib2::ib3::ii) -> Some (ib2, pp_optb, ib3, ii) + | _ -> failwith "impossible") + >>= (fun pp_opta pp_optb -> let (ib23,pp_optb,ii) = match pp_optb with - None -> ([],None, ii) + None -> ([], None, ii) | Some (ib2, pp_optb, ib3, ii) -> ([ib2;ib3],Some pp_optb,ii) in - option (fun ia4 _ -> + (* next two options for matchings paranthesis around type *) + option (fun ia4 _ -> match ii with ib4::ii -> tokenf ia4 ib4 >>= (fun ia4 ib4-> return (ia4, (ib4, ii))) | _ -> fail) - ia4_opt (if ia4_opt=None then None else Some (ib1, [])) >>= - (fun ia4_opt ib4_opt -> + ia4_opt + (fmap (function _ -> (ib1, ii)) ia4_opt) + >>= (fun ia4_opt ib4_opt -> let (ib4, ii) = match ib4_opt with None -> ([], ii) @@ -1624,32 +1628,38 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = ib5::ii -> tokenf ia5 ib5 >>= (fun ia5 ib5 -> return (ia5, (ib5, ii))) | _ -> fail) - ia5_opt (if ia5_opt=None then None else Some (ib1, [])) >>= (*EXPLAIN WHY I MADE THE CODE SO WEIRD*) - (fun ia5_opt ib5_opt -> + ia5_opt + (fmap (function _ -> (ib1, ii)) ia5_opt) + >>= (fun ia5_opt ib5_opt -> let (ib5, ii) = match ib5_opt with None -> ([], ii) | Some (ib5, ii) -> ([ib5], ii) in - option (fun (ia6, x, ia7) (_, y, _) -> + (* for matching init_opt *) + option (fun (ia6, x, ia7) (ib6, y, ib7, ii) -> arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> let x = A.rewrap x xunwrap in - match ii with - [ib6;ib7] -> tokenf ia6 ib6 >>= (fun ia6 ib6 -> tokenf ia7 ib7 >>= (fun ia7 ib7 -> - return ((ia6, x, ia7), (ib6, y, ib7)))) - | ib5::ib6::l -> fail (* EXPLAIN TO MADAM WHY THIS IS NOT failwith*) - | _ -> failwith "impossible")) - init_opta (match init_optb with - None -> None - | Some init_optb -> Some (ib1, init_optb, ib1)) >>= (fun init_opta init_optb -> - let (ib67, init_optb) = match init_optb with - None -> ([], None) - | Some (ib6, init_optb, ib7) -> ([ib6;ib7], Some init_optb) in - return ( - ((A.New(ia1, pp_opta, ia4_opt, typa, ia5_opt ,init_opta))) +> wa, - ((B.New(pp_optb, typb, init_optb), typ), [ib1]@ib23@ib4@ib5@ib67) - ))))))) + return ((ia6, x, ia7), (ib6, y, ib7, ii)))) + )) + init_opta + (match (init_optb, ii) with + (None,_) -> None + | (Some init_optb, ib6::ib7::ii) -> Some (ib6, init_optb, ib7, ii) + | _ -> failwith "impossible" ) + >>= (fun init_opta init_optb -> + let (ib67, init_optb, ii) = + match init_optb with + None -> ([], None, ii) + | Some (ib6, init_optb, ib7, ii) -> ([ib6;ib7], Some init_optb, ii) in + if ii != [] (* ALL TOKENS SHOULD HAVE BEEN MATCHED *) + then fail + else + return ( + ((A.New(ia1, pp_opta, ia4_opt, typa, ia5_opt ,init_opta))) +> wa, + ((B.New(pp_optb, typb, init_optb), typ), ib1::ib23@ib4@ib5@ib67) + ))))))) (* todo? iso ? allow all the combinations ? *) -- GitLab From 74e0c0a67bd61106dee11b1046a840a5f86741c4 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Fri, 24 Jun 2022 23:10:22 +0530 Subject: [PATCH 07/24] Added "new" tests and updated unparse_cocci to pretty_print_cocci Signed-off-by: Tathagata Roy --- parsing_c/unparse_cocci.ml | 12 ++++++++++++ tests/newsimple.cocci | 14 ++++++++++++++ tests/newsimple.cpp | 6 ++++++ tests/newsimple.res | 6 ++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/newsimple.cocci create mode 100644 tests/newsimple.cpp create mode 100644 tests/newsimple.res diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index de8d4598..849d6d89 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -513,6 +513,13 @@ let rec expression e = mcode print_string sizeof; mcode print_string_box lp; fullType ty; close_box(); mcode print_string rp + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> + mcode print_string nw; + print_option print_args pp_opt; + print_option (function e -> mcode print_string e) lp_opt; + fullType ty; + print_option (function e -> mcode print_string e) rp_opt; + print_option print_args args_opt; | Ast.TypeExp(ty) -> fullType ty | Ast.Constructor(lp,ty,rp,init) -> mcode print_string_box lp; fullType ty; close_box(); @@ -581,6 +588,11 @@ let rec expression e = | Ast.OptExp(exp) -> raise CantBeInPlus in loop e top +and print_args (lp,args,rp) = + mcode print_string lp; + dots (function _ -> ()) expression args; + mcode print_string rp + and arg_expression e = match Ast.unwrap e with Ast.EComma(cm) -> diff --git a/tests/newsimple.cocci b/tests/newsimple.cocci new file mode 100644 index 00000000..cefa99b6 --- /dev/null +++ b/tests/newsimple.cocci @@ -0,0 +1,14 @@ +#spatch --c++ + +@@ +expression E; +@@ + +int main() +{ +... + sizeof(E); +- new int(1); ++ new int(2); +... +} \ No newline at end of file diff --git a/tests/newsimple.cpp b/tests/newsimple.cpp new file mode 100644 index 00000000..8ba0db65 --- /dev/null +++ b/tests/newsimple.cpp @@ -0,0 +1,6 @@ +int main() +{ + sizeof(Test); + new int(1); +} + diff --git a/tests/newsimple.res b/tests/newsimple.res new file mode 100644 index 00000000..8155ddfe --- /dev/null +++ b/tests/newsimple.res @@ -0,0 +1,6 @@ +int main() +{ + sizeof(Test); + new int(2); +} + -- GitLab From fb5dfc75fd465856276bdb78ab71c58fe9b53023 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Fri, 24 Jun 2022 23:13:30 +0530 Subject: [PATCH 08/24] Added new to the lexer Signed-off-by: Tathagata Roy --- parsing_cocci/lexer_cocci.mll | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index fb8067da..b79e568b 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -293,17 +293,16 @@ let id_tokens lexbuf = | "EXEC" when !Flag.ibm -> Texec linetype | "auto" -> - let open Flag in - begin match !c_plus_plus with - On None -> + begin match !Flag.c_plus_plus with + Flag.On None -> raise ( Semantic_cocci.Semantic ( "auto has different meaning in different versions of C++. Please specify a version using --c++=")) - | On (Some i) -> + | Flag.On (Some i) -> if i >= 2011 then TautoType linetype else Tauto linetype - | Off -> Tauto linetype end + | Flag.Off -> Tauto linetype end | "register" -> Tregister linetype | "extern" -> Textern linetype | "static" -> Tstatic linetype @@ -329,6 +328,8 @@ let id_tokens lexbuf = | "sizeof" -> TSizeof linetype | "typeof" -> TTypeof linetype + | "new" when !Flag.c_plus_plus != Flag.Off -> TNew linetype + | "__attribute__" -> TAttr_ linetype | "Expression" when !Data.in_iso -> TIsoExpression -- GitLab From cffab31bf3241250876f1293b07903f925ab41ef Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 28 Jun 2022 21:34:00 +0530 Subject: [PATCH 09/24] Fixed one shift/reduce confilcts concerning new --- parsing_c/parser_c.mly | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 0da55e44..cd60c6dc 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1009,9 +1009,7 @@ postfix_expr: | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct TCBrace { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] } - -primary_expr: - | identifier_cpp { mk_e(Ident ($1)) [] } +primary_expr_without_ident: | TInt { let (str,(sign,base)) = fst $1 in mk_e(Constant (Int (str,Si(sign,base)))) [snd $1] } @@ -1032,7 +1030,11 @@ primary_expr: { mk_e(Constant (MultiString ["TODO: MultiString"])) ($1 @ $2) } /*(* gccext: allow statement as expressions via ({ statement }) *)*/ - | TOPar compound TCPar { mk_e(StatementExpr ($2)) [$1;$3] } + | TOPar compound TCPar { mk_e(StatementExpr ($2)) [$1;$3] } + +primary_expr: + identifier_cpp { mk_e(Ident ($1)) [] } + | primary_expr_without_ident { $1 } string_fragments: | /* empty */ { [] } @@ -1057,7 +1059,7 @@ argument_ne: | action_higherordermacro_ne { Right (ArgAction $1) } argument_ne_without_paramdecl: - | assign_expr { Left $1 } + | primary_expr_without_ident { Left $1 } | action_higherordermacro_ne { Right (ArgAction $1) } argument: -- GitLab From fdb66ef3b4003da2b6b362afc52b2a58a3789dae Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 14 Jun 2022 20:33:54 +0530 Subject: [PATCH 10/24] added enum definitions and conflict-laden menhir file --- parsing_cocci/ast0_cocci.ml | 11 +++++++++-- parsing_cocci/ast0_cocci.mli | 10 ++++++++-- parsing_cocci/parser_cocci_menhir.mly | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 228a853e..c4ecd5c9 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -215,8 +215,8 @@ and base_typeC = string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | EnumDef of enum_key option (* struct/class/None *) * typeC option (* either StructUnionName or metavar *) * + enum_base option (* base type like int *) * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -236,6 +236,13 @@ and base_typeC = and typeC = base_typeC wrap +and enum_key = + Class of string mcode + | Struct of string mcode + +and enum_base = + | Base of string mcode (* : *) * typeC + (* --------------------------------------------------------------------- *) (* Variable declaration *) (* Even if the Cocci program specifies a list of declarations, they are diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index fdce084e..f0e3894f 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -206,8 +206,8 @@ and base_typeC = string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | EnumDef of enum_key option (*class/struct*) * typeC option(* either StructUnionName or metavar *) * + enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -228,6 +228,12 @@ and base_typeC = and typeC = base_typeC wrap +and enum_key = + Class of string mcode + | Struct of string mcode + +and enum_base = string mcode (* : *) * typeC + (* --------------------------------------------------------------------- *) (* Variable declaration *) (* Even if the Cocci program specifies a list of declarations, they are diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index be589eca..31d85b3f 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1021,6 +1021,14 @@ non_signable_types_no_ident_without_braces: { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.PtrDiffType,[Parse_aux.clt2mcode "ptrdiff_t" ty])) } | s=Tenum i=ident { Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, Some i)) } +<<<<<<< HEAD +======= +| s=Tenum key=option(enum_key) name=option(ident) base=option(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace + { (if name = None && !Data.in_iso + then failwith "enums must be named in the iso file"); + Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, name, base)), + Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } +>>>>>>> ef7e7e2c (added enum definitions and conflict-laden menhir file) | s=struct_or_union i=type_ident // allow typedef name { Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, Some i)) } | Tdecimal TOPar enum_val TComma enum_val TCPar @@ -1239,6 +1247,13 @@ enum_decl_list: nonempty_list_start(enum_decl_one,edots_when(TEllipsis,enum_decl_one)) { Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) } +enum_key: + Tstruct { Parse_aux.cl2mcode "struct" $1 }//still have to add class + +enum_base: + c=TDotDot t=ctype + { Ast0_cocci.wrap(Ast0_cocci.Base(Parse_aux.cl2mcode ":" c, t))} + /*****************************************************************************/ /* have to inline everything to avoid conflicts? switch to proper -- GitLab From e6ac4359bcae454dbaadbeb81daf7b222f75e159 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 14 Jun 2022 23:33:37 +0530 Subject: [PATCH 11/24] fixed some conflicts in rebasing --- parsing_cocci/parser_cocci_menhir.mly | 3 --- 1 file changed, 3 deletions(-) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 31d85b3f..8dd7da68 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1021,14 +1021,11 @@ non_signable_types_no_ident_without_braces: { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.PtrDiffType,[Parse_aux.clt2mcode "ptrdiff_t" ty])) } | s=Tenum i=ident { Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, Some i)) } -<<<<<<< HEAD -======= | s=Tenum key=option(enum_key) name=option(ident) base=option(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace { (if name = None && !Data.in_iso then failwith "enums must be named in the iso file"); Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, name, base)), Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } ->>>>>>> ef7e7e2c (added enum definitions and conflict-laden menhir file) | s=struct_or_union i=type_ident // allow typedef name { Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, Some i)) } | Tdecimal TOPar enum_val TComma enum_val TCPar -- GitLab From ca82ea0e0055038d562bdb408ab16ed8fa592421 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Wed, 15 Jun 2022 02:04:47 +0530 Subject: [PATCH 12/24] Resolved all conflicts in parser_cocci_menhir.mly file Signed-off-by: Tathagata Roy --- parsing_cocci/ast0_cocci.mli | 3 ++- parsing_cocci/parser_cocci_menhir.mly | 31 +++++++++++---------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index f0e3894f..be96fea2 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -232,7 +232,8 @@ and enum_key = Class of string mcode | Struct of string mcode -and enum_base = string mcode (* : *) * typeC +and enum_base = + Base of string mcode (* : *) * typeC (* --------------------------------------------------------------------- *) (* Variable declaration *) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 8dd7da68..67c912d1 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -968,22 +968,22 @@ signable_types: Ast0_cocci.Impure (*will be ignored*))) } non_signable_types_no_ident_with_braces: - s=Tenum i=ioption(ident) l=TOBrace ids=enum_decl_list r=TCBrace - { (if i = None && !Data.in_iso + | s=Tenum key=option(enum_key) name=option(ident) base=option(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace + { (if name = None && !Data.in_iso then failwith "enums must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, i)), + Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, name, base)), Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } | s=struct_or_union i=ioption(type_ident) - l=TOBrace d=struct_decl_list r=TCBrace - { (if i = None && !Data.in_iso - then failwith "structures must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, i)), - Parse_aux.clt2mcode "{" l, + l=TOBrace d=struct_decl_list r=TCBrace + { (if i = None && !Data.in_iso + then failwith "structures must be named in the iso file"); + Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, i)), + Parse_aux.clt2mcode "{" l, d, Parse_aux.clt2mcode "}" r)) } | s=TMetaType l=TOBrace d=struct_decl_list r=TCBrace - { let (nm,cstr,pure,clt) = s in - let ty = Ast0_cocci.wrap(Ast0_cocci.MetaType(Parse_aux.clt2mcode nm clt,cstr,pure)) in - Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(ty,Parse_aux.clt2mcode "{" l,d,Parse_aux.clt2mcode "}" r)) } + { let (nm,cstr,pure,clt) = s in + let ty = Ast0_cocci.wrap(Ast0_cocci.MetaType(Parse_aux.clt2mcode nm clt,cstr,pure)) in + Ast0_cocci.wrap(Ast0_cocci.StructUnionDef(ty,Parse_aux.clt2mcode "{" l,d,Parse_aux.clt2mcode "}" r)) } non_signable_types_no_ident_without_braces: ty=Tvoid @@ -1019,13 +1019,6 @@ non_signable_types_no_ident_without_braces: { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.SSizeType,[Parse_aux.clt2mcode "ssize_t" ty])) } | ty=Tptrdiff_t { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.PtrDiffType,[Parse_aux.clt2mcode "ptrdiff_t" ty])) } -| s=Tenum i=ident - { Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, Some i)) } -| s=Tenum key=option(enum_key) name=option(ident) base=option(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace - { (if name = None && !Data.in_iso - then failwith "enums must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, name, base)), - Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } | s=struct_or_union i=type_ident // allow typedef name { Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, Some i)) } | Tdecimal TOPar enum_val TComma enum_val TCPar @@ -1248,7 +1241,7 @@ enum_key: Tstruct { Parse_aux.cl2mcode "struct" $1 }//still have to add class enum_base: - c=TDotDot t=ctype + c=TDotDot t=ctype_without_braces { Ast0_cocci.wrap(Ast0_cocci.Base(Parse_aux.cl2mcode ":" c, t))} /*****************************************************************************/ -- GitLab From 8c02afbde84e96574f56b8dfb70cfe21457b9de3 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Wed, 15 Jun 2022 13:16:56 +0530 Subject: [PATCH 13/24] Defined EnumName and EnumDef --- parsing_cocci/ast0_cocci.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index c4ecd5c9..6215609e 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -214,9 +214,9 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of enum_key option (* struct/class/None *) * typeC option (* either StructUnionName or metavar *) * - enum_base option (* base type like int *) * string mcode (* { *) * enum_decl dots option * string mcode (* } *) + | EnumName of string mcode (*enum*) * enum_key option (* struct/class/None *) * ident option (* name *) + | EnumDef of typeC (* either StructUnionName or metavar *) * enum_base option (* base type *) * + string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) -- GitLab From 5b5e099088c3fb4688881571dfa47b79fbd99ec8 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Sun, 19 Jun 2022 16:49:30 +0530 Subject: [PATCH 14/24] bitfield problems persist, will fix in the next commit --- parsing_cocci/parser_cocci_menhir.mly | 88 ++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 67c912d1..013d5761 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -230,7 +230,7 @@ let inline_id aft = function %token Tchar Tshort Tint Tdouble Tfloat Tcomplex Tlong %token Tsize_t Tssize_t Tptrdiff_t -%token Tvoid Tstruct Tunion Tenum +%token Tvoid Tstruct Tunion Tenum Tclass %token Tunsigned Tsigned %token TautoType @@ -506,14 +506,13 @@ metadec: ar=arity ispure=pure kindfn=metakind ids=comma_list(pure_ident_or_meta_ident_with_constraints) TMPtVirg { Parse_aux.create_metadec_with_constraints ar ispure kindfn ids } -| ar=arity ispure=pure kindfn=metakind_bitfield bf=ioption(bitfield) +| ar=arity ispure=pure kindfn=metakind_bitfield_only_signed bf=bitfield ids=comma_list(pure_ident_or_meta_ident_with_constraints) TMPtVirg - { match bf with - None -> - Parse_aux.create_metadec_with_constraints ar ispure (kindfn None) ids - | Some bf' -> - Parse_aux.create_len_metadec ar ispure (fun lenname -> kindfn (Some lenname)) - bf' ids } + { Parse_aux.create_len_metadec ar ispure (fun lenname -> kindfn (Some lenname)) + bf ids } +| ar=arity ispure=pure kindfn=metakind_nobitfield + ids=comma_list(pure_ident_or_meta_ident_with_constraints) TMPtVirg + { Parse_aux.create_metadec_with_constraints ar ispure (kindfn None) ids } | ar=arity ispure=pure kind_ids=metakindnosym TMPtVirg { let (ids,kindfn) = kind_ids in Parse_aux.create_metadec ar ispure kindfn ids } @@ -813,7 +812,7 @@ delimited_list_len: let ty' = Common.map_option (List.map (Ast0toast.typeC false)) ty in check_meta (Ast_cocci.MetaConstDecl(arity,name,ty'))) } -%inline metakind_bitfield: +%inline metakind_nobitfield: | TExpression ty=expression_type { (fun lenname arity name pure check_meta constraints -> !Data.add_exp_meta (Some [ty]) name constraints pure lenname; @@ -850,6 +849,43 @@ delimited_list_len: tok) } +%inline metakind_bitfield_only_signed: +| TExpression ty=expression_type + { (fun lenname arity name pure check_meta constraints -> + !Data.add_exp_meta (Some [ty]) name constraints pure lenname; + let ty' = Some [Ast0toast.typeC false ty] in + check_meta (Ast_cocci.MetaExpDecl (arity, name, ty', lenname))) } +| TExpression + { (fun lenname arity name pure check_meta constraints -> + let tok = check_meta(Ast_cocci.MetaExpDecl(arity,name,None,lenname)) in + !Data.add_exp_meta None name constraints pure lenname; tok) } +| vl=meta_exp_type_only_signed // no error if use $1 but doesn't type check + { (fun lenname arity name pure check_meta constraints -> + let ty = Some vl in + let cstr_expr = Some begin function c -> + match Ast0_cocci.unwrap c with + Ast0_cocci.Constant(_) -> + if not + (List.exists + (fun ty -> + match Ast0_cocci.unwrap ty with + Ast0_cocci.BaseType (Ast_cocci.IntType, _) -> true + | Ast0_cocci.BaseType (Ast_cocci.ShortType, _) -> true + | Ast0_cocci.BaseType (Ast_cocci.LongType, _) -> true + | _ -> false) + vl) + then + failwith "metavariable with int constraint must be an int" + | _ -> () + end in + Ast_cocci.cstr_iter { Ast_cocci.empty_cstr_transformer with Ast_cocci.cstr_expr } + constraints; + !Data.add_exp_meta ty name constraints pure lenname; + let ty' = Some (List.map (Ast0toast.typeC false) vl) in + let tok = check_meta (Ast_cocci.MetaExpDecl (arity,name,ty',lenname)) in + tok) + } + %inline metakindnosym: TTypedef ids=comma_list(pure_ident_or_meta_ident_nosym2(TTypeId)) @@ -919,6 +955,17 @@ meta_exp_type: | TOBrace t=comma_list(ctype) TCBrace m=list(TMul) { List.map (fun x -> Parse_aux.ty_pointerify x m) t } +meta_exp_type_only_signed: + t=typedef_ctype_only_signed + { [t] } +| t=typedef_ctype_only_signed TOCro TCCro + { [Ast0_cocci.wrap + (Ast0_cocci.Array + (t, + Ast0_cocci.make_mcode "", None, Ast0_cocci.make_mcode ""))] } +| TOBrace t=comma_list(ctype) TCBrace m=list(TMul) + { List.map (fun x -> Parse_aux.ty_pointerify x m) t } + arity: TWhy0 { Ast_cocci.OPT } | TPlus0 { Ast_cocci.MULTI } | /* empty */ { Ast_cocci.NONE } @@ -968,11 +1015,11 @@ signable_types: Ast0_cocci.Impure (*will be ignored*))) } non_signable_types_no_ident_with_braces: - | s=Tenum key=option(enum_key) name=option(ident) base=option(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace + | s=Tenum k=option(enum_key) i=option(type_ident) base=ioption(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace { (if name = None && !Data.in_iso - then failwith "enums must be named in the iso file"); - Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, name, base)), - Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } + then failwith "enums must be named in the iso file"); + Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, k, i)), + base, Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } | s=struct_or_union i=ioption(type_ident) l=TOBrace d=struct_decl_list r=TCBrace { (if i = None && !Data.in_iso @@ -1019,6 +1066,8 @@ non_signable_types_no_ident_without_braces: { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.SSizeType,[Parse_aux.clt2mcode "ssize_t" ty])) } | ty=Tptrdiff_t { Ast0_cocci.wrap(Ast0_cocci.BaseType(Ast_cocci.PtrDiffType,[Parse_aux.clt2mcode "ptrdiff_t" ty])) } +| s=Tenum key=option(enum_key) i=type_ident + { Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, key, Some i)) } | s=struct_or_union i=type_ident // allow typedef name { Ast0_cocci.wrap(Ast0_cocci.StructUnionName(s, Some i)) } | Tdecimal TOPar enum_val TComma enum_val TCPar @@ -1153,6 +1202,15 @@ typedef_ctype: (Ast0_cocci.DisjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } | TMeta { tmeta_to_type $1 } +typedef_ctype_only_signed: + cv=ioption(const_vol) ty=signable_types m=list(TMul) + { Parse_aux.pointerify (Parse_aux.make_cv cv ty) m } +| lp=TOPar0 t=midzero_list(mctype,mctype) rp=TCPar0 + { let (mids,code) = t in + Ast0_cocci.wrap + (Ast0_cocci.DisjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } +| TMeta { tmeta_to_type $1 } + /* ---------------------------------------------------------------------- */ struct_or_union: @@ -1238,7 +1296,8 @@ enum_decl_list: { Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) } enum_key: - Tstruct { Parse_aux.cl2mcode "struct" $1 }//still have to add class + Tstruct { Parse_aux.cl2mcode "struct" $1 } + | Tclass { Parse_aux.cl2mcode "class" $1 } enum_base: c=TDotDot t=ctype_without_braces @@ -3485,6 +3544,7 @@ anything: /* used for script code */ | Tptrdiff_t { "ptrdiff_t" } | Tvoid { "void" } | Tstruct { "struct" } + | Tclass { "class" } | Tunion { "union" } | Tenum { "enum" } | Tunsigned { "unsigned" } -- GitLab From 443ef9a542978b3849411e1475187a86593f05ba Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Sun, 19 Jun 2022 19:50:08 +0530 Subject: [PATCH 15/24] Fixed all conflicts --- parsing_cocci/parser_cocci_menhir.mly | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 013d5761..03638e86 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -958,13 +958,6 @@ meta_exp_type: meta_exp_type_only_signed: t=typedef_ctype_only_signed { [t] } -| t=typedef_ctype_only_signed TOCro TCCro - { [Ast0_cocci.wrap - (Ast0_cocci.Array - (t, - Ast0_cocci.make_mcode "", None, Ast0_cocci.make_mcode ""))] } -| TOBrace t=comma_list(ctype) TCBrace m=list(TMul) - { List.map (fun x -> Parse_aux.ty_pointerify x m) t } arity: TWhy0 { Ast_cocci.OPT } | TPlus0 { Ast_cocci.MULTI } @@ -1203,13 +1196,8 @@ typedef_ctype: | TMeta { tmeta_to_type $1 } typedef_ctype_only_signed: - cv=ioption(const_vol) ty=signable_types m=list(TMul) - { Parse_aux.pointerify (Parse_aux.make_cv cv ty) m } -| lp=TOPar0 t=midzero_list(mctype,mctype) rp=TCPar0 - { let (mids,code) = t in - Ast0_cocci.wrap - (Ast0_cocci.DisjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } -| TMeta { tmeta_to_type $1 } + ty=signable_types + { Parse_aux.pointerify (Parse_aux.make_cv None ty) None } /* ---------------------------------------------------------------------- */ @@ -1233,7 +1221,7 @@ struct_decl_one: { let (mids,code) = t in Ast0_cocci.wrap (Ast0_cocci.ConjField(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } - | t=ctype d=direct_decl_option(type_ident) bf=struct_bitfield? pv=TPtVirg + | t=signable_types d=direct_decl_option(type_ident) bf=struct_bitfield? pv=TPtVirg { let (id,fn) = d in Ast0_cocci.wrap(Ast0_cocci.Field(fn t,id,bf,Parse_aux.clt2mcode ";" pv)) } | cv=ioption(const_vol) i=pure_ident_or_symbol -- GitLab From 07f9c05a55b299c8ae982ba43b087a6fc9797350 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 21 Jun 2022 15:16:30 +0530 Subject: [PATCH 16/24] Added Enum to cocci Signed-off-by: Tathagata Roy --- parsing_cocci/adjust_pragmas.ml | 8 +++---- parsing_cocci/arity.ml | 14 +++++++---- parsing_cocci/ast0_cocci.ml | 13 ++++------ parsing_cocci/ast0_cocci.mli | 11 +++------ parsing_cocci/ast0toast.ml | 17 +++++++++----- parsing_cocci/ast_cocci.ml | 24 +++++++++++-------- parsing_cocci/ast_cocci.mli | 8 +++---- parsing_cocci/check_meta.ml | 7 +++--- parsing_cocci/commas_on_lists.ml | 4 ++-- parsing_cocci/compute_lines.ml | 24 ++++++++++++------- parsing_cocci/context_neg.ml | 14 +++++++---- parsing_cocci/disjdistr.ml | 17 +++++++++----- parsing_cocci/free_vars.ml | 2 +- parsing_cocci/function_prototypes.ml | 12 +++++----- parsing_cocci/index.ml | 4 ++-- parsing_cocci/iso_pattern.ml | 25 ++++++++++++-------- parsing_cocci/parse_cocci.ml | 12 ++++++---- parsing_cocci/parser_cocci_menhir.mly | 14 +++++------ parsing_cocci/pretty_print_cocci.ml | 14 +++++++---- parsing_cocci/single_statement.ml | 4 ++-- parsing_cocci/unify_ast.ml | 11 +++++---- parsing_cocci/unparse_ast0.ml | 13 ++++++---- parsing_cocci/visitor_ast.ml | 34 +++++++++++++++++++-------- parsing_cocci/visitor_ast0.ml | 18 ++++++++++---- 24 files changed, 194 insertions(+), 130 deletions(-) diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml index bd335dc4..6ab1f28a 100644 --- a/parsing_cocci/adjust_pragmas.ml +++ b/parsing_cocci/adjust_pragmas.ml @@ -180,11 +180,11 @@ let rec left_ty t = | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> call_right left_mcode dec t (function dec -> Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) - | Ast0.EnumName(kind,name) -> - call_right left_mcode kind t (function kind -> Ast0.EnumName(kind,name)) - | Ast0.EnumDef(ty,lb,ids,rb) -> + | Ast0.EnumName(kind,key,name) -> + call_right left_mcode kind t (function kind -> Ast0.EnumName(kind,key,name)) + | Ast0.EnumDef(ty,base,lb,ids,rb) -> call_right left_ty ty t - (function ty -> Ast0.EnumDef(ty,lb,ids,rb)) + (function ty -> Ast0.EnumDef(ty,base,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> call_right left_mcode kind t (function kind -> Ast0.StructUnionName(kind,name)) diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 1e4111c5..ac0bed5a 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -469,21 +469,25 @@ and top_typeC tgt opt_allowed typ = let rp = mcode rp in make_typeC typ tgt arity (Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) - | Ast0.EnumName(kind,name) -> + | Ast0.EnumName(kind,key,name) -> let arity = all_same opt_allowed tgt (mcode2line kind) [mcode2arity kind] in let kind = mcode kind in + let key = get_option mcode key in let name = get_option (ident false arity) name in - make_typeC typ tgt arity (Ast0.EnumName(kind,name)) - | Ast0.EnumDef(ty,lb,decls,rb) -> + make_typeC typ tgt arity (Ast0.EnumName(kind,key,name)) + | Ast0.EnumDef(ty,base,lb,decls,rb) -> let arity = all_same opt_allowed tgt (mcode2line lb) (List.map mcode2arity [lb;rb]) in let ty = typeC arity ty in + let base = get_option + (function (td, ty) -> (mcode td, typeC arity ty)) + base in let lb = mcode lb in - let ids = dots (enum_decl tgt) decls in + let ids = get_option (dots (enum_decl tgt)) decls in let rb = mcode rb in - make_typeC typ tgt arity (Ast0.EnumDef(ty,lb,ids,rb)) + make_typeC typ tgt arity (Ast0.EnumDef(ty,base,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> let arity = all_same opt_allowed tgt (mcode2line kind) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 6215609e..04adb628 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -214,8 +214,8 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * enum_key option (* struct/class/None *) * ident option (* name *) - | EnumDef of typeC (* either StructUnionName or metavar *) * enum_base option (* base type *) * + | EnumName of string mcode (*enum*) * string mcode option (* struct/class/None *) * ident option (* name *) + | EnumDef of typeC (* EnumName *) * enum_base option (* base type *) * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * @@ -236,12 +236,7 @@ and base_typeC = and typeC = base_typeC wrap -and enum_key = - Class of string mcode - | Struct of string mcode - -and enum_base = - | Base of string mcode (* : *) * typeC +and enum_base = string mcode (* : *) * typeC (* --------------------------------------------------------------------- *) (* Variable declaration *) @@ -780,7 +775,7 @@ let rec meta_names_of_typeC ty = | Signed (_, Some ty) | Pointer (ty, _) | Array (ty, _, _, _) -> meta_names_of_typeC ty - | EnumName (_, Some ident) + | EnumName (_, _, Some ident) | StructUnionName(_, Some ident) -> meta_names_of_ident ident | MetaType (tyname, _, _) -> [unwrap_mcode tyname] | Decimal (_, _, e1, _, e2, _) -> diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index be96fea2..a0d580e4 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -205,8 +205,8 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of enum_key option (*class/struct*) * typeC option(* either StructUnionName or metavar *) * + | EnumName of string mcode (*enum*) * string mcode option (* struct/class/None *) * ident option (* name *) + | EnumDef of typeC (* EnumName *) * enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * @@ -228,12 +228,7 @@ and base_typeC = and typeC = base_typeC wrap -and enum_key = - Class of string mcode - | Struct of string mcode - -and enum_base = - Base of string mcode (* : *) * typeC +and enum_base = string mcode (* : *) * typeC (* --------------------------------------------------------------------- *) (* Variable declaration *) diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index 32669ad5..876ecae3 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -581,8 +581,8 @@ and typeC allminus t = | Ast0.BaseType(_) | Ast0.Signed(_,_) | Ast0.Pointer(_,_) | Ast0.ParenType(_,_,_) | Ast0.FunctionType(_,_,_,_) | Ast0.Array(_,_,_,_) | Ast0.Decimal(_,_,_,_,_,_) - | Ast0.EnumName(_,_) | Ast0.StructUnionName(_,_) - | Ast0.StructUnionDef(_,_,_,_) | Ast0.EnumDef(_,_,_,_) + | Ast0.EnumName(_,_,_) | Ast0.StructUnionName(_,_) + | Ast0.StructUnionDef(_,_,_,_) | Ast0.EnumDef(_,_,_,_,_) | Ast0.TypeOfExpr(_,_,_,_) | Ast0.TypeOfType(_,_,_,_) | Ast0.TypeName(_) | Ast0.AutoType(_) | Ast0.MetaType(_,_,_) -> Ast.Type(allminus,[],rewrap t no_isos (base_typeC allminus t)) @@ -614,10 +614,10 @@ and base_typeC allminus t = Ast.Decimal(mcode dec,mcode lp,expression length, get_option mcode comma,get_option expression precision_opt, mcode rp) - | Ast0.EnumName(kind,name) -> - Ast.EnumName(mcode kind,get_option ident name) - | Ast0.EnumDef(ty,lb,ids,rb) -> - Ast.EnumDef(typeC allminus ty,mcode lb,enum_decl_dots ids,mcode rb) + | Ast0.EnumName(kind,key,name) -> + Ast.EnumName(mcode kind,get_option mcode key,get_option ident name) + | Ast0.EnumDef(ty,base,lb,ids,rb) -> + Ast.EnumDef(typeC allminus ty,get_option (enum_base allminus) base,mcode lb,get_option enum_decl_dots ids,mcode rb) | Ast0.StructUnionName(kind,name) -> Ast.StructUnionName(mcode kind,get_option ident name) | Ast0.StructUnionDef(ty,lb,decls,rb) -> @@ -773,6 +773,11 @@ and annotated_field bef d = and field_dots l = dots (annotated_field None) l +and enum_base allminus (tdd, typ) = + let tdd = mcode tdd in + let typ = typeC allminus typ in + (tdd, typ) + and enum_decl d = rewrap d (do_isos (Ast0.get_iso d)) (match Ast0.unwrap d with diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index 7794fdc4..f020f141 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -355,9 +355,9 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of fullType (* either EnumName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | EnumName of string mcode (*enum*) * string mcode option(*struct/class/None*) * ident option (* name *) + | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * + string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) @@ -456,6 +456,7 @@ and base_enum_decl = | EnumComma of string mcode (* , *) | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *) +and enum_base = string mcode (* : *) * fullType and enum_decl = base_enum_decl wrap (* --------------------------------------------------------------------- *) @@ -1134,6 +1135,9 @@ let string_of_structUnion = function Struct -> "struct" | Union -> "union" +let string_of_enumkey = function + Struct -> "struct" + let rec string_of_typeC ty = match unwrap ty with BaseType (bt, _) -> string_of_baseType bt ^ " " @@ -1152,12 +1156,12 @@ let rec string_of_typeC ty = let s0 = string_of_expression e0 and s1 = Common.default "?" string_of_expression e1 in Printf.sprintf "decimal(%s,%s) " s0 s1 - | EnumName (_, name) -> "enum " ^ (Common.default "?" string_of_ident name) + | EnumName (_, key, name) -> "enum " ^ (Common.default "?" string_of_ident name) (* should I make use the function string_of_enumkey or delete it*) | StructUnionName (kind, name) -> Printf.sprintf "%s %s" (string_of_structUnion (unwrap_mcode kind)) (Common.default "?" string_of_ident name) - | EnumDef (ty', _, _, _) + | EnumDef (ty', _ , _, _, _) | StructUnionDef (ty', _, _, _) -> string_of_fullType ty' | TypeOfExpr(_,_,e,_) -> "typeof("^string_of_expression e^")" | TypeOfType(_,_,t,_) -> "typeof("^string_of_fullType t^")" @@ -1232,7 +1236,7 @@ and typeC_map tr ty = rewrap ty (FunctionType (fullType_map tr ty', s0, s1, s2)) | Array (ty', s0, s1, s2) -> rewrap ty (Array (fullType_map tr ty', s0, s1, s2)) - | EnumName (s0, ident) -> + | EnumName (s0, key, ident) -> begin match tr.enumName with None -> ty @@ -1269,8 +1273,8 @@ and typeC_map tr ty = | SignedT (_, None) -> ty | SignedT (sgn, Some ty') -> rewrap ty (SignedT (sgn, Some (typeC_map tr ty'))) - | EnumDef (ty', s0, e, s1) -> - rewrap ty (EnumDef (fullType_map tr ty', s0, e, s1)) + | EnumDef (ty', base, s0, e, s1) -> + rewrap ty (EnumDef (fullType_map tr ty', base, s0, e, s1)) | StructUnionDef (ty', s0, a, s1) -> rewrap ty (StructUnionDef (fullType_map tr ty', s0, a, s1)) @@ -1292,11 +1296,11 @@ and typeC_fold tr ty v = | ParenType (_, ty', _) | FunctionType (ty', _, _, _) | Array (ty', _, _, _) - | EnumDef (ty', _, _, _) + | EnumDef (ty', _, _, _, _) | StructUnionDef (ty', _, _, _) -> fullType_fold tr ty' v | Decimal (s0, s1, e0, s2, e1, s3) -> Common.default v (fun f -> f s0 s1 e0 s2 e1 s3 v) tr.decimal - | EnumName (s0, ident) -> Common.default v (fun f -> f s0 ident v) tr.enumName + | EnumName (s0, key, ident) -> Common.default v (fun f -> f s0 ident v) tr.enumName (* Not sure about this *) | StructUnionName (su, ident) -> Common.default v (fun f -> f su ident v) tr.structUnionName | TypeOfExpr(_,_,e,_) -> v diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index eff292d4..0f6ecc58 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -337,9 +337,9 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * ident option (* name *) - | EnumDef of fullType (* either EnumName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | EnumName of string mcode (*enum*) * string mcode option * ident option (* name *) + | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * + string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) @@ -438,7 +438,7 @@ and base_enum_decl = | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *) and enum_decl = base_enum_decl wrap - +and enum_base = string mcode (* : *) * fullType (* --------------------------------------------------------------------- *) (* Initializers *) diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index de1c67cb..47de948c 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -278,10 +278,11 @@ and typeC old_metas table minus t = | Ast0.DisjType(_,types,_,_) | Ast0.ConjType(_,types,_,_) -> List.iter (typeC old_metas table minus) types - | Ast0.EnumName(en,Some id) -> ident GLOBAL old_metas table minus id - | Ast0.EnumDef(ty,lb,ids,rb) -> + | Ast0.EnumName(en, key, Some id) -> ident GLOBAL old_metas table minus id + | Ast0.EnumDef(ty,base,lb,ids,rb) -> typeC old_metas table minus ty; - dots (enum_decl GLOBAL old_metas table minus) ids + Common.do_option (function (td,ty) -> typeC old_metas table minus ty) base; + Common.do_option (dots (enum_decl GLOBAL old_metas table minus)) ids | Ast0.StructUnionName(su,Some id) -> ident GLOBAL old_metas table minus id | Ast0.StructUnionDef(ty,lb,decls,rb) -> typeC old_metas table minus ty; diff --git a/parsing_cocci/commas_on_lists.ml b/parsing_cocci/commas_on_lists.ml index 9ea23ef5..aa163e0d 100644 --- a/parsing_cocci/commas_on_lists.ml +++ b/parsing_cocci/commas_on_lists.ml @@ -50,9 +50,9 @@ trailing comma is allowed but not required *) let base_typeC r k t = let t = k t in match Ast0.unwrap t with - Ast0.EnumDef(ty,lb,ids,rb) -> + Ast0.EnumDef(ty,base,lb,Some ids,rb) -> let ids = add_enum_decl_comma ids in - Ast0.rewrap t (Ast0.EnumDef(ty,lb,ids,rb)) + Ast0.rewrap t (Ast0.EnumDef(ty,base,lb,Some ids,rb)) | _ -> t let initialiser r k i = diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index b7fde029..882413b4 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -609,21 +609,29 @@ and typeC t = let rp = normal_mcode rp in mkres t (Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) (promote_mcode dec) (promote_mcode rp) - | Ast0.EnumName(kind,Some name) -> + | Ast0.EnumName(kind, key, Some name) -> let kind = normal_mcode kind in + let key = get_option normal_mcode key in let name = ident name in - mkres t (Ast0.EnumName(kind,Some name)) (promote_mcode kind) name - | Ast0.EnumName(kind,None) -> + mkres t (Ast0.EnumName(kind,key,Some name)) (promote_mcode kind) name + | Ast0.EnumName(kind,key,None) ->(* Never needed, but removing will cause warnings *) let kind = normal_mcode kind in let mc = promote_mcode kind in - mkres t (Ast0.EnumName(kind,None)) mc mc - | Ast0.EnumDef(ty,lb,ids,rb) -> + mkres t (Ast0.EnumName(kind,key,None)) mc mc + | Ast0.EnumDef(ty,base,lb,ids,rb) -> let ty = typeC ty in + let base = get_option (function (td, ty) -> (normal_mcode td, typeC ty)) base in let lb = normal_mcode lb in - let ids = - dots is_enum_decl_dots (Some(promote_mcode lb)) enum_decl ids in + let ids = get_option + (dots is_enum_decl_dots + (Some + (match base with + None -> promote_mcode lb + | Some (td, _) -> promote_mcode td) + ) + enum_decl) ids in let rb = normal_mcode rb in - mkres t (Ast0.EnumDef(ty,lb,ids,rb)) ty (promote_mcode rb) + mkres t (Ast0.EnumDef(ty,base,lb,ids,rb)) ty (promote_mcode rb) | Ast0.StructUnionName(kind,Some name) -> let kind = normal_mcode kind in let name = ident name in diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index 8f7d8232..c8a407aa 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -750,12 +750,16 @@ let equal_typeC t1 t2 = Ast0.Decimal(dec2,lp2,_,comma2,_,rp2)) -> equal_mcode dec1 dec2 && equal_mcode lp1 lp2 && equal_option comma1 comma2 && equal_mcode rp1 rp2 - | (Ast0.EnumName(kind1,_),Ast0.EnumName(kind2,_)) -> - equal_mcode kind1 kind2 - | (Ast0.EnumDef(_,lb1,_,rb1),Ast0.EnumDef(_,lb2,_,rb2)) -> + | (Ast0.EnumName(kind1,key1,_),Ast0.EnumName(kind2,key2,_)) -> + equal_mcode kind1 kind2 && equal_option key1 key2 + | (Ast0.EnumDef(_,base1,lb1,_,rb1),Ast0.EnumDef(_,base2,lb2,_,rb2)) -> let tru1 = equal_mcode lb1 lb2 in - let tru2 = equal_mcode rb1 rb2 in - tru1 && tru2 + let tru2 = (match (base1,base2) with + (None, None) -> true + | (Some (td1, _), Some (td2, _)) -> equal_mcode td1 td2 + | _ -> false) in + let tru3 = equal_mcode rb1 rb2 in + tru1 && tru2 && tru3 | (Ast0.StructUnionName(kind1,_),Ast0.StructUnionName(kind2,_)) -> equal_mcode kind1 kind2 | (Ast0.StructUnionDef(_,lb1,_,rb1), diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 81ac5ecf..6dd7fc7a 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -85,18 +85,23 @@ and disjtypeC bty = disjmult2 (disjexp length) (disjoption disjexp precision_opt) (function length -> function precision_opt -> Ast.rewrap bty (Ast.Decimal(dec,lp,length,comma,precision_opt,rp))) - | Ast.EnumName(enum,name) -> + | Ast.EnumName(enum,key,name) -> let name = disjoption disjident name in - List.map (function name -> Ast.rewrap bty (Ast.EnumName(enum,name))) name + List.map (function name -> Ast.rewrap bty (Ast.EnumName(enum,key,name))) name | Ast.StructUnionName(su,name) -> let name = disjoption disjident name in List.map (function name -> Ast.rewrap bty (Ast.StructUnionName(su,name))) name - | Ast.EnumDef(ty,lb,ids,rb) -> - disjmult2 (disjty ty) (disjdots disjenumdecl ids) - (function ty -> function ids -> - Ast.rewrap bty (Ast.EnumDef(ty,lb,ids,rb))) + | Ast.EnumDef(ty,base,lb,ids,rb) -> + disjmult3 (disjty ty) + (disjoption (function (td, ty1) -> + let ty1 = disjty ty1 in + List.map (function ty1 -> (td, ty1)) ty1) + base) + (disjoption (disjdots disjenumdecl) ids) + (fun ty base ids -> + Ast.rewrap bty (Ast.EnumDef(ty,base,lb,ids,rb))) | Ast.StructUnionDef(ty,lb,decls,rb) -> disjmult2 (disjty ty) (disjdots anndisjfield decls) (function ty -> function decls -> diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml index fac7a672..bf9affa7 100644 --- a/parsing_cocci/free_vars.ml +++ b/parsing_cocci/free_vars.ml @@ -728,7 +728,7 @@ let classify_variables metavar_decls minirules used_after = Ast.Decimal (s0, s1, e2mv e1, s2, Common.map_option e2mv e2, s3)); enumName = Some (fun s0 ident -> let ident' = Common.map_option classify_ident ident in - Ast.EnumName (s0, ident')); + Ast.EnumName (s0, None, ident')); (* have to change this *) structUnionName = Some (fun su ident -> let ident' = Common.map_option classify_ident ident in Ast.StructUnionName (su, ident')); diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index 220d4489..b4817a35 100644 --- a/parsing_cocci/function_prototypes.ml +++ b/parsing_cocci/function_prototypes.ml @@ -243,12 +243,12 @@ let rec attach_right strings ty = Ast0.Array(ty,lb,e,right_attach_mcode strings rb) | Ast0.Decimal(dec,lp,e1,comma,e2,rp) -> Ast0.Decimal(dec,lp,e1,comma,e2,right_attach_mcode strings rp) - | Ast0.EnumName(enum,None) -> - Ast0.EnumName(right_attach_mcode strings enum, None) - | Ast0.EnumName(enum,Some id) -> - Ast0.EnumName(enum,Some (right_attach_ident strings id)) - | Ast0.EnumDef(ty,lb,es,rb) -> - Ast0.EnumDef(ty,lb,es,right_attach_mcode strings rb) + | Ast0.EnumName(enum,key,None) -> + Ast0.EnumName(right_attach_mcode strings enum, key, None) + | Ast0.EnumName(enum,key,Some id) -> + Ast0.EnumName(enum, key, Some (right_attach_ident strings id)) + | Ast0.EnumDef(ty,base,lb,es,rb) -> + Ast0.EnumDef(ty,base,lb,es,right_attach_mcode strings rb) | Ast0.StructUnionName(su,None) -> Ast0.StructUnionName(right_attach_mcode strings su, None) | Ast0.StructUnionName(su,Some id) -> diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index cc4f5a34..60abb037 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -98,8 +98,8 @@ let typeC t = | Ast0.FunctionType(ty,lp,params,rp) -> [139] | Ast0.Array(ty,lb,size,rb) -> [50] | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> [160] - | Ast0.EnumName(kind,name) -> [146] - | Ast0.EnumDef(ty,lb,decls,rb) -> [150] + | Ast0.EnumName(kind,key,name) -> [146] + | Ast0.EnumDef(ty,base,lb,decls,rb) -> [150] | Ast0.StructUnionName(kind,name) -> [51] | Ast0.StructUnionDef(ty,lb,decls,rb) -> [117] | Ast0.TypeOfExpr(tf,lp,exp,rp) -> [135] diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 86cb7240..9c795d00 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -905,16 +905,21 @@ let match_maker checks_needed context_required whencode_allowed = match_option check_mcode comma1 comma2; match_option match_expr prec_opt1 prec_opt2; check_mcode rp1 rp2] - | (Ast0.EnumName(kinda,Some namea), - Ast0.EnumName(kindb,Some nameb)) -> - conjunct_bindings (check_mcode kinda kindb) - (match_ident namea nameb) - | (Ast0.EnumDef(tya,lb1,idsa,rb1), - Ast0.EnumDef(tyb,lb,idsb,rb)) -> + | (Ast0.EnumName(kinda,keya,Some namea), + Ast0.EnumName(kindb,keyb,Some nameb)) -> + conjunct_many_bindings [check_mcode kinda kindb; + match_option check_mcode keya keyb; + match_ident namea nameb] + | (Ast0.EnumDef(tya,base1,lb1,idsa,rb1), + Ast0.EnumDef(tyb,base2,lb,idsb,rb)) -> conjunct_many_bindings [check_mcode lb1 lb; check_mcode rb1 rb; + match_option + (fun (td1, ty1) (td2, ty2) -> conjunct_bindings + (check_mcode td1 td2) (match_typeC ty1 ty2) ) + base1 base2; match_typeC tya tyb; - match_dots match_enum_decl no_list do_nolist_match idsa idsb] + match_option (match_dots match_enum_decl no_list do_nolist_match) idsa idsb] | (Ast0.StructUnionName(kinda,Some namea), Ast0.StructUnionName(kindb,Some nameb)) -> if mcode_equal kinda kindb @@ -1927,8 +1932,8 @@ let instantiate bindings mv_bindings model = | Ast0.Signed(s, ty') -> let ty'' = Common.map_option renamer ty' in Ast0.rewrap ty (Ast0.Signed (s, ty'')) - | Ast0.EnumDef(ty', s0, e, s1) -> - Ast0.rewrap ty (Ast0.EnumDef (renamer ty', s0, e, s1)) + | Ast0.EnumDef(ty', base, s0, e, s1) -> (* do I need to unwrap base *) + Ast0.rewrap ty (Ast0.EnumDef (renamer ty', base, s0, e, s1)) | Ast0.StructUnionDef(ty', s0, d, s1) -> let ty'' = renamer ty' in Ast0.rewrap ty (Ast0.StructUnionDef (ty'', s0, d, s1)) @@ -1947,7 +1952,7 @@ let instantiate bindings mv_bindings model = Ast0.rewrap ty (Ast0.OptType (renamer ty')) | Ast0.BaseType(_, _) | Ast0.Decimal(_, _, _, _, _, _) - | Ast0.EnumName(_, _) + | Ast0.EnumName(_, _, _) | Ast0.StructUnionName (_, _) | Ast0.TypeOfExpr(_, _, _, _) | Ast0.TypeName _ diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index b2aa431b..8d0489ac 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -120,6 +120,7 @@ let token2c (tok,_) add_clt = | PC.Tptrdiff_t(clt) -> add_clt "ptrdiff_t" clt | PC.Tstruct(clt) -> add_clt "struct" clt | PC.Tunion(clt) -> add_clt "union" clt + | PC.Tclass(clt) -> add_clt "class" clt | PC.Tenum(clt) -> add_clt "enum" clt | PC.Tunsigned(clt) -> add_clt "unsigned" clt | PC.Tsigned(clt) -> add_clt "signed" clt @@ -331,7 +332,7 @@ let plus_attachable only_plus (tok,_) = PC.Tchar(clt) | PC.Tshort(clt) | PC.Tint(clt) | PC.Tdouble(clt) | PC.Tfloat(clt) | PC.Tcomplex(clt) | PC.Tlong(clt) | PC.Tvoid(clt) | PC.Tsize_t(clt) | PC.Tssize_t(clt) | PC.Tptrdiff_t(clt) - | PC.Tstruct(clt) + | PC.Tstruct(clt) | PC.Tclass(clt) | PC.Tunion(clt) | PC.Tenum(clt) | PC.Tunsigned(clt) | PC.Tsigned(clt) | PC.TautoType(clt) | PC.Tdecimal(clt) | PC.Texec(clt) | PC.Tstatic(clt) @@ -422,7 +423,7 @@ let get_clt (tok,_) = PC.Tchar(clt) | PC.Tshort(clt) | PC.Tint(clt) | PC.Tdouble(clt) | PC.Tfloat(clt) | PC.Tcomplex(clt) | PC.Tlong(clt) | PC.Tvoid(clt) | PC.Tsize_t(clt) | PC.Tssize_t(clt) | PC.Tptrdiff_t(clt) - | PC.Tstruct(clt) + | PC.Tstruct(clt) | PC.Tclass(clt) | PC.Tunion(clt) | PC.Tenum(clt) | PC.Tunsigned(clt) | PC.Tsigned(clt) | PC.TautoType(clt) | PC.Tdecimal(clt) | PC.Texec(clt) | PC.Tstatic(clt) | PC.Ttypedef(clt) @@ -585,6 +586,7 @@ let update_clt (tok,x) clt = | PC.Tssize_t(_) -> (PC.Tssize_t(clt),x) | PC.Tptrdiff_t(_) -> (PC.Tptrdiff_t(clt),x) | PC.Tstruct(_) -> (PC.Tstruct(clt),x) + | PC.Tclass(_) -> (PC.Tclass(clt),x) | PC.Tunion(_) -> (PC.Tunion(clt),x) | PC.Tenum(_) -> (PC.Tenum(clt),x) | PC.Tdecimal(_) -> (PC.Tdecimal(clt),x) @@ -902,7 +904,7 @@ let split_token ((tok,_) as t) = | PC.Tchar(clt) | PC.Tshort(clt) | PC.Tint(clt) | PC.Tdouble(clt) | PC.Tfloat(clt) | PC.Tcomplex(clt) | PC.Tlong(clt) | PC.Tvoid(clt) | PC.Tsize_t(clt) | PC.Tssize_t(clt) | PC.Tptrdiff_t(clt) - | PC.Tstruct(clt) + | PC.Tstruct(clt) | PC.Tclass(clt) | PC.Tunion(clt) | PC.Tenum(clt) | PC.Tdecimal(clt) | PC.Texec(clt) | PC.Tunsigned(clt) | PC.Tsigned(clt) | PC.TautoType(clt) | PC.Tstatic(clt) | PC.Tauto(clt) | PC.Tregister(clt) | PC.Textern(clt) @@ -1189,6 +1191,8 @@ let detect_attr l = | [x] -> [x] | ((PC.Tstruct _,_) as t1)::x::rest -> t1::x::loop rest + | ((PC.Tclass _,_) as t1)::x::rest -> + t1::x::loop rest | ((PC.Tunion _,_) as t1)::x::rest -> t1::x::loop rest | ((PC.TIdent(nm,clt),info) as t1)::id::rest when is_id id -> @@ -1336,7 +1340,7 @@ let token2line (tok,_) = PC.Tchar(clt) | PC.Tshort(clt) | PC.Tint(clt) | PC.Tdouble(clt) | PC.Tfloat(clt) | PC.Tcomplex(clt) | PC.Tlong(clt) | PC.Tvoid(clt) | PC.Tsize_t(clt) | PC.Tssize_t(clt) | PC.Tptrdiff_t(clt) - | PC.Tstruct(clt) + | PC.Tstruct(clt) | PC.Tclass(clt) | PC.Tunion(clt) | PC.Tenum(clt) | PC.Tdecimal(clt) | PC.Texec(clt) | PC.Tunsigned(clt) | PC.Tsigned(clt) | PC.TautoType(clt) | PC.Tstatic(clt) | PC.Tauto(clt) | PC.Tregister(clt) | PC.Textern(clt) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 03638e86..4c40e90a 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -934,7 +934,7 @@ delimited_list_len: expression_type: m=nonempty_list(TMul) { Parse_aux.ty_pointerify unknown_type m } | Tenum m=list(TMul) - { Parse_aux.ty_pointerify (Ast0_cocci.wrap (Ast0_cocci.EnumName (Ast0_cocci.make_mcode "", None))) m } + { Parse_aux.ty_pointerify (Ast0_cocci.wrap (Ast0_cocci.EnumName (Ast0_cocci.make_mcode "", None, None))) m } | Tstruct m=list(TMul) { Parse_aux.ty_pointerify (Ast0_cocci.wrap @@ -1008,8 +1008,8 @@ signable_types: Ast0_cocci.Impure (*will be ignored*))) } non_signable_types_no_ident_with_braces: - | s=Tenum k=option(enum_key) i=option(type_ident) base=ioption(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace - { (if name = None && !Data.in_iso + | s=Tenum k=option(enum_key) i=option(type_ident) base=ioption(enum_base) l=TOBrace ids=option(enum_decl_list) r=TCBrace + { (if i = None && !Data.in_iso then failwith "enums must be named in the iso file"); Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, k, i)), base, Parse_aux.clt2mcode "{" l, ids, Parse_aux.clt2mcode "}" r)) } @@ -1197,7 +1197,7 @@ typedef_ctype: typedef_ctype_only_signed: ty=signable_types - { Parse_aux.pointerify (Parse_aux.make_cv None ty) None } + { Parse_aux.pointerify (Parse_aux.make_cv None ty) [] } /* ---------------------------------------------------------------------- */ @@ -1284,12 +1284,12 @@ enum_decl_list: { Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) } enum_key: - Tstruct { Parse_aux.cl2mcode "struct" $1 } - | Tclass { Parse_aux.cl2mcode "class" $1 } + Tstruct { Parse_aux.clt2mcode "struct" $1 } + | Tclass { Parse_aux.clt2mcode "class" $1 } enum_base: c=TDotDot t=ctype_without_braces - { Ast0_cocci.wrap(Ast0_cocci.Base(Parse_aux.cl2mcode ":" c, t))} + { (Parse_aux.clt2mcode ":" c, t) } /*****************************************************************************/ diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index ac2f085c..9d13354b 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -513,12 +513,15 @@ and typeC ty = print_option (mcode print_string) comma; print_option expression precision_opt; mcode print_string rp - | Ast.EnumName(kind,name) -> + | Ast.EnumName(kind,key,name) -> mcode print_string kind; + print_option (mcode print_string) key; print_option (function x -> ident x; print_string " ") name - | Ast.EnumDef(ty,lb,ids,rb) -> - fullType ty; mcode print_string lb; - dots force_newline enum_decl ids; + | Ast.EnumDef(ty,base,lb,ids,rb) -> + fullType ty; + print_option enum_base base; + mcode print_string lb; + print_option (dots force_newline enum_decl) ids; mcode print_string rb | Ast.StructUnionName(kind,name) -> mcode structUnion kind; @@ -682,6 +685,9 @@ and enum_decl d = mcode print_string dots; print_string " when != "; enum_decl whencode | Ast.EnumDots(dots,None) -> mcode print_string dots +and enum_base (td, ty) = + mcode print_string td; + fullType ty; (* --------------------------------------------------------------------- *) (* Initialiser *) diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 9206a77c..a05f0bac 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -171,8 +171,8 @@ and left_typeC t = | Ast0.Array(ty,lb,size,rb) -> left_typeC ty | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> modif_before_mcode dec - | Ast0.EnumName(kind,name) -> modif_before_mcode kind - | Ast0.EnumDef(ty,lb,ids,rb) -> left_typeC ty + | Ast0.EnumName(kind,key,name) -> modif_before_mcode kind + | Ast0.EnumDef(ty,base,lb,ids,rb) -> left_typeC ty | Ast0.StructUnionName(kind,name) -> modif_before_mcode kind | Ast0.StructUnionDef(ty,lb,decls,rb) -> left_typeC ty | Ast0.TypeOfExpr(tf,_,_,_) -> modif_before_mcode tf diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 307fc68e..65aebfec 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -359,13 +359,14 @@ and unify_typeC t1 t2 = Ast.Decimal(dec2,lp2,len2,comma2,prec_opt2,rp2)) -> unify_expression len1 len2 && unify_option unify_expression prec_opt1 prec_opt2 - | (Ast.EnumName(s1,Some ts1),Ast.EnumName(s2,Some ts2)) -> - if unify_mcode s1 s2 then unify_ident ts1 ts2 else false - | (Ast.EnumName(s1,None),Ast.EnumName(s2,None)) -> + | (Ast.EnumName(s1,key1,Some ts1),Ast.EnumName(s2,key2,Some ts2)) -> + if (unify_mcode s1 s2) && (unify_option unify_mcode key1 key2) then unify_ident ts1 ts2 else false + | (Ast.EnumName(s1,key1,None),Ast.EnumName(s2,key2,None)) -> true - | (Ast.EnumDef(ty1,lb1,ids1,rb1),Ast.EnumDef(ty2,lb2,ids2,rb2)) -> + | (Ast.EnumDef(ty1,base1,lb1,ids1,rb1),Ast.EnumDef(ty2,base2,lb2,ids2,rb2)) -> unify_fullType ty1 ty2 && - unify_dots unify_enum_decl enumdots ids1 ids2 + unify_option (fun (_, ty1) (_,ty2) -> unify_fullType ty1 ty2) base1 base2 && + unify_option (unify_dots unify_enum_decl enumdots) ids1 ids2 | (Ast.StructUnionName(s1,Some ts1),Ast.StructUnionName(s2,Some ts2)) -> if unify_mcode s1 s2 then unify_ident ts1 ts2 else false | (Ast.StructUnionName(s1,None),Ast.StructUnionName(s2,None)) -> diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index d65a1b64..018c1d17 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -361,12 +361,17 @@ and typeC t = print_option (mcode print_string) comma; print_option expression precision_opt; mcode print_string rp - | Ast0.EnumName(kind,name) -> + | Ast0.EnumName(kind,key,name) -> mcode print_string kind; + print_option (mcode print_string) key; print_option (function x -> ident x; print_string " ") name - | Ast0.EnumDef(ty,lb,ids,rb) -> - typeC ty; mcode print_string lb; - dots force_newline enum_decl ids; + | Ast0.EnumDef(ty,base,lb,ids,rb) -> + typeC ty; + print_option + (function (td, ty) -> mcode print_string td; typeC ty;) + base; + mcode print_string lb; + print_option (dots force_newline enum_decl) ids; mcode print_string rb | Ast0.StructUnionName(kind,name) -> mcode U.structUnion kind; diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 17204ab1..f6f47e15 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -402,16 +402,18 @@ let combiner bind option_default let lprecision_opt = get_option expression precision_opt in let lrp = string_mcode rp in multibind [ldec; llp; llength; lcomma; lprecision_opt; lrp] - | Ast.EnumName(kind,name) -> + | Ast.EnumName(kind,key,name) -> let lkind = string_mcode kind in + let lkey = get_option string_mcode key in let lname = get_option ident name in - bind lkind lname - | Ast.EnumDef(ty,lb,ids,rb) -> + multibind [lkind; lkey; lname] + | Ast.EnumDef(ty,base,lb,ids,rb) -> let lty = fullType ty in + let lbase = get_option enum_base base in let llb = string_mcode lb in - let lids = enum_decl_dots ids in + let lids = get_option enum_decl_dots ids in let lrb = string_mcode rb in - multibind [lty; llb; lids; lrb] + multibind [lty; lbase; llb; lids; lrb] | Ast.StructUnionName(kind,name) -> let lkind = struct_mcode kind in let lname = get_option ident name in @@ -583,6 +585,11 @@ let combiner bind option_default bind ldots lwhncode in enum_declfn all_functions k d + and enum_base (td,ty) = + let ltd = string_mcode td in + let lty = fullType ty in + bind ltd lty + and initialiser i = let k i = match Ast.unwrap i with @@ -1423,16 +1430,18 @@ let rebuilder let lprecision_opt = get_option expression precision_opt in let lrp = string_mcode rp in Ast.Decimal(ldec, llp, llength, lcomma, lprecision_opt, lrp) - | Ast.EnumName(kind,name) -> + | Ast.EnumName(kind,key,name) -> let lkind = string_mcode kind in + let lkey = get_option string_mcode key in let lname = get_option ident name in - Ast.EnumName(lkind, lname) - | Ast.EnumDef(ty,lb,ids,rb) -> + Ast.EnumName(lkind, lkey, lname) + | Ast.EnumDef(ty,base,lb,ids,rb) -> let lty = fullType ty in + let lbase = get_option enum_base base in let llb = string_mcode lb in - let lids = enum_decl_dots ids in + let lids = get_option enum_decl_dots ids in let lrb = string_mcode rb in - Ast.EnumDef (lty, llb, lids, lrb) + Ast.EnumDef (lty, lbase, llb, lids, lrb) | Ast.StructUnionName(kind,name) -> let lkind = struct_mcode kind in let lname = get_option ident name in @@ -1604,6 +1613,11 @@ let rebuilder Ast.EnumDots(ldots, lwhncode)) in enum_declfn all_functions k d + and enum_base (td,ty) = + let ltd = string_mcode td in + let lty = fullType ty in + (ltd, lty) + and initialiser i = let k i = Ast.rewrap i diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index 385e9de0..85316918 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -370,16 +370,18 @@ let visitor mode bind option_default let (rp_n,rp) = string_mcode rp in (multibind [dec_n; lp_n; length_n; comma_n; precision_n; rp_n], Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) - | Ast0.EnumName(kind,name) -> + | Ast0.EnumName(kind,key,name) -> let (kind_n,kind) = string_mcode kind in + let (key_n, key) = get_option string_mcode key in let (name_n,name) = get_option ident name in - (bind kind_n name_n, Ast0.EnumName(kind,name)) - | Ast0.EnumDef(ty,lb,ids,rb) -> + (multibind [kind_n;key_n;name_n], Ast0.EnumName(kind,key,name)) + | Ast0.EnumDef(ty,base,lb,ids,rb) -> let (ty_n,ty) = typeC ty in + let (base_n, base) = get_option enum_base base in let (lb_n,lb) = string_mcode lb in - let (ids_n,ids) = enum_decl_dots ids in + let (ids_n,ids) = get_option enum_decl_dots ids in let (rb_n,rb) = string_mcode rb in - (multibind [ty_n;lb_n;ids_n;rb_n], Ast0.EnumDef(ty,lb,ids,rb)) + (multibind [ty_n;lb_n;ids_n;rb_n], Ast0.EnumDef(ty,base,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> let (kind_n,kind) = struct_mcode kind in let (name_n,name) = get_option ident name in @@ -748,6 +750,12 @@ let visitor mode bind option_default let (n,decl) = field decl in (n,Ast0.OptField(decl))) in fieldfn all_functions k d + and enum_base base = + let (tdd, typ) = base in + let (tdd_n, tdd) = string_mcode tdd in + let (typ_n, typ) = typeC typ in + ((bind tdd_n typ_n), (tdd, typ)) + and enum_decl d = let k d = rewrap d -- GitLab From 57010c9bf0a25c9116578cb36c292506f375c53b Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Mon, 27 Jun 2022 12:49:08 +0530 Subject: [PATCH 17/24] Changed the definition of EnumName to include class Signed-off-by: Tathagata Roy --- parsing_cocci/arity.ml | 5 +++-- parsing_cocci/ast0_cocci.ml | 2 +- parsing_cocci/ast0_cocci.mli | 2 +- parsing_cocci/ast_cocci.ml | 27 ++++++++++++++------------- parsing_cocci/ast_cocci.mli | 6 +++--- parsing_cocci/compute_lines.ml | 6 +----- parsing_cocci/disjdistr.ml | 7 ++++--- parsing_cocci/free_vars.ml | 4 ++-- parsing_cocci/get_constants2.ml | 8 +++++--- parsing_cocci/parser_cocci_menhir.mly | 4 ++-- parsing_cocci/pretty_print_cocci.ml | 2 +- parsing_cocci/unparse_ast0.ml | 2 +- parsing_cocci/visitor_ast.ml | 4 ++-- parsing_cocci/visitor_ast0.ml | 2 +- 14 files changed, 41 insertions(+), 40 deletions(-) diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index ac0bed5a..d99f98c7 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -471,7 +471,8 @@ and top_typeC tgt opt_allowed typ = (Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) | Ast0.EnumName(kind,key,name) -> let arity = - all_same opt_allowed tgt (mcode2line kind) [mcode2arity kind] in + all_same opt_allowed tgt (mcode2line kind) + ((mcode2arity kind)::(Common.default [] (function x -> [mcode2arity x]) key)) in let kind = mcode kind in let key = get_option mcode key in let name = get_option (ident false arity) name in @@ -479,7 +480,7 @@ and top_typeC tgt opt_allowed typ = | Ast0.EnumDef(ty,base,lb,decls,rb) -> let arity = all_same opt_allowed tgt (mcode2line lb) - (List.map mcode2arity [lb;rb]) in + (List.map mcode2arity ((Common.default [] (function (td,ty) -> [td]) base)@[lb;rb])) in let ty = typeC arity ty in let base = get_option (function (td, ty) -> (mcode td, typeC arity ty)) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 04adb628..6dbb9442 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -214,7 +214,7 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * string mcode option (* struct/class/None *) * ident option (* name *) + | EnumName of string mcode (*enum*) * Ast.structUnion mcode option (* struct/class/None *) * ident option (* name *) | EnumDef of typeC (* EnumName *) * enum_base option (* base type *) * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index a0d580e4..36569495 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -205,7 +205,7 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * string mcode option (* struct/class/None *) * ident option (* name *) + | EnumName of string mcode (*enum*) * Ast_cocci.structUnion mcode option (* struct/class/None *) * ident option (* name *) | EnumDef of typeC (* EnumName *) * enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index f020f141..170383d0 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -355,7 +355,7 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * string mcode option(*struct/class/None*) * ident option (* name *) + | EnumName of string mcode (*enum*) * structUnion mcode option(*struct/class/None*) * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) @@ -381,7 +381,7 @@ and baseType = VoidType | CharType | ShortType | ShortIntType | IntType | SizeType | SSizeType | PtrDiffType | BoolType | Unknown -and structUnion = Struct | Union +and structUnion = Struct | Union | Class and sign = Signed | Unsigned @@ -1134,9 +1134,7 @@ let string_of_expression e = let string_of_structUnion = function Struct -> "struct" | Union -> "union" - -let string_of_enumkey = function - Struct -> "struct" + | Class -> "class" let rec string_of_typeC ty = match unwrap ty with @@ -1156,7 +1154,8 @@ let rec string_of_typeC ty = let s0 = string_of_expression e0 and s1 = Common.default "?" string_of_expression e1 in Printf.sprintf "decimal(%s,%s) " s0 s1 - | EnumName (_, key, name) -> "enum " ^ (Common.default "?" string_of_ident name) (* should I make use the function string_of_enumkey or delete it*) + | EnumName (_, key, name) -> "enum " ^ (Common.default "" (function x -> string_of_structUnion (unwrap_mcode x)) key) ^ + (Common.default "" (function x -> " ") key) ^ (Common.default "" string_of_ident name) | StructUnionName (kind, name) -> Printf.sprintf "%s %s" (string_of_structUnion (unwrap_mcode kind)) @@ -1195,7 +1194,7 @@ type 'a transformer = { baseType: (baseType -> string mcode list -> 'a) option; decimal: (string mcode -> string mcode -> expression -> string mcode option -> expression option -> string mcode -> 'a) option; - enumName: (string mcode -> ident option -> 'a) option; + enumName: (string mcode -> structUnion mcode option -> ident option -> 'a) option; structUnionName: (structUnion mcode -> ident option -> 'a) option; typeName: (string mcode -> 'a) option; metaType: (meta_name mcode -> constraints -> keep_binding -> @@ -1240,7 +1239,7 @@ and typeC_map tr ty = begin match tr.enumName with None -> ty - | Some f -> rewrap ty (f s0 ident) + | Some f -> rewrap ty (f s0 key ident) end | StructUnionName (su, ident) -> begin @@ -1300,7 +1299,7 @@ and typeC_fold tr ty v = | StructUnionDef (ty', _, _, _) -> fullType_fold tr ty' v | Decimal (s0, s1, e0, s2, e1, s3) -> Common.default v (fun f -> f s0 s1 e0 s2 e1 s3 v) tr.decimal - | EnumName (s0, key, ident) -> Common.default v (fun f -> f s0 ident v) tr.enumName (* Not sure about this *) + | EnumName (s0, key, ident) -> Common.default v (fun f -> f s0 key ident v) tr.enumName (* Not sure about this *) | StructUnionName (su, ident) -> Common.default v (fun f -> f su ident v) tr.structUnionName | TypeOfExpr(_,_,e,_) -> v @@ -1315,7 +1314,7 @@ let fullType_iter tr ty = baseType = Common.map_option (fun f ty' s0 () -> f ty' s0) tr.baseType; decimal = Common.map_option (fun f s0 s1 e0 s2 e1 s3 () -> f s0 s1 e0 s2 e1 s3) tr.decimal; - enumName = Common.map_option (fun f s0 ident () -> f s0 ident) tr.enumName; + enumName = Common.map_option (fun f s0 key ident () -> f s0 key ident) tr.enumName; structUnionName = Common.map_option (fun f su ident () -> f su ident) tr.structUnionName; typeName = Common.map_option (fun f name () -> f name) tr.typeName; @@ -1340,15 +1339,17 @@ let rec ident_fold_meta_names f ident v = let expression_fold_ident f e v = f (Common.just (ident_of_expression_opt e)) v let fullType_fold_meta_names f ty v = - let enumOrStructUnionName _ ident v = + let structUnionName _ ident v = + Common.default v (fun ident' -> ident_fold_meta_names f ident' v) ident in + let enumName _ _ ident v = Common.default v (fun ident' -> ident_fold_meta_names f ident' v) ident in fullType_fold { empty_transformer with decimal = Some (fun _ _ e1 _ e2 _ v -> let v' = expression_fold_ident (ident_fold_meta_names f) e1 v in Common.default v' (fun e -> expression_fold_ident (ident_fold_meta_names f) e v) e2); - enumName = Some enumOrStructUnionName; - structUnionName = Some enumOrStructUnionName; + enumName = Some enumName; + structUnionName = Some structUnionName; metaType = Some (fun tyname _ _ _ v -> f (unwrap_mcode tyname) v) } ty v diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 0f6ecc58..22bf06f8 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -337,7 +337,7 @@ and base_typeC = expression * string mcode option (* , *) * expression option * string mcode (* ) *) (* IBM C only *) - | EnumName of string mcode (*enum*) * string mcode option * ident option (* name *) + | EnumName of string mcode (*enum*) * structUnion mcode option * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) @@ -363,7 +363,7 @@ and baseType = VoidType | CharType | ShortType | ShortIntType | IntType | SizeType | SSizeType | PtrDiffType | BoolType | Unknown -and structUnion = Struct | Union +and structUnion = Struct | Union | Class and sign = Signed | Unsigned @@ -905,7 +905,7 @@ type 'a transformer = { baseType: (baseType -> string mcode list -> 'a) option; decimal: (string mcode -> string mcode -> expression -> string mcode option -> expression option -> string mcode -> 'a) option; - enumName: (string mcode -> ident option -> 'a) option; + enumName: (string mcode -> structUnion mcode option -> ident option -> 'a) option; structUnionName: (structUnion mcode -> ident option -> 'a) option; typeName: (string mcode -> 'a) option; metaType: (meta_name mcode -> constraints -> keep_binding -> diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 882413b4..da6e78d5 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -624,11 +624,7 @@ and typeC t = let lb = normal_mcode lb in let ids = get_option (dots is_enum_decl_dots - (Some - (match base with - None -> promote_mcode lb - | Some (td, _) -> promote_mcode td) - ) + (Some (Common.default (promote_mcode lb) (function (td,ty) -> promote_mcode td) base)) enum_decl) ids in let rb = normal_mcode rb in mkres t (Ast0.EnumDef(ty,base,lb,ids,rb)) ty (promote_mcode rb) diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 6dd7fc7a..5e559852 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -95,9 +95,10 @@ and disjtypeC bty = name | Ast.EnumDef(ty,base,lb,ids,rb) -> disjmult3 (disjty ty) - (disjoption (function (td, ty1) -> - let ty1 = disjty ty1 in - List.map (function ty1 -> (td, ty1)) ty1) + (disjoption + (function (td, ty1) -> + let ty1 = disjty ty1 in + List.map (function ty1 -> (td, ty1)) ty1) base) (disjoption (disjdots disjenumdecl) ids) (fun ty base ids -> diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml index bf9affa7..7e40c3e3 100644 --- a/parsing_cocci/free_vars.ml +++ b/parsing_cocci/free_vars.ml @@ -726,9 +726,9 @@ let classify_variables metavar_decls minirules used_after = Ast.Ident ident -> Ast.rewrap e (Ast.Ident (classify_ident ident)) | _ -> e in Ast.Decimal (s0, s1, e2mv e1, s2, Common.map_option e2mv e2, s3)); - enumName = Some (fun s0 ident -> + enumName = Some (fun s0 s1 ident -> let ident' = Common.map_option classify_ident ident in - Ast.EnumName (s0, None, ident')); (* have to change this *) + Ast.EnumName (s0, s1, ident')); structUnionName = Some (fun su ident -> let ident' = Common.map_option classify_ident ident in Ast.StructUnionName (su, ident')); diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index cfb86ba2..419168ff 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -409,7 +409,9 @@ let do_get_constants constants keywords env (neg_pos,_) = Ast.Id name -> add (constants (Ast.unwrap_mcode name)) | Ast.MetaId(name,_,_,_) -> add (minherited name) | _ -> Common.id in - let enumOrStructUnionName _ ident res = + let structUnionName _ ident res = + Common.default res (fun ident' -> add_ident ident' res) ident in + let enumName _ _ ident res = Common.default res (fun ident' -> add_ident ident' res) ident in let pieces ty res = Ast.fullType_fold @@ -419,8 +421,8 @@ let do_get_constants constants keywords env (neg_pos,_) = Some (fun tyname _ _ _ -> add (inherited (Ast.unwrap_mcode tyname))); typeName = Some(fun tyname -> add (constants (Ast.unwrap_mcode tyname))); - enumName = Some enumOrStructUnionName; - structUnionName = Some enumOrStructUnionName + enumName = Some enumName; + structUnionName = Some structUnionName } ty res in let rec loop ty = match Ast.unwrap ty with diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 4c40e90a..5dfa3604 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1284,8 +1284,8 @@ enum_decl_list: { Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) } enum_key: - Tstruct { Parse_aux.clt2mcode "struct" $1 } - | Tclass { Parse_aux.clt2mcode "class" $1 } + Tstruct { Parse_aux.clt2mcode Ast_cocci.Struct $1 } + | Tclass { Parse_aux.clt2mcode Ast_cocci.Class $1 } enum_base: c=TDotDot t=ctype_without_braces diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 9d13354b..fe3d99d8 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -515,7 +515,7 @@ and typeC ty = mcode print_string rp | Ast.EnumName(kind,key,name) -> mcode print_string kind; - print_option (mcode print_string) key; + print_option (mcode structUnion) key; print_option (function x -> ident x; print_string " ") name | Ast.EnumDef(ty,base,lb,ids,rb) -> fullType ty; diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index 018c1d17..c89b7c7c 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -363,7 +363,7 @@ and typeC t = mcode print_string rp | Ast0.EnumName(kind,key,name) -> mcode print_string kind; - print_option (mcode print_string) key; + print_option (mcode U.structUnion) key; print_option (function x -> ident x; print_string " ") name | Ast0.EnumDef(ty,base,lb,ids,rb) -> typeC ty; diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index f6f47e15..a3af25d9 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -404,7 +404,7 @@ let combiner bind option_default multibind [ldec; llp; llength; lcomma; lprecision_opt; lrp] | Ast.EnumName(kind,key,name) -> let lkind = string_mcode kind in - let lkey = get_option string_mcode key in + let lkey = get_option struct_mcode key in let lname = get_option ident name in multibind [lkind; lkey; lname] | Ast.EnumDef(ty,base,lb,ids,rb) -> @@ -1432,7 +1432,7 @@ let rebuilder Ast.Decimal(ldec, llp, llength, lcomma, lprecision_opt, lrp) | Ast.EnumName(kind,key,name) -> let lkind = string_mcode kind in - let lkey = get_option string_mcode key in + let lkey = get_option struct_mcode key in let lname = get_option ident name in Ast.EnumName(lkind, lkey, lname) | Ast.EnumDef(ty,base,lb,ids,rb) -> diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index 85316918..bd5eaa90 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -372,7 +372,7 @@ let visitor mode bind option_default Ast0.Decimal(dec,lp,length,comma,precision_opt,rp)) | Ast0.EnumName(kind,key,name) -> let (kind_n,kind) = string_mcode kind in - let (key_n, key) = get_option string_mcode key in + let (key_n, key) = get_option struct_mcode key in let (name_n,name) = get_option ident name in (multibind [kind_n;key_n;name_n], Ast0.EnumName(kind,key,name)) | Ast0.EnumDef(ty,base,lb,ids,rb) -> -- GitLab From f7c112db09bee849efd138dd2eea0801ddaa1e83 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 12 Jul 2022 01:11:25 +0530 Subject: [PATCH 18/24] Added enum in cocci and C, and wrote partial code for engine/ --- engine/c_vs_c.ml | 29 ++- engine/check_exhaustive_pattern.ml | 4 +- engine/cocci_vs_c.ml | 259 ++++++++++++----------- ocaml/coccilib.mli | 18 +- parsing_c/ast_c.ml | 5 +- parsing_c/ast_c.mli | 4 +- parsing_c/includes_cache.ml | 10 +- parsing_c/includes_cache.mli | 2 +- parsing_c/parser_c.mly | 86 +++++++- parsing_c/pretty_print_c.ml | 75 +++---- parsing_c/type_annoter_c.ml | 18 +- parsing_c/type_c.ml | 4 +- parsing_c/unparse_cocci.ml | 22 +- parsing_c/visitor_c.ml | 16 +- parsing_cocci/arity.ml | 2 +- parsing_cocci/ast0_cocci.ml | 2 +- parsing_cocci/ast0_cocci.mli | 2 +- parsing_cocci/ast0toast.ml | 3 +- parsing_cocci/ast_cocci.ml | 10 +- parsing_cocci/ast_cocci.mli | 2 +- parsing_cocci/check_meta.ml | 2 +- parsing_cocci/commas_on_lists.ml | 4 +- parsing_cocci/compute_lines.ml | 2 +- parsing_cocci/disjdistr.ml | 2 +- parsing_cocci/iso_pattern.ml | 7 +- parsing_cocci/parse_cocci.ml | 2 +- parsing_cocci/parser_cocci_menhir.mly | 19 +- parsing_cocci/pretty_print_cocci.ml | 6 +- parsing_cocci/unify_ast.ml | 4 +- parsing_cocci/unparse_ast0.ml | 8 +- parsing_cocci/visitor_ast.ml | 4 +- parsing_cocci/visitor_ast0.ml | 2 +- tools/spgen/source/meta_variable.ml | 2 +- tools/spgen/source/position_generator.ml | 12 +- 34 files changed, 381 insertions(+), 268 deletions(-) diff --git a/engine/c_vs_c.ml b/engine/c_vs_c.ml index 209e01de..1770407c 100644 --- a/engine/c_vs_c.ml +++ b/engine/c_vs_c.ml @@ -170,22 +170,21 @@ and typeC tya tyb = return (FunctionType (returnx, paramsx), iix) )) - | Enum (saopt, enuma), Enum (sbopt, enumb) -> + | EnumDef (saopt, basea, enuma), EnumDef (sbopt, baseb, enumb) -> (saopt = sbopt && - List.length enuma = List.length enumb && - Common.zip enuma enumb +> List.for_all (fun - (((namesa,eopta), iicommaa), ((namesb,eoptb),iicommab)) - -> - let sa = str_of_name namesa in - let sb = str_of_name namesb in - sa = sb && - (* todo ? eopta and b can have some info so ok to use = ? *) - eopta = eoptb - ) - ) >&&> - return (Enum (saopt, enuma), iix) - - | EnumName sa, EnumName sb -> sa = sb >&&> return (EnumName sa, iix) + List.length enuma = List.length enumb && + Common.zip enuma enumb +> + List.for_all + (fun (((namesa,eopta), iicommaa), ((namesb,eoptb),iicommab)) -> + let sa = str_of_name namesa in + let sb = str_of_name namesb in + sa = sb && + (* todo ? eopta and b can have some info so ok to use = ? *) + eopta = eoptb)) >&&> + option fullType basea baseb >>= (fun x -> + return (EnumDef (saopt, x, enuma), iix)) + + | EnumName (sa, ia), EnumName (sb, ib) -> (sa = sb && ia = ib) >&&> return (EnumName (sa, ia), iix) | ParenType a, ParenType b -> (* iso here ? *) diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml index c215a0dc..f082c814 100644 --- a/engine/check_exhaustive_pattern.ml +++ b/engine/check_exhaustive_pattern.ml @@ -152,8 +152,8 @@ let dumb_astcocci_type = function | A.FunctionType(ty,lp,params,rp) -> () | A.Array (typa, _, eaopt, _) -> () | A.Decimal(_, _, _, _, _, _) -> () - | A.EnumName(en, ena) -> () - | A.EnumDef(ty, lb, ids, rb) -> () + | A.EnumName(k, key, ena) -> () + | A.EnumDef(ty, base, lb, ids, rb) -> () | A.StructUnionName(sa, sua) -> () | A.StructUnionDef(ty, lb, decls, rb) -> () | A.TypeOfExpr(tf, lp, exp, rp) -> () diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 50d88c88..740ff1a9 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -114,8 +114,6 @@ let generalize_mcode ia = in (s1, i, new_mck, pos) - - (*---------------------------------------------------------------------------*) (* 0x0 is equivalent to 0, value format isomorphism *) @@ -185,6 +183,7 @@ let equal_structUnion a b = match a, b with | A.Struct, B.Struct -> true | A.Union, B.Union -> true + | A.Class, B.Class -> true | _, (B.Struct|B.Union|B.Class) -> false let equal_sign a b = @@ -784,6 +783,33 @@ module type PARAM = end + +let extract_one = function + a::ii -> (a, ii) + | _ -> failwith "impossible" + +let token_option y ii = + match y, ii with + None, _ -> None + | Some y, ib::ii -> Some (y, ib, ii) + | _ -> failwith "impossible" + +let token_option2 y ii = + match y, ii with + None, _ -> None + | Some y, ib1::ib2::ii -> Some (y, ib1, ib2, ii) + | _ -> failwith "impossible" + +let option_ret_unwrap y ii = + match y with + None -> (None, [], ii) + | Some (y, ib, ii) -> (Some y, [ib], ii) + +let option_ret_unwrap2 y ii = + match y with + None -> (None, [], ii) + | Some (y, ib1, ib2, ii) -> (Some y, [ib1;ib2], ii) + let satisfies_script_constraint (name, lang, params, pos, body) ida idb env = let values = try Some ((ida, idb) :: List.map (fun (p,_) -> (p, env p)) params) @@ -872,6 +898,7 @@ let (option: ('a,'b) matcher -> ('a option,'b option) matcher)= fun f t1 t2 -> | (None, None) -> return (None, None) | _ -> fail + (* Dots are sometimes used as metavariables, since like metavariables they can match other things. But they no longer have the same type. Perhaps these functions could be avoided by introducing an appropriate level of polymorphism, @@ -1587,72 +1614,53 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = ((B.SizeOfType (typb),typ),[ib1;ib2;ib3]) ))))) - | A.New (ia1, pp_opta,ia4_opt,typa,ia5_opt,init_opta), ((B.New (pp_optb,typb,init_optb), typ), ib1::ii) -> + | A.New (ia1,pp_opta,ia4_opt,typa,ia5_opt,init_opta), ((B.New (pp_optb,typb,init_optb), typ), ib1::ii) -> tokenf ia1 ib1 >>= (fun ia1 ib1 -> (* for checking pp_opt *) - option (fun (ia2, x, ia3) (ib2,y,ib3,ii) -> + option (fun (ia2, x, ia3) (y,ib2,ib3,ii) -> arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> let x = A.rewrap x xunwrap in tokenf ia2 ib2 >>= (fun ia2 ib2 -> tokenf ia3 ib3 >>= (fun ia3 ib3 -> - return ((ia2, x, ia3), (ib2, y, ib3, ii)) + return ((ia2, x, ia3), (y, ib2, ib3, ii)) )) )) pp_opta - (match (pp_optb,ii) with - (None,_) -> None - | (Some pp_optb, ib2::ib3::ii) -> Some (ib2, pp_optb, ib3, ii) - | _ -> failwith "impossible") + (token_option2 pp_optb ii) >>= (fun pp_opta pp_optb -> - let (ib23,pp_optb,ii) = - match pp_optb with - None -> ([], None, ii) - | Some (ib2, pp_optb, ib3, ii) -> ([ib2;ib3],Some pp_optb,ii) in + let (pp_optb, ib23, ii) = + option_ret_unwrap2 pp_optb ii in (* next two options for matchings paranthesis around type *) - option (fun ia4 _ -> - match ii with - ib4::ii -> - tokenf ia4 ib4 >>= (fun ia4 ib4-> - return (ia4, (ib4, ii))) - | _ -> fail) + option (fun ia4 (ignoredtoken,ib4,ii) -> + tokenf ia4 ib4 >>= (fun ia4 ib4-> + return (ia4, (ignoredtoken, ib4, ii)))) ia4_opt - (fmap (function _ -> (ib1, ii)) ia4_opt) + (token_option ia4_opt ii) >>= (fun ia4_opt ib4_opt -> - let (ib4, ii) = - match ib4_opt with - None -> ([], ii) - | Some (ib4, ii) -> ([ib4], ii) in + let (_, ib4, ii) = + option_ret_unwrap ib4_opt ii in fullType typa typb >>= (fun typa typb -> - option ( fun ia5 _ -> - match ii with - ib5::ii -> tokenf ia5 ib5 >>= (fun ia5 ib5 -> - return (ia5, (ib5, ii))) - | _ -> fail) + option ( fun ia5 (ignoredtoken, ib5, ii) -> + tokenf ia5 ib5 >>= (fun ia5 ib5 -> + return (ia5, (ignoredtoken, ib5, ii)))) ia5_opt - (fmap (function _ -> (ib1, ii)) ia5_opt) + (token_option ia5_opt ii) >>= (fun ia5_opt ib5_opt -> - let (ib5, ii) = - match ib5_opt with - None -> ([], ii) - | Some (ib5, ii) -> ([ib5], ii) in + let (_, ib5, ii) = + option_ret_unwrap ib5_opt ii in (* for matching init_opt *) - option (fun (ia6, x, ia7) (ib6, y, ib7, ii) -> + option (fun (ia6, x, ia7) (y, ib6, ib7, ii) -> arguments (seqstyle x) (A.unwrap x) y >>= (fun xunwrap y -> let x = A.rewrap x xunwrap in tokenf ia6 ib6 >>= (fun ia6 ib6 -> tokenf ia7 ib7 >>= (fun ia7 ib7 -> - return ((ia6, x, ia7), (ib6, y, ib7, ii)))) + return ((ia6, x, ia7), (y, ib6, ib7, ii)))) )) init_opta - (match (init_optb, ii) with - (None,_) -> None - | (Some init_optb, ib6::ib7::ii) -> Some (ib6, init_optb, ib7, ii) - | _ -> failwith "impossible" ) + (token_option2 init_optb ii) >>= (fun init_opta init_optb -> - let (ib67, init_optb, ii) = - match init_optb with - None -> ([], None, ii) - | Some (ib6, init_optb, ib7, ii) -> ([ib6;ib7], Some init_optb, ii) in + let (init_optb, ib67, ii) = + option_ret_unwrap2 init_optb ii in if ii != [] (* ALL TOKENS SHOULD HAVE BEEN MATCHED *) then fail else @@ -4152,87 +4160,72 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | _, (B.TypeOfType e, ii) -> fail | _, (B.ParenType e, ii) -> fail (* todo ?*) - | A.EnumName(en,Some namea), (B.EnumName nameb, ii) -> - let (ib1,ib2) = tuple_of_list2 ii in - ident DontKnow namea (nameb, ib2) >>= (fun namea (nameb, ib2) -> - tokenf en ib1 >>= (fun en ib1 -> - return ( - (A.EnumName (en, Some namea)) +> A.rewrap ta, - (B.EnumName nameb, [ib1;ib2]) - ))) - - | A.EnumDef(ty, lba, idsa, rba), - (B.Enum (sbopt, idsb), ii) -> - - let (ii_sub_sb, lbb, rbb, comma_opt) = - match ii with - [iisub; lbb; rbb; comma_opt] -> - (Common.Left iisub,lbb,rbb,comma_opt) - | [iisub; iisb; lbb; rbb; comma_opt] -> - (Common.Right (iisub,iisb),lbb,rbb,comma_opt) - | _ -> error ii "list of length 4 or 5 expected" in - - let process_type = - match (sbopt,ii_sub_sb) with - (None,Common.Left iisub) -> - (* the following doesn't reconstruct the complete SP code, just - the part that matched *) - let rec loop s = - match A.unwrap s with - A.Type(allminus,[],ty) -> - (match A.unwrap ty with - A.EnumName(sua, None) -> - tokenf sua iisub >>= (fun sua iisub -> - let ty = - A.Type(allminus,[],A.EnumName(sua, None) +> - A.rewrap ty) - +> A.rewrap s in - return (ty,[iisub])) - | _ -> fail) - | A.DisjType(disjs) -> (* do we need a conj type case here? *) - disjs +> - List.fold_left (fun acc disj -> acc >|+|> (loop disj)) fail - | _ -> fail in - loop ty - - | (Some sb,Common.Right (iisub,iisb)) -> - - (* build an EnumName from an Enum *) - let fake_su = B.nQ, (B.EnumName sb, [iisub;iisb]) in - - fullType ty fake_su >>= (fun ty fake_su -> - match fake_su with - | _nQ, (B.EnumName sb, [iisub;iisb]) -> - return (ty, [iisub; iisb]) - | _ -> raise (Impossible 47)) - | _ -> fail in - - process_type - >>= (fun ty ii_sub_sb -> - - tokenf lba lbb >>= (fun lba lbb -> - tokenf rba rbb >>= (fun rba rbb -> - let idsb = resplit_initialiser idsb [comma_opt] in - let idsb = - List.concat - (List.map - (function (elem,comma) -> [Left elem; Right [comma]]) - idsb) in - enum_fields (A.unwrap idsa) idsb >>= (fun unidsa idsb -> - let idsa = A.rewrap idsa unidsa in - let idsb,iicomma = - match List.rev idsb with - (Right comma)::rest -> - (Ast_c.unsplit_comma (List.rev rest),comma) - | (Left _)::_ -> (Ast_c.unsplit_comma idsb,[]) (* possible *) - | [] -> ([],[]) in - return ( - (A.EnumDef(ty, lba, idsa, rba)) +> A.rewrap ta, - (B.Enum (sbopt, idsb),ii_sub_sb@[lbb;rbb]@iicomma) - )) - ))) - - | _, (B.Enum _, _) -> fail (* todo cocci ?*) + + | A.EnumName(ena, sta, idta), + (B.EnumName(stb, idtb), ii) -> + Printf.printf "Worked!\n"; + let (enb, ii) = extract_one ii in + tokenf ena enb >>= (fun ena enb -> + option (fun x (y, ib, ii) -> + if equal_structUnion (term x) y + then + tokenf x ib >>= (fun x ib1 -> return (x, (y, ib1, ii))) + else fail) + sta + (token_option stb ii) >>= (fun sta stb -> + let (stb, ib1, ii) = option_ret_unwrap stb ii in + option + (fun x (y, ib, ii) -> + ident DontKnow x (y, ib) >>= (fun idta (idtb, ib) -> + return (idta, (idtb, ib, ii)))) + idta + (token_option idtb ii) >>= (fun idta idtb -> + let (idtb, ib2, ii) = option_ret_unwrap idtb ii in + return + ((A.EnumName(ena, sta, idta)) +> A.rewrap ta, + (B.EnumName(stb, idtb), enb::ib1@ib2))))) + + | A.EnumDef(tya, basea, lba, idsa, rba), + (B.EnumDef (tyb, baseb, idsb), ii) -> + fullType tya tyb >>= (fun tya tyb -> + Printf.printf "Worked before!\n"; + option + (fun (td, basea) (baseb, ib1, ii) -> + tokenf td ib1 >>= (fun td ib1 -> + fullType basea baseb >>= (fun basea baseb -> + return ((td, basea), (baseb, ib1, ii))))) + basea + (token_option baseb ii) >>= (fun basea baseb -> + let (baseb, ib1, ii) = + option_ret_unwrap baseb ii in + Printf.printf "Worked comma!\n"; + Printf.printf "Number of ii elems - %d: %s \n" (List.length ii) (String.concat " " (List.map Dumper.dump ii)); + match ii with + [ib2;ib3;comma_opt] -> + tokenf lba ib2 >>= (fun lba lbb -> + tokenf rba ib3 >>= (fun rba rbb -> + let idsb = resplit_initialiser idsb [comma_opt] in + let idsb = + List.concat + (List.map + (function (elem,comma) -> [Left elem; Right [comma]]) + idsb) in + enum_fields (A.unwrap idsa) idsb >>= (fun unidsa idsb -> + let idsa = A.rewrap idsa unidsa in + let idsb,iicomma = + match List.rev idsb with + (Right comma)::rest -> + (Ast_c.unsplit_comma (List.rev rest),comma) + | (Left _)::_ -> (Ast_c.unsplit_comma idsb,[]) (* possible *) + | [] -> ([],[]) in + return + ( + Printf.printf "Worked!"; + (A.EnumDef(tya, basea, lba, idsa, rba)) +> A.rewrap ta, + (B.EnumDef(tyb, baseb, idsb), ib1@[lbb;rbb]@iicomma))))) + | _ -> failwith "impossible")) + + | _, (B.EnumDef _, _) -> fail (* todo cocci ?*) | A.AutoType autoa, (B.AutoType, ii) -> let autob = tuple_of_list1 ii in @@ -4646,8 +4639,18 @@ and compatible_typeC a (b,local) = if equal_structUnion_type_cocci sua sub then structure_type_name name sb ii else fail - | A.EnumName (_, name), - (qub, (B.EnumName (sb),ii)) -> structure_type_name name sb ii + | A.EnumName (_, sta, name), + (qub, (B.EnumName (stb, Some sb),ii)) -> + let tmp = + (match sta, stb with + None, None -> true + | Some x, Some y -> + equal_structUnion_type_cocci x y + | _ -> false) in + if tmp then + structure_type_name name sb ii + else + fail | A.TypeName sa, (qub, (B.TypeName (namesb, _typb),noii)) -> let sb = Ast_c.str_of_name namesb in if A.unwrap_mcode sa = sb @@ -4681,7 +4684,7 @@ and compatible_typeC a (b,local) = (( B.AutoType| B.TypeOfType _|B.TypeOfExpr _| - B.EnumName _|B.StructUnion (_, _, _, _)|B.Enum (_, _)| + B.EnumName (_, _ )|B.StructUnion (_, _, _, _)|B.EnumDef (_, _, _)| B.StructUnionName (_, _)| B.FunctionType _| B.Array (_, _)|B.Decimal (_, _)|B.Pointer _|B.TypeName _| diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 03c58275..bdd5ae93 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -59,9 +59,9 @@ module Ast_c : | Array of constExpression option * fullType | Decimal of constExpression * constExpression option | FunctionType of functionType - | Enum of string option * enumType + | EnumDef of fullType * fullType option * enumType | StructUnion of structUnion * string option * base_class wrap2 list * structType - | EnumName of string + | EnumName of structUnion option * string option | StructUnionName of structUnion * string | TypeName of name * fullType option | FieldType of fullType * name * constExpression option @@ -2762,8 +2762,8 @@ module Ast_cocci : | Array of fullType * string mcode * expression option * string mcode | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode - | EnumName of string mcode * ident option - | EnumDef of fullType * string mcode * enum_decl dots * string mcode + | EnumName of string mcode * structUnion mcode option * ident option + | EnumDef of fullType * enum_base option * string mcode * enum_decl dots * string mcode | StructUnionName of structUnion mcode * ident option | StructUnionDef of fullType * string mcode * annotated_field dots * string mcode @@ -2796,7 +2796,8 @@ module Ast_cocci : | PtrDiffType | BoolType | Unknown - and structUnion = Ast_cocci.structUnion = Struct | Union + and structUnion = Ast_cocci.structUnion = Struct | Union | Class + and enum_base = string mcode (* : *) * fullType and sign = Ast_cocci.sign = Signed | Unsigned and const_vol = Ast_cocci.const_vol = Const | Volatile and base_declaration = @@ -3220,7 +3221,7 @@ module Ast_cocci : expression -> string mcode option -> expression option -> string mcode -> 'a) option; - enumName : (string mcode -> ident option -> 'a) option; + enumName : (string mcode -> structUnion mcode option -> ident option -> 'a) option; structUnionName : (structUnion mcode -> ident option -> 'a) option; typeName : (string mcode -> 'a) option; metaType : @@ -3433,8 +3434,8 @@ module Ast0_cocci : | Array of typeC * string mcode * expression option * string mcode | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode - | EnumName of string mcode * ident option - | EnumDef of typeC * string mcode * enum_decl dots * string mcode + | EnumName of string mcode * Ast_cocci.structUnion mcode option * ident option + | EnumDef of typeC * enum_base option * string mcode * enum_decl dots * string mcode | StructUnionName of Ast_cocci.structUnion mcode * ident option | StructUnionDef of typeC * string mcode * field dots * string mcode | TypeOfExpr of string mcode * string mcode * expression * string mcode @@ -3449,6 +3450,7 @@ module Ast0_cocci : string mcode | OptType of typeC and typeC = base_typeC wrap + and enum_base = string mcode (* : *) * typeC and base_declaration = Ast0_cocci.base_declaration = MetaDecl of Ast_cocci.meta_name mcode * constraints * pure diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml index 2892363b..9627b656 100644 --- a/parsing_c/ast_c.ml +++ b/parsing_c/ast_c.ml @@ -189,10 +189,10 @@ and fullType = typeQualifier * typeC | Decimal of constExpression * constExpression option | FunctionType of functionType - | Enum of string option * enumType + | EnumDef of fullType * fullType (*enum_base*) option * enumType | StructUnion of structUnion * string option * base_class wrap2 list (* C++ *) * structType (* new scope *) - | EnumName of string + | EnumName of structUnion option * string option | StructUnionName of structUnion * string | TypeName of name * fullType option (* semantic: filled later *) @@ -218,7 +218,6 @@ and fullType = typeQualifier * typeC | AutoType (* c++ >= 11 *) (* cppext: IfdefType TODO *) - (* -------------------------------------- *) and baseType = Void | IntType of intType diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli index 44d62838..c39998ce 100644 --- a/parsing_c/ast_c.mli +++ b/parsing_c/ast_c.mli @@ -31,10 +31,10 @@ and typeCbis = | Array of constExpression option * fullType | Decimal of constExpression * constExpression option | FunctionType of functionType - | Enum of string option * enumType + | EnumDef of fullType * fullType option * enumType | StructUnion of structUnion * string option * base_class wrap2 list (* C++ *) * structType - | EnumName of string + | EnumName of structUnion option * string option | StructUnionName of structUnion * string | TypeName of name * fullType option | FieldType of fullType * name * constExpression option diff --git a/parsing_c/includes_cache.ml b/parsing_c/includes_cache.ml index b6143876..90e52937 100644 --- a/parsing_c/includes_cache.ml +++ b/parsing_c/includes_cache.ml @@ -118,7 +118,7 @@ type cache_exp = (* Not very elegant. Basically a copy-paste of namedef in type_annoter_c. *) type cache_return = | RetVarOrFunc of string * Ast_c.exp_type - | RetEnumConstant of string * string option + | RetEnumConstant of string * Ast_c.fullType | RetTypeDef of string * Ast_c.fullType | RetStructUnionNameDef of string * (Ast_c.structUnion * Ast_c.structType) Ast_c.wrap @@ -183,7 +183,7 @@ let cache_name_visitor file = Ast_c.StructUnion (_, Some n, _, def) -> (* Cache field names *) cache_struct_fields n def - | Ast_c.Enum(_, def) -> + | Ast_c.EnumDef(_, base, def) -> (* Cache enumeration constants *) cache_enum_constants def | _ -> k p)) in @@ -195,7 +195,7 @@ let cache_name_visitor file = let get_type_visitor file l = let add_to_ret ret = l := [ret] @ !l in - let get_enum_constants sopt def = + let get_enum_constants sopt base def = def +> List.iter (fun ec -> @@ -233,8 +233,8 @@ let get_type_visitor file l = add_to_ret (RetStructUnionNameDef (s, ((su, def'),ii'))) | None -> k p) - | Ast_c.Enum(sopt, def) -> - get_enum_constants sopt def + | Ast_c.EnumDef(sopt, base, def) -> + get_enum_constants sopt base def | _ -> k p)) in List.iter get_name defs | _ -> k p diff --git a/parsing_c/includes_cache.mli b/parsing_c/includes_cache.mli index 2384cb2f..79b81b8e 100644 --- a/parsing_c/includes_cache.mli +++ b/parsing_c/includes_cache.mli @@ -24,7 +24,7 @@ type cache_exp = type cache_return = | RetVarOrFunc of string * Ast_c.exp_type - | RetEnumConstant of string * string option + | RetEnumConstant of string * Ast_c.fullType | RetTypeDef of string * Ast_c.fullType | RetStructUnionNameDef of string * (Ast_c.structUnion * Ast_c.structType) Ast_c.wrap diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index cd60c6dc..d5687be8 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -814,8 +814,7 @@ cond_expr: { $1 } | arith_expr TWhy gcc_opt_expr TDotDot cond_expr { mk_e (CondExpr ($1,$3,$5)) [$2;$4] } - | Tnew cpp_type /*ask about using a Tnull*/ - /* does cpp_type support class names and nested-specifiers */ + | Tnew cpp_type cpp_initialiser_opt { let (ty,par2) = $2 in @@ -2298,12 +2297,85 @@ cpp_struct_decl_list_gcc: /*(* enum *)*/ /*(*************************************************************************)*/ enum_spec: - | Tenum tobrace_enum enumerator_list gcc_comma_opt_struct tcbrace_enum - { Enum (None, $3), [$1;$2;$5] @ $4 } - | Tenum ident tobrace_enum enumerator_list gcc_comma_opt_struct tcbrace_enum - { Enum (Some (fst $2), $4), [$1; snd $2; $3;$6] @ $5 } + | enum_ident enum_base tobrace_enum enumerator_list gcc_comma_opt_struct tcbrace_enum + { + let (ty, td) = Common.default (None, []) (function x -> x) $2 in + let (enumname, ii) = $1 in + (EnumDef ( enumname, ty, $4), ii@td@[$3;$6] @ $5) + } + + + +enum_ident: + | Tenum enum_key ident + { + let rt = ((Some (fst $2), $3), [$1; snd $2; snd $3]) in + let ((key, ident), ii) = rt in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); (Right3 (EnumName (key, Some (fst ident))), ii)),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + (snd ret), ii + } | Tenum ident - { EnumName (fst $2), [$1; snd $2] } + { + let rt = ((None, $2), [$1; snd $2]) in + let ((key, ident), ii) = rt in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); (Right3 (EnumName (key, Some (fst ident))), snd rt)),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + (snd ret), ii + } +| Tenum enum_key + { + let rt = ((Some (fst $2), None), [$1; snd $2]) in + let ((key, ident), ii) = rt in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); (Right3 (EnumName (key, ident)), ii)),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + (snd ret), ii + } +| Tenum + { + let rt = ((None, None), [$1]) in + let ((key, ident), ii) = rt in + let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); (Right3 (EnumName (key, ident)), ii)),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + (snd ret), ii + } + + +enum_base: + | TDotDot simple_type + { let tmp = + (dt "spec_qualif" (); + ([],(addTypeD( + (dt "type" (); $2),nullDecl)))) in + let (attrs, ds) = tmp in + let (returnType, _) = fixDeclSpecForDecl ds in + let ret = (attrs, returnType) in + Some (Some (snd ret), [$1]) } + | /* empty */ { None } + +enum_key: + Tstruct { et "su" (); (Struct, $1) } + | Tclass { et "su" (); (Class, $1) } enumerator: | idente { $1, None } diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index 02a694ff..6e8b057e 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -611,39 +611,40 @@ and pp_string_format (e,ii) = | x -> raise (Impossible 102) ) - | (Enum (sopt, enumt), iis) -> + | (EnumDef (sopt, base, enumt), iis) -> print_sto_qu (sto, qu); - - (match sopt, iis with - | (Some s, ([i1;i2;i3;i4]|[i1;i2;i3;i4;_])) -> - pr_elem i1; pr_elem i2; pr_elem i3; - | (None, ([i1;i2;i3]|[i1;i2;i3;_])) -> - pr_elem i1; pr_elem i2 - | x -> raise (Impossible 103) - ); - - enumt +> List.iter (fun ((name, eopt), iicomma) -> - assert (List.length iicomma <= 1); - iicomma +> List.iter (function x -> pr_elem x; pr_space()); - pp_name name; - eopt +> Common.do_option (fun (ieq, e) -> - pr_elem ieq; - pp_expression e; - )); - - (match sopt, iis with - | (Some s, [i1;i2;i3;i4]) -> pr_elem i4 - | (Some s, [i1;i2;i3;i4;i5]) -> + let rest = + (match iis with + | ( (i1::i2::i3::ii)) -> + pr_elem i1; pr_elem i2; pr_elem i3; ii + | ((i1::i2::ii)) -> + pr_elem i1; pr_elem i2; ii + | x -> raise (Impossible 103)) in + + (match (base, rest) with + (Some base, i4::ii) -> pr_elem i4; pp_base_type base sto; + | (None, ii) -> () + | (Some _, []) -> raise (Impossible 103)); + + enumt +> List.iter (fun ((name, eopt), iicomma) -> + assert (List.length iicomma <= 1); + iicomma +> List.iter (function x -> pr_elem x; pr_space()); + pp_name name; + eopt +> Common.do_option (fun (ieq, e) -> + pr_elem ieq; + pp_expression e; + )); + + (match (base, iis) with + | (Some base, [i1;i2;i3;i4;i5]) -> pr_elem i5 + | (None, [i1;i2;i3;i4]) -> pr_elem i4 + | (Some base, [i1;i2;i3;i4;i5;i6]) -> + pr_elem i6; pr_elem i5 (* trailing comma *) + | (None, [i1;i2;i3;i4;i5]) -> pr_elem i5; pr_elem i4 (* trailing comma *) - | (None, [i1;i2;i3]) -> pr_elem i3 - | (None, [i1;i2;i3;i4]) -> - pr_elem i4; pr_elem i3 (* trailing comma *) - - | x -> raise (Impossible 104) - ); - - + ) + | (BaseType _, iis) -> print_sto_qu_ty (sto, qu, iis); @@ -651,7 +652,7 @@ and pp_string_format (e,ii) = assert (List.length iis = 2); print_sto_qu_ty (sto, qu, iis); - | (EnumName s, iis) -> + | (EnumName (key, s), iis) -> assert (List.length iis = 2); print_sto_qu_ty (sto, qu, iis); @@ -829,10 +830,10 @@ and pp_string_format (e,ii) = (* the work is to do in base_type !! *) | (NoType, iis) -> () | (BaseType _, iis) -> print_ident ident - | (Enum (sopt, enumt), iis) -> print_ident ident + | (EnumDef (sopt, base, enumt), iis) -> print_ident ident | (StructUnion (_, sopt, base_classes, fields),iis) -> print_ident ident | (StructUnionName (s, structunion), iis) -> print_ident ident - | (EnumName s, iis) -> print_ident ident + | (EnumName (key, s), iis) -> print_ident ident | (Decimal _, iis) -> print_ident ident | (TypeName (_name,_typ), iis) -> print_ident ident | (FieldType (_typ,_,_), iis) -> print_ident ident @@ -946,10 +947,10 @@ and pp_string_format (e,ii) = | (BaseType _, iis) -> () - | (Enum (sopt, enumt), iis) -> () + | (EnumDef (sopt, base, enumt), iis) -> () | (StructUnion (_, sopt, _, fields),iis) -> () | (StructUnionName (s, structunion), iis) -> () - | (EnumName s, iis) -> () + | (EnumName (key, s), iis) -> () | (Decimal(l,p), iis) -> () | (TypeName (_name,_typ), iis) -> () | FieldType (_, _, _), _ -> () @@ -1004,10 +1005,10 @@ and pp_string_format (e,ii) = pr_elem i2 | (BaseType _, iis) -> () - | (Enum (sopt, enumt), iis) -> () + | (EnumDef (sopt, base, enumt), iis) -> () | (StructUnion (_, sopt, _, fields),iis)-> () | (StructUnionName (s, structunion), iis) -> () - | (EnumName s, iis) -> () + | (EnumName (key, s), iis) -> () | (Decimal(l,p), iis) -> () | (TypeName (name,_typ), iis) -> () | (FieldType (_, _, _), _) -> () diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml index 6d1332f9..cae660cc 100644 --- a/parsing_c/type_annoter_c.ml +++ b/parsing_c/type_annoter_c.ml @@ -155,7 +155,7 @@ let pr2, pr2_once = Common.mk_pr2_wrappers Flag_parsing_c.verbose_type *) type namedef = | VarOrFunc of string * Ast_c.exp_type - | EnumConstant of string * string option + | EnumConstant of string * fullType (* also used for macro type aliases *) | TypeDef of string * fullType @@ -179,7 +179,7 @@ type typedefs = { defs : (fullType * typedefs * int) StringMap.t } type nameenv = { level : int; var_or_func : Ast_c.exp_type StringMap.t; - enum_constant : string option StringMap.t; + enum_constant : Ast_c.fullType StringMap.t; typedef : typedefs; struct_union_name_def : ((structUnion * structType) wrap) StringMap.t; macro : (define_kind * define_val) StringMap.t @@ -410,9 +410,9 @@ let rec type_unfold_one_step ty env = | StructUnion (sopt, su, base_classes, fields) -> ty | FunctionType t -> ty - | Enum (s, enumt) -> ty + | EnumDef (ename, base, enumt) -> ty - | EnumName s -> ty (* todo: look in env when will have EnumDef *) + | EnumName (key, id) -> ty (* todo: look in env when will have EnumDef *) | ParenType t -> ty @@ -488,10 +488,10 @@ let rec typedef_fix ty env = Type_c.structdef_to_struct_name ty | FunctionType ft -> (FunctionType ft) (* todo ? *) +> Ast_c.rewrap_typeC ty - | Enum (s, enumt) -> - (Enum (s, enumt)) (* todo? *) +> Ast_c.rewrap_typeC ty - | EnumName s -> - (EnumName s) (* todo? *) +> Ast_c.rewrap_typeC ty + | EnumDef (ename, base, enumt) -> + (EnumDef (ename, base, enumt)) (* todo? *) +> Ast_c.rewrap_typeC ty + | EnumName (key, id) -> + (EnumName (key, id)) (* todo? *) +> Ast_c.rewrap_typeC ty | Decimal(l,p) -> (Decimal(l,p)) (* todo? *) +> Ast_c.rewrap_typeC ty @@ -1364,7 +1364,7 @@ let rec visit_toplevel ~just_add_in_env ~depth elem = if need_annotate_body then k typ (* todo: restrict ? new scope so use do_in_scope ? *) - | Enum (sopt, enums) -> + | EnumDef (sopt, base, enums) -> enums +> List.iter (fun ((name, eopt), iicomma) -> diff --git a/parsing_c/type_c.ml b/parsing_c/type_c.ml index dca74e9f..f043387c 100644 --- a/parsing_c/type_c.ml +++ b/parsing_c/type_c.ml @@ -119,9 +119,9 @@ let rec is_completed_and_simplified ty = | FunctionType ft -> (* todo? return type is completed ? params completed ? *) true - | Enum (s, enumt) -> + | EnumDef (ename, s, enumt) -> true - | EnumName s -> + | EnumName (key, id) -> true (* we prefer StructUnionName to StructUnion when it comes to typed metavar *) diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 849d6d89..9ec2c631 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -776,14 +776,17 @@ and typeC ty = print_option (mcode print_string) comma; print_option expression precision_opt; mcode print_string rp - | Ast.EnumName(kind,name) -> + | Ast.EnumName(kind,key,name) -> mcode print_string kind; - print_option_prespace ident name - | Ast.EnumDef(ty,lb,ids,rb) -> - fullType ty; ft_space ty; - mcode print_string lb; - dots force_newline enum_decl ids; - mcode print_string rb + print_option (mcode structUnion) key; + print_option (function x -> ident x) name + | Ast.EnumDef(ty,base,lb,ids,rb) -> + fullType ty; + print_option enum_base base; + mcode print_string lb; + (dots force_newline enum_decl) ids; + mcode print_string rb + | Ast.StructUnionName(kind,name) -> mcode structUnion kind; print_option_prespace ident name | Ast.StructUnionDef(ty,lb,decls,rb) -> @@ -809,6 +812,11 @@ and typeC ty = and baseType ty = print_string (Ast.string_of_baseType ty ^ " ") +and enum_base (td, ty) = + mcode print_string td; + print_string " "; + fullType ty + and structUnion = function Ast.Struct -> print_string "struct" | Ast.Union -> print_string "union" diff --git a/parsing_c/visitor_c.ml b/parsing_c/visitor_c.ml index b5a00331..100598d8 100644 --- a/parsing_c/visitor_c.ml +++ b/parsing_c/visitor_c.ml @@ -502,15 +502,17 @@ and vk_type = fun bigf t -> vk_param_list bigf ts ) - | Enum (sopt, enumt) -> - vk_enum_fields bigf enumt + | EnumDef (sen, baset, enumt) -> + (vk_type bigf) sen; + do_option (vk_type bigf) baset; + vk_enum_fields bigf enumt | StructUnion (sopt, _su, base_classes, fields) -> vk_base_class_list bigf base_classes; vk_struct_fields bigf fields | StructUnionName (s, structunion) -> () - | EnumName s -> () + | EnumName (s,structUnion) -> () (* don't go in _typ *) | TypeName (name,_typ) -> @@ -1473,8 +1475,10 @@ and vk_type_s = fun bigf t -> (b, iif iihas3dots)) )) - | Enum (sopt, enumt) -> - Enum (sopt, vk_enum_fields_s bigf enumt) + | EnumDef (sen, baset, enumt) -> + EnumDef (sen, + fmap (function baset -> baset) baset, + vk_enum_fields_s bigf enumt) | StructUnion (sopt, su, base_classes, fields) -> StructUnion (sopt, su, vk_base_class_list_s bigf base_classes, @@ -1482,7 +1486,7 @@ and vk_type_s = fun bigf t -> | StructUnionName (s, structunion) -> StructUnionName (s, structunion) - | EnumName s -> EnumName s + | EnumName (s, key) -> EnumName (s, key) | TypeName (name, typ) -> TypeName (vk_name_s bigf name, typ) | FieldType (t, a, b) -> FieldType (typef t, a, b) diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index d99f98c7..e3eda3ad 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -486,7 +486,7 @@ and top_typeC tgt opt_allowed typ = (function (td, ty) -> (mcode td, typeC arity ty)) base in let lb = mcode lb in - let ids = get_option (dots (enum_decl tgt)) decls in + let ids = (dots (enum_decl tgt)) decls in let rb = mcode rb in make_typeC typ tgt arity (Ast0.EnumDef(ty,base,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 6dbb9442..b8bf34bd 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -216,7 +216,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * Ast.structUnion mcode option (* struct/class/None *) * ident option (* name *) | EnumDef of typeC (* EnumName *) * enum_base option (* base type *) * - string mcode (* { *) * enum_decl dots option * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index 36569495..0b4c3315 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -207,7 +207,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * Ast_cocci.structUnion mcode option (* struct/class/None *) * ident option (* name *) | EnumDef of typeC (* EnumName *) * - enum_base option * string mcode (* { *) * enum_decl dots option * string mcode (* } *) + enum_base option * string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index 876ecae3..8d910dc7 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -617,7 +617,8 @@ and base_typeC allminus t = | Ast0.EnumName(kind,key,name) -> Ast.EnumName(mcode kind,get_option mcode key,get_option ident name) | Ast0.EnumDef(ty,base,lb,ids,rb) -> - Ast.EnumDef(typeC allminus ty,get_option (enum_base allminus) base,mcode lb,get_option enum_decl_dots ids,mcode rb) + Ast.EnumDef(typeC allminus ty,get_option (enum_base allminus) base, + mcode lb, enum_decl_dots ids, mcode rb) | Ast0.StructUnionName(kind,name) -> Ast.StructUnionName(mcode kind,get_option ident name) | Ast0.StructUnionDef(ty,lb,decls,rb) -> diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index 170383d0..6c511159 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -357,7 +357,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * structUnion mcode option(*struct/class/None*) * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * - string mcode (* { *) * enum_decl dots option * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) @@ -1154,8 +1154,12 @@ let rec string_of_typeC ty = let s0 = string_of_expression e0 and s1 = Common.default "?" string_of_expression e1 in Printf.sprintf "decimal(%s,%s) " s0 s1 - | EnumName (_, key, name) -> "enum " ^ (Common.default "" (function x -> string_of_structUnion (unwrap_mcode x)) key) ^ - (Common.default "" (function x -> " ") key) ^ (Common.default "" string_of_ident name) + | EnumName (_, key, name) -> + "enum " ^ + (Common.default "" + (function x -> string_of_structUnion (unwrap_mcode x)) key) ^ + (Common.default "" + (function x -> " ") key) ^ (Common.default "" string_of_ident name) | StructUnionName (kind, name) -> Printf.sprintf "%s %s" (string_of_structUnion (unwrap_mcode kind)) diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 22bf06f8..048a4bea 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -339,7 +339,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * structUnion mcode option * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * enum_base option * - string mcode (* { *) * enum_decl dots option * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 47de948c..62972b79 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -282,7 +282,7 @@ and typeC old_metas table minus t = | Ast0.EnumDef(ty,base,lb,ids,rb) -> typeC old_metas table minus ty; Common.do_option (function (td,ty) -> typeC old_metas table minus ty) base; - Common.do_option (dots (enum_decl GLOBAL old_metas table minus)) ids + (dots (enum_decl GLOBAL old_metas table minus)) ids | Ast0.StructUnionName(su,Some id) -> ident GLOBAL old_metas table minus id | Ast0.StructUnionDef(ty,lb,decls,rb) -> typeC old_metas table minus ty; diff --git a/parsing_cocci/commas_on_lists.ml b/parsing_cocci/commas_on_lists.ml index aa163e0d..09f87961 100644 --- a/parsing_cocci/commas_on_lists.ml +++ b/parsing_cocci/commas_on_lists.ml @@ -50,9 +50,9 @@ trailing comma is allowed but not required *) let base_typeC r k t = let t = k t in match Ast0.unwrap t with - Ast0.EnumDef(ty,base,lb,Some ids,rb) -> + Ast0.EnumDef(ty,base,lb,ids,rb) -> let ids = add_enum_decl_comma ids in - Ast0.rewrap t (Ast0.EnumDef(ty,base,lb,Some ids,rb)) + Ast0.rewrap t (Ast0.EnumDef(ty,base,lb,ids,rb)) | _ -> t let initialiser r k i = diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index da6e78d5..2ee72c96 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -622,7 +622,7 @@ and typeC t = let ty = typeC ty in let base = get_option (function (td, ty) -> (normal_mcode td, typeC ty)) base in let lb = normal_mcode lb in - let ids = get_option + let ids = (dots is_enum_decl_dots (Some (Common.default (promote_mcode lb) (function (td,ty) -> promote_mcode td) base)) enum_decl) ids in diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 5e559852..0b1a6a1b 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -100,7 +100,7 @@ and disjtypeC bty = let ty1 = disjty ty1 in List.map (function ty1 -> (td, ty1)) ty1) base) - (disjoption (disjdots disjenumdecl) ids) + ((disjdots disjenumdecl) ids) (fun ty base ids -> Ast.rewrap bty (Ast.EnumDef(ty,base,lb,ids,rb))) | Ast.StructUnionDef(ty,lb,decls,rb) -> diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 9c795d00..e4f6be47 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -915,11 +915,12 @@ let match_maker checks_needed context_required whencode_allowed = conjunct_many_bindings [check_mcode lb1 lb; check_mcode rb1 rb; match_option - (fun (td1, ty1) (td2, ty2) -> conjunct_bindings - (check_mcode td1 td2) (match_typeC ty1 ty2) ) + (fun (td1, ty1) (td2, ty2) -> + conjunct_bindings + (check_mcode td1 td2) (match_typeC ty1 ty2)) base1 base2; match_typeC tya tyb; - match_option (match_dots match_enum_decl no_list do_nolist_match) idsa idsb] + (match_dots match_enum_decl no_list do_nolist_match) idsa idsb] | (Ast0.StructUnionName(kinda,Some namea), Ast0.StructUnionName(kindb,Some nameb)) -> if mcode_equal kinda kindb diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index 8d0489ac..76a7a0de 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -1192,7 +1192,7 @@ let detect_attr l = | ((PC.Tstruct _,_) as t1)::x::rest -> t1::x::loop rest | ((PC.Tclass _,_) as t1)::x::rest -> - t1::x::loop rest + t1::x::loop rest | ((PC.Tunion _,_) as t1)::x::rest -> t1::x::loop rest | ((PC.TIdent(nm,clt),info) as t1)::id::rest when is_id id -> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 5dfa3604..bd336562 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1008,7 +1008,7 @@ signable_types: Ast0_cocci.Impure (*will be ignored*))) } non_signable_types_no_ident_with_braces: - | s=Tenum k=option(enum_key) i=option(type_ident) base=ioption(enum_base) l=TOBrace ids=option(enum_decl_list) r=TCBrace + | s=Tenum k=option(enum_key) i=option(type_ident) base=ioption(enum_base) l=TOBrace ids=enum_decl_list r=TCBrace { (if i = None && !Data.in_iso then failwith "enums must be named in the iso file"); Ast0_cocci.wrap(Ast0_cocci.EnumDef(Ast0_cocci.wrap(Ast0_cocci.EnumName(Parse_aux.clt2mcode "enum" s, k, i)), @@ -1280,8 +1280,10 @@ enum_val: (Ast0_cocci.MetaExpr(Parse_aux.clt2mcode nm clt,constraints,ty,Ast_cocci.ID,pure,None)) } enum_decl_list: - nonempty_list_start(enum_decl_one,edots_when(TEllipsis,enum_decl_one)) - { Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) } + empty_list_start_if_cpp(enum_decl_one,edots_when(TEllipsis,enum_decl_one)) + { + Ast0_cocci.wrap($1 Parse_aux.mkenumdots (fun c -> Ast0_cocci.EnumComma c)) + } enum_key: Tstruct { Parse_aux.clt2mcode Ast_cocci.Struct $1 } @@ -2936,6 +2938,17 @@ empty_list_start(elem,dotter): /* empty */ { fun build_dots build_comma -> [] } | list=nonempty_list_start(elem,dotter) { list } +empty_list_start_if_cpp(elem,dotter): + /* empty */ + { + if !Flag.c_plus_plus = Flag.Off + then + failwith "C does not allow empty enumerator lists!" + else + fun build_dots build_comma -> [] + } +| list=nonempty_list_start(elem,dotter) { list } + nonempty_list_start(elem,dotter): /* dots allowed */ element=elem { fun build_dots build_comma -> [element] } | element=elem comma=TComma diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index fe3d99d8..a38a2acd 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -515,13 +515,14 @@ and typeC ty = mcode print_string rp | Ast.EnumName(kind,key,name) -> mcode print_string kind; + print_string " "; print_option (mcode structUnion) key; print_option (function x -> ident x; print_string " ") name | Ast.EnumDef(ty,base,lb,ids,rb) -> fullType ty; print_option enum_base base; mcode print_string lb; - print_option (dots force_newline enum_decl) ids; + dots force_newline enum_decl ids; mcode print_string rb | Ast.StructUnionName(kind,name) -> mcode structUnion kind; @@ -687,7 +688,8 @@ and enum_decl d = and enum_base (td, ty) = mcode print_string td; - fullType ty; + print_string " "; + fullType ty (* --------------------------------------------------------------------- *) (* Initialiser *) diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 65aebfec..4b3232e1 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -362,11 +362,11 @@ and unify_typeC t1 t2 = | (Ast.EnumName(s1,key1,Some ts1),Ast.EnumName(s2,key2,Some ts2)) -> if (unify_mcode s1 s2) && (unify_option unify_mcode key1 key2) then unify_ident ts1 ts2 else false | (Ast.EnumName(s1,key1,None),Ast.EnumName(s2,key2,None)) -> - true + unify_option unify_mcode key1 key2 | (Ast.EnumDef(ty1,base1,lb1,ids1,rb1),Ast.EnumDef(ty2,base2,lb2,ids2,rb2)) -> unify_fullType ty1 ty2 && unify_option (fun (_, ty1) (_,ty2) -> unify_fullType ty1 ty2) base1 base2 && - unify_option (unify_dots unify_enum_decl enumdots) ids1 ids2 + (unify_dots unify_enum_decl enumdots) ids1 ids2 | (Ast.StructUnionName(s1,Some ts1),Ast.StructUnionName(s2,Some ts2)) -> if unify_mcode s1 s2 then unify_ident ts1 ts2 else false | (Ast.StructUnionName(s1,None),Ast.StructUnionName(s2,None)) -> diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index c89b7c7c..c42835a1 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -363,15 +363,19 @@ and typeC t = mcode print_string rp | Ast0.EnumName(kind,key,name) -> mcode print_string kind; + print_string " "; print_option (mcode U.structUnion) key; print_option (function x -> ident x; print_string " ") name | Ast0.EnumDef(ty,base,lb,ids,rb) -> typeC ty; print_option - (function (td, ty) -> mcode print_string td; typeC ty;) + (function (td, ty) -> + mcode print_string td; + print_string " "; + typeC ty) base; mcode print_string lb; - print_option (dots force_newline enum_decl) ids; + dots force_newline enum_decl ids; mcode print_string rb | Ast0.StructUnionName(kind,name) -> mcode U.structUnion kind; diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index a3af25d9..fe95323c 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -411,7 +411,7 @@ let combiner bind option_default let lty = fullType ty in let lbase = get_option enum_base base in let llb = string_mcode lb in - let lids = get_option enum_decl_dots ids in + let lids = enum_decl_dots ids in let lrb = string_mcode rb in multibind [lty; lbase; llb; lids; lrb] | Ast.StructUnionName(kind,name) -> @@ -1439,7 +1439,7 @@ let rebuilder let lty = fullType ty in let lbase = get_option enum_base base in let llb = string_mcode lb in - let lids = get_option enum_decl_dots ids in + let lids = enum_decl_dots ids in let lrb = string_mcode rb in Ast.EnumDef (lty, lbase, llb, lids, lrb) | Ast.StructUnionName(kind,name) -> diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index bd5eaa90..57685eef 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -379,7 +379,7 @@ let visitor mode bind option_default let (ty_n,ty) = typeC ty in let (base_n, base) = get_option enum_base base in let (lb_n,lb) = string_mcode lb in - let (ids_n,ids) = get_option enum_decl_dots ids in + let (ids_n,ids) = enum_decl_dots ids in let (rb_n,rb) = string_mcode rb in (multibind [ty_n;lb_n;ids_n;rb_n], Ast0.EnumDef(ty,base,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> diff --git a/tools/spgen/source/meta_variable.ml b/tools/spgen/source/meta_variable.ml index a8cda878..37559074 100644 --- a/tools/spgen/source/meta_variable.ml +++ b/tools/spgen/source/meta_variable.ml @@ -269,7 +269,7 @@ let types ~rn = function get_meta_id_opt acc (Common.default None Ast_cocci.ident_of_expression_opt nm2) in acc - | Ast.EnumName (_, Some n) + | Ast.EnumName (_, _, Some n) | Ast.StructUnionName(_, Some n) -> get_meta_id acc n | Ast.SignedT (_, Some t) -> get_meta_type acc t | Ast.Pointer (t, _) diff --git a/tools/spgen/source/position_generator.ml b/tools/spgen/source/position_generator.ml index 93e0e24b..b9d98246 100644 --- a/tools/spgen/source/position_generator.ml +++ b/tools/spgen/source/position_generator.ml @@ -204,14 +204,14 @@ let rec type_pos t snp | Ast0.Decimal(dec,lp,expr,comma,expr2,rp) -> let constructor ~mc = Ast0.Decimal(dec,lp,expr,comma,expr2,mc) in mcode_wrap ~mc:rp ~constructor snp - | Ast0.EnumName(enum,Some nm) -> - let constructor ~id = Ast0.EnumName(enum,Some id) in + | Ast0.EnumName(enum, key, Some nm) -> + let constructor ~id = Ast0.EnumName(enum, key, Some id) in id_wrap ~id:nm ~constructor snp - | Ast0.EnumName(enum,None) -> - let constructor ~mc = Ast0.EnumName(mc,None) in + | Ast0.EnumName(enum, key, None) -> + let constructor ~mc = Ast0.EnumName(mc, key, None) in mcode_wrap ~mc:enum ~constructor snp - | Ast0.EnumDef(t,lcb,exprdots,rcb) -> - let c ~item ~mc = Ast0.EnumDef(item,lcb,exprdots,mc) in + | Ast0.EnumDef(t,base,lcb,exprdots,rcb) -> + let c ~item ~mc = Ast0.EnumDef(item,base,lcb,exprdots,mc) in let alt() = mcode_wrap ~mc:rcb ~constructor:(c ~item:t) snp in item_wrap ~item:t ~item_posfn:type_pos ~constructor:(c ~mc:rcb) ~alt snp | Ast0.StructUnionName(sumc,Some nm) -> -- GitLab From 22579609924e8ded3ef4162ee50c70062a5dc063 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 12 Jul 2022 03:12:43 +0530 Subject: [PATCH 19/24] enum_key and ident work, and removed some wrong code from prettyprint --- engine/cocci_vs_c.ml | 8 +--- parsing_c/parser_c.mly | 76 +++++++++++++------------------------ parsing_c/pretty_print_c.ml | 16 ++------ 3 files changed, 32 insertions(+), 68 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 740ff1a9..98aa7073 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -4163,7 +4163,7 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | A.EnumName(ena, sta, idta), (B.EnumName(stb, idtb), ii) -> - Printf.printf "Worked!\n"; + Printf.printf "testing"; let (enb, ii) = extract_one ii in tokenf ena enb >>= (fun ena enb -> option (fun x (y, ib, ii) -> @@ -4179,7 +4179,7 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = ident DontKnow x (y, ib) >>= (fun idta (idtb, ib) -> return (idta, (idtb, ib, ii)))) idta - (token_option idtb ii) >>= (fun idta idtb -> + (token_option idtb ii) >>= (fun idta idtb -> let (idtb, ib2, ii) = option_ret_unwrap idtb ii in return ((A.EnumName(ena, sta, idta)) +> A.rewrap ta, @@ -4188,7 +4188,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | A.EnumDef(tya, basea, lba, idsa, rba), (B.EnumDef (tyb, baseb, idsb), ii) -> fullType tya tyb >>= (fun tya tyb -> - Printf.printf "Worked before!\n"; option (fun (td, basea) (baseb, ib1, ii) -> tokenf td ib1 >>= (fun td ib1 -> @@ -4198,8 +4197,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = (token_option baseb ii) >>= (fun basea baseb -> let (baseb, ib1, ii) = option_ret_unwrap baseb ii in - Printf.printf "Worked comma!\n"; - Printf.printf "Number of ii elems - %d: %s \n" (List.length ii) (String.concat " " (List.map Dumper.dump ii)); match ii with [ib2;ib3;comma_opt] -> tokenf lba ib2 >>= (fun lba lbb -> @@ -4220,7 +4217,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | [] -> ([],[]) in return ( - Printf.printf "Worked!"; (A.EnumDef(tya, basea, lba, idsa, rba)) +> A.rewrap ta, (B.EnumDef(tyb, baseb, idsb), ib1@[lbb;rbb]@iicomma))))) | _ -> failwith "impossible")) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index d5687be8..839eb2cf 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1414,7 +1414,8 @@ simple_type: | _ -> warning "attributes found in typeof(...), dropping" ret } type_spec2_without_braces: - simple_type { $1 } + simple_type { $1 } + | enum_ident_independant { Right3 (fst $1), snd $1 } type_spec2_with_braces: | struct_or_union_spec { Right3 (fst $1), snd $1 } | enum_spec { Right3 (fst $1), snd $1 } @@ -2301,66 +2302,42 @@ enum_spec: { let (ty, td) = Common.default (None, []) (function x -> x) $2 in let (enumname, ii) = $1 in - (EnumDef ( enumname, ty, $4), ii@td@[$3;$6] @ $5) + let tmp = + (dt "spec_qualif" (); + (addTypeD( + (dt "type" (); (Right3 enumname, ii)),nullDecl))) in + let (returnType, _) = fixDeclSpecForDecl tmp in + (EnumDef (returnType, ty, $4), td@[$3;$6] @ $5) } - - -enum_ident: +enum_ident_independant: | Tenum enum_key ident { let rt = ((Some (fst $2), $3), [$1; snd $2; snd $3]) in let ((key, ident), ii) = rt in - let tmp = - (dt "spec_qualif" (); - ([],(addTypeD( - (dt "type" (); (Right3 (EnumName (key, Some (fst ident))), ii)),nullDecl)))) in - let (attrs, ds) = tmp in - let (returnType, _) = fixDeclSpecForDecl ds in - let ret = (attrs, returnType) in - (snd ret), ii + (EnumName (key, Some (fst ident)), ii) } | Tenum ident { let rt = ((None, $2), [$1; snd $2]) in let ((key, ident), ii) = rt in - let tmp = - (dt "spec_qualif" (); - ([],(addTypeD( - (dt "type" (); (Right3 (EnumName (key, Some (fst ident))), snd rt)),nullDecl)))) in - let (attrs, ds) = tmp in - let (returnType, _) = fixDeclSpecForDecl ds in - let ret = (attrs, returnType) in - (snd ret), ii + (EnumName (key, Some (fst ident)), ii) } -| Tenum enum_key - { - let rt = ((Some (fst $2), None), [$1; snd $2]) in - let ((key, ident), ii) = rt in - let tmp = - (dt "spec_qualif" (); - ([],(addTypeD( - (dt "type" (); (Right3 (EnumName (key, ident)), ii)),nullDecl)))) in - let (attrs, ds) = tmp in - let (returnType, _) = fixDeclSpecForDecl ds in - let ret = (attrs, returnType) in - (snd ret), ii - } -| Tenum - { - let rt = ((None, None), [$1]) in - let ((key, ident), ii) = rt in - let tmp = - (dt "spec_qualif" (); - ([],(addTypeD( - (dt "type" (); (Right3 (EnumName (key, ident)), ii)),nullDecl)))) in - let (attrs, ds) = tmp in - let (returnType, _) = fixDeclSpecForDecl ds in - let ret = (attrs, returnType) in - (snd ret), ii - } - +enum_ident_dependant: + | Tenum enum_key + { + (EnumName (Some (fst $2), None), [$1; snd $2]) + } + | Tenum + { + (EnumName (None, None), [$1]) + } + +enum_ident: + enum_ident_independant { $1 } +| enum_ident_dependant { $1 } + enum_base: | TDotDot simple_type { let tmp = @@ -2374,7 +2351,7 @@ enum_base: | /* empty */ { None } enum_key: - Tstruct { et "su" (); (Struct, $1) } + Tcpp_struct { et "su" (); (Struct, $1) } | Tclass { et "su" (); (Class, $1) } enumerator: @@ -2917,6 +2894,7 @@ enumerator_list: | enumerator_list TComma cpp_directive_list enumerator { $1 @ [$4, [$2]] } | enumerator_list TComma enumerator { $1 @ [$3, [$2]] } + | /* empty */ { [] } init_declarator_list: diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index 6e8b057e..b75b9963 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -624,7 +624,7 @@ and pp_string_format (e,ii) = (match (base, rest) with (Some base, i4::ii) -> pr_elem i4; pp_base_type base sto; | (None, ii) -> () - | (Some _, []) -> raise (Impossible 103)); + | (Some _, []) -> raise (Impossible 1030)); enumt +> List.iter (fun ((name, eopt), iicomma) -> assert (List.length iicomma <= 1); @@ -633,18 +633,8 @@ and pp_string_format (e,ii) = eopt +> Common.do_option (fun (ieq, e) -> pr_elem ieq; pp_expression e; - )); - - (match (base, iis) with - | (Some base, [i1;i2;i3;i4;i5]) -> pr_elem i5 - | (None, [i1;i2;i3;i4]) -> pr_elem i4 - | (Some base, [i1;i2;i3;i4;i5;i6]) -> - pr_elem i6; pr_elem i5 (* trailing comma *) - | (None, [i1;i2;i3;i4;i5]) -> - pr_elem i5; pr_elem i4 (* trailing comma *) - | x -> raise (Impossible 104) - ) - + )) + | (BaseType _, iis) -> print_sto_qu_ty (sto, qu, iis); -- GitLab From 17d68f0274512726a3a6e7df02a1f11e5d4e46c7 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 12 Jul 2022 03:16:26 +0530 Subject: [PATCH 20/24] Changed assertion from previous code --- engine/cocci_vs_c.ml | 1 - parsing_c/pretty_print_c.ml | 1 - 2 files changed, 2 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 98aa7073..6fe2231e 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -4163,7 +4163,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = | A.EnumName(ena, sta, idta), (B.EnumName(stb, idtb), ii) -> - Printf.printf "testing"; let (enb, ii) = extract_one ii in tokenf ena enb >>= (fun ena enb -> option (fun x (y, ib, ii) -> diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index b75b9963..608e2034 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -643,7 +643,6 @@ and pp_string_format (e,ii) = print_sto_qu_ty (sto, qu, iis); | (EnumName (key, s), iis) -> - assert (List.length iis = 2); print_sto_qu_ty (sto, qu, iis); | (Decimal(l,p), [dec;lp;cm;rp]) -> -- GitLab From f6e0c6c32bc63c2896cd86c1caa704fe715b9d39 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 12 Jul 2022 11:46:29 +0530 Subject: [PATCH 21/24] made comma_opt empty in case the enumerator list was empty --- engine/cocci_vs_c.ml | 4 ++-- parsing_c/parser_c.mly | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 6fe2231e..6768fb5a 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -4197,10 +4197,10 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) = let (baseb, ib1, ii) = option_ret_unwrap baseb ii in match ii with - [ib2;ib3;comma_opt] -> + ib2::ib3::comma_opt -> tokenf lba ib2 >>= (fun lba lbb -> tokenf rba ib3 >>= (fun rba rbb -> - let idsb = resplit_initialiser idsb [comma_opt] in + let idsb = resplit_initialiser idsb comma_opt in let idsb = List.concat (List.map diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 839eb2cf..e3bbb43f 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -2307,7 +2307,10 @@ enum_spec: (addTypeD( (dt "type" (); (Right3 enumname, ii)),nullDecl))) in let (returnType, _) = fixDeclSpecForDecl tmp in - (EnumDef (returnType, ty, $4), td@[$3;$6] @ $5) + let comma_opt = + if List.length $5 != 0 + then [] else $5 in + (EnumDef (returnType, ty, $4), td@[$3;$6] @ comma_opt) } enum_ident_independant: -- GitLab From e3e22da484b0d55cc83f8de1bc4d8ebb91501e35 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Tue, 12 Jul 2022 12:17:28 +0530 Subject: [PATCH 22/24] Removed newlines while printing --- parsing_c/unparse_cocci.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 9ec2c631..145d92de 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -784,9 +784,8 @@ and typeC ty = fullType ty; print_option enum_base base; mcode print_string lb; - (dots force_newline enum_decl) ids; + (dots (function _ -> ()) enum_decl) ids; mcode print_string rb - | Ast.StructUnionName(kind,name) -> mcode structUnion kind; print_option_prespace ident name | Ast.StructUnionDef(ty,lb,decls,rb) -> -- GitLab From e47fa520b7552d91306823842ec06944156fdd3d Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Wed, 13 Jul 2022 00:09:55 +0530 Subject: [PATCH 23/24] Added class in the lexer and unparse cocci, as well as fixed a logical mistkae in parser_c --- parsing_c/parser_c.mly | 2 +- parsing_c/unparse_cocci.ml | 1 + parsing_cocci/lexer_cocci.mll | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index e3bbb43f..7c7988b5 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -2308,7 +2308,7 @@ enum_spec: (dt "type" (); (Right3 enumname, ii)),nullDecl))) in let (returnType, _) = fixDeclSpecForDecl tmp in let comma_opt = - if List.length $5 != 0 + if List.length $5 = 0 then [] else $5 in (EnumDef (returnType, ty, $4), td@[$3;$6] @ comma_opt) } diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 145d92de..06d08b43 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -819,6 +819,7 @@ and enum_base (td, ty) = and structUnion = function Ast.Struct -> print_string "struct" | Ast.Union -> print_string "union" + | Ast.Class -> print_string "class" and sign = function Ast.Signed -> print_string "signed" diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index b79e568b..279aa741 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -285,6 +285,7 @@ let id_tokens lexbuf = (* in_meta is only for the first keyword; drop it now to allow any type name *) | "struct" -> Data.saw_struct := true; Tstruct linetype + | "class" -> Data.saw_struct := true; Tclass linetype | "union" -> Data.saw_struct := true; Tunion linetype | "enum" -> Data.saw_struct := true; Tenum linetype | "unsigned" -> Tunsigned linetype -- GitLab From 49faa6109ecb489b3a71f4eaadc20458ce9ba832 Mon Sep 17 00:00:00 2001 From: Tathagata Roy Date: Wed, 13 Jul 2022 11:16:51 +0530 Subject: [PATCH 24/24] fixed pretty_print_c.mly Signed-off-by: Tathagata Roy --- parsing_c/parser_c.mly | 2 +- parsing_c/pretty_print_c.ml | 54 +++++++++++++++++++------------------ tests/enum.cocci | 46 ++++++++++++++++++++----------- tests/enum.res | 21 +-------------- 4 files changed, 60 insertions(+), 63 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 7c7988b5..86624f6f 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -2308,7 +2308,7 @@ enum_spec: (dt "type" (); (Right3 enumname, ii)),nullDecl))) in let (returnType, _) = fixDeclSpecForDecl tmp in let comma_opt = - if List.length $5 = 0 + if List.length $4 = 0 then [] else $5 in (EnumDef (returnType, ty, $4), td@[$3;$6] @ comma_opt) } diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml index 608e2034..3130b36e 100644 --- a/parsing_c/pretty_print_c.ml +++ b/parsing_c/pretty_print_c.ml @@ -611,30 +611,32 @@ and pp_string_format (e,ii) = | x -> raise (Impossible 102) ) - | (EnumDef (sopt, base, enumt), iis) -> - print_sto_qu (sto, qu); - let rest = - (match iis with - | ( (i1::i2::i3::ii)) -> - pr_elem i1; pr_elem i2; pr_elem i3; ii - | ((i1::i2::ii)) -> - pr_elem i1; pr_elem i2; ii - | x -> raise (Impossible 103)) in - - (match (base, rest) with - (Some base, i4::ii) -> pr_elem i4; pp_base_type base sto; - | (None, ii) -> () - | (Some _, []) -> raise (Impossible 1030)); + | (EnumDef (enident, base, enumt), iis) -> + pp_base_type (qu, snd enident) sto; + + let rest = + match (base, iis) with + (Some base, i4::ii) -> pr_elem i4; pp_base_type base sto; ii + | (None, ii) -> ii + | (Some _, []) -> raise (Impossible 1030) in - enumt +> List.iter (fun ((name, eopt), iicomma) -> - assert (List.length iicomma <= 1); - iicomma +> List.iter (function x -> pr_elem x; pr_space()); - pp_name name; - eopt +> Common.do_option (fun (ieq, e) -> - pr_elem ieq; - pp_expression e; - )) - + (match rest with + lb::rb::ii -> + pr_elem lb; + enumt +> List.iter (fun ((name, eopt), iicomma) -> + assert (List.length iicomma <= 1); + iicomma +> List.iter (function x -> pr_elem x; pr_space()); + pp_name name; + eopt +> Common.do_option (fun (ieq, e) -> + pr_elem ieq; + pp_expression e; + )); + pr_elem rb; + (match ii with + [co] -> pr_elem co + | _ -> ()) + | _ -> raise (Impossible 1031)) + | (BaseType _, iis) -> print_sto_qu_ty (sto, qu, iis); @@ -642,9 +644,9 @@ and pp_string_format (e,ii) = assert (List.length iis = 2); print_sto_qu_ty (sto, qu, iis); - | (EnumName (key, s), iis) -> - print_sto_qu_ty (sto, qu, iis); - + | (EnumName (key, s), ii) -> + print_sto_qu_ty (sto, qu, ii) + | (Decimal(l,p), [dec;lp;cm;rp]) -> (* hope that sto before qu is right... cf print_sto_qu_ty *) let stoqulp = get_sto sto @ (snd qu) @ [dec] in diff --git a/tests/enum.cocci b/tests/enum.cocci index ae0adbee..2190ddef 100644 --- a/tests/enum.cocci +++ b/tests/enum.cocci @@ -1,17 +1,31 @@ -@@ -expression *E; -@@ +@@ identifier l1, l2, l3, l4, l11, l12, l13, l14, l21, l22, l33, l32, zl1, zl2, zl3, zl4, zl11, zl12, zl13, zl14, zl21, zl22, zl33, zl32; @@ -( - E == -- 0 -+ NULL -| - E != -- 0 -+ NULL -| - E = -- 0 -+ NULL -) +- enum struct l1 {A, B}; +- enum class l2 {A2, B2}; +- enum struct l3:int {A3,B3}; +- enum class l4:int {A4,B4}; + +- enum l11 {A11, B11}; +- enum l12 {A12, B12}; +- enum l13:int {A13,B13}; +- enum l14:int {A14,B14}; + +- enum {A21, B21} l21; +- enum {A22, B22} l22; +- enum :int {A33,B33} l33; +- enum :int {A32,B32} l32; + +- enum struct zl1 {}; +- enum class zl2 {}; +- enum struct zl3:int {}; +- enum class zl4:int {}; + +- enum zl11 {}; +- enum zl12 {}; +- enum zl13:int {}; +- enum zl14:int {}; + +- enum {} zl21; +- enum {} zl22; +- enum :int {} zl33; +- enum :int {} zl32; \ No newline at end of file diff --git a/tests/enum.res b/tests/enum.res index 94e77004..5047a34e 100644 --- a/tests/enum.res +++ b/tests/enum.res @@ -1,22 +1,3 @@ -typedef enum +int main() { -} another_test; - -typedef enum -{ -xxx -#ifdef FOO -,bar -#endif -} another_test2; - -typedef enum -{ -xxx -} this_one_works; - -static reg_errcode_t -regex_compile () -{ - unsigned char *pending_exact = NULL; } -- GitLab