#!/usr/local/bin/perl # # This is a perl script to translate standard STL calls into # macro calls. Also add necessary "fwd_*.h" include files. # # This is a first pass filter. Assumes the containers have only # first argument speicified (if more are specified, you will need # to add one or more suffixes by hand). # # Outputs to new file prefixed with "STL_". Also lists changes on # stdout -- you may want to direct this to a file. # # Note: assumes no whitespace next to (inside) template delimiters: # e.g., vector is OK, but not vector < int > or vector # in input. (Alternative has other problems.) # # ONLY MAKES ONE SUBSTITUTION PER LINE! (need second pass?) # May be a problem for container adapters. # # John Bartelt 20-Feb-1998 # open(READFL, $ARGV[0]) || die "Cannot open $ARGV[0]. usage: macroize.pl \n"; ($infile) = $ARGV[0]; chomp $infile; $outfile = 'STL_'.$infile; open(READFL, "$infile"); print ("\n reading ", $infile, "\n"); open(WRITEFL, ">$outfile"); print (" writing ", $outfile, "\n\n"); while(){ ($inline) = $_; #First, handle "sequence" (vector, deque, list) containers: # #look for include file, add if($inline =~ /#\s*include\s*<\s*vector\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*vector.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a vector template with no allocator specified: } elsif($inline =~ /(.*)(vector)(\s*)(<)(\S*)(>)(.*)/) { $outline = $1 . 'STL_VECTOR' . $3 . '('. $5 .')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # #look for include file, add } elsif($inline =~ /#\s*include\s*<\s*deque\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*deque.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a deque template with no allocator specified: } elsif($inline =~ /(.*)(deque)(\s*)(<)(\S*)(>)(.*)/) { $outline = $1 . 'STL_DEQUE' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # #look for include file, add } elsif($inline =~ /#\s*include\s*<\s*list\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*list.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a list template with no allocator specified: } elsif($inline =~ /(.*)(list)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_LIST' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #Now do associative containers (maps and sets) # Caution: For templates, do multimap before map, multiset before set #look for include file, add ; for maps and multimaps } elsif($inline =~ /#\s*include\s*<\s*map\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*map.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for (nonstandard) include file, replace with and # } elsif($inline =~ /#\s*include\s*<\s*multimap.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # #look for a multimap template with no comparison nor allocator specified: } elsif($inline =~ /(.*)(multimap)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_MULTIMAP' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a map template with no comparison nor allocator specified: } elsif($inline =~ /(.*)(\s+map)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . ' STL_MAP' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # #look for include file, add ! } elsif($inline =~ /#\s*include\s*<\s*set\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*set.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for (nonstandard) include file, replace with and # } elsif($inline =~ /#\s*include\s*<\s*multiset.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a multiset template with no comparison nor allocator specified: } elsif($inline =~ /(.*)(multiset)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_MULTISET' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a set template with no comparison nor allocator specified: } elsif($inline =~ /(.*)(set)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_SET' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # # Finally, try the container adapters: stack, queue, priority_queue # Only limited cases implemented here for now. # #look for include file, add } elsif($inline =~ /#\s*include\s*<\s*stack\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with , and # , } elsif($inline =~ /#\s*include\s*<\s*stack.h\s*>.*/) { $outline = "#include \n#include \n#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); print ("INFO: fwd_queue.h and queue added to file $outfile.\nINFO: May not be needed."); #look for a stack template with no container or allocator specified: } elsif($inline =~ /(.*)(stack)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_STACK' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # #look for include file, add } elsif($inline =~ /#\s*include\s*<\s*queue\s*>.*/) { $outline = "#include \n" . $inline; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for include file, replace with and } elsif($inline =~ /#\s*include\s*<\s*queue.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a priority_queue template with no container, comparison, or # allocator specified: } elsif($inline =~ /(.*)(priority_queue)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_PRIORITY_QUEUE' . $3 . '('. $5 .')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for a queue template with no container or allocator specified: } elsif($inline =~ /(.*)(queue)(\s*)(<)(.*)(>)(.*)/) { $outline = $1 . 'STL_QUEUE' . $3 . '(' . $5 . ')' .$7."\n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); #look for (nonstandard) include file, replace with # and } elsif($inline =~ /#\s*include\s*<\s*priority_queue.h\s*>.*/) { $outline = "#include \n#include \n"; print ("in: \n", $inline, "\n", "out: \n", $outline, "\n\n"); # else, just write the line as is: } else { $outline = $inline; } print WRITEFL ($outline); } close(READFL); close(WRITEFL);