def getDefaultValue(self, _type): if self.isBasicType(_type): return '0' elif _type.endswith('*'): return 'nullptr' elif _type in ['Float32x4']: return 'Float32x4()' else: # enum value ? stat = '' if _type in self.type_tree[self.ns]['enum']: default_val = self.type_tree[ self.ns]['enum'][_type]['enums'][0] default_val_t_name = NameUtil['cpp_enum'](self.ns, _type) if isinstance(default_val, dict): stat = '::'.join([ default_val_t_name, make_name_AxxBxx(default_val.keys()[0]) ]) else: stat = '::'.join( [default_val_t_name, make_name_AxxBxx(default_val)]) elif _type in self.type_tree[self.ns]['struct']: stat = NameUtil['cpp_struct'](self.ns, _type) + '()' else: stat = _type return stat
def write_function(self, function, is_cpp=True): func_decl = function['val'] ret = 'void' if 'return' not in func_decl else func_decl['return'] exported = 'exported' in func_decl c_api = 'c_api' in func_decl ret_type = self.get_real_type_name(ret, None, is_cpp) if exported: if c_api: self.__header__.write('\nextern "C" {0} NGFX_API {1}'.format( ret_type, make_name_AxxBxx(function['function']))) else: self.__header__.write('\n{0} NGFX_API {1}'.format( ret_type, make_name_AxxBxx(function['function']))) else: self.__header__.write('\n{0} {1}'.format( ret_type, make_name_AxxBxx(function['function']))) if 'params' in func_decl: self.__header__.write('(') paralist = [] for param in func_decl['params']: param_name = param['name'] param_t = param['type'] paralist.append('{0} {1}'.format( self.get_real_type_name(param_t, None, is_cpp), param_name)) paralist_str = ', '.join(paralist) self.__header__.write(paralist_str + ');\n')
def write_enum(self, enum, is_cpp=False): enum_name = enum['enum'] val = enum['val'] enum_vals = val['enums'] # write comment if 'comment' in val: self.__header__.write('\n// {0}'.format(val['comment'])) r_enum_name = NameUtil['cpp_enum' if is_cpp else 'enum'](self.ns, enum_name) if not is_cpp: self.__header__.write( '\ntypedef enum {0}\n{{\n'.format(r_enum_name)) bit = 1 for enum_val in enum_vals: if not isinstance(enum_val, dict): enum_val_name = make_enum_value( make_name_XXX_XXX(enum_name), enum_val) else: enum_val_name = make_enum_value( make_name_XXX_XXX(enum_name), enum_val.keys()[0]) # write table if self.ns: enum_val_name = self.ns.upper() + '_' + enum_val_name if 'bitmask' in val: self.__header__.write(' {0} = {1},\n'.format( enum_val_name, bit)) bit = bit << 1 else: self.__header__.write(' {0},\n'.format(enum_val_name)) self.__header__.write('}} {0};\n'.format(r_enum_name)) else: self.write_enum_table(enum_name, val, True) self.__header__.write( '\nenum class {0} : uint32_t\n{{\n'.format(r_enum_name)) bit = 1 for enum_val in enum_vals: if not isinstance(enum_val, dict): enum_val_name = make_name_AxxBxx(enum_val) else: enum_val_name = make_name_AxxBxx(enum_val.keys()[0]) # write table #if self.ns: # enum_val_name = self.ns.upper() + '_' + enum_val_name if 'bitmask' in val: self.__header__.write(' {0} = {1},\n'.format( enum_val_name, bit)) bit = bit << 1 else: self.__header__.write(' {0},\n'.format(enum_val_name)) self.__header__.write('}};// Enum {0}\n'.format(r_enum_name))
def write_enum_table(self, enum_name, enum_tree, is_cpp): if 'vulkan' in enum_tree and is_cpp: enum_values = enum_tree['enums'] real_converted_enum = enum_tree['vulkan'] real_enum_name = NameUtil['cpp_enum' if is_cpp else 'enum']( self.ns, enum_name) table_src = '{0} Convert{1}ToVulkanEnum({2} const& e) {{\n switch(e) {{\n'.format( real_converted_enum, make_name_AxxBxx(enum_name), real_enum_name) for enum_val in enum_values: converted_val = enum_val[enum_val.keys()[0]]['vulkan'] enum_val_name = '::'.join( [real_enum_name, make_name_AxxBxx(enum_val.keys()[0])]) case_sec = ' case {0}:\n return {1};\n'.format( enum_val_name, converted_val) table_src = table_src + case_sec table_src = table_src + ' }\n}\n' self.__table__.write(table_src) elif 'glslang' in enum_tree and is_cpp: enum_values = enum_tree['enums'] real_converted_enum = enum_tree['glslang'] real_enum_name = NameUtil['cpp_enum' if is_cpp else 'enum']( self.ns, enum_name) table_src = '{0} Convert{1}ToGlslangEnum({2} const& e) {{\n switch(e) {{\n'.format( real_converted_enum, make_name_AxxBxx(enum_name), real_enum_name) for enum_val in enum_values: converted_val = enum_val[enum_val.keys()[0]]['glslang'] enum_val_name = '::'.join( [real_enum_name, make_name_AxxBxx(enum_val.keys()[0])]) case_sec = ' case {0}:\n return {1};\n'.format( enum_val_name, converted_val) table_src = table_src + case_sec table_src = table_src + ' }\n}\n' self.__table__.write(table_src)