zetasql/resolved_ast/gen_resolved_ast.py
def Field(name,
          ctype,
          tag_id,
          vector=False,
          ignorable=NOT_IGNORABLE,
          is_constructor_arg=True,
          to_string_method=None,
          java_to_string_method=None,
          comment=None,
          propagate_order=False):
  """Make a field to put in a node class.

  Args:
    name: field name
    ctype: c++ type for this field
           Should be a ScalarType like an int, string or enum type,
           or the name of a node class type (e.g. ResolvedProjectScan).
           Cannot be a pointer type, and should not include modifiers like
           const.
    tag_id: unique tag number for the proto field. This should never change or
            be reused.
    vector: True if this field is a vector of ctype. (Not supported for
            scalars.)
    ignorable: one of the IGNORABLE enums above.
    is_constructor_arg: True if this field should be in the constructor's
                        argument list.
    to_string_method: Override the default ToStringImpl method used to print
                      this object.
    java_to_string_method: Override the default to_string_method method used for
                           java.
    comment: Comment text for this field.  Text will be stripped and
             de-indented.
    propagate_order: If true, this field and the parent node must both be
                     ResolvedScan subclasses, and the is_ordered property of
                     the field will be propagated to the containing scan.
  Returns:
    The newly created field.
  """
  assert tag_id > 1, tag_id
  assert ignorable in (IGNORABLE, NOT_IGNORABLE, IGNORABLE_DEFAULT)
  member_name = name + '_'

  if vector:
    assert name.endswith('_list') or name.endswith('_path'), (
        'Vector fields should normally be named <x>_list or <x>_path: %s' %
        name)

  # C++ code requires a large number of variations of the same type declaration.
  # These are:
  #   member_type - type of the class member
  #   member_accessor - get the member variable, unwrapping unique_ptr if needed
  #   setter_arg_type - type when passed to constructor or setter method.
  #   maybe_ptr_setter_arg_type - type when passed to constructor or setter
  #                               method as a bare pointer which transfers
  #                               ownership.
  #   getter_return_type - type returned from a getter method
  #   release_return_type - type returned from a release method, or None to
  #                         indicate there should be no release() method.
  #   element_arg_type - for vectors, the element type for get/set methods
  #   element_storage_type - for vectors, the type inside the vector.
  #   element_unwrapper - '.get()', if necessary, to unwrap unique_ptrs.
  #   is_move_only - setters must use std::move instead of assign/copy as
  #                  for anything wrapped in a unique_ptr/vector<unique_ptr>.
  if isinstance(ctype, ScalarType):
    is_node_type = False
    member_type = ctype.ctype
    proto_type = ctype.proto_type
    has_proto_setter = ctype.has_proto_setter
    java_default = ctype.java_default
    nullable_java_type = ctype.java_reference_type
    member_accessor = member_name
    element_arg_type = None
    element_storage_type = None
    element_unwrapper = ''
    release_return_type = None
    is_enum = ctype.is_enum
    is_move_only = False

    if ctype.passed_by_reference:
      setter_arg_type = 'const %s&' % member_type
      getter_return_type = 'const %s&' % member_type
    else:
      setter_arg_type = member_type
      getter_return_type = ctype.ctype

    if vector:
      element_arg_type = ctype.ctype
      element_storage_type = ctype.ctype
      member_type = 'std::vector<%s>' % ctype.ctype
      setter_arg_type = 'const %s&' % member_type
      getter_return_type = setter_arg_type
      java_type = ctype.java_reference_type
      java_default = 'ImmutableList.of()'
    else:
      java_type = ctype.java_type
      java_default = ctype.java_default

    # For scalars, these are always the same
    maybe_ptr_setter_arg_type = setter_arg_type

  else:
    # Non-scalars should all be node types (possibly node vectors).
    assert 'const' not in ctype, ctype
    assert '*' not in ctype, ctype
    assert ctype.startswith(NODE_NAME_PREFIX)
    is_node_type = True
    has_proto_setter = False
    element_pointer_type = 'const %s*' % ctype
    element_storage_type = 'std::unique_ptr<const %s>' % ctype
    element_unwrapper = '.get()'
    proto_type = '%sProto' % ctype
    java_type = ctype
    nullable_java_type = ctype
    java_default = None
    is_enum = False
    is_move_only = True
    if vector:
      element_arg_type = element_pointer_type
      member_type = 'std::vector<%s>' % element_storage_type
      maybe_ptr_setter_arg_type = (
          'const std::vector<%s>&' % element_pointer_type)
      getter_return_type = 'const %s&' % member_type
      release_return_type = 'std::vector<%s>' % element_pointer_type
      member_accessor = member_name
      java_default = 'ImmutableList.of()'
    else:
      member_type = element_storage_type
      maybe_ptr_setter_arg_type = element_pointer_type
      getter_return_type = element_pointer_type
      release_return_type = element_pointer_type
      element_arg_type = None
      element_storage_type = None
      member_accessor = member_name + '.get()'
      java_default = None

    # For node vector, we use std::move, which requires setters = member.
    setter_arg_type = member_type

  if vector:
    optional_or_repeated = 'repeated'
    full_java_type = 'ImmutableList<%s>' % java_type
    nullable_java_type = full_java_type
  else:
    optional_or_repeated = 'optional'
    full_java_type = java_type

  if not to_string_method:
    to_string_method = 'ToStringImpl'
  if not java_to_string_method:
    java_to_string_method = to_string_method[0].lower() + to_string_method[1:]

  if is_enum:
    scoped_setter_arg_type = ctype.scoped_ctype
  else:
    scoped_setter_arg_type = setter_arg_type

  if (not is_constructor_arg) and java_default is None:
    logging.fatal(
        'Field %s must either be a constructor arg, or have a java_default. ctype:\n%s',
        name, ctype)

  return {
      'ctype': ctype,
      'java_type': java_type,
      'full_java_type': full_java_type,
      'nullable_java_type': nullable_java_type,
      'java_default': java_default,
      'tag_id': tag_id,
      'member_name': member_name,  # member variable name
      'name': name,  # name without trailing underscore
      'comment': _CleanComment(comment, prefix='  // '),
      'javadoc': _JavaDoc(comment, indent=4),
      'member_accessor': member_accessor,
      'member_type': member_type,
      'proto_type': proto_type,
      'optional_or_repeated': optional_or_repeated,
      'has_proto_setter': has_proto_setter,
      'setter_arg_type': setter_arg_type,
      'maybe_ptr_setter_arg_type': maybe_ptr_setter_arg_type,
      'scoped_setter_arg_type': scoped_setter_arg_type,
      'getter_return_type': getter_return_type,
      'release_return_type': release_return_type,
      'is_vector': vector,
      'element_arg_type': element_arg_type,
      'element_storage_type': element_storage_type,
      'element_unwrapper': element_unwrapper,
      'is_node_ptr': is_node_type and not vector,
      'is_node_vector': is_node_type and vector,
      'is_enum_vector': is_enum and vector,
      'is_move_only': is_move_only,
      'is_not_ignorable': ignorable == NOT_IGNORABLE,
      'is_ignorable_default': ignorable == IGNORABLE_DEFAULT,
      'is_constructor_arg': is_constructor_arg,
      'to_string_method': to_string_method,
      'java_to_string_method': java_to_string_method,
      'propagate_order': propagate_order
  }
