The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

compile.c File Reference

#include "jam.h"
#include "lists.h"
#include "parse.h"
#include "compile.h"
#include "variable.h"
#include "expand.h"
#include "rules.h"
#include "newstr.h"
#include "make.h"
#include "search.h"
#include "hdrmacro.h"
#include "hash.h"
#include "modules.h"
#include "strings.h"
#include "builtins.h"
#include "class.h"
#include <time.h>
#include <assert.h>
#include <string.h>

Include dependency graph for compile.c:

Include dependency graph

Go to the source code of this file.

Classes

struct  profile_frame
struct  profile_info

Defines

#define TYPE_CLOSE_DELIM   ']'
#define TYPE_OPEN_DELIM   '['

Typedefs

typedef profile_frame profile_frame
typedef profile_info profile_info

Functions

char arg_modifier (LIST *formal)
void argument_error (char *message, RULE *rule, FRAME *frame, LIST *arg)
void backtrace (FRAME *frame)
void backtrace_line (FRAME *frame)
SETTINGScollect_arguments (RULE *rule, FRAME *frame)
LISTcompile_append (PARSE *parse, FRAME *frame)
LISTcompile_class (PARSE *p, FRAME *frame)
LISTcompile_eval (PARSE *parse, FRAME *frame)
LISTcompile_foreach (PARSE *parse, FRAME *frame)
LISTcompile_if (PARSE *p, FRAME *frame)
LISTcompile_include (PARSE *parse, FRAME *frame)
LISTcompile_list (PARSE *parse, FRAME *frame)
 Todo: check for empty class name.
LISTcompile_local (PARSE *parse, FRAME *frame)
LISTcompile_module (PARSE *p, FRAME *frame)
LISTcompile_null (PARSE *parse, FRAME *frame)
LISTcompile_on (PARSE *parse, FRAME *frame)
LISTcompile_rule (PARSE *parse, FRAME *frame)
LISTcompile_rules (PARSE *parse, FRAME *frame)
LISTcompile_set (PARSE *parse, FRAME *frame)
LISTcompile_setcomp (PARSE *parse, FRAME *frame)
LISTcompile_setexec (PARSE *parse, FRAME *frame)
LISTcompile_settings (PARSE *parse, FRAME *frame)
LISTcompile_switch (PARSE *parse, FRAME *frame)
LISTcompile_while (PARSE *p, FRAME *frame)
void debug_compile (int which, char *s, FRAME *frame)
void dump_profile_entry (void *p_, void *ignored)
LISTevaluate_in_module (char *module_name, PARSE *p, FRAME *frame)
LISTevaluate_rule (char *rulename, FRAME *frame)
void frame_free (FRAME *frame)
void frame_init (FRAME *frame)
int glob (char *s, char *c)
int is_type_name (char *s)
int lcmp (LIST *t, LIST *s)
void print_source_line (PARSE *p)
void profile_dump ()
void profile_enter (char *rulename, profile_frame *frame)
void profile_exit (profile_frame *frame)
void type_check (char *type_name, LIST *values, FRAME *caller, RULE *called, LIST *arg_name)

Variables

hashprofile_hash = 0
profile_frameprofile_stack = 0


Define Documentation

#define TYPE_CLOSE_DELIM   ']'
 

Definition at line 623 of file compile.c.

#define TYPE_OPEN_DELIM   '['
 

Definition at line 622 of file compile.c.

Referenced by is_type_name().


Typedef Documentation

typedef struct profile_frame profile_frame
 

Definition at line 818 of file compile.c.

Referenced by evaluate_rule().

typedef struct profile_info profile_info
 

Definition at line 808 of file compile.c.

Referenced by dump_profile_entry(), and profile_enter().


Function Documentation

char arg_modifier LIST formal  )  [static]
 

Definition at line 641 of file compile.c.

References LIST, _list::next, and _list::string.

Referenced by collect_arguments().

00642 {
00643     if ( formal->next )
00644     {
00645         char *next = formal->next->string;
00646         if ( next && next[0] != 0 && next[1] == 0 )
00647             return next[0];
00648     }
00649     return 0;
00650 }

void argument_error char *  message,
RULE rule,
FRAME frame,
LIST arg
[static]
 

Definition at line 603 of file compile.c.

References frame::args, _rule::arguments, backtrace(), backtrace_line(), argument_list::data, FRAME, LIST, LOL, lol_print(), _rule::name, frame::prev, print_source_line(), _rule::procedure, frame::procedure, RULE, frame::rulename, and _list::string.

Referenced by collect_arguments(), and type_check().

00604 {
00605     LOL* actual = frame->args;
00606     assert( frame->procedure != 0 );
00607     backtrace_line( frame->prev );
00608     printf( "*** argument error\n* rule %s ( ", frame->rulename );
00609     lol_print( rule->arguments->data );
00610     printf( " )\n* called with: ( " );
00611     lol_print( actual );
00612     printf( " )\n* %s %s\n", message, arg ? arg->string : "" );
00613     print_source_line( rule->procedure );
00614     printf( "see definition of rule '%s' being called\n", rule->name );
00615     backtrace( frame->prev );
00616     exit(1);
00617 }

Here is the call graph for this function:

void backtrace FRAME frame  ) 
 

Referenced by argument_error(), builtin_import(), evaluate_rule(), and unknown_rule().

void backtrace_line FRAME frame  ) 
 

