def c_gen_code_create_array(self): from parser.ast.ast_type import ASTType type_ = ASTType.from_str(str(self.name), is_primitive=False) type_.definition = self offset = CodeGenManager.get_subtype_table_index(type_) return ASTClass.c_gen_code_create_array_helper( self.c_create_array_function_label, self.c_array_cit_label, offset)
def make_subtype_table(asts): # Create a list of all ReferenceTypes. class_or_interface_types = [] # Arrays of primitives, classes and arrays are also reference types. array_types = [] for ast in [ast for ast in asts if ast.class_or_interface]: class_or_interface = ast.class_or_interface type_ = ASTType.from_str(str(class_or_interface.name), is_primitive=False) type_.definition = class_or_interface array_type = ASTType.from_str(str(class_or_interface.name), is_primitive=False, is_array=True) array_type.definition = class_or_interface class_or_interface_types.append(type_) array_types.append(array_type) # Add the primitive array types. for prim in ['boolean', 'byte', 'char', 'int', 'short']: array_type = ASTType.from_str(prim, is_primitive=True, is_array=True) array_types.append(array_type) # Add indices to all the types. ref_types = class_or_interface_types + array_types indexed_types = zip(range(len(ref_types)), ref_types) # Add subtype columns to classes and interfaces. for type_ in class_or_interface_types: column = calculate_subtype_column(type_, indexed_types) type_.definition.c_subtype_column = column prim_array_subtype_cols = {} for array_type in array_types: if array_type.is_primitive: column = calculate_subtype_column(array_type, indexed_types) prim_array_subtype_cols[array_type] = column else: column = calculate_subtype_column(array_type, indexed_types) array_type.definition.c_array_subtype_column = column # Store the indexed types on the CodeGenManager to allow lookups in both # directions. CodeGenManager._subtype_column_guide = indexed_types # Store the columns for the primitive types on CodeGenManager: CodeGenManager.prim_array_subtype_cols = prim_array_subtype_cols
def _get_valueof_method_from_type(t): '''Gets the method for String's valueOf method given the param type''' env = CodeGenManager.java_lang_string_defn.environment param_t = t if not t.is_primitive or t.is_array or t == ASTType.ASTNull: tmp = ASTType.from_str('java.lang.Object') tmp.definition = CodeGenManager.java_lang_object_defn param_t = tmp m, encl_type = env.lookup_method(('valueOf', [param_t])) if m is None: raise Exception('No valueOf method found for type {0}.'.format(t)) return m