Make a field to put in a node class.

  Args:
    name: field name
    ctype: c++ type for this field
           Should be a ScalarType like an int, string or enum type,
           or the name of a node class type (e.g. ResolvedProjectScan).
           Cannot be a pointer type, and should not include modifiers like
           const.
    tag_id: unique tag number for the proto field. This should never change or
            be reused.
    vector: True if this field is a vector of ctype. (Not supported for
            scalars.)
    ignorable: one of the IGNORABLE enums above.
    is_constructor_arg: True if this field should be in the constructor's
                        argument list.
    to_string_method: Override the default ToStringImpl method used to print
                      this object.
    java_to_string_method: Override the default to_string_method method used for
                           java.
    comment: Comment text for this field.  Text will be stripped and
             de-indented.
    propagate_order: If true, this field and the parent node must both be
                     ResolvedScan subclasses, and the is_ordered property of
                     the field will be propagated to the containing scan.
  Returns:
    The newly created field.
  
Make a field to put in a node class.
Make a field to put in a node class .
def Field(name,
          ctype,
          tag_id,
          vector=False,
          ignorable=NOT_IGNORABLE,
          is_constructor_arg=True,
          to_string_method=None,
          java_to_string_method=None,
          comment=None,
          propagate_order=False):
  assert tag_id > 1, tag_id
  assert ignorable in (IGNORABLE, NOT_IGNORABLE, IGNORABLE_DEFAULT)
  member_name = name + '_'
  if vector:
    assert name.endswith('_list') or name.endswith('_path'), (
        'Vector fields should normally be named <x>_list or <x>_path: %s' %
        name)
  if isinstance(ctype, ScalarType):
    is_node_type = False
    member_type = ctype.ctype
    proto_type = ctype.proto_type
    has_proto_setter = ctype.has_proto_setter
    java_default = ctype.java_default
    nullable_java_type = ctype.java_reference_type
    member_accessor = member_name
    element_arg_type = None
    element_storage_type = None
    element_unwrapper = ''
    release_return_type = None
    is_enum = ctype.is_enum
    is_move_only = False
    if ctype.passed_by_reference:
      setter_arg_type = 'const %s&' % member_type
      getter_return_type = 'const %s&' % member_type
    else:
      setter_arg_type = member_type
      getter_return_type = ctype.ctype
    if vector:
      element_arg_type = ctype.ctype
      element_storage_type = ctype.ctype
      member_type = 'std::vector<%s>' % ctype.ctype
      setter_arg_type = 'const %s&' % member_type
      getter_return_type = setter_arg_type
      java_type = ctype.java_reference_type
      java_default = 'ImmutableList.of()'
    else:
      java_type = ctype.java_type
      java_default = ctype.java_default
    maybe_ptr_setter_arg_type = setter_arg_type
  else:
    assert 'const' not in ctype, ctype
    assert '*' not in ctype, ctype
    assert ctype.startswith(NODE_NAME_PREFIX)
    is_node_type = True
    has_proto_setter = False
    element_pointer_type = 'const %s*' % ctype
    element_storage_type = 'std::unique_ptr<const %s>' % ctype
    element_unwrapper = '.get()'
    proto_type = '%sProto' % ctype
    java_type = ctype
    nullable_java_type = ctype
    java_default = None
    is_enum = False
    is_move_only = True
    if vector:
      element_arg_type = element_pointer_type
      member_type = 'std::vector<%s>' % element_storage_type
      maybe_ptr_setter_arg_type = (
          'const std::vector<%s>&' % element_pointer_type)
      getter_return_type = 'const %s&' % member_type
      release_return_type = 'std::vector<%s>' % element_pointer_type
      member_accessor = member_name
      java_default = 'ImmutableList.of()'
    else:
      member_type = element_storage_type
      maybe_ptr_setter_arg_type = element_pointer_type
      getter_return_type = element_pointer_type
      release_return_type = element_pointer_type
      element_arg_type = None
      element_storage_type = None
      member_accessor = member_name + '.get()'
      java_default = None
    setter_arg_type = member_type
  if vector:
    optional_or_repeated = 'repeated'
    full_java_type = 'ImmutableList<%s>' % java_type
    nullable_java_type = full_java_type
  else:
    optional_or_repeated = 'optional'
    full_java_type = java_type
  if not to_string_method:
    to_string_method = 'ToStringImpl'
  if not java_to_string_method:
    java_to_string_method = to_string_method[0].lower() + to_string_method[1:]
  if is_enum:
    scoped_setter_arg_type = ctype.scoped_ctype
  else:
    scoped_setter_arg_type = setter_arg_type
  if (not is_constructor_arg) and java_default is None:
    logging.fatal(
        'Field %s must either be a constructor arg, or have a java_default. ctype:\n%s',
        name, ctype)
  return {
      'ctype': ctype,
      'java_type': java_type,
      'full_java_type': full_java_type,
      'nullable_java_type': nullable_java_type,
      'java_default': java_default,
      'tag_id': tag_id,
      'member_name': member_name,  
      'name': name,  
      'comment': _CleanComment(comment, prefix='  // '),
      'javadoc': _JavaDoc(comment, indent=4),
      'member_accessor': member_accessor,
      'member_type': member_type,
      'proto_type': proto_type,
      'optional_or_repeated': optional_or_repeated,
      'has_proto_setter': has_proto_setter,
      'setter_arg_type': setter_arg_type,
      'maybe_ptr_setter_arg_type': maybe_ptr_setter_arg_type,
      'scoped_setter_arg_type': scoped_setter_arg_type,
      'getter_return_type': getter_return_type,
      'release_return_type': release_return_type,
      'is_vector': vector,
      'element_arg_type': element_arg_type,
      'element_storage_type': element_storage_type,
      'element_unwrapper': element_unwrapper,
      'is_node_ptr': is_node_type and not vector,
      'is_node_vector': is_node_type and vector,
      'is_enum_vector': is_enum and vector,
      'is_move_only': is_move_only,
      'is_not_ignorable': ignorable == NOT_IGNORABLE,
      'is_ignorable_default': ignorable == IGNORABLE_DEFAULT,
      'is_constructor_arg': is_constructor_arg,
      'to_string_method': to_string_method,
      'java_to_string_method': java_to_string_method,
      'propagate_order': propagate_order
  }
