######################################################################## # # # This software is part of the ast package # # Copyright (c) 1989-2011 AT&T Intellectual Property # # and is licensed under the # # Eclipse Public License, Version 1.0 # # by AT&T Intellectual Property # # # # A copy of the License is available at # # http://www.eclipse.org/org/documents/epl-v10.html # # (with md5 checksum b35adb5213ca9657e911e9befb180842) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # Glenn Fowler # # # ######################################################################## : convert mam to old make makefile proc convert { typeset buf=$ifsjoin(Argv); typeset -i i set -s -A variable $(variable[@]) for (( i = ${#variable[@]} - 1; i >= 0; i-- )) do buf=${buf//\$${variable[i]}/\$(${variable[i]})}; done print -r -- $buf } proc closure { typeset i jfor i in @Argv { [[ " $list " == *" $i "* ]] && continue global list := ""$list $i"" for j in [$(implicit[$i])] { closure $j; } } } typeset -A prereqs implicit action typeset -i level=0 nvariables=0 typeset rule list order target variable print "# # oldmake makefile generated by $0 # #" while read -r op arg val extra junk { matchstr $op { [0-9]* { global op := $arg global arg := $val global val := $extra } } matchstr $op { setv { variable[nvariables++]=$arg convert "$arg = $val" } make|prev { global rule := $(target[level]) [[ " $val " == *" implicit "* ]] && implicit[$rule]="$(implicit[$rule]) $arg" || prereqs[$rule]="$(prereqs[$rule]) $arg" [[ $op == prev ]] && continue target[++level]=$arg [[ " $order " != *" $arg "* ]] && global order := ""$order $arg"" } exec { [[ $arg == - ]] && global arg := $(target[level]) [[ ${action[$arg]} ]] && action[$arg]=$(action[$arg])$'\n'$'\t'$val || action[$arg]=$'\t'$val } done { global level := 'level-1' } } } for rule in [$order] { [[ ! ${prereqs[$rule]} && ! ${action[$rule]} ]] && continue global list := '' closure $(prereqs[$rule]) && print && convert "$rule :$list" [[ ${action[$rule]} ]] && convert $(action[$rule]) } (CommandList children: [ (C {(Lit_Other ":")} {(convert)} {(mam)} {(to)} {(old)} {(make)} {(makefile)}) (FuncDef name: convert body: (BraceGroup children: [ (Sentence child: (C {(typeset)} {(Lit_VarLike "buf=") ($ VSub_Star "$*")}) terminator: ) (C {(typeset)} {(-i)} {(i)}) (C {(set)} {(-s)} {(-A)} {(variable)} { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [100 105] ) } ) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithBinary op_id: Arith_Minus left: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound bracket_op: (WholeArray op_id:Lit_At) spids: [116 122] ) } ) right: (ArithWord w:{(Lit_Digits 1)}) ) ) cond: (ArithBinary op_id: Arith_GreatEqual left: (ArithVarRef name:i) right: (ArithWord w:{(Lit_Digits 0)}) ) update: (UnaryAssign op_id:Node_PostDMinus child:(LhsName name:i)) body: (DoGroup children: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:buf) op: Equal rhs: { (BracedVarSub token: suffix_op: (PatSub pat: {(EscapedLiteralPart token:) (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithVarRef name:i)) spids: [151 156] ) } replace: {(EscapedLiteralPart token:) ("(") (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithVarRef name:i)) spids: [160 165] ) (")") } do_all: True do_prefix: False do_suffix: False ) spids: [146 167] ) } spids: [145] ) ] spids: [145] ) terminator: ) ] spids: [143 170] ) ) (C {(print)} {(-r)} {(--)} {(DQ ($ VSub_Name "$buf"))}) ] spids: [76] ) spids: [72 75] ) (FuncDef name: closure body: (BraceGroup children: [ (C {(typeset)} {(i)} {(j)}) (ForEach iter_name: i do_arg_iter: True body: (DoGroup children: [ (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (" ") ($ VSub_Name "$list") (" "))} right: {(Lit_Other "*") (DQ (" ") ($ VSub_Name "$i") (" ")) (Lit_Other "*")} ) ) (ControlFlow token:) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:list) op: Equal rhs: {(DQ ($ VSub_Name "$list") (" ") ($ VSub_Name "$i"))} spids: [231] ) ] spids: [231] ) (ForEach iter_name: j iter_words: [ { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [245 250] ) } ] do_arg_iter: False body: (DoGroup children: [ (Sentence child: (C {(closure)} {($ VSub_Name "$j")}) terminator: ) ] spids: [253 260] ) spids: [244 -1] ) ] spids: [204 263] ) spids: [-1 -1] ) ] spids: [189] ) spids: [185 188] ) (C {(typeset)} {(-A)} {(prereqs)} {(implicit)} {(action)}) (C {(typeset)} {(-i)} {(Lit_VarLike "level=") (0)} {(Lit_VarLike "nvariables=") (0)}) (C {(typeset)} {(rule)} {(list)} {(order)} {(target)} {(variable)}) (C {(print)} {(DQ ("# # oldmake makefile generated by ") ($ VSub_Number "$0") (" # #"))}) (While cond: [(C {(read)} {(-r)} {(op)} {(arg)} {(val)} {(extra)} {(junk)})] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$op")} arms: [ (case_arm pat_list: [{(Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:op) op: Equal rhs: {($ VSub_Name "$arg")} spids: [340] ) ] spids: [340] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:arg) op: Equal rhs: {($ VSub_Name "$val")} spids: [344] ) ] spids: [344] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:val) op: Equal rhs: {($ VSub_Name "$extra")} spids: [348] ) ] spids: [348] ) ] spids: [334 338 352 -1] ) ] spids: [327 331 355] ) (Case to_match: {($ VSub_Name "$op")} arms: [ (case_arm pat_list: [{(setv)}] action: [ (C {(variable) (Lit_Other "[") (nvariables) (Lit_Other "+") (Lit_Other "+") (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$arg") } ) (C {(convert)} {(DQ ($ VSub_Name "$arg") (" = ") ($ VSub_Name "$val"))}) ] spids: [365 366 387 -1] ) (case_arm pat_list: [{(make)} {(prev)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rule) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithVarRef name:level)) spids: [396 401] ) } spids: [395] ) ] spids: [395] ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (" ") ($ VSub_Name "$val") (" "))} right: {(Lit_Other "*") (DQ (" implicit ")) (Lit_Other "*")} ) ) (AndOr children: [ (C {(implicit) (Lit_Other "[") ($ VSub_Name "$rule") (Lit_Other "]") (Lit_Other "=") (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [431 436] ) (" ") ($ VSub_Name "$arg") ) } ) (C {(prereqs) (Lit_Other "[") ($ VSub_Name "$rule") (Lit_Other "]") (Lit_Other "=") (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [450 455] ) (" ") ($ VSub_Name "$arg") ) } ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$op")} right: {(prev)} ) ) (ControlFlow token:) ] op_id: Op_DAmp ) (C {(target) (Lit_Other "[") (Lit_Other "+") (Lit_Other "+") (level) (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$arg") } ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ (" ") ($ VSub_Name "$order") (" "))} right: {(Lit_Other "*") (DQ (" ") ($ VSub_Name "$arg") (" ")) (Lit_Other "*") } ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:order) op: Equal rhs: {(DQ ($ VSub_Name "$order") (" ") ($ VSub_Name "$arg"))} spids: [508] ) ] spids: [508] ) ] op_id: Op_DAmp ) ] spids: [390 393 516 -1] ) (case_arm pat_list: [{(exec)}] action: [ (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$arg")} right: {(-)} ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:arg) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithVarRef name:level)) spids: [535 540] ) } spids: [534] ) ] spids: [534] ) ] op_id: Op_DAmp ) (AndOr children: [ (DBracket expr: (WordTest w: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$arg")})) spids: [545 550] ) } ) ) (AndOr children: [ (C {(action) (Lit_Other "[") ($ VSub_Name "$arg") (Lit_Other "]") (Lit_Other "=") (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$arg")})) spids: [562 567] ) (SQ ) (SQ ) ($ VSub_Name "$val") } ) (C {(action) (Lit_Other "[") ($ VSub_Name "$arg") (Lit_Other "]") (Lit_Other "=") (SQ ) ($ VSub_Name "$val") } ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] spids: [519 520 590 -1] ) (case_arm pat_list: [{(KW_Done done)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:level) op: Equal rhs: {(level-1)} spids: [596] ) ] spids: [596] ) ] spids: [593 594 600 -1] ) ] spids: [358 362 603] ) ] spids: [325 605] ) ) (ForEach iter_name: rule iter_words: [{($ VSub_Name "$order")}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (DBracket expr: (LogicalAnd left: (LogicalNot child: (WordTest w: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [621 626] ) } ) ) right: (LogicalNot child: (WordTest w: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [632 637] ) } ) ) ) ) (ControlFlow token:) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:list) op:Equal rhs:{(SQ )} spids:[646])] spids: [646] ) (AndOr children: [ (C {(closure)} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [651 656] ) } ) (AndOr children: [ (C {(print)}) (C {(convert)} {(DQ ($ VSub_Name "$rule") (" :") ($ VSub_Name "$list"))}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (AndOr children: [ (DBracket expr: (WordTest w: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [675 680] ) } ) ) (C {(convert)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$rule")})) spids: [689 694] ) ) } ) ] op_id: Op_DAmp ) ] spids: [615 697] ) spids: [612 -1] ) ] )