def _convert_function(function): result = list() if (converter_helper.lower_name(function.name) == 'main'): return_type = 'int' else: return_type = converter_helper.convert_type(c_lib._type_switcher, function.return_type) #parameter_declaration = '' #parameters = _convert_variable_list(function.parameters, areParams=True) #count = len(function.parameters) #parameter_declaration += '(' #for parameter in parameters: # parameter_declaration += parameter # count -= 1 # if (count > 1 ): # parameter_declaration += ',' #parameter_declaration += ')' #result.append(return_type + ' ' + converter_helper.lower_name(function.name) + parameter_declaration) result.append('{') if (converter_helper.lower_name(function.name) == 'main'): result.append('load_default_colors();') if (function.isFunction) : result.append(converter_helper.convert_type(c_lib._type_switcher, function.return_type) + 'result;') result.extend(_convert_block(function.block, function.isFunction)) # return result will be added if isFunction result.append('}') return result
def _convert_function(function): result = list() if (converter_helper.lower_name(function.name) == 'main'): return_type = 'int' else: return_type = converter_helper.convert_type(c_lib._type_switcher, function.return_type) #parameter_declaration = '' #parameters = _convert_variable_list(function.parameters, areParams=True) #count = len(function.parameters) #parameter_declaration += '(' #for parameter in parameters: # parameter_declaration += parameter # count -= 1 # if (count > 1 ): # parameter_declaration += ',' #parameter_declaration += ')' #result.append(return_type + ' ' + converter_helper.lower_name(function.name) + parameter_declaration) result.append('{') if (converter_helper.lower_name(function.name) == 'main'): result.append('load_default_colors();') if (function.isFunction): result.append( converter_helper.convert_type(c_lib._type_switcher, function.return_type) + 'result;') result.extend(_convert_block( function.block, function.isFunction)) # return result will be added if isFunction result.append('}') return result
def to_code(self): import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) self._code['pas_lib_reference'] = "%s" % (self._name ) self._code['c_lib_reference'] = "%s" % ( converter_helper.lower_name(self._name )) for (name, module) in converter_helper.converters.items(): my_data[name + '_type'] = converter_helper.convert_type(module._type_switcher, self._type, None) self._code[name] = module.record_field_template % my_data
def to_code(self): ''' This method creates the code to declare all it's variables for each of the modules ''' import converter_helper # Need to convert arguments # -> parse arguments into an arguments object? # not always comma seperated (obj-c) my_data = dict() my_data['pas_lib_identifier'] = self._identifier my_data['c_lib_identifier'] = converter_helper.lower_name( self._identifier) self._arguments.to_code() for (name, module) in converter_helper.converters.items(): my_data[name + '_args'] = self._arguments.code[name] # if the function call is a statement then we indent it if self._inExpr: self._code[name] = module.function_call_expr_template % my_data else: self._code[name] = (module.function_call_template % my_data) self._code[name] = converter_helper.apply_indents( self._code[name], module.indenter['statement'])
def to_code(self): ''' This method creates the code to declare all it's variables for each of the modules ''' import converter_helper # Need to convert arguments # -> parse arguments into an arguments object? # not always comma seperated (obj-c) my_data = dict() my_data['pas_lib_identifier'] = self._identifier my_data['c_lib_identifier'] = converter_helper.lower_name(self._identifier) self._arguments.to_code() for (name, module) in converter_helper.converters.items(): my_data[name + '_args'] = self._arguments.code[name] # if the function call is a statement then we indent it if self._inExpr: self._code[name] = module.function_call_expr_template % my_data else: self._code[name] = (module.function_call_template % my_data) self._code[name] = converter_helper.apply_indents(self._code[name], module.indenter['statement'])
def to_code(self): import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for (name, module) in converter_helper.converters.items(): self._code[name] = module.unit_reference_template % my_data
def _variable_to_str(var): from pascal_parser.types.pas_type_cache import find_or_add_type if var.type is find_or_add_type('enumeration'): # if the type is an enumeration type... return converter_helper.upper_name(var.name) elif var.type is find_or_add_type('color'): return var.name # assuming input is PascalCase else: return converter_helper.lower_name(var.name)
def _variable_to_str(var): from pascal_parser.types.pas_type_cache import find_or_add_type if var.type is find_or_add_type( 'enumeration'): # if the type is an enumeration type... return converter_helper.upper_name(var.name) elif var.type is find_or_add_type('color'): return var.name # assuming input is PascalCase else: return converter_helper.lower_name(var.name)
def convert_array_declaration(array, is_parameter): """ converts an array to a string describing the array """ from converter_helper import lower_name, convert_type var_name = lower_name(array.name) type_name = convert_type(_type_switcher, array.type.nested_type, None) if is_parameter: return type_name + ' *' + var_name else: result = type_name + var_name for dimension in array.type.dimensions: result += '[%s]' % dimension[1] return result + ';\n'
def to_code(self, indentation=0): import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for field in self._fields: field.to_code() for (name, module) in converter_helper.converters.items(): my_data["fields"] = "" for field in self._fields: my_data["fields"] += field.code[name] + '\n' my_data["fields"] = converter_helper.apply_indents(my_data['fields'], module.indenter["record_field"]) self._code[name] = module.record_template % my_data
def to_code(self, indentation=0): import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for field in self._fields: field.to_code() for (name, module) in converter_helper.converters.items(): my_data["fields"] = "" for field in self._fields: my_data["fields"] += field.code[name] + '\n' my_data["fields"] = converter_helper.apply_indents( my_data['fields'], module.indenter["record_field"]) self._code[name] = module.record_template % my_data
def to_code(self): ''' Creates a _code entry for each of the converter modules ''' import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for (name, module) in converter_helper.converters.items(): # types need to be evaluated in the loop because they are module specific if self._type.kind is 'array': self._code[name] = module.convert_array_declaration( self, self._is_parameter) else: my_data[name + '_type'] = converter_helper.convert_type( module._type_switcher, self._type, self._modifier) self._code[name] = module.variable_template % my_data self._code[name + "_reference"] = my_data[name + "_identifier"]
def to_code(self, indentation): ''' This method creates the code to declare all it's variables for each of the modules ''' import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name if (self._isFunction): my_data['pas_lib_type'] = self._return_type.name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) self._parameters.to_code() self._block.to_code(indentation) for (name, module) in converter_helper.converters.items(): # types need to be evaluated in the loop because they are module specific comments = '' code = """""" for current_line in self._comments: comments += module.comment_template % {"comment": current_line} my_data[name + '_comments'] = comments my_data[name + '_parameters'] = self._parameters.code[name] # if the function isn't a forward declaration then it doesn't have a block if (not self._is_forward): my_data[name + '_block'] = self._block.code[name] else: my_data[name + '_block'] = '' if (self._isFunction): my_data[name + '_type'] = converter_helper.convert_type( module._type_switcher, self._return_type) code = module.function_declaration_template % my_data else: code = module.procedure_declaration_template % my_data self._code[name] = converter_helper.apply_indents( code, indentation)
def to_code(self, indentation): ''' This method creates the code to declare all it's variables for each of the modules ''' import converter_helper my_data = dict() my_data['pas_lib_identifier'] = self._name if (self._isFunction): my_data['pas_lib_type'] = self._return_type.name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) self._parameters.to_code() self._block.to_code(indentation) for (name, module) in converter_helper.converters.items(): # types need to be evaluated in the loop because they are module specific comments = '' code = """""" for current_line in self._comments: comments += module.comment_template % { "comment" : current_line} my_data[name + '_comments'] = comments my_data[name + '_parameters'] = self._parameters.code[name] # if the function isn't a forward declaration then it doesn't have a block if (not self._is_forward): my_data[name + '_block'] = self._block.code[name] else: my_data[name + '_block'] = '' if (self._isFunction): my_data[name + '_type'] = converter_helper.convert_type(module._type_switcher, self._return_type) code = module.function_declaration_template % my_data else: code = module.procedure_declaration_template % my_data self._code[name] = converter_helper.apply_indents(code, indentation)
def to_code(self, indentation=0): import converter_helper for value in self._values: value.to_code() my_data = dict() # seperators need to be set for every new package # these could go in the __init__ for each library? my_data['c_lib_seperator'] = ',' my_data['pas_lib_seperator'] = ',' my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for (name, module) in converter_helper.converters.items(): enum_values = "" for index in range(len(self._values)): enum_values += self._values[index].code[name] if index < (len(self._values) - 1): enum_values += my_data[name + '_seperator'] my_data["values"] = enum_values self._code[name] = module.enum_template % my_data
def to_code(self,indentation = 0): import converter_helper for value in self._values: value.to_code() my_data = dict() # seperators need to be set for every new package # these could go in the __init__ for each library? my_data['c_lib_seperator'] = ',' my_data['pas_lib_seperator'] = ',' my_data['pas_lib_identifier'] = self._name my_data['c_lib_identifier'] = converter_helper.lower_name(self._name) for (name, module) in converter_helper.converters.items(): enum_values = "" for index in range(len(self._values)): enum_values += self._values[index].code[name] if index < (len(self._values)-1): enum_values += my_data[name + '_seperator'] my_data["values"] = enum_values self._code[name] = module.enum_template % my_data