Exemplo n.º 1
0
    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'])
Exemplo n.º 2
0
    def to_code(self):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper

        self._expression.to_code()
        self._statement.to_code()
        if not (self._else_statement is None):
            self._else_statement.to_code()

        for (name, module) in converter_helper.converters.items():
            if_data = dict()
            if_data['expression'] = self._expression.code[name]
            statement = self._statement.code[name]

            if_data['statement'] = statement
            if_data['else'] = ''

            if not (self._else_statement is None):
                statement = self._else_statement.code[name]
                if_data['else'] = module.else_statement_template % {
                    "statement": statement
                }

            self._code[name] = module.if_statement_template % if_data
            self._code[name] = converter_helper.apply_indents(
                self._code[name], module.indenter['statement'])
Exemplo n.º 3
0
    def to_code(self):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        for case in self._case:
            case[1].to_code()   # statement to code...
        for statement in self._else_statements:
            statement.to_code()
        self._expression.to_code()

        if len(self._else_statements) > 0:
            for statement in self._else_statements:
                statement.to_code()
        cases = ''
        for name, module in converter_helper.converters.items():
            expression = self._expression.code[name]
            cases = ''
            else_statements = ''
            # convert case statements
            for case in self._case:
                cases += module.case_template % {'constant' : case[0], 'statement' : case[1].code[name] }
            cases = converter_helper.apply_indents(cases, module.indenter['cases'])
            # convert else statements if they exist
            if len(self._else_statements) > 0:
                for statement in self._else_statements:
                    else_statements += statement.to_code[name]
            self._code[name] = module.case_statement_template % { 'expression' : expression, 'cases' : cases , 'else' : else_statements }
Exemplo n.º 4
0
    def to_code(self, indentation=0):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        
        for part in self._contents:
            part.to_code(indentation)

        if (self._compound_statement != None):
            self._compound_statement.to_code()

        for (name, module) in converter_helper.converters.items():
            part_code = ""
            lang_data = dict()
            for part in self._contents:
                part_code += part.code[name]
            lang_data['declarations'] = part_code;

            if (self._compound_statement is None):
                lang_data['statement'] = ''
            else:
                lang_data['statement'] = self._compound_statement.code[name]

            self._code[name] = module.block_template % lang_data
            self._code[name] = converter_helper.apply_indents(self._code[name], indentation)
Exemplo n.º 5
0
    def to_code(self, indentation=0):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper

        for part in self._contents:
            part.to_code(indentation)

        if (self._compound_statement != None):
            self._compound_statement.to_code()

        for (name, module) in converter_helper.converters.items():
            part_code = ""
            lang_data = dict()
            for part in self._contents:
                part_code += part.code[name]
            lang_data['declarations'] = part_code

            if (self._compound_statement is None):
                lang_data['statement'] = ''
            else:
                lang_data['statement'] = self._compound_statement.code[name]

            self._code[name] = module.block_template % lang_data
            self._code[name] = converter_helper.apply_indents(
                self._code[name], indentation)
Exemplo n.º 6
0
    def to_code(self, indentation=0):
        '''

        '''
        import converter_helper

        for key, type in self._type_declarations.items():
            type.to_code()

        my_data = dict()
        # seperators need to be set for every new package
        #   these could go in the __init__ for each library?
        for (key, type) in self._type_declarations.items():
            type.to_code(indentation)

        for (name, module) in converter_helper.converters.items():
            declaration = ""
            index = 0
            for (key, type) in self._type_declarations.items():
                declaration += type.code[name]
            declaration = converter_helper.apply_indents(
                declaration, module.indenter['types'])
            self._code[name] = module.type_declaration_template % {
                "declaration": declaration
            }
Exemplo n.º 7
0
    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'])