def Field ( name , ctype , tag_id , vector = False , ignorable = NOT_IGNORABLE , is_constructor_arg = True , to_string_method = None , java_to_string_method = None , comment = None , propagate_order = False ) : assert tag_id > 1 , tag_id assert ignorable in ( IGNORABLE , NOT_IGNORABLE , IGNORABLE_DEFAULT ) member_name = name + '_' if vector : assert name . endswith ( '_list' ) or name . endswith ( '_path' ) , ( 'Vector fields should normally be named <x>_list or <x>_path: %s' % name ) if isinstance ( ctype , ScalarType ) : is_node_type = False member_type = ctype . ctype proto_type = ctype . proto_type has_proto_setter = ctype . has_proto_setter java_default = ctype . java_default nullable_java_type = ctype . java_reference_type member_accessor = member_name element_arg_type = None element_storage_type = None element_unwrapper = '' release_return_type = None is_enum = ctype . is_enum is_move_only = False if ctype . passed_by_reference : setter_arg_type = 'const %s&' % member_type getter_return_type = 'const %s&' % member_type else : setter_arg_type = member_type getter_return_type = ctype . ctype if vector : element_arg_type = ctype . ctype element_storage_type = ctype . ctype member_type = 'std::vector<%s>' % ctype . ctype setter_arg_type = 'const %s&' % member_type getter_return_type = setter_arg_type java_type = ctype . java_reference_type java_default = 'ImmutableList.of()' else : java_type = ctype . java_type java_default = ctype . java_default maybe_ptr_setter_arg_type = setter_arg_type else : assert 'const' not in ctype , ctype assert '*' not in ctype , ctype assert ctype . startswith ( NODE_NAME_PREFIX ) is_node_type = True has_proto_setter = False element_pointer_type = 'const %s*' % ctype element_storage_type = 'std::unique_ptr<const %s>' % ctype element_unwrapper = '.get()' proto_type = '%sProto' % ctype java_type = ctype nullable_java_type = ctype java_default = None is_enum = False is_move_only = True if vector : element_arg_type = element_pointer_type member_type = 'std::vector<%s>' % element_storage_type maybe_ptr_setter_arg_type = ( 'const std::vector<%s>&' % element_pointer_type ) getter_return_type = 'const %s&' % member_type release_return_type = 'std::vector<%s>' % element_pointer_type member_accessor = member_name java_default = 'ImmutableList.of()' else : member_type = element_storage_type maybe_ptr_setter_arg_type = element_pointer_type getter_return_type = element_pointer_type release_return_type = element_pointer_type element_arg_type = None element_storage_type = None member_accessor = member_name + '.get()' java_default = None setter_arg_type = member_type if vector : optional_or_repeated = 'repeated' full_java_type = 'ImmutableList<%s>' % java_type nullable_java_type = full_java_type else : optional_or_repeated = 'optional' full_java_type = java_type if not to_string_method : to_string_method = 'ToStringImpl' if not java_to_string_method : java_to_string_method = to_string_method [ 0 ] . lower ( ) + to_string_method [ 1 : ] if is_enum : scoped_setter_arg_type = ctype . scoped_ctype else : scoped_setter_arg_type = setter_arg_type if ( not is_constructor_arg ) and java_default is None : logging . fatal ( 'Field %s must either be a constructor arg, or have a java_default. ctype:\n%s' , name , ctype ) return { 'ctype' : ctype , 'java_type' : java_type , 'full_java_type' : full_java_type , 'nullable_java_type' : nullable_java_type , 'java_default' : java_default , 'tag_id' : tag_id , 'member_name' : member_name , 'name' : name , 'comment' : _CleanComment ( comment , prefix = '  // ' ) , 'javadoc' : _JavaDoc ( comment , indent = 4 ) , 'member_accessor' : member_accessor , 'member_type' : member_type , 'proto_type' : proto_type , 'optional_or_repeated' : optional_or_repeated , 'has_proto_setter' : has_proto_setter , 'setter_arg_type' : setter_arg_type , 'maybe_ptr_setter_arg_type' : maybe_ptr_setter_arg_type , 'scoped_setter_arg_type' : scoped_setter_arg_type , 'getter_return_type' : getter_return_type , 'release_return_type' : release_return_type , 'is_vector' : vector , 'element_arg_type' : element_arg_type , 'element_storage_type' : element_storage_type , 'element_unwrapper' : element_unwrapper , 'is_node_ptr' : is_node_type and not vector , 'is_node_vector' : is_node_type and vector , 'is_enum_vector' : is_enum and vector , 'is_move_only' : is_move_only , 'is_not_ignorable' : ignorable == NOT_IGNORABLE , 'is_ignorable_default' : ignorable == IGNORABLE_DEFAULT , 'is_constructor_arg' : is_constructor_arg , 'to_string_method' : to_string_method , 'java_to_string_method' : java_to_string_method , 'propagate_order' : propagate_order }
Make a field to put in a node class.
Make a field to put in a node class .
"""Make a field to put in a node class.

  Args:
    name: field name
    ctype: c++ type for this field
           Should be a ScalarType like an int, string or enum type,
           or the name of a node class type (e.g. ResolvedProjectScan).
           Cannot be a pointer type, and should not include modifiers like
           const.
    tag_id: unique tag number for the proto field. This should never change or
            be reused.
    vector: True if this field is a vector of ctype. (Not supported for
            scalars.)
    ignorable: one of the IGNORABLE enums above.
    is_constructor_arg: True if this field should be in the constructor's
                        argument list.
    to_string_method: Override the default ToStringImpl method used to print
                      this object.
    java_to_string_method: Override the default to_string_method method used for
                           java.
    comment: Comment text for this field.  Text will be stripped and
             de-indented.
    propagate_order: If true, this field and the parent node must both be
                     ResolvedScan subclasses, and the is_ordered property of
                     the field will be propagated to the containing scan.
  Returns:
    The newly created field.
  """ # C++ code requires a large number of variations of the same type declaration. # These are: #   member_type - type of the class member #   member_accessor - get the member variable, unwrapping unique_ptr if needed #   setter_arg_type - type when passed to constructor or setter method. #   maybe_ptr_setter_arg_type - type when passed to constructor or setter #                               method as a bare pointer which transfers #                               ownership. #   getter_return_type - type returned from a getter method #   release_return_type - type returned from a release method, or None to #                         indicate there should be no release() method. #   element_arg_type - for vectors, the element type for get/set methods #   element_storage_type - for vectors, the type inside the vector. #   element_unwrapper - '.get()', if necessary, to unwrap unique_ptrs. #   is_move_only - setters must use std::move instead of assign/copy as #                  for anything wrapped in a unique_ptr/vector<unique_ptr>. # For scalars, these are always the same # Non-scalars should all be node types (possibly node vectors). # For node vector, we use std::move, which requires setters = member. # member variable name # name without trailing underscore
