Example #1
0
 def standart_funcs():
     datatype_int = datatype.SimpleDataType('Int')
     datatype_string = datatype.SimpleDataType('String')
     std_signature = ast.FuncSignature(
         return_type=datatype.SimpleDataType('Int'),
         param_list=[
             ast.Param(name='a', datatype=datatype_int),
             ast.Param(name='b', datatype=datatype_int),
         ],
     )
     ident_list = {
         # Int constructor
         'Int': ast.FuncSignature(
             return_type=datatype_int,
             param_list=[
                 ast.Param(name='n', datatype=datatype_int),
             ],
         ),
         'printNewLine': ast.FuncSignature(),
         'print': [
             ast.FuncSignature(
                 param_list=[
                     ast.Param(name='s', datatype=datatype_string),
                 ],
             ),
             ast.FuncSignature(
                 param_list=[
                     ast.Param(name='n', datatype=datatype_int),
                 ],
             ),
         ],
         'allocInt': ast.FuncSignature(
             return_type=datatype.SimpleDataType(
                 name='Int',
                 prefix_list=['R'],
             ),
         ),
         'isEqual': std_signature,
         'isLess': std_signature,
         'isGreater': std_signature,
         'minus': std_signature,
         'plus': std_signature,
         'multiply': std_signature,
     }
     return ident_list
Example #2
0
 def test_simple_func_with_2_params(self):
     ''' Parse func that takes two params. '''
     input_string = 'func testfunc (par1 ParamType, par2 ParamType) {}'
     real_ast = _parse(input_string)
     signature = ast.FuncSignature(param_list=[
         ast.Param(
             name='par1',
             datatype=datatype.SimpleDataType('ParamType'),
         ),
         ast.Param(
             name='par2',
             datatype=datatype.SimpleDataType('ParamType'),
         )
     ])
     expected_ast = ast.Module(
         decl_list=[ast.FuncDecl(
             name='testfunc',
             signature=signature,
         )])
     misc.assert_equal(self, expected_ast, real_ast)
Example #3
0
    def test_multiply_func_params(self):
        check_translation(
            test_case=self,
            input_ast=ast.Module(decl_list=[
                ast.FuncDecl(
                    name='testFunc',
                    signature=ast.FuncSignature(param_list=[
                        ast.Param(name='n1', datatype=ast.Ident('Int')),
                        ast.Param(name='n2', datatype=ast.Ident('Int')),
                    ], ),
                ),
                ast.FuncDecl(name='start',
                             signature=ast.FuncSignature(),
                             body=[
                                 ast.FuncCall(
                                     expr=ast.Ident('testFunc'),
                                     arg_list=[ast.Number(1),
                                               ast.Number(2)],
                                 ),
                             ])
            ]),
            expected_output='''
                void testFunc_Int_Int(Int* n1, Int* n2);
                void start(void);

                void testFunc_Int_Int(Int* n1, Int* n2) {
                }

                void start(void) {
                  Int const_0;
                  Int const_1;

                  const_0 = 1;
                  const_1 = 2;

                  testFunc_Int_Int(&const_0, &const_1);
                }

            ''',
        )
Example #4
0
 def p_param(p):
     'param : IDENT type'
     p[0] = ast.Param(name=p[1], datatype=p[2])