77from api .debug import __DEBUG__
88
99
10- class MacroCall (object ):
10+ DEBUG_LEVEL = 3 # Which -d level is required to show debug info
11+
12+
13+ class MacroCall :
1114 """ A call to a macro, stored in an object.
1215 Every time the macro() is called, the macro returns
1316 it value.
@@ -21,7 +24,8 @@ def __init__(self, lineno, table, id_, args=None):
2124 self .callargs = args
2225 self .lineno = lineno
2326
24- def eval (self , arg ):
27+ @staticmethod
28+ def eval (arg ):
2529 """ Evaluates a given argument. The token will be returned by default
2630 "as is", except if it's a macrocall. In such case it will be evaluated
2731 recursively.
@@ -31,41 +35,41 @@ def eval(self, arg):
3135 def __call__ (self , symbolTable = None ):
3236 """ Execute the macro call using LAZY evaluation
3337 """
34- __DEBUG__ ("evaluating '%s'" % self .id_ , 2 )
38+ __DEBUG__ ("evaluating '%s'" % self .id_ , DEBUG_LEVEL )
3539 if symbolTable is None :
3640 symbolTable = self .table
3741
3842 # The macro is not defined => returned as is
3943 if not self .is_defined (symbolTable ):
40- __DEBUG__ ("macro '%s' not defined" % self .id_ , 2 )
44+ __DEBUG__ ("macro '%s' not defined" % self .id_ , DEBUG_LEVEL )
4145 tmp = self .id_
4246 if self .callargs is not None :
4347 tmp += str (self .callargs )
44- __DEBUG__ ("evaluation result: %s" % tmp , 2 )
48+ __DEBUG__ ("evaluation result: %s" % tmp , DEBUG_LEVEL )
4549 return tmp
4650
4751 # The macro is defined
48- __DEBUG__ ("macro '%s' defined" % self .id_ , 2 )
52+ __DEBUG__ ("macro '%s' defined" % self .id_ , DEBUG_LEVEL )
4953 TABLE = copy .deepcopy (symbolTable )
5054 ID = TABLE [self .id_ ] # Get the defined macro
5155 if ID .hasArgs and self .callargs is None :
5256 return self .id_ # If no args passed, returned as is
5357
5458 if self .callargs : # has args. Evaluate them removing spaces
55- __DEBUG__ ("'%s' has args defined" % self .id_ , 2 )
59+ __DEBUG__ ("'%s' has args defined" % self .id_ , DEBUG_LEVEL )
5660 __DEBUG__ ("evaluating %i arg(s) for '%s'" %
57- (len (self .callargs ), self .id_ ), 2 )
61+ (len (self .callargs ), self .id_ ), DEBUG_LEVEL )
5862 args = [x (TABLE ).strip () for x in self .callargs ]
5963 __DEBUG__ ("macro call: %s%s" %
60- (self .id_ , '(' + ', ' .join (args ) + ')' ), 2 )
64+ (self .id_ , '(' + ', ' .join (args ) + ')' ), DEBUG_LEVEL )
6165
6266 if not ID .hasArgs : # The macro doesn't need args
63- __DEBUG__ ("'%s' has no args defined" % self .id_ , 2 )
67+ __DEBUG__ ("'%s' has no args defined" % self .id_ , DEBUG_LEVEL )
6468 tmp = ID (TABLE ) # If no args passed, returned as is
6569 if self .callargs is not None :
6670 tmp += '(' + ', ' .join (args ) + ')'
6771
68- __DEBUG__ ("evaluation result: %s" % tmp , 2 )
72+ __DEBUG__ ("evaluation result: %s" % tmp , DEBUG_LEVEL )
6973 return tmp
7074
7175 # Now ensure both args and callargs have the same length
@@ -75,14 +79,14 @@ def __call__(self, symbolTable=None):
7579 len (self .callargs )), self .lineno )
7680
7781 # Carry out unification
78- __DEBUG__ ('carrying out args unification' , 2 )
82+ __DEBUG__ ('carrying out args unification' , DEBUG_LEVEL )
7983 for i in range (len (self .callargs )):
80- __DEBUG__ ("arg '%s' = '%s'" % (ID .args [i ].name , args [i ]), 2 )
84+ __DEBUG__ ("arg '%s' = '%s'" % (ID .args [i ].name , args [i ]), DEBUG_LEVEL )
8185 TABLE .set (ID .args [i ].name , self .lineno , args [i ])
8286
8387 tmp = ID (TABLE )
8488 if '\n ' in tmp :
85- tmp += '\n #line %i\n ' % ( self .lineno )
89+ tmp += '\n #line %i\n ' % self .lineno
8690
8791 return tmp
8892
0 commit comments