The newly created field.
The newly created field .
name
None
ctype
c++ type for this field
Should be a ScalarType like an int, string or enum type,
or the name of a node class type .
Cannot be a pointer type, and should not include modifiers like
const.
c ++ type for this field Should be a ScalarType like an int string or enum type or the name of a node class type . Cannot be a pointer type and should not include modifiers like const .
tag_id
unique tag number for the proto field. This should never change or
be reused.
unique tag number for the proto field . This should never change or be reused .
vector
True if this field is a vector of ctype. (Not supported for
scalars.)
True if this field is a vector of ctype . ( Not supported for scalars . )
ignorable
one of the IGNORABLE enums above.
one of the IGNORABLE enums above .
is_constructor_arg
True if this field should be in the constructor's
argument list.
True if this field should be in the constructor ' s argument list .
to_string_method
Override the default ToStringImpl method used to print
this object.
Override the default ToStringImpl method used to print this object .
java_to_string_method
Override the default to_string_method method used for
java.
Override the default to_string_method method used for java .
comment
Comment text for this field.  Text will be stripped and
de-indented.
Comment text for this field . Text will be stripped and de - indented .
propagate_order
If true, this field and the parent node must both be
ResolvedScan subclasses, and the is_ordered property of
the field will be propagated to the containing scan.
If true this field and the parent node must both be ResolvedScan subclasses and the is_ordered property of the field will be propagated to the containing scan .