/[m4]/m4/m4/macro.c
ViewVC logotype

Diff of /m4/m4/macro.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by gary, Thu Aug 16 22:21:30 2001 UTC revision 1.4 by gary, Sun Aug 19 10:53:56 2001 UTC
# Line 32  M4_GLOBAL_DATA int m4_expansion_level = Line 32  M4_GLOBAL_DATA int m4_expansion_level =
32  /* The number of the current call of expand_macro ().  */  /* The number of the current call of expand_macro ().  */
33  static int macro_call_id = 0;  static int macro_call_id = 0;
34    
35  /*----------------------------------------------------------------------.  /* This function read all input, and expands each token, one at a time.  */
 | This function read all input, and expands each token, one at a time.  |  
 `----------------------------------------------------------------------*/  
   
36  void  void
37  m4_expand_input (void)  m4_expand_input (void)
38  {  {
# Line 47  m4_expand_input (void) Line 44  m4_expand_input (void)
44  }  }
45    
46    
47  /*------------------------------------------------------------------------.  /* Expand one token, according to its type.  Potential macro names
48  | Expand one token, according to its type.  Potential macro names         |     (TOKEN_WORD) are looked up in the symbol table, to see if they have a
49  | (TOKEN_WORD) are looked up in the symbol table, to see if they have a   |     macro definition.  If they have, they are expanded as macros, otherwise
50  | macro definition.  If they have, they are expanded as macros, otherwise |     the text are just copied to the output.  */
 | the text are just copied to the output.                                 |  
 `------------------------------------------------------------------------*/  
   
51  static void  static void
52  expand_token (struct obstack *obs, m4_token_t t, m4_token_data *td)  expand_token (struct obstack *obs, m4_token_t t, m4_token_data *td)
53  {  {
# Line 102  expand_token (struct obstack *obs, m4_to Line 96  expand_token (struct obstack *obs, m4_to
96  }  }
97    
98    
99  /*-------------------------------------------------------------------------.  /* This function parses one argument to a macro call.  It expects the first
100  | This function parses one argument to a macro call.  It expects the first |     left parenthesis, or the separating comma to have been read by the
101  | left parenthesis, or the separating comma to have been read by the       |     caller.  It skips leading whitespace, and reads and expands tokens,
102  | caller.  It skips leading whitespace, and reads and expands tokens,      |     until it finds a comma or an right parenthesis at the same level of
103  | until it finds a comma or an right parenthesis at the same level of      |     parentheses.  It returns a flag indicating whether the argument read are
104  | parentheses.  It returns a flag indicating whether the argument read are |     the last for the active macro call.  The argument are build on the
105  | the last for the active macro call.  The argument are build on the       |     obstack OBS, indirectly through expand_token ().      */
 | obstack OBS, indirectly through expand_token ().                         |  
 `-------------------------------------------------------------------------*/  
   
106  static boolean  static boolean
107  expand_argument (struct obstack *obs, m4_token_data *argp)  expand_argument (struct obstack *obs, m4_token_data *argp)
108  {  {
# Line 191  INTERNAL ERROR: Bad token type in expand Line 182  INTERNAL ERROR: Bad token type in expand
182      }      }
183  }  }
184    
185  /*-------------------------------------------------------------------------.  /* Collect all the arguments to a call of the macro SYM.  The arguments are
186  | Collect all the arguments to a call of the macro SYM.  The arguments are |     stored on the obstack ARGUMENTS and a table of pointers to the arguments
187  | stored on the obstack ARGUMENTS and a table of pointers to the arguments |     on the obstack ARGPTR.  */
 | on the obstack ARGPTR.                                                   |  
 `-------------------------------------------------------------------------*/  
   
188  static void  static void
189  collect_arguments (m4_symbol *symbol, struct obstack *argptr,  collect_arguments (m4_symbol *symbol, struct obstack *argptr,
190                     struct obstack *arguments)                     struct obstack *arguments)
# Line 234  collect_arguments (m4_symbol *symbol, st Line 222  collect_arguments (m4_symbol *symbol, st
222  }  }
223    
224    
 /*-------------------------------------------------------------------.  
 | The actual call of a macro is handled by m4_call_macro ().         |  
 | m4_call_macro () is passed a symbol SYM, whose type is used to     |  
 | call either a builtin function, or the user macro expansion        |  
 | function expand_predefine () (lives in builtin.c).  There are ARGC |  
 | arguments to the call, stored in the ARGV table.  The expansion is |  
 | left on the obstack EXPANSION.  Macro tracing is also handled      |  
 | here.                                                              |  
 `-------------------------------------------------------------------*/  
225    
226    /* The actual call of a macro is handled by m4_call_macro ().
227       m4_call_macro () is passed a symbol SYM, whose type is used to
228       call either a builtin function, or the user macro expansion
229       function expand_predefine () (lives in builtin.c).  There are ARGC
230       arguments to the call, stored in the ARGV table.  The expansion is
231       left on the obstack EXPANSION.  Macro tracing is also handled here.  */
232  void  void
233  m4_call_macro (m4_symbol *symbol, int argc, m4_token_data **argv,  m4_call_macro (m4_symbol *symbol, int argc, m4_token_data **argv,
234                 struct obstack *expansion)                 struct obstack *expansion)
# Line 265  m4_call_macro (m4_symbol *symbol, int ar Line 250  m4_call_macro (m4_symbol *symbol, int ar
250      }      }
251  }  }
252    
253  /*-------------------------------------------------------------------------.  /* The macro expansion is handled by expand_macro ().  It parses the
254  | The macro expansion is handled by expand_macro ().  It parses the        |     arguments, using collect_arguments (), and builds a table of pointers to
255  | arguments, using collect_arguments (), and builds a table of pointers to |     the arguments.  The arguments themselves are stored on a local obstack.
256  | the arguments.  The arguments themselves are stored on a local obstack.  |     Expand_macro () uses call_macro () to do the call of the macro.
 | Expand_macro () uses call_macro () to do the call of the macro.          |  
 |                                                                          |  
 | Expand_macro () is potentially recursive, since it calls expand_argument |  
 | (), which might call expand_token (), which might call expand_macro ().  |  
 `-------------------------------------------------------------------------*/  
257    
258       Expand_macro () is potentially recursive, since it calls expand_argument
259       (), which might call expand_token (), which might call expand_macro ().  */
260  static void  static void
261  expand_macro (m4_symbol *symbol)  expand_macro (m4_symbol *symbol)
262  {  {
# Line 325  ERROR: Recursion limit of %d exceeded, u Line 307  ERROR: Recursion limit of %d exceeded, u
307    obstack_free (&argptr, NULL);    obstack_free (&argptr, NULL);
308  }  }
309    
310  /*-------------------------------------------------------------------------.  /* This function handles all expansion of user defined and predefined
311  | This function handles all expansion of user defined and predefined       |     macros.  It is called with an obstack OBS, where the macros expansion
312  | macros.  It is called with an obstack OBS, where the macros expansion    |     will be placed, as an unfinished object.  SYMBOL points to the macro
313  | will be placed, as an unfinished object.  SYMBOL points to the macro     |     definition, giving the expansion text.  ARGC and ARGV are the arguments,
314  | definition, giving the expansion text.  ARGC and ARGV are the arguments, |     as usual.  */
 | as usual.                                                                |  
 `-------------------------------------------------------------------------*/  
   
315  void  void
316  m4_process_macro (obs, symbol, argc, argv)  m4_process_macro (obs, symbol, argc, argv)
317       struct obstack *obs;       struct obstack *obs;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26