Example #1
0
 def setUp(self):
     self.expression_parser = expression_parser.expression_parser()
     self.expression_evaluator = mock.MagicMock()
     self.macro_expander = macro_expander.MacroExpander(
         self.expression_parser,
         self.expression_evaluator,
     )
Example #2
0
def _if_expression():
  expression = expression_parser.expression_parser()
  expression.ignore(pyparsing.cppStyleComment)
  return (
      _IF
      + _parse_to_line_end(expression)
  )
Example #3
0
def _bit_field():
  expression = expression_parser.expression_parser()
  return (
      pyparsing.Optional(_identifier(), None)
      + _COLON
      + pyparsing.SkipTo(_SEMICOLON | _COMA)
  ).setParseAction(_construct_bitfield(expression))
Example #4
0
def _elif_block(elements):
  expression = expression_parser.expression_parser()
  return (
      _ELIF
      + pyparsing.restOfLine
      + elements
  ).setParseAction(_construct_elif_block(expression))
Example #5
0
 def setUp(self):
   self.expression_parser = expression_parser.expression_parser()
   self.expression_evaluator = mock.MagicMock()
   self.macro_expander = macro_expander.MacroExpander(
       self.expression_parser,
       self.expression_evaluator,
   )
Example #6
0
def _elif_block(content):
  expression = expression_parser.expression_parser()
  expression.ignore(pyparsing.cppStyleComment)
  return (
      _ELIF
      + _parse_to_line_end(expression)
      + content
  ).setParseAction(util.action(pre_ast.ConditionalBlock))
Example #7
0
def _attribute_aligned():
  expression = expression_parser.expression_parser()
  return (
      _attribute_name('aligned')
      + _OPEN_PARENTHESIS
      + _anything_beetween('()')
      + _CLOSE_PARENTHESIS
  ).setParseAction(_create_aligned(expression))
Example #8
0
def _replacement_list():
  element = (
      expression_parser.expression_parser()
      | _semicolon()
  )
  expressions = pyparsing.Group(
      pyparsing.OneOrMore(element)
  ).setParseAction(_create_single_or_composite_block)
  expressions.ignore(pyparsing.cppStyleComment)
  return expressions
Example #9
0
def _get_preprocessor(config_flags):
  """A function that is a factory for preprocessor object."""
  object_like_macros = _get_object_like_macros(config_flags)

  function_like_macros = {}

  preprocessor_and_64bit_functions = (
      functions.get_preprocessor_and_64bit_functions()
  )

  lazy_and_state_dependent_functions = (
      lazy_functions.get_lazy_and_state_dependent_functions(
          object_like_macros,
          function_like_macros,
      )
  )

  macro_expression_evaluator = (
      macro_expression_evaluator_visitor.MacroExpressionEvaluatorVisitor(
          object_likes=object_like_macros,
          function_likes=function_like_macros,
          functions=preprocessor_and_64bit_functions,
          lazy_functions=lazy_and_state_dependent_functions,
      )
  )

  state_dependent_functions = lazy_functions.get_state_dependent_functions(
      object_like_macros,
      function_like_macros,
  )

  expression_parser_ = expression_parser.expression_parser()
  term_expression_evaluator = (
      macro_expression_evaluator_visitor.MacroExpressionEvaluatorVisitor(
          object_likes=object_like_macros,
          function_likes=function_like_macros,
          functions=functions.get_preprocessor_functions(),
          lazy_functions=state_dependent_functions,
          keep_parentheses=True,
      )
  )

  macro_expander_ = macro_expander.MacroExpander(
      expression_parser=expression_parser_,
      expression_evaluator=term_expression_evaluator,
  )

  return preprocessing_visitor.PreprocessingVisitor(
      object_likes=object_like_macros,
      function_likes=function_like_macros,
      functions=preprocessor_and_64bit_functions,
      expression_evaluator=macro_expression_evaluator,
      macro_expander=macro_expander_,
  )
