def get_field_from_final(t, ids, code, get_addr=False): '''Returns code to get the instance field using the final idens part''' env = t.environment # The final part should be an instance field acccess. final_part = str(ids.parts[-1]) f, encl_type = env.lookup_field(final_part) if get_addr: # Put the address of the field in eax. code.extend(common.get_instance_field_addr('eax', 'eax', f)) else: # Put the actual value in eax. code.extend(common.get_instance_field('eax', 'eax', f)) return code
def get_simple_var(decl): '''Given a declaration, return code to get the variable''' if isinstance(decl, ast_param.ASTParam): # Method param. index = CodeGenManager.cur_method.c_get_param_index(decl) return common.get_param('eax', index, CodeGenManager.N_PARAMS) elif decl.c_parent_method is not None: # Local variable. return common.get_local_var('eax', decl) # Only remaining case should be an (instance) field of the encl type. if not isinstance(decl, ast_variable_declaration.ASTVariableDeclaration): raise Exception('Invalid instance var value retrieval.') # "this" is always the first param from an implicit "this". return [ '; Field access of implicit "this"', common.get_param('eax', 0, CodeGenManager.N_PARAMS), common.get_instance_field('eax', 'eax', decl) ]
def _get_to_final_from_type(t, annotation, code): '''Resolve to the final part of the identifier starting at a type Returns (ASTType, asm_code)''' env = t.definition.environment # After the start, keep doing instance field accesses off the previous # result. for name, decl in annotation[1:]: f, encl_type = env.lookup_field(name) t = f.type_node code.extend(common.get_instance_field('eax', 'eax', f)) if t.is_array: # Crazy hack for arrays! # If the type is an array, it's going to be the last part (because the # next part will be .length or one of J.L.O's methods. return t, code env = t.definition.environment return t, code