Exemplo n.º 8
0
    def to_code(self, indentation=0):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper

        for (key, variable) in self._vars.items():
            variable.to_code()

        for (name, module) in converter_helper.converters.items():
            variables = ""
            for (key, variable) in self._vars.items():
                variables += variable.code[name]
            variables = converter_helper.apply_indents(variables, module.indenter['variable'])
            self._code[name] = module.variable_decl_template % { "variables": variables }
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    def to_code(self, indentation=0):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        
        self._expression.to_code()

        for statement in self._statements:
            statement.to_code()

        for (name, module) in converter_helper.converters.items():
            statements = ''
            for statement in self._statements:
                statements += statement.code[name] + module.statement_seperator + '\n'
            #statements = converter_helper.apply_indents(statements, module.indenter['statement'])
            self._code[name] = module.repeat_statement_template % {'expression' : self._expression.code[name], 'statements' : statements }
            self._code[name] = converter_helper.apply_indents(self._code[name], module.indenter['statement'])
Exemplo n.º 12
0
    def to_code(self, indentation=0):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper

        for (key, variable) in self._vars.items():
            variable.to_code()

        for (name, module) in converter_helper.converters.items():
            variables = ""
            for (key, variable) in self._vars.items():
                variables += variable.code[name]
            variables = converter_helper.apply_indents(
                variables, module.indenter['variable'])
            self._code[name] = module.variable_decl_template % {
                "variables": variables
            }
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    def to_code(self, indentation=0):
        '''

        '''
        import converter_helper

        for key, type in self._type_declarations.items():
            type.to_code()

        my_data = dict()
        # seperators need to be set for every new package
        #   these could go in the __init__ for each library?
        for (key, type) in self._type_declarations.items():
            type.to_code(indentation)

        for (name, module) in converter_helper.converters.items():
            declaration = ""
            index = 0
            for (key, type) in self._type_declarations.items():
                declaration += type.code[name]
            declaration = converter_helper.apply_indents(declaration, module.indenter['types'])
            self._code[name] =  module.type_declaration_template % {"declaration" : declaration}
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    def to_code(self):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        my_data = dict()
        self._operand.to_code()
        #my_data['pas_lib_operand'] = self._operand.code['pas_lib_reference']
        #my_data['c_lib_operand'] = converter_helper.lower_name(self.operand.name)

        self._operator.to_code()
        self._expression.to_code()

        for (name, module) in converter_helper.converters.items():
            # operator / expression
            my_data[name + '_operand'] = self._operand.code[name + '_reference']
            my_data[name + '_expression'] = self._expression.code[name]
            my_data[name + '_operator'] = self._operator.code[name]
            self._code[name] = module.assignment_template % my_data

            self._code[name] = converter_helper.apply_indents(self._code[name], module.indenter['statement'])
            
Exemplo n.º 17
0
    def to_code(self):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        for case in self._case:
            case[1].to_code()  # statement to code...
        for statement in self._else_statements:
            statement.to_code()
        self._expression.to_code()

        if len(self._else_statements) > 0:
            for statement in self._else_statements:
                statement.to_code()
        cases = ''
        for name, module in converter_helper.converters.items():
            expression = self._expression.code[name]
            cases = ''
            else_statements = ''
            # convert case statements
            for case in self._case:
                cases += module.case_template % {
                    'constant': case[0],
                    'statement': case[1].code[name]
                }
            cases = converter_helper.apply_indents(cases,
                                                   module.indenter['cases'])
            # convert else statements if they exist
            if len(self._else_statements) > 0:
                for statement in self._else_statements:
                    else_statements += statement.to_code[name]
            self._code[name] = module.case_statement_template % {
                'expression': expression,
                'cases': cases,
                'else': else_statements
            }
    def to_code(self):
        '''
        This method creates the code to declare all it's variables
        for each of the modules
        '''
        import converter_helper
        my_data = dict()
        self._operand.to_code()
        #my_data['pas_lib_operand'] = self._operand.code['pas_lib_reference']
        #my_data['c_lib_operand'] = converter_helper.lower_name(self.operand.name)

        self._operator.to_code()
        self._expression.to_code()

        for (name, module) in converter_helper.converters.items():
            # operator / expression
            my_data[name + '_operand'] = self._operand.code[name +
                                                            '_reference']
            my_data[name + '_expression'] = self._expression.code[name]
            my_data[name + '_operator'] = self._operator.code[name]
            self._code[name] = module.assignment_template % my_data

            self._code[name] = converter_helper.apply_indents(
                self._code[name], module.indenter['statement'])