~arankine/distcc/issue16

« back to all changes in this revision

Viewing changes to include_server/parse_file.py

  • Committer: Alastair Rankine
  • Date: 2011-03-02 03:28:12 UTC
  • Revision ID: alastair@girtby.net-20110302032812-jnvtyon59neii1s3
Add ability to handle n-arity function macro called with macro returning an n-tuple (where n > 1).
Move override macro handling into macro_eval instead of parse_file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
# FOR SEARCHING AFTER /* .. */.
128
128
PAIRED_COMMENT_RE = re.compile(r"(/[*].*?[*]/)")
129
129
 
130
 
# Fixed macro definitions
131
 
# TODO: Make these configurable at runtime, perhaps by parsing an override file?
132
 
OVERRIDE_MACROS = {
133
 
  "BOOST_PP_CAT" : [ ( ['a', 'b'], "a ## b" ) ],
134
 
  "BOOST_PP_STRINGIZE" : [ ( ['text'], "#text" ) ],
135
 
  "BOOST_PP_ITERATE": [ ( [], "BOOST_PP_FILENAME_1" ), ( [], "BOOST_PP_FILENAME_2" ), \
136
 
                          ( [], "BOOST_PP_TUPLE_ELEM_3_2(BOOST_PP_TUPLE_ELEM_2_1(BOOST_PP_ITERATION_PARAMS_1))") ],
137
 
  "AUX778076_PREPROCESSED_HEADER" : [ "BOOST_MPL_CFG_COMPILER_DIR/BOOST_MPL_PREPROCESSED_HEADER" ],
138
 
  "AUX778076_INCLUDE_STRING" : [ "" ],
139
 
  "BOOST_MPL_CFG_COMPILER_DIR" : [ "gcc" ],
140
 
  "BOOST_COMPILER_CONFIG" : [ "boost/config/compiler/gcc.hpp" ],
141
 
  "BOOST_STDLIB_CONFIG" : [ "boost/config/stdlib/libstdcpp3.hpp"],
142
 
  "BOOST_PLATFORM_CONFIG" : [ "boost/config/platform/macos.hpp" ]
143
 
}
144
 
 
145
130
def InsertMacroDefInTable(lhs, rhs, symbol_table, callback_function):
146
131
  """Insert the definition of a pair (lhs, rhs) into symbol table.
147
132
 
155
140
  if m_expr.end(0) != len(lhs):
156
141
    raise NotCoveredError(
157
142
      "Unexpected macro definition with LHS: '%s'." % lhs)
158
 
  if m_expr.group('symbol') in OVERRIDE_MACROS:
 
143
  # Calculate the definition df, either
 
144
  # - a pair ([arg_1, .., arg_n], rhs) where arg_i is the
 
145
  #   i'th formal parameter (function-like macro definition), or
 
146
  # - just a symbol (object-like macro definition)
 
147
  if m_expr.group('args') != None:  # perhaps ''
 
148
    # A function-like macro definition.
 
149
    # Construct pair (list of formal parameters, rhs).
 
150
    args = [param.strip() for param in m_expr.group('args').split(',')]
 
151
    df = args, rhs
 
152
    # lhs is adjusted to be just the 'function' name
159
153
    lhs = m_expr.group('symbol')
160
 
    if lhs not in symbol_table:
161
 
      symbol_table[lhs] = OVERRIDE_MACROS[lhs]
162
 
      callback_function(lhs)
 
154
  else: # m_expr.group('args')
 
155
    # An object-like macro definition
 
156
    assert m_expr.group('symbol') == lhs
 
157
    df = rhs
 
158
  if lhs not in symbol_table:
 
159
    symbol_table[lhs] = [df]
163
160
  else:
164
 
    # Calculate the definition df, either
165
 
    # - a pair ([arg_1, .., arg_n], rhs) where arg_i is the
166
 
    #   i'th formal parameter (function-like macro definition), or
167
 
    # - just a symbol (object-like macro definition)
168
 
    if m_expr.group('args') != None:  # perhaps ''
169
 
      # A function-like macro definition.
170
 
      # Construct pair (list of formal parameters, rhs).
171
 
      args = [param.strip() for param in m_expr.group('args').split(',')]
172
 
      df = args, rhs
173
 
      # lhs is adjusted to be just the 'function' name
174
 
      lhs = m_expr.group('symbol')
175
 
    else: # m_expr.group('args')
176
 
      # An object-like macro definition
177
 
      assert m_expr.group('symbol') == lhs
178
 
      df = rhs
179
 
    if lhs not in symbol_table:
180
 
      symbol_table[lhs] = [df]
181
 
    else:
182
 
      symbol_table[lhs].append(df)
183
 
    callback_function(lhs)
 
161
    symbol_table[lhs].append(df)
 
162
  callback_function(lhs)
184
163
 
185
164
 
186
165
class ParseFile(object):