Example #10
0
def _array_type_instance(type_instance_constructor):
  brackets_with_expression_inside = (
      _OPEN_BRACKET
      + (~_CLOSE_BRACKET)
      + pyparsing.SkipTo(_CLOSE_BRACKET)
      + _CLOSE_BRACKET
  )
  expression = expression_parser.expression_parser()
  return (
      _simple_type_instance(type_instance_constructor)
      + pyparsing.OneOrMore(brackets_with_expression_inside)
  ).setParseAction(_insert_array_type_definitions(expression))
Example #11
0
def _pragma_argument():
  expression = expression_parser.expression_parser()
  expression.ignore(pyparsing.cppStyleComment)
  arguments = pyparsing.Group(
      _OPEN_PARENTHESES
      + _maybe_empty_delimited_list(expression)
      + _CLOSE_PARENTHESES
  )
  value_assignment = _EQUALS + expression
  return (
      (_identifier() | pyparsing.dblQuotedString)
      + pyparsing.Optional(arguments, None)
      + pyparsing.Optional(value_assignment, None)
  ).setParseAction(util.action(pre_ast.PragmaArgument))
Example #12
0
def _get_preprocessor(config_flags):
    """A function that is a factory for preprocessor object."""
    object_like_macros = _get_object_like_macros(config_flags)

    function_like_macros = {}

    preprocessor_and_64bit_functions = (
        functions.get_preprocessor_and_64bit_functions())

    lazy_and_state_dependent_functions = (
        lazy_functions.get_lazy_and_state_dependent_functions(
            object_like_macros,
            function_like_macros,
        ))

    macro_expression_evaluator = (
        macro_expression_evaluator_visitor.MacroExpressionEvaluatorVisitor(
            object_likes=object_like_macros,
            function_likes=function_like_macros,
            functions=preprocessor_and_64bit_functions,
            lazy_functions=lazy_and_state_dependent_functions,
        ))

    state_dependent_functions = lazy_functions.get_state_dependent_functions(
        object_like_macros,
        function_like_macros,
    )

    expression_parser_ = expression_parser.expression_parser()
    term_expression_evaluator = (
        macro_expression_evaluator_visitor.MacroExpressionEvaluatorVisitor(
            object_likes=object_like_macros,
            function_likes=function_like_macros,
            functions=functions.get_preprocessor_functions(),
            lazy_functions=state_dependent_functions,
            keep_parentheses=True,
        ))

    macro_expander_ = macro_expander.MacroExpander(
        expression_parser=expression_parser_,
        expression_evaluator=term_expression_evaluator,
    )

    return preprocessing_visitor.PreprocessingVisitor(
        object_likes=object_like_macros,
        function_likes=function_like_macros,
        functions=preprocessor_and_64bit_functions,
        expression_evaluator=macro_expression_evaluator,
        macro_expander=macro_expander_,
    )
 def setUp(self):
   self.parser = expression_parser.expression_parser()
   self.unary_operators = '+', '-', '!', '~'
   self.binary_operators = (
       '##',
       '*', '/', '%',
       '+', '-',
       '<<', '>>',
       '<', '<=', '>', '>=',
       '==', '!=',
       '&',
       '^',
       '|',
       '&&',
       '||',
   )
Example #14
0
 def setUp(self):
     self.parser = expression_parser.expression_parser()
     self.unary_operators = '+', '-', '!', '~'
     self.binary_operators = (
         '##',
         '*',
         '/',
         '%',
         '+',
         '-',
         '<<',
         '>>',
         '<',
         '<=',
         '>',
         '>=',
         '==',
         '!=',
         '&',
         '^',
         '|',
         '&&',
         '||',
     )
Example #15
0
def _if_expression():
  expression = expression_parser.expression_parser()
  return (
      _IF
      + pyparsing.restOfLine
  ).setParseAction(_create_if_expression(expression))