# ---------------------------------------------------------------- # FILE # Gen_creator.awk # # DESCRIPTION # awk script for Gen_creator.sh # (was originally included as argument to awk in Gen_creator.sh, # but bash dropped core instead of procesing this) -- kai # # ---------------------------------------------------------------- # ---------------- # initialize variables # ---------------- BEGIN { SAVEFS = FS; ORS = " "; OFS = ""; nc = 0; } # ---------------- # first scan slots file and read in slot definitions # generated by inherits.sh # ---------------- FILENAME != "-" && /{/, /}/ { if ($1 ~ /{/) { newclass = 1; next; } if (newclass == 1) { s = 1; slotclass = $2 numslots[ slotclass ] = $1 FS = ":"; newclass = 0; # print FILENAME "--- " slotclass "\n" > "/dev/tty"; next; } if ($1 ~ /}/) { FS = SAVEFS; next; } slots[ slotclass s ] = $1; slotdefs[ slotclass s++ ] = $2; next; } # ---------------- # finished scanning slots file, now process stdin... # # Here we have found the start of a new class definition. # Get the class name and begin generating the Make creator. # ---------------- { FS = SAVEFS; } /class /,/{/ { class = substr($2,2,length($2)-2); # print FILENAME "*** " class "\n" > "/dev/tty"; # ---- # generate RInit initialization function # ---- print "\n/* ----------------"; print "\n * RInit", class, " - Raw initializer for ", class; print "\n * "; print "\n * This function just initializes the internal"; print "\n * information in a node. "; print "\n * ----------------"; print "\n */"; print "\nextern void RInit", class, "();"; print "\n"; print "\nvoid \n", "RInit", class, "(p)"; print "\nPointer p;"; print "\n{"; print "\n\textern void Out", class, "();"; print "\n\textern bool Equal", class, "();"; print "\n\textern bool Copy", class, "();"; print "\n\n\t", class, " node = (", class, ") p;\n"; print "\n\tnode->type = classTag(", class, ");"; print "\n\tnode->outFunc = Out", class, ";"; print "\n\tnode->equalFunc = Equal", class, ";"; print "\n\tnode->copyFunc = Copy", class, ";"; print "\n\n\treturn;\n}\n"; # ---- # generate the Make creator # ---- print "\n/* ----------------"; print "\n * Make creator function for ", class; print "\n * "; print "\n * This function is in some sence \"broken\" because"; print "\n * it takes parameters for only this nodes slots and"; print "\n * leaves this nodes inherited slots uninitialized."; print "\n * "; print "\n * This is here for backward compatibility with code"; print "\n * that relies on this behaviour."; print "\n * ----------------"; print "\n */"; print "\nextern ", class, " Make", class, "();"; print "\n"; print "\n", class, "\nMake", class, "("; i = 0; } # ---------------- # Now process all the lines inbetween the { and the } # ---------------- /{/,/}/ { if ($1 !~ /inherits/ && $1 !~ /struct/ && \ $1 !~ /class/ && $1 !~ /}/ ) { type[i] = $1; whole[i] = $0; decl[i++] = $2; } if ($1 ~ /struct/ ) { type[i] = $1+$2 ; whole[i] = $0; decl[i++] = substr($3,2,length($3)-1); } } # ---------------- # Now generate the Make creator function, the Out, Equal # and Copy functions, and the IMake and RMake creators. # ---------------- /}/ { for (x=0;x 0) { for (s=1; s<=n-1; s++) print slots[ class s ], ","; print slots[ class s ], ")\n"; for (s=1; s<=n; s++) print slotdefs[ class s ], ";\n"; } else { print ")\n"; } print "\n{"; print "\n\t", class, " node = New_Node(", class, ");\n"; print "\n\tRInit", class, "(node);\n"; if (n > 0) { for (s=1; s<=n ; s++) { slot = slots[ class s ]; print "\n\tset_", slot, "(node, ", slot, ");"; } } print "\n\n\treturn(node);\n}\n"; # ---- # generate RMake creator # ---- print "\n/* ----------------"; print "\n * RMake", class, " - Raw Make creator for ", class; print "\n * "; print "\n * This creator function does not initialize"; print "\n * any of its slots.. This is left up to the"; print "\n * calling routine."; print "\n * ----------------"; print "\n */"; print "\nextern ", class, " RMake", class, "();"; print "\n"; print "\n", class, "\n", "RMake", class, "()"; print "\n{"; print "\n\t", class, " node = New_Node(", class, ");\n"; print "\n\tRInit", class, "(node);"; print "\n\n\treturn(node);\n}\n"; } # ---------------- # thats all folks # ---------------- END { print "\n/* end-of-file */\n" }