tools/disable_tests/gtest.py
def cc_format_condition(cond: Condition, add_brackets=False) -> str:
  """The reverse of canonicalise - produce a C++ expression for a Condition."""

  def bracket(s: str) -> str:
    return f"({s})" if add_brackets else s

  assert cond != conditions.ALWAYS
  assert cond != conditions.NEVER

  if isinstance(cond, conditions.Terminal):
    value = cond.gtest_info.name
    if cond.gtest_info.type == MACRO_TYPE:
      return f'defined({value})'
    if cond.gtest_info.type == BUILDFLAG_TYPE:
      return f'BUILDFLAG({value})'

    raise Exception(f"Don't know how to express condition '{cond}' in C++")

  assert isinstance(cond, tuple)

  # TODO: Avoid redundant brackets? We probably want to keep them even when
  # redundant in most cases, but !(defined(X)) should be !defined(X).
  op, args = cond
  if op == 'not':
    return f'!({cc_format_condition(args)})'
  if op == 'and':
    return bracket(' && '.join(cc_format_condition(arg, True) for arg in args))
  if op == 'or':
    return bracket(' || '.join(cc_format_condition(arg, True) for arg in args))

  raise Exception(f'Unknown op "{op}"')
The reverse of canonicalise - produce a C++ expression for a Condition.
The reverse of canonicalise - produce a C++ expression for a Condition.
The reverse of canonicalise - produce a C ++ expression for a Condition .
def cc_format_condition(cond: Condition, add_brackets=False) -> str:
  def bracket(s: str) -> str:
    return f"({s})" if add_brackets else s
  assert cond != conditions.ALWAYS
  assert cond != conditions.NEVER
  if isinstance(cond, conditions.Terminal):
    value = cond.gtest_info.name
    if cond.gtest_info.type == MACRO_TYPE:
      return f'defined({value})'
    if cond.gtest_info.type == BUILDFLAG_TYPE:
      return f'BUILDFLAG({value})'
    raise Exception(f"Don't know how to express condition '{cond}' in C++")
  assert isinstance(cond, tuple)
  op, args = cond
  if op == 'not':
    return f'!({cc_format_condition(args)})'
  if op == 'and':
    return bracket(' && '.join(cc_format_condition(arg, True) for arg in args))
  if op == 'or':
    return bracket(' || '.join(cc_format_condition(arg, True) for arg in args))
  raise Exception(f'Unknown op "{op}"')
def cc_format_condition ( cond : Condition , add_brackets = False ) -> str : def bracket ( s : str ) -> str : return f"({s})" if add_brackets else s assert cond != conditions . ALWAYS assert cond != conditions . NEVER if isinstance ( cond , conditions . Terminal ) : value = cond . gtest_info . name if cond . gtest_info . type == MACRO_TYPE : return f'defined({value})' if cond . gtest_info . type == BUILDFLAG_TYPE : return f'BUILDFLAG({value})' raise Exception ( f"Don't know how to express condition '{cond}' in C++" ) assert isinstance ( cond , tuple ) op , args = cond if op == 'not' : return f'!({cc_format_condition(args)})' if op == 'and' : return bracket ( ' && ' . join ( cc_format_condition ( arg , True ) for arg in args ) ) if op == 'or' : return bracket ( ' || ' . join ( cc_format_condition ( arg , True ) for arg in args ) ) raise Exception ( f'Unknown op "{op}"' )
The reverse of canonicalise - produce a C++ expression for a Condition.
The reverse of canonicalise - produce a C ++ expression for a Condition .
"""The reverse of canonicalise - produce a C++ expression for a Condition.""" # TODO: Avoid redundant brackets? We probably want to keep them even when # redundant in most cases, but !(defined(X)) should be !defined(X).
cond
Condition
add_brackets