Referenced by argument_error(), backtrace(), builtin_import(), evaluate_rule(), and unknown_rule().

SETTINGS* collect_arguments RULE rule,
FRAME frame
[static]
 

Definition at line 716 of file compile.c.

References addsettings(), arg_modifier(), frame::args, argument_error(), _rule::arguments, _lol::count, argument_list::data, FRAME, is_type_name(), LIST, list_copy(), list_new(), LOL, lol_get(), max, n, _list::next, RULE, SETTINGS, _list::string, and type_check().

Referenced by evaluate_rule().

00717 {
00718     SETTINGS *locals = 0;
00719     
00720     LOL* all_actual = frame->args;
00721     LOL *all_formal = rule->arguments ? rule->arguments->data : 0;
00722     if ( all_formal ) /* Nothing to set; nothing to check */
00723     {
00724         int max = all_formal->count > all_actual->count
00725             ? all_formal->count
00726             : all_actual->count;
00727         
00728         int n;
00729         for ( n = 0; n < max ; ++n )
00730         {
00731             LIST *actual = lol_get( all_actual, n );
00732             char *type_name = 0;
00733             
00734             LIST *formal;
00735             for ( formal = lol_get( all_formal, n ); formal; formal = formal->next )
00736             {
00737                 char* name = formal->string;
00738 
00739                 if ( is_type_name(name) )
00740                 {
00741                     if ( type_name )
00742                         argument_error( "missing argument name before type name:", rule, frame, formal );
00743                     
00744                     if ( !formal->next )
00745                         argument_error( "missing argument name after type name:", rule, frame, formal );
00746 
00747                     type_name = formal->string;
00748                 }
00749                 else
00750                 {
00751                     LIST* value = 0;
00752                     char modifier;
00753                     LIST* arg_name = formal; /* hold the argument name for type checking */
00754                     
00755                     /* Stop now if a variable number of arguments are specified */
00756                     if ( name[0] == '*' && name[1] == 0 )
00757                         return locals;
00758 
00759                     modifier = arg_modifier( formal );
00760                 
00761                     if ( !actual && modifier != '?' && modifier != '*' )
00762                         argument_error( "missing argument", rule, frame, formal );
00763 
00764                     switch ( modifier )
00765                     {
00766                     case '+':
00767                     case '*':
00768                         value = list_copy( 0, actual );
00769                         actual = 0;
00770                         /* skip an extra element for the modifier */
00771                         formal = formal->next; 
00772                         break;
00773                     case '?':
00774                         /* skip an extra element for the modifier */
00775                         formal = formal->next; 
00776                         /* fall through */
00777                     default:
00778                         if ( actual ) /* in case actual is missing */
00779                         {
00780                             value = list_new( 0, actual->string );
00781                             actual = actual->next;
00782                         }
00783                     }
00784                 
00785                     locals = addsettings( locals, 0, name, value );
00786                     type_check( type_name, value, frame, rule, arg_name );
00787                     type_name = 0;
00788                 }
00789             }
00790             
00791             if ( actual )
00792             {
00793                 argument_error( "extra argument", rule, frame, actual );
00794             }
00795         }
00796     }
00797     return locals;
00798 }

Here is the call graph for this function:

LIST* compile_append PARSE parse,
FRAME frame
 

Definition at line 121 of file compile.c.

References FRAME, _PARSE::left, list_append(), PARSE, parse_evaluate(), and _PARSE::right.

00124 {
00125     /* Append right to left. */
00126 
00127     return list_append( 
00128         parse_evaluate( parse->left, frame ),
00129         parse_evaluate( parse->right, frame ) );
00130 }

Here is the call graph for this function:

LIST* compile_class PARSE p,
FRAME frame
 

Definition at line 427 of file compile.c.

References evaluate_in_module(), FRAME, _PARSE::left, LIST, make_class_module(), p, PARSE, parse_evaluate(), and _PARSE::right.

00430 {
00434     char* class_module = 0;
00435 
00436     LIST* name = parse_evaluate( p->left->right, frame );
00437     LIST* bases = 0;
00438 
00439     if (p->left->left)
00440         bases = parse_evaluate( p->left->left->right, frame );
00441 
00442     class_module = make_class_module(name, bases, frame);    
00443     evaluate_in_module( class_module, p->right, frame );
00444 
00445     return L0;    
00446 }

Here is the call graph for this function:

LIST* compile_eval PARSE parse,
FRAME frame
 

Definition at line 160 of file compile.c.

References debug_compile(), eval(), EXPR_AND, EXPR_EQUALS, EXPR_EXISTS, EXPR_IN, EXPR_LESS, EXPR_LESSEQ, EXPR_MORE, EXPR_MOREEQ, EXPR_NOT, EXPR_NOTEQ, EXPR_OR, FRAME, L0, lcmp(), _PARSE::left, LIST, list_free(), list_new(), list_next, list_print(), newstr(), _PARSE::num, PARSE, parse_evaluate(), _PARSE::right, s, and _list::string.

