Changes between Version 73 and Version 74 of Orio


Ignore:
Timestamp:
06/14/08 16:05:52 (15 years ago)
Author:
hartono
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Orio

    v73 v74  
    283283Below, we present a very simple example, which extends Orio with a new module that simply rewrites the annotated code without applying any code transformations at all. The new module has no parser component since there is no necessity to extract information from the annotated code, significantly simplifying the module implementation. First, we need to create a new subdirectory (with a name `simplyrewrite`, for instance) inside `src/module`. And then, we create an ''empty'' special file `__init__.py` inside directory `src/module/simplyrewrite`, so that Python will know that this folder is a package (i.e. a Python module). 
    284284 
     285{{{ 
     286#  
     287# File: src/module/simplyrewrite/simplyrewrite.py  
     288#  
     289  
     290import module.module  
     291 
     292class SimplyRewrite(module.module.Module):  
     293    '''A simple rewriting module'''  
     294  
     295    def __init__(self, perf_params, module_body_code, annot_body_code, cmd_line_opts, line_no, indent_size):  
     296        '''To instantiate a simple rewriting module'''  
     297        module.module.Module.__init__(self, perf_params, module_body_code, annot_body_code,  
     298                                      cmd_line_opts, line_no, indent_size)  
     299 
     300    def transform(self):  
     301        '''To simply rewrite the annotated code'''  
     302 
     303        # to create a comment containing information about the class attributes  
     304        comment = '''  
     305        /*  
     306         perf_params = %s  
     307         module_body_code = "%s"  
     308         annot_body_code = "%s"  
     309         line_no = %s  
     310         indent_size = %s  
     311        */  
     312        ''' % (self.perf_params, self.module_body_code, self.annot_body_code, self.line_no, self.indent_size)  
     313  
     314        # to rewrite the annotated code, with the class-attribute comment being prepended  
     315        output_code = comment + self.annot_body_code  
     316  
     317        # to return the output code  
     318        return output_code  
     319}}} 
    285320 
    286321''Currently under construction''