diff --git a/engine/c_vs_c.ml b/engine/c_vs_c.ml index 209e01de0b5d203d20c3ba403be8ed42544b65a1..1770407c2eacdba71baffd84a4397f8f031e78a9 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 c215a0dc67d5a143e19b406425e038dbbb7ebc77..f082c814e51cc322cdaf9b3401cc52e13c3c852b 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 8b40b3a0a9bb9dee5fe4a31d755059d128a2ce13..6768fb5a5ca9f5ed4dd0aebd2fe4bc3858eb8115 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,6 +1614,61 @@ 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) -> + tokenf ia1 ib1 >>= (fun ia1 ib1 -> + (* for checking pp_opt *) + 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), (y, ib2, ib3, ii)) + )) + )) + pp_opta + (token_option2 pp_optb ii) + >>= (fun pp_opta pp_optb -> + let (pp_optb, ib23, ii) = + option_ret_unwrap2 pp_optb ii in + (* next two options for matchings paranthesis around type *) + option (fun ia4 (ignoredtoken,ib4,ii) -> + tokenf ia4 ib4 >>= (fun ia4 ib4-> + return (ia4, (ignoredtoken, ib4, ii)))) + ia4_opt + (token_option ia4_opt ii) + >>= (fun ia4_opt ib4_opt -> + let (_, ib4, ii) = + option_ret_unwrap ib4_opt ii in + fullType typa typb >>= (fun typa typb -> + option ( fun ia5 (ignoredtoken, ib5, ii) -> + tokenf ia5 ib5 >>= (fun ia5 ib5 -> + return (ia5, (ignoredtoken, ib5, ii)))) + ia5_opt + (token_option ia5_opt ii) + >>= (fun ia5_opt ib5_opt -> + let (_, ib5, ii) = + option_ret_unwrap ib5_opt ii in + (* for matching init_opt *) + 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), (y, ib6, ib7, ii)))) + )) + init_opta + (token_option2 init_optb ii) + >>= (fun init_opta init_optb -> + let (init_optb, ib67, ii) = + option_ret_unwrap2 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 ? *) | A.Paren (ia1, ea, ia2), ((B.ParenExpr (eb), typ),ii) -> @@ -4078,87 +4160,67 @@ 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) -> + 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 -> + 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 + 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 + ( + (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 @@ -4572,8 +4634,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 @@ -4607,7 +4679,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 36f2fe5b2fcf37d5178708761fd405194cc6ff23..bdd5ae93fc67eaff0f01749627a93a353499e7c4 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 @@ -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 @@ -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 + | 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 @@ -2630,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 @@ -2759,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 @@ -2793,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 = @@ -3217,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 : @@ -3363,6 +3367,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 + | 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 @@ -3383,6 +3389,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 = @@ -3427,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 @@ -3443,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 76568e7456b9cda12de6e083281b7e2ff710c180..9627b656a9a2a814f93c33316de082e931ce5fdc 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 @@ -368,14 +367,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 c7a012de17835b179da3913900049776ad18bff0..c39998cee8ea644ddaa17d17f95e7fc549ec0b95 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 @@ -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/includes_cache.ml b/parsing_c/includes_cache.ml index b6143876597f09130d01ce405d1062d61d086323..90e529377ced6e75c683c40205c726bd41ae32b0 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 2384cb2f7ca766fc33122c27097c2d21e2bb3f5d..79b81b8e38d97c655f26b671c35d9c568856222a 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 581379e1cea843d7d57347c4b36169f5d3be7ce7..86624f6f2c1bf637e862ec900473659209d0e5b8 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -814,9 +814,76 @@ 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 + 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 } @@ -941,9 +1008,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] } @@ -964,7 +1029,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 */ { [] } @@ -988,6 +1057,9 @@ argument_ne: | parameter_decl_arg { Right (ArgType $1) } | action_higherordermacro_ne { Right (ArgAction $1) } +argument_ne_without_paramdecl: + | primary_expr_without_ident { Left $1 } + | action_higherordermacro_ne { Right (ArgAction $1) } argument: | assign_expr { Left $1 } @@ -1341,8 +1413,10 @@ simple_type: [] -> ret | _ -> warning "attributes found in typeof(...), dropping" ret } -type_spec2: - simple_type { $1 } +type_spec2_without_braces: + 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 } @@ -1350,7 +1424,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 +1769,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 +1790,6 @@ type_name: let (returnType, _) = fixDeclSpecForDecl ds in (attrs1@attrs2, fn returnType) } - - abstract_declaratort: | abstract_declarator { $1 } /*(* gccext: *)*/ @@ -2225,12 +2298,64 @@ 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 + let tmp = + (dt "spec_qualif" (); + (addTypeD( + (dt "type" (); (Right3 enumname, ii)),nullDecl))) in + let (returnType, _) = fixDeclSpecForDecl tmp in + let comma_opt = + if List.length $4 = 0 + then [] else $5 in + (EnumDef (returnType, ty, $4), td@[$3;$6] @ comma_opt) + } + +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 + (EnumName (key, Some (fst ident)), ii) + } | Tenum ident - { EnumName (fst $2), [$1; snd $2] } + { + let rt = ((None, $2), [$1; snd $2]) in + let ((key, ident), ii) = rt in + (EnumName (key, Some (fst ident)), 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 = + (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: + Tcpp_struct { et "su" (); (Struct, $1) } + | Tclass { et "su" (); (Class, $1) } enumerator: | idente { $1, None } @@ -2736,6 +2861,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]] } @@ -2768,6 +2897,7 @@ enumerator_list: | enumerator_list TComma cpp_directive_list enumerator { $1 @ [$4, [$2]] } | enumerator_list TComma enumerator { $1 @ [$3, [$2]] } + | /* empty */ { [] } init_declarator_list: @@ -2837,6 +2967,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 dc94fc5602d4abff3a77e3ba257a91c24415a579..3130b36edb2b91ff786abb3486f1715d8010d463 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 @@ -584,39 +611,32 @@ and pp_string_format (e,ii) = | x -> raise (Impossible 102) ) - | (Enum (sopt, 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]) -> - 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) - ); - - + | (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 + + (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); @@ -624,10 +644,9 @@ and pp_string_format (e,ii) = assert (List.length iis = 2); print_sto_qu_ty (sto, qu, iis); - | (EnumName s, iis) -> - assert (List.length iis = 2); - 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 @@ -802,10 +821,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 @@ -919,10 +938,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 (_, _, _), _ -> () @@ -977,10 +996,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 1dbb89aa290be2771f514e8bfd752243c47056c2..cae660ccccae9abefc76becd2931906db3077418 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 @@ -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 *) @@ -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 dca74e9f207f0d94e7094f6d564a0a60056e5827..f043387cc4a52fe790c01fefab6b7eaed0f79414 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 37265e2eecda48390dee7a7ca23a2aaf26b1dd1a..06d08b435fc46b916857502e9bd9a66c17a51f4b 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 @@ -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) -> @@ -764,14 +776,16 @@ 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 (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) -> @@ -797,9 +811,15 @@ 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" + | Ast.Class -> print_string "class" and sign = function Ast.Signed -> print_string "signed" diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml index ffa2268b6aafadc8cf64e4cc4f6342f4d02c9b51..4a95a859ebaa571798d8966c7f191454a0d1eed0 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 47a27ece53d6201efee9611b56e0aaa7b0867fc1..100598d827e501ee2ba08d7b429313920756a1bd 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 @@ -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) -> @@ -1248,10 +1250,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) @@ -1470,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, @@ -1479,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/#parser_cocci_menhir.conflicts# b/parsing_cocci/#parser_cocci_menhir.conflicts# new file mode 100644 index 0000000000000000000000000000000000000000..2b84b440c03357b66d0146fd9fbe7634159963c0 --- /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/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml index bd335dc46663a50ff11b2349ddbc0c972812c52f..6ab1f28a1b9e859848cfcc6ddb9c8c2248001e1f 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 8113c3f393a94529ba111f688c149019743c2d6d..e3eda3ad30592283355aa988e9023f938d0a2f23 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,6 +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.New(nw,pp_opt,lp2_opt,ty,rp2_opt,args_opt) -> + let arity = + 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 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 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 @@ -338,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") @@ -451,21 +469,26 @@ 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 + 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 - 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 + (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)) + base in let lb = mcode lb in - let ids = 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,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 8b7733289cd5fb7df0052cf7fc7cbd5d07ccc11c..b8bf34bd795740b529ecfd92eda88bb4fd2451c6 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 (* ) *) + | 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 @@ -155,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 = @@ -209,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 typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | 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 * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -231,6 +236,8 @@ and base_typeC = and typeC = base_typeC wrap +and enum_base = string mcode (* : *) * typeC + (* --------------------------------------------------------------------- *) (* Variable declaration *) (* Even if the Cocci program specifies a list of declarations, they are @@ -768,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 a852ffc5a06079aa566e1cdb5f745b0c9d18509a..0b4c3315282f0c1f1bfaaef75cfbbb809ac05cca 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 (* ) *) + | 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 @@ -144,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 = @@ -200,9 +205,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 typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * enum_decl dots * string mcode (* } *) + | 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 * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -223,6 +228,8 @@ and base_typeC = and typeC = base_typeC wrap +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/ast0toast.ml b/parsing_cocci/ast0toast.ml index c9915fa7f7b0adb74d50b4bc9f7a6029eaeaf00c..8d910dc719beea133f99a7748e32c97a90a5a770 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -448,6 +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.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 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) @@ -489,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 @@ -566,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)) @@ -599,10 +614,11 @@ 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, enum_decl_dots ids, mcode rb) | Ast0.StructUnionName(kind,name) -> Ast.StructUnionName(mcode kind,get_option ident name) | Ast0.StructUnionDef(ty,lb,decls,rb) -> @@ -758,6 +774,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 9af4aedc1d086c7e8b56d58c8f7146001f185816..6c511159ac48641b278a93e632dd7734845f4e80 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -200,6 +200,9 @@ and base_expression = | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * 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*) @@ -276,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 @@ -350,8 +355,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 fullType (* either EnumName or metavar *) * + | 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 * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * @@ -376,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 @@ -451,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 (* --------------------------------------------------------------------- *) @@ -1128,6 +1134,7 @@ let string_of_expression e = let string_of_structUnion = function Struct -> "struct" | Union -> "union" + | Class -> "class" let rec string_of_typeC ty = match unwrap ty with @@ -1147,12 +1154,17 @@ 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 "" + (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)) (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^")" @@ -1186,7 +1198,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 -> @@ -1227,11 +1239,11 @@ 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 - | Some f -> rewrap ty (f s0 ident) + | Some f -> rewrap ty (f s0 key ident) end | StructUnionName (su, ident) -> begin @@ -1264,8 +1276,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)) @@ -1287,11 +1299,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 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 @@ -1306,7 +1318,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; @@ -1331,15 +1343,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 97e424c6cad506560dbf5ea144eae31d38853b5b..048a4beadad4b0012a2d7586202be82f6568241a 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 (* ) *) + | New of string mcode (* new *) * arguments option * + string mcode (* ( *) option * fullType * + string mcode (* ) *) option * arguments option | TypeExp of fullType | Paren of string mcode (* ( *) * expression * @@ -259,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 @@ -332,8 +337,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 fullType (* either EnumName or metavar *) * + | 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 * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * @@ -358,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 @@ -433,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 *) @@ -900,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/check_meta.ml b/parsing_cocci/check_meta.ml index 8179b7d3caadde77a86016fcb6db201e6ce19407..62972b794c17789071331d4f2a308979be1bba07 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -202,6 +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.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> + typeC old_metas table minus ty; + 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 @@ -243,6 +247,8 @@ and check_len table minus len = constraints table minus cstr | _ -> () +and check_args fn (_,args,_) = + dots fn args (* --------------------------------------------------------------------- *) (* Types *) @@ -272,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; + (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 9ea23ef5808ac376ea8890adf23e0b944b01f5b9..09f87961b8a7528fa1bc459d7bffc323461a81d5 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,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,ids,rb)) | _ -> t let initialiser r k i = diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 5204258b2b69cc2eccbabba306b65cb6dae43536..2ee72c96f9806d4479cfa87d6ab8182555d77fa4 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -441,6 +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.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> (* HIGH doubts in this one *) + let nw = normal_mcode nw in + 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) -> @@ -500,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 = @@ -591,21 +609,25 @@ 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 + (dots is_enum_decl_dots + (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,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 81453bedb21eb7dda9d20c5a93392c2c21251440..c8a407aa15d14a245fab75f0ea076acf7c71e1b0 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,6 +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.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 @@ -738,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 b30f19af2c833a9726c2d11aa3987ca77f098418..0b1a6a1bbe6343e2503793eac10ca6778b41d345 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -85,18 +85,24 @@ 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) + ((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 -> @@ -230,6 +236,10 @@ and disjexp e = let ty = disjty ty in List.map (function ty -> Ast.rewrap e (Ast.SizeOfType(szf,lp,ty,rp))) ty + | 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 @@ -258,6 +268,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/free_vars.ml b/parsing_cocci/free_vars.ml index fac7a67203f4685664f6677bbdd7097e87628f64..7e40c3e305b3e5b3e4df0d9e98d54d53c2be32c8 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, ident')); + 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/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index 220d448975b2048267661217d5cd6ccd778b24b9..b4817a3521d4f96246958deda3d0ad79e80f5990 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/get_constants.ml b/parsing_cocci/get_constants.ml index ebab24871f44dff8a3eb3d77ccdaa7d32a57fd82..85a746a5f75f8586251ff64bbf208d136f4c485b 100644 --- a/parsing_cocci/get_constants.ml +++ b/parsing_cocci/get_constants.ml @@ -53,6 +53,10 @@ 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(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) | Ast.Edots(_,_) | Ast.Ecircles(_,_) | Ast.Estars(_,_) -> [] diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index 39ddbd1e4f208275ce3fa14e052d1af42ac249db..419168ffab4a2d1ab09ee5697ef5035a1dacb6f6 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 @@ -489,6 +491,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.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 abff93d1b19d5e12753900fc00d6c31dd2445f06..60abb0378c88e21220d23dd04c8904224b48203e 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, 65 +*) (* 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.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] @@ -97,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 f0a514f2e60a4e26299a46088c961f4ff35cee2d..e4f6be47600f1a07e2c19ca2c91837ae4a5573e6 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -782,6 +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.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 @@ -841,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 @@ -892,16 +905,22 @@ 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_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 @@ -1914,8 +1933,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)) @@ -1934,7 +1953,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/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index fb8067daeffbdbdd88f10c71b06c844aef375024..279aa741cb58fcddec17bee58ce8ec51081da5e3 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 @@ -293,17 +294,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 +329,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 diff --git a/parsing_cocci/menhir_output b/parsing_cocci/menhir_output new file mode 100644 index 0000000000000000000000000000000000000000..4e6d37e324bcf424d163699e5a98dfa8a009002c --- /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 dbbca37c73604684e96f487626efb28aac4837a2..76a7a0ded106c9306312f6c673c50af7bb05dc20 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 @@ -178,7 +179,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 @@ -330,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) @@ -352,7 +354,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) @@ -421,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) @@ -442,7 +444,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) @@ -584,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) @@ -637,6 +640,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) @@ -900,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) @@ -919,7 +923,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) @@ -1187,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 -> @@ -1334,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) @@ -1345,7 +1351,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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 0148113cd56bde0dd64f95d2b619171beead330e..bd33656257fc742087b2000042aa4595194abf19 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 @@ -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 @@ -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)) @@ -898,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 @@ -919,6 +955,10 @@ 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] } + arity: TWhy0 { Ast_cocci.OPT } | TPlus0 { Ast_cocci.MULTI } | /* empty */ { Ast_cocci.NONE } @@ -967,7 +1007,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 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)), + 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, + 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 @@ -1001,26 +1059,10 @@ non_signable_types_no_ident: { 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 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=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)) } -| 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 +1096,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 +1113,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 +1135,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) @@ -1120,6 +1195,10 @@ typedef_ctype: (Ast0_cocci.DisjType(Parse_aux.id2mcode lp,code,mids, Parse_aux.id2mcode rp)) } | TMeta { tmeta_to_type $1 } +typedef_ctype_only_signed: + ty=signable_types + { Parse_aux.pointerify (Parse_aux.make_cv None ty) [] } + /* ---------------------------------------------------------------------- */ struct_or_union: @@ -1142,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 @@ -1201,8 +1280,18 @@ 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 } + | Tclass { Parse_aux.clt2mcode Ast_cocci.Class $1 } + +enum_base: + c=TDotDot t=ctype_without_braces + { (Parse_aux.clt2mcode ":" c, t) } /*****************************************************************************/ @@ -2153,6 +2242,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 } @@ -2245,8 +2335,36 @@ 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)) } +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 + { Ast0_cocci.wrap(Ast0_cocci.New ( Parse_aux.clt2mcode "new" n, None, None, t, None, 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 )) } + +cpp_initialiser: + 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: @@ -2261,9 +2379,37 @@ 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 + { 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 } @@ -2792,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 @@ -3031,14 +3188,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) @@ -3047,6 +3207,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 @@ -3377,6 +3545,7 @@ anything: /* used for script code */ | Tptrdiff_t { "ptrdiff_t" } | Tvoid { "void" } | Tstruct { "struct" } + | Tclass { "class" } | Tunion { "union" } | Tenum { "enum" } | Tunsigned { "unsigned" } @@ -3408,6 +3577,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 cdab97068c4bc2440130b64001cd0bbdae7a13f9..a38a2acd276b7460e85154d6e99c44c84f7688c4 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -259,6 +259,15 @@ 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_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 " "; + 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(); @@ -285,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 @@ -498,11 +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_string " "; + print_option (mcode structUnion) key; print_option (function x -> ident x; print_string " ") name - | Ast.EnumDef(ty,lb,ids,rb) -> - fullType ty; mcode print_string lb; + | 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) -> @@ -667,6 +686,10 @@ 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; + print_string " "; + fullType ty (* --------------------------------------------------------------------- *) (* Initialiser *) diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 4c1ae0c56c342488eb7c0cc22961a4f40c3d27ff..a05f0bac1e6002d5d5d3d063b2ef3f954fee8c33 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.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 @@ -170,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/type_infer.ml b/parsing_cocci/type_infer.ml index d20d963bbdda7391cefcc13ac675537e1218ad2b..1be5ad6d1583a185cfe3fec501fba4c5e1d7e77a 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.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 28650a0c4531bfa9855d5295e06f2f7cc372c289..4b3232e1c19bf11174607f71dfea16dc3ecbd4fe 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -229,6 +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.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_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 @@ -273,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 *) @@ -351,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)) -> - true - | (Ast.EnumDef(ty1,lb1,ids1,rb1),Ast.EnumDef(ty2,lb2,ids2,rb2)) -> + | (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)) -> + 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_dots unify_enum_decl enumdots ids1 ids2 + unify_option (fun (_, ty1) (_,ty2) -> unify_fullType ty1 ty2) base1 base2 && + (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 3075832ef0d76056f81b5dbf034ba27f7b26e8cf..c42835a1dfe3d32e332933757b629e4a539eb449 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -231,6 +231,15 @@ let rec expression e = mcode print_string szf; mcode print_string_box lp; typeC ty; close_box(); mcode print_string rp + | 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 " "; + 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(); @@ -269,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 @@ -345,11 +361,20 @@ 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_string " "; + print_option (mcode U.structUnion) key; print_option (function x -> ident x; print_string " ") name - | Ast0.EnumDef(ty,lb,ids,rb) -> - typeC ty; mcode print_string lb; + | Ast0.EnumDef(ty,base,lb,ids,rb) -> + typeC ty; + print_option + (function (td, ty) -> + mcode print_string td; + print_string " "; + typeC ty) + base; + mcode print_string lb; dots force_newline enum_decl ids; mcode print_string rb | Ast0.StructUnionName(kind,name) -> diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index d9a4997140e575ffe3a77d727666c52f390e8ad2..fe95323c9799af42bf990601682c173906ef841b 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -217,6 +217,14 @@ let combiner bind option_default let lty = fullType ty in let lrp = string_mcode rp in multibind [lszf; llp; lty; lrp] + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> + let lnw = string_mcode nw 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 = 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 @@ -251,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 @@ -388,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 struct_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 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 @@ -569,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 @@ -1254,6 +1275,14 @@ let rebuilder let lty = fullType ty in let lrp = string_mcode rp in Ast.SizeOfType(lszf, llp, lty, lrp) + | Ast.New(nw,pp_opt,lp_opt,ty,rp_opt,args_opt) -> + let lnw = string_mcode nw 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_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 @@ -1293,6 +1322,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 @@ -1395,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 struct_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 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 @@ -1576,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 89a0f63b194b2b9e396d92d81cce02e1e0075fc8..57685eef8670c19a896f1daa9ca1cb6a91223293 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -202,6 +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.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 (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)) @@ -253,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 @@ -358,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 struct_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 (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 @@ -736,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 diff --git a/tests/enum.cocci b/tests/enum.cocci index ae0adbee7c308e7dc3a3f247f6f1af28ddf33b7c..2190ddef8c82627c658ed56eb50beb8931c15e55 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 94e77004cfeed58be5f4dc0f007d3cec6d1ec231..5047a34e393afabd94f779966acc69b8edf9570d 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; } diff --git a/tests/newsimple.cocci b/tests/newsimple.cocci new file mode 100644 index 0000000000000000000000000000000000000000..cefa99b6378b4bdc8bfc871f533a39531ec815ab --- /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 0000000000000000000000000000000000000000..8ba0db6558ed7bb1cf1e6490f8b0b56b767e325f --- /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 0000000000000000000000000000000000000000..8155ddfe6958b5ea9707535f2a6cd6f87f036f51 --- /dev/null +++ b/tests/newsimple.res @@ -0,0 +1,6 @@ +int main() +{ + sizeof(Test); + new int(2); +} + diff --git a/tools/spgen/source/meta_variable.ml b/tools/spgen/source/meta_variable.ml index a8cda8784606b12ecb4447fca2c3150e48653763..375590740d62f1d65ec59846c228460684dfadf1 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 93e0e24b78334b4892ba1cb253ba076fbac782ec..b9d982465c247e2ef8cc4ea1cb00ab6bff152c64 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) ->