00163 {
00164         LIST *ll, *lr, *s, *t;
00165         int status = 0;
00166 
00167         /* Short circuit lr eval for &&, ||, and 'in' */
00168 
00169         ll = parse_evaluate( parse->left, frame );
00170         lr = 0;
00171 
00172         switch( parse->num )
00173         {
00174         case EXPR_AND: 
00175         case EXPR_IN:   if( ll ) goto eval; break;
00176         case EXPR_OR:   if( !ll ) goto eval; break;
00177         default: eval:  lr = parse_evaluate( parse->right, frame );
00178         }
00179 
00180         /* Now eval */
00181 
00182         switch( parse->num )
00183         {
00184         case EXPR_NOT:  
00185                 if( !ll ) status = 1;
00186                 break;
00187 
00188         case EXPR_AND:
00189                 if( ll && lr ) status = 1;
00190                 break;
00191 
00192         case EXPR_OR:
00193                 if( ll || lr ) status = 1;
00194                 break;
00195 
00196         case EXPR_IN:
00197                 /* "a in b": make sure each of */
00198                 /* ll is equal to something in lr. */
00199 
00200                 for( t = ll; t; t = list_next( t ) )
00201                 {
00202                     for( s = lr; s; s = list_next( s ) )
00203                         if( !strcmp( t->string, s->string ) )
00204                             break;
00205                     if( !s ) break;
00206                 }
00207 
00208                 /* No more ll? Success */
00209 
00210                 if( !t ) status = 1;
00211 
00212                 break;
00213 
00214         case EXPR_EXISTS:       if( lcmp( ll, L0 ) != 0 ) status = 1; break;
00215         case EXPR_EQUALS:       if( lcmp( ll, lr ) == 0 ) status = 1; break;
00216         case EXPR_NOTEQ:        if( lcmp( ll, lr ) != 0 ) status = 1; break;
00217         case EXPR_LESS:         if( lcmp( ll, lr ) < 0  ) status = 1; break;
00218         case EXPR_LESSEQ:       if( lcmp( ll, lr ) <= 0 ) status = 1; break;
00219         case EXPR_MORE:         if( lcmp( ll, lr ) > 0  ) status = 1; break;
00220         case EXPR_MOREEQ:       if( lcmp( ll, lr ) >= 0 ) status = 1; break;
00221 
00222         }
00223 
00224         if( DEBUG_IF )
00225         {
00226             debug_compile( 0, "if", frame );
00227             list_print( ll );
00228             printf( "(%d) ", status );
00229             list_print( lr );
00230             printf( "\n" );
00231         }
00232 
00233         /* Find something to return. */
00234         /* In odd circumstances (like "" = "") */
00235         /* we'll have to return a new string. */
00236 
00237         if( !status ) t = 0;
00238         else if( ll ) t = ll, ll = 0;
00239         else if( lr ) t = lr, lr = 0;
00240         else t = list_new( L0, newstr( "1" ) );
00241 
00242         if( ll ) list_free( ll );
00243         if( lr ) list_free( lr );
00244         return t;
00245 }

Here is the call graph for this function:

LIST* compile_foreach PARSE parse,
FRAME frame
 

Definition at line 260 of file compile.c.

References addsettings(), copystr(), FRAME, freesettings(), L0, _PARSE::left, LIST, list_free(), list_new(), list_next, _PARSE::num, PARSE, parse_evaluate(), popsettings(), pushsettings(), _PARSE::right, s, SETTINGS, _PARSE::string, _list::string, var_set(), and VAR_SET.

00263 {
00264     LIST    *nv = parse_evaluate( parse->left, frame );
00265     LIST    *l;
00266     SETTINGS *s = 0;
00267         
00268         if ( parse->num )
00269         {
00270             s = addsettings( s, 0, parse->string, L0 );
00271             pushsettings( s );
00272         }
00273 
00274     /* Call var_set to reset $(parse->string) for each val. */
00275 
00276     for( l = nv; l; l = list_next( l ) )
00277     {
00278         LIST *val = list_new( L0, copystr( l->string ) );
00279 
00280         var_set( parse->string, val, VAR_SET );
00281 
00282         list_free( parse_evaluate( parse->right, frame ) );
00283     }
00284 
00285         if ( parse->num )
00286         {
00287             popsettings( s );
00288             freesettings( s );
00289         }
00290 
00291     list_free( nv );
00292 
00293     return L0;
00294 }

Here is the call graph for this function:

LIST* compile_if PARSE p,
FRAME frame
 

Definition at line 305 of file compile.c.

References FRAME, _PARSE::left, LIST, list_free(), p, PARSE, parse_evaluate(), _PARSE::right, and _PARSE::third.

00308 {
00309     LIST *l = parse_evaluate( p->left, frame );
00310     if( l )
00311     {
00312         list_free( l );
00313         return parse_evaluate( p->right, frame );
00314     }
00315     else
00316     {
00317         return parse_evaluate( p->third, frame );
00318     }
00319 }

Here is the call graph for this function:

LIST* compile_include PARSE parse,
FRAME frame
 

Definition at line 345 of file compile.c.

References bindtarget(), _target::boundname, debug_compile(), FRAME, _PARSE::left, LIST, list_free(), list_print(), _target::name, PARSE, parse_evaluate(), parse_file(), popsettings(), pushsettings(), search(), _target::settings, _list::string, TARGET, and _target::time.

00348 {
00349     LIST    *nt = parse_evaluate( parse->left, frame );
00350 
00351     if( DEBUG_COMPILE )
00352     {
00353         debug_compile( 0, "include", frame);
00354         list_print( nt );
00355         printf( "\n" );
00356     }
00357 
00358     if( nt )
00359     {
00360         TARGET *t = bindtarget( nt->string );
00361 
00362             /* DWA 2001/10/22 - Perforce Jam clears the arguments here, which
00363              * prevents an included file from being treated as part of the body
00364              * of a rule. I didn't see any reason to do that, so I lifted the
00365              * restriction.
00366              */
00367                
00368         /* Bind the include file under the influence of */
00369         /* "on-target" variables.  Though they are targets, */
00370         /* include files are not built with make(). */
00371 
00372         pushsettings( t->settings );
00373         /* We don't expect that file to be included is generated by some
00374            action. Therefore, pass 0 as third argument. */
00375         t->boundname = search( t->name, &t->time, 0 );
00376         popsettings( t->settings );
00377 
00378         parse_file( t->boundname, frame );
00379     }
00380 
00381     list_free( nt );
00382 
00383     return L0;
00384 }

Here is the call graph for this function:

LIST* compile_list PARSE parse,
FRAME frame
 

Todo: check for empty class name.

Definition at line 456 of file compile.c.

References frame::args, FRAME, L0, PARSE, s, _PARSE::string, and var_expand().

00459 {
00460     /* voodoo 1 means: s is a copyable string */
00461     char *s = parse->string;
00462     return var_expand( L0, s, s + strlen( s ), frame->args, 1 );
00463 }

Here is the call graph for this function:

LIST* compile_local PARSE parse,
FRAME frame
 

Definition at line 474 of file compile.c.

References addsettings(), debug_compile(), FRAME, freesettings(), _PARSE::left, LIST, list_copy(), list_free(), list_next, list_print(), PARSE, parse_evaluate(), popsettings(), pushsettings(), _PARSE::right, s, SETTINGS, _list::string, and _PARSE::third.

00477 {
00478     LIST *l;
00479     SETTINGS *s = 0;
00480     LIST    *nt = parse_evaluate( parse->left, frame );
00481     LIST    *ns = parse_evaluate( parse->right, frame );
00482     LIST    *result;
00483 
00484     if( DEBUG_COMPILE )
00485     {
00486         debug_compile( 0, "local", frame);
00487         list_print( nt );
00488         printf( " = " );
00489         list_print( ns );
00490         printf( "\n" );
00491     }
00492 
00493     /* Initial value is ns */
00494 
00495     for( l = nt; l; l = list_next( l ) )
00496         s = addsettings( s, 0, l->string, list_copy( (LIST*)0, ns ) );
00497 
00498     list_free( ns );
00499     list_free( nt );
00500 
00501     /* Note that callees of the current context get this "local" */
00502     /* variable, making it not so much local as layered. */
00503 
00504     pushsettings( s );
00505     result = parse_evaluate( parse->third, frame );
00506     popsettings( s );
00507 
00508     freesettings( s );
00509 
00510     return result;
00511 }

Here is the call graph for this function:

LIST* compile_module PARSE p,
FRAME frame
 

Definition at line 412 of file compile.c.

References evaluate_in_module(), FRAME, _PARSE::left, LIST, list_free(), p, PARSE, parse_evaluate(), _PARSE::right, and _list::string.

00415 {
00416     /* Here we are entering a module declaration block. 
00417      */
00418     LIST* module_name = parse_evaluate( p->left, frame );
00419     LIST* result = evaluate_in_module( module_name ? module_name->string : 0, 
00420                                        p->right, frame );
00421     
00422     list_free( module_name );
00423     return result;
00424 }

Here is the call graph for this function:

LIST* compile_null PARSE parse,
FRAME frame
 

Definition at line 518 of file compile.c.

References FRAME, and PARSE.

00521 {
00522     return L0;
00523 }

LIST* compile_on PARSE parse,
FRAME frame
 

Definition at line 535 of file compile.c.

References bindtarget(), debug_compile(), FRAME, _PARSE::left, LIST, list_free(), list_print(), PARSE, parse_evaluate(), popsettings(), pushsettings(), _PARSE::right, _target::settings, _list::string, and TARGET.

00538 {
00539         LIST    *nt = parse_evaluate( parse->left, frame );
00540         LIST    *result = 0;
00541 
00542         if( DEBUG_COMPILE )
00543         {
00544             debug_compile( 0, "on", frame );
00545             list_print( nt );
00546             printf( "\n" );
00547         }
00548 
00549         if( nt )
00550         {
00551             TARGET *t = bindtarget( nt->string );
00552             pushsettings( t->settings );
00553 
00554             result = parse_evaluate( parse->right, frame );
00555 
00556             popsettings( t->settings );
00557         }
00558 
00559         list_free( nt );
00560 
00561         return result;
00562 }

Here is the call graph for this function:

LIST* compile_rule PARSE parse,
FRAME frame
 

Definition at line 575 of file compile.c.

References frame::args, evaluate_rule(), FRAME, frame_free(), frame_init(), _PARSE::left, LIST, lol_add(), frame::module, p, PARSE, parse_evaluate(), frame::prev, frame::procedure, _PARSE::right, and _PARSE::string.

00578 {
00579     FRAME       inner[1];
00580     LIST    *result;
00581     PARSE   *p;
00582     
00583 
00584     /* Build up the list of arg lists */
00585 
00586     frame_init( inner );
00587     inner->prev = frame;
00588     inner->module = frame->module; /* This gets fixed up in evaluate_rule(), below */
00589     inner->procedure = parse;
00590 
00591     for( p = parse->left; p; p = p->left )
00592         lol_add( inner->args, parse_evaluate( p->right, frame ) );
00593 
00594     /* And invoke rule */
00595 
00596     result = evaluate_rule( parse->string, inner );
00597 
00598     frame_free( inner );
00599 
00600     return result;
00601 }

Here is the call graph for this function:

LIST* compile_rules PARSE parse,
FRAME frame
 

Definition at line 1044 of file compile.c.

References FRAME, _PARSE::left, list_free(), PARSE, parse_evaluate(), and _PARSE::right.

01047 {
01048     /* Ignore result from first statement; return the 2nd. */
01049         /* Optimize recursion on the right by looping. */
01050 
01051     do list_free( parse_evaluate( parse->left, frame ) );
01052     while( (parse = parse->right)->func == compile_rules );
01053 
01054     return parse_evaluate( parse, frame );
01055 }

Here is the call graph for this function:

LIST* compile_set PARSE parse,
FRAME frame
 

Definition at line 1066 of file compile.c.

References ASSIGN_APPEND, ASSIGN_DEFAULT, ASSIGN_SET, debug_compile(), FRAME, L0, _PARSE::left, LIST, list_copy(), list_free(), list_next, list_print(), _PARSE::num, PARSE, parse_evaluate(), _PARSE::right, _list::string, and var_set().

01069 {
01070     LIST    *nt = parse_evaluate( parse->left, frame );
01071     LIST    *ns = parse_evaluate( parse->right, frame );
01072     LIST    *l;
01073     int     setflag;
01074     char    *trace;
01075 
01076     switch( parse->num )
01077     {
01078     case ASSIGN_SET:    setflag = VAR_SET; trace = "="; break;
01079     case ASSIGN_APPEND: setflag = VAR_APPEND; trace = "+="; break;
01080     case ASSIGN_DEFAULT:    setflag = VAR_DEFAULT; trace = "?="; break;
01081     default:        setflag = VAR_SET; trace = ""; break;
01082     }
01083 
01084     if( DEBUG_COMPILE )
01085     {
01086         debug_compile( 0, "set", frame);
01087         list_print( nt );
01088         printf( " %s ", trace );
01089         list_print( ns );
01090         printf( "\n" );
01091     }
01092 
01093     /* Call var_set to set variable */
01094     /* var_set keeps ns, so need to copy it */
01095 
01096     for( l = nt; l; l = list_next( l ) )
01097         var_set( l->string, list_copy( L0, ns ), setflag );
01098 
01099     list_free( nt );
01100 
01101     return ns;
01102 }

Here is the call graph for this function:

LIST* compile_setcomp PARSE parse,
FRAME frame
 

Definition at line 1113 of file compile.c.

References args_new(), argument_list::data, FRAME, _PARSE::left, lol_add(), frame::module, new_rule_body(), _PARSE::num, p, PARSE, parse_evaluate(), _PARSE::right, and _PARSE::string.

01116 {
01117     argument_list* arg_list = 0;
01118     
01119     /* Create new LOL describing argument requirements if supplied */
01120     if ( parse->right )
01121     {
01122         PARSE *p;
01123         arg_list = args_new();
01124         for( p = parse->right; p; p = p->left )
01125             lol_add( arg_list->data, parse_evaluate( p->right, frame ) );
01126     }
01127     
01128     new_rule_body( frame->module, parse->string, arg_list, parse->left, !parse->num );
01129     return L0;
01130 }

Here is the call graph for this function:

LIST* compile_setexec PARSE parse,
FRAME frame
 

Definition at line 1145 of file compile.c.

References FRAME, _PARSE::left, LIST, frame::module, new_rule_actions(), _PARSE::num, PARSE, parse_evaluate(), _PARSE::string, and _PARSE::string1.

01148 {
01149     LIST* bindlist = parse_evaluate( parse->left, frame );
01150 
01151     new_rule_actions( frame->module, parse->string, parse->string1, bindlist, parse->num );
01152 
01153     return L0;
01154 }

Here is the call graph for this function:

LIST* compile_settings PARSE parse,
FRAME frame
 

Definition at line 1166 of file compile.c.

References addsettings(), bindtarget(), debug_compile(), FRAME, _PARSE::left, LIST, list_copy(), list_free(), list_next, list_print(), _PARSE::num, PARSE, parse_evaluate(), _PARSE::right, _target::settings, _list::string, TARGET, and _PARSE::third.

01169 {
01170     LIST    *nt = parse_evaluate( parse->left, frame );
01171     LIST    *ns = parse_evaluate( parse->third, frame );
01172     LIST    *targets = parse_evaluate( parse->right, frame );
01173     LIST    *ts;
01174     int append = parse->num == ASSIGN_APPEND;
01175 
01176     if( DEBUG_COMPILE )
01177     {
01178         debug_compile( 0, "set", frame);
01179         list_print( nt );
01180         printf( " on " );
01181         list_print( targets );
01182         printf( " %s ", append ? "+=" : "=" );
01183         list_print( ns );
01184         printf( "\n" );
01185     }
01186 
01187     /* Call addsettings to save variable setting */
01188     /* addsettings keeps ns, so need to copy it */
01189     /* Pass append flag to addsettings() */
01190 
01191     for( ts = targets; ts; ts = list_next( ts ) )
01192     {
01193         TARGET  *t = bindtarget( ts->string );
01194         LIST    *l;
01195 
01196         for( l = nt; l; l = list_next( l ) )
01197         t->settings = addsettings( t->settings, append, 
01198                 l->string, list_copy( (LIST*)0, ns ) );
01199     }
01200 
01201     list_free( nt );
01202     list_free( targets );
01203 
01204     return ns;
01205 }

Here is the call graph for this function:

LIST* compile_switch PARSE parse,
FRAME frame
 

Definition at line 1221 of file compile.c.

References debug_compile(), FRAME, glob(), _PARSE::left, LIST, list_free(), list_print(), PARSE, parse_evaluate(), _PARSE::right, _PARSE::string, and _list::string.

01224 {
01225     LIST    *nt = parse_evaluate( parse->left, frame );
01226     LIST    *result = 0;
01227 
01228     if( DEBUG_COMPILE )
01229     {
01230         debug_compile( 0, "switch", frame);
01231         list_print( nt );
01232         printf( "\n" );
01233     }
01234 
01235     /* Step through cases */
01236 
01237     for( parse = parse->right; parse; parse = parse->right )
01238     {
01239         if( !glob( parse->left->string, nt ? nt->string : "" ) )
01240         {
01241         /* Get & exec parse tree for this case */
01242         parse = parse->left->left;
01243         result = parse_evaluate( parse, frame );
01244         break;
01245         }
01246     }
01247 
01248     list_free( nt );
01249 
01250     return result;
01251 }

Here is the call graph for this function:

LIST* compile_while PARSE p,
FRAME frame
 

Definition at line 322 of file compile.c.

References FRAME, _PARSE::left, LIST, list_free(), p, PARSE, parse_evaluate(), r, and _PARSE::right.

00325 {
00326     LIST *r = 0;
00327     LIST *l;
00328     while ( l = parse_evaluate( p->left, frame ) )
00329     {
00330         list_free( l );
00331         if( r ) list_free( r );
00332         r = parse_evaluate( p->right, frame );
00333     }
00334     return r;
00335 }

Here is the call graph for this function:

void debug_compile int  which,
char *  s,
FRAME frame
[static]
 

Definition at line 1258 of file compile.c.

References FRAME, i, indent(), print_source_line(), frame::procedure, and s.

Referenced by compile_eval(), compile_include(), compile_local(), compile_on(), compile_set(), compile_settings(), compile_switch(), and evaluate_rule().

01259 {
01260     static int level = 0;
01261     static char indent[36] = ">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|";
01262 
01263     if ( which >= 0 )
01264     {
01265       int i;
01266       
01267       print_source_line( frame->procedure );
01268       
01269       i = (level+1)*2;
01270       while ( i > 35 )
01271       {
01272         printf( indent );
01273         i -= 35;
01274       }
01275 
01276       printf( "%*.*s ", i, i, indent );
01277     }
01278 
01279     if( s )
01280         printf( "%s ", s );
01281 
01282     level += which;
01283 }

Here is the call graph for this function:

void dump_profile_entry void *  p_,
void *  ignored
[static]
 

Definition at line 875 of file compile.c.

References profile_info::cumulative, profile_info::name, profile_info::net, profile_info::num_entries, p, and profile_info.

Referenced by profile_dump().

00876 {
00877     profile_info* p = (profile_info*)p_;
00878     printf("%10d %10d %10d %s\n", p->cumulative, p->net, p->num_entries, p->name);
00879 }

LIST* evaluate_in_module char *  module_name,
PARSE p,
FRAME frame
[static]
 

Definition at line 386 of file compile.c.

References bindmodule(), enter_module(), exit_module(), FRAME, LIST, frame::module, p, PARSE, parse_evaluate(), and root_module().

Referenced by compile_class(), and compile_module().

00387 {
00388     LIST* result;
00389 
00390     module_t* outer_module = frame->module;
00391     frame->module = module_name ? bindmodule( module_name ) : root_module();
00392 
00393     if ( outer_module != frame->module )
00394     {
00395         exit_module( outer_module );
00396         enter_module( frame->module );
00397     }
00398     
00399     result = parse_evaluate( p, frame );
00400     
00401     if ( outer_module != frame->module )
00402     {
00403         exit_module( frame->module );
00404         enter_module( outer_module );
00405         frame->module = outer_module;
00406     }
00407 
00408     return result;
00409 }

Here is the call graph for this function:

LIST* evaluate_rule char *  rulename,
FRAME frame
 

Definition at line 895 of file compile.c.

References ACTION, actionlist(), _rule::actions, _target::actions, frame::args, backtrace(), backtrace_line(), bindrule(), collect_arguments(), debug_compile(), DEBUG_PROFILE, enter_module(), exit_module(), FRAME, freesettings(), L0, LIST, _lol::list, list_append(), list_pop_front(), LOL, lol_get(), lol_init(), lol_print(), frame::module, _rule::module, module_t::name, _rule::name, _targets::next, PARSE, parse_evaluate(), parse_free(), parse_refer(), popsettings(), frame::prev, _rule::procedure, profile_enter(), profile_exit(), profile_frame, pushsettings(), RULE, _action::rule, _PARSE::rulename, frame::rulename, SETTINGS, _list::string, _targets::target, targetlist(), TARGETS, and var_expand().

Referenced by call_bind_rule(), compile_rule(), headers(), and type_check().

00898 {
00899     LIST      *result = L0;
00900     RULE          *rule;
00901     profile_frame prof[1];
00902     module_t    *prev_module = frame->module;
00903     
00904     LIST      *l;
00905     {
00906         LOL arg_context_, *arg_context = &arg_context_;
00907         if ( !frame->prev )
00908             lol_init(arg_context);
00909         else
00910             arg_context = frame->prev->args;
00911         
00912         l = var_expand( L0, rulename, rulename+strlen(rulename), arg_context, 0 );
00913     }
00914 
00915     if ( !l )
00916     {
00917         backtrace_line( frame->prev );
00918         printf( "warning: rulename %s expands to empty string\n", rulename );
00919         backtrace( frame->prev );
00920         return result;
00921     }
00922 
00923     rulename = l->string;
00924     rule = bindrule( l->string, frame->module );
00925 
00926     /* drop the rule name */
00927     l = list_pop_front( l );
00928 
00929     /* tack the rest of the expansion onto the front of the first argument */
00930     frame->args->list[0] = list_append( l, lol_get( frame->args, 0 ) );
00931 
00932     if ( DEBUG_COMPILE )
00933     {
00934         /* Try hard to indicate in which module the rule is going to execute */
00935         if ( rule->module != frame->module
00936              && rule->procedure != 0 && strcmp(rulename, rule->procedure->rulename) )
00937         {
00938             char buf[256] = "";
00939             strncat( buf, rule->module->name, sizeof(buf) - 1 );
00940             strncat( buf, rule->name, sizeof(buf) - 1 );
00941             debug_compile( 1, buf, frame);
00942         }
00943         else
00944         {
00945             debug_compile( 1, rulename, frame);
00946         }
00947 
00948         lol_print( frame->args );
00949         printf( "\n" );
00950     }
00951     
00952     if ( rule->procedure && rule->module != prev_module )
00953     {
00954         /* propagate current module to nested rule invocations */
00955         frame->module = rule->module;
00956         
00957         /* swap variables */
00958         exit_module( prev_module );
00959         enter_module( rule->module );
00960     }
00961         
00962     /* record current rule name in frame */
00963     if ( rule->procedure )
00964     {
00965         frame->rulename = rulename;
00966         /* and enter record profile info */
00967         if ( DEBUG_PROFILE )
00968             profile_enter( rule->procedure->rulename, prof );
00969     }
00970 
00971     /* Check traditional targets $(<) and sources $(>) */
00972 
00973     if( !rule->actions && !rule->procedure )
00974     {
00975         backtrace_line( frame->prev );
00976         printf( "rule %s unknown in module %s\n", rule->name, frame->module->name );
00977         backtrace( frame->prev );
00978         exit(1);
00979     }
00980 
00981     /* If this rule will be executed for updating the targets */
00982     /* then construct the action for make(). */
00983 
00984     if( rule->actions )
00985     {
00986         TARGETS *t;
00987         ACTION  *action;
00988 
00989         /* The action is associated with this instance of this rule */
00990 
00991         action = (ACTION *)malloc( sizeof( ACTION ) );
00992         memset( (char *)action, '\0', sizeof( *action ) );
00993 
00994         action->rule = rule;
00995         action->targets = targetlist( (TARGETS *)0, lol_get( frame->args, 0 ) );
00996         action->sources = targetlist( (TARGETS *)0, lol_get( frame->args, 1 ) );
00997 
00998         /* Append this action to the actions of each target */
00999 
01000         for( t = action->targets; t; t = t->next )
01001             t->target->actions = actionlist( t->target->actions, action );
01002     }
01003 
01004     /* Now recursively compile any parse tree associated with this rule */
01005     /* refer/free to ensure rule not freed during use */
01006 
01007     if( rule->procedure )
01008     {
01009         SETTINGS *local_args = collect_arguments( rule, frame );
01010         PARSE *parse = rule->procedure;
01011         parse_refer( parse );
01012         
01013         pushsettings( local_args );
01014         result = parse_evaluate( parse, frame );
01015         popsettings( local_args );
01016         freesettings( local_args );
01017         
01018         parse_free( parse );
01019     }
01020 
01021     if ( frame->module != prev_module )
01022     {
01023         exit_module( frame->module );
01024         enter_module( prev_module );
01025     }
01026 
01027     if ( DEBUG_PROFILE && rule->procedure )
01028         profile_exit( prof );
01029 
01030     if( DEBUG_COMPILE )
01031         debug_compile( -1, 0, frame);
01032 
01033     return result;
01034 }

Here is the call graph for this function:

void frame_free FRAME frame  ) 
 

Definition at line 108 of file compile.c.

00109 {
00110     lol_free( frame->args );
00111 }

void frame_init FRAME frame  ) 
 

Definition at line 99 of file compile.c.

00100 {
00101     frame->prev = 0;
00102     lol_init(frame->args);
00103     frame->module = root_module();
00104     frame->rulename = "module scope";
00105     frame->procedure = 0;
00106 }

int glob char *  s,
char *  c
 

int is_type_name char *  s  )  [static]
 

Definition at line 629 of file compile.c.

References s, and TYPE_OPEN_DELIM.

Referenced by collect_arguments().

00630 {
00631     return s[0] == TYPE_OPEN_DELIM
00632         && s[strlen(s) - 1] == TYPE_CLOSE_DELIM;
00633 }

int lcmp LIST t,
LIST s
[static]
 

Definition at line 141 of file compile.c.

References LIST, list_next, s, and _list::string.

Referenced by compile_eval().

00142 {
00143         int status = 0;
00144 
00145         while( !status && ( t || s ) )
00146         {
00147             char *st = t ? t->string : "";
00148             char *ss = s ? s->string : "";
00149 
00150             status = strcmp( st, ss );
00151 
00152             t = t ? list_next( t ) : t;
00153             s = s ? list_next( s ) : s;
00154         }
00155 
00156         return status;
00157 }

void print_source_line PARSE p  ) 
 

Referenced by argument_error(), backtrace_line(), and debug_compile().

void profile_dump  ) 
 

Definition at line 881 of file compile.c.

References dump_profile_entry(), hashenumerate(), and profile_hash.

Referenced by main().

00882 {
00883     if ( profile_hash )
00884     {
00885         printf("%10s %10s %10s %s\n", "gross", "net", "# entries", "name");
00886         hashenumerate( profile_hash, dump_profile_entry, 0 );
00887     }
00888 }

Here is the call graph for this function:

void profile_enter char *  rulename,
profile_frame frame
[static]
 

Definition at line 823 of file compile.c.

References profile_frame::caller, profile_frame::entry_time, HASHDATA, hashenter, hashinit(), profile_frame::info, profile_info::name, profile_frame::overhead, p, profile_hash, profile_info, profile_stack, and profile_frame::subrules.

Referenced by evaluate_rule().

00824 {
00825     clock_t start = clock();
00826     profile_info info, *p = &info;
00827     
00828     if ( !profile_hash )
00829         profile_hash = hashinit(sizeof(profile_info), "profile");
00830 
00831     info.name = rulename;
00832     
00833     if ( hashenter( profile_hash, (HASHDATA **)&p ) )
00834         p->cumulative = p->net = p->num_entries = p->stack_count = 0;
00835 
00836     ++(p->num_entries);
00837     ++(p->stack_count);
00838     
00839     frame->info = p;
00840     
00841     frame->caller = profile_stack;
00842     profile_stack = frame;
00843 
00844     frame->entry_time = clock();
00845     frame->overhead = 0;
00846     frame->subrules = 0;
00847 
00848     /* caller pays for the time it takes to play with the hash table */
00849     if ( frame->caller )
00850         frame->caller->overhead += frame->entry_time - start;
00851 }

Here is the call graph for this function:

void profile_exit profile_frame frame  )  [static]
 

Definition at line 853 of file compile.c.

References profile_frame::caller, profile_info::cumulative, profile_frame::entry_time, profile_frame::info, profile_info::net, profile_frame::overhead, profile_stack, profile_info::stack_count, and profile_frame::subrules.

Referenced by evaluate_rule().

00854 {
00855     /* cumulative time for this call */
00856     clock_t t = clock() - frame->entry_time - frame->overhead;
00857     /* If this rule is already present on the stack, don't add the time for
00858        this instance. */
00859     if (frame->info->stack_count == 1)
00860         frame->info->cumulative += t;
00861     /* Net time does not depend on presense of the same rule in call stack. */
00862     frame->info->net += t - frame->subrules;
00863         
00864     if (frame->caller)
00865     {
00866         /* caller's cumulative time must account for this overhead */
00867         frame->caller->overhead += frame->overhead;
00868         frame->caller->subrules += t;
00869     }
00870     /* pop this stack frame */
00871     --frame->info->stack_count;
00872     profile_stack = frame->caller;
00873 }

void type_check char *  type_name,
LIST values,
FRAME caller,
RULE called,
LIST arg_name
[static]
 

Definition at line 665 of file compile.c.

References frame::args, argument_error(), bindmodule(), enter_module(), evaluate_rule(), exit_module(), FRAME, frame_free(), frame_init(), hashcheck, HASHDATA, L0, LIST, list_new(), lol_add(), frame::module, _rule::name, _list::next, frame::prev, RULE, module_t::rules, and _list::string.

Referenced by collect_arguments().

00666 {
00667     static module_t *typecheck = 0;
00668 
00669     /* if nothing to check, bail now */
00670     if ( !values || !type_name )
00671         return;
00672 
00673     if ( !typecheck )
00674         typecheck = bindmodule(".typecheck");
00675 
00676     /* if the checking rule can't be found, also bail */
00677     {
00678         RULE checker_, *checker = &checker_;
00679 
00680         checker->name = type_name;
00681         if ( !typecheck->rules || !hashcheck( typecheck->rules, (HASHDATA**)&checker ) )
00682             return;
00683     }
00684     
00685     exit_module( caller->module );
00686     
00687     while ( values != 0 )
00688     {
00689         LIST *error;
00690         FRAME frame[1];
00691         frame_init( frame );
00692         frame->module = typecheck;
00693         frame->prev = caller;
00694 
00695         enter_module( typecheck );
00696         /* Prepare the argument list */
00697         lol_add( frame->args, list_new( L0, values->string ) );
00698         error = evaluate_rule( type_name, frame );
00699         
00700         exit_module( typecheck );
00701         
00702         if ( error )
00703             argument_error( error->string, called, caller, arg_name );
00704 
00705         frame_free( frame );
00706                 values = values->next;
00707     }
00708 
00709     enter_module( caller->module );
00710 }

Here is the call graph for this function:


Variable Documentation

struct hash* profile_hash = 0 [static]
 

Definition at line 821 of file compile.c.

Referenced by profile_dump(), and profile_enter().

profile_frame* profile_stack = 0 [static]
 

Definition at line 820 of file compile.c.

Referenced by profile_enter(), and profile_exit().


Generated on Mon Nov 8 17:07:57 2004 for MPT by  doxygen 1.3.9.1