Package analysis :: Package output :: Package visitors :: Module C :: Class CVisitor
[show private | hide private]
[frames | no frames]

Class CVisitor

ASTVisitor --+    
             |    
       Visitor --+
                 |
                CVisitor


A simple C-emitting visitor.
Method Summary
  __init__(self, generator, header_generator)
Initialise the visitor with the given 'generator' to which the final output is sent.
  call_function(self, node)
Write function calls, associated with the given 'node'.
  default(self, node)
  get_const_value(self, value)
  get_generator(self)
Return the generator according to the output status attributes.
  type_of(self, operand, ref)
Write a TYPEOF test for the 'operand' compared to the given 'ref'.
  visitAdd(self, node)
  visitAnd(self, node)
  visitAssAttr(self, node)
  visitAssign(self, node)
  visitAssList(self, node)
  visitAssName(self, node)
  visitAssTuple(self, node)
  visitCallFunc(self, node)
Translate this...
  visitClass(self, node)
  visitCompare(self, node)
  visitConst(self, node)
  visitDiscard(self, node)
  visitFor(self, node)
  visitFunction(self, node)
  visitGetattr(self, node)
  visitGlobal(self, node)
  visitIf(self, node)
  visitImport(self, node)
  visitList(self, node)
  visitModule(self, node)
Visit the module 'node', producing the top-level declarations and initialisations.
  visitName(self, node)
  visitNot(self, node)
  visitOr(self, node)
  visitPass(self, node)
  visitPrintnl(self, node)
  visitReturn(self, node)
  visitSlice(self, node)
  visitStmt(self, node)
  visitSub(self, node)
  visitSubscript(self, node)
  visitTuple(self, node)
  visitWhile(self, node)
  write_attr(self, node, obj, attr, attrname, write_case)
For the given 'node' expressing an attribute lookup, Write a reference to the attribute of the given object or class 'obj' using the suggested 'attr' and having the given 'attrname'.
  write_compare(self, compare)
  write_locals(self, node, prefix, include_parameters, declaration_mode)
Write the locals for the given block 'node'.
  write_name(self, node)
Write the name for the given 'node' according to scope and style of access.
  write_new(self, node)
Write a reference to a new object instantiated by the given 'node'.
  write_parameters(self, node, args, refcontext)
Write the parameters associated with the given function call 'node' using the given call 'args' and a 'refcontext' used to indicate how reference objects used in the call are to be represented.
  write_signature(self, node)
  write_stack(self, generator)
  write_target_test(self, node, args, refcontext, target)
Write the test which selects a particular function call.
  write_target_test_end(self, node, args, refcontext, target)
Write the end of the function call selection test.
    Inherited from Visitor
  is_builtin_module(self, node)
  is_native(self, node)
  uses_call(self, node)
  uses_reference(self, params)
    Inherited from ASTVisitor
  dispatch(self, node, *args)
  preorder(self, tree, visitor, *args)
Do preorder walk of tree using visitor

Class Variable Summary
int constant_start = 0                                                                     
int FUNCTION = 3                                                                     
int FUNCTION_BODY = 4                                                                     
int magic_number = 100                                                                   
int MAIN = 0                                                                     
int TOP_LEVEL_DECLARATIONS = 2                                                                     
int TOP_LEVEL_DEFINITIONS = 1                                                                     
    Inherited from ASTVisitor
int VERBOSE = 0                                                                     

Method Details

__init__(self, generator, header_generator=None)
(Constructor)

Initialise the visitor with the given 'generator' to which the final output is sent. Note that the visitor itself maintains a number of generators, controlled by a special status attribute.

If an optional 'header_generator' is given, send declarations to that generator in order to produce a header file which can be referenced by other modules in the same program.
Overrides:
analysis.output.visitors.common.Visitor.__init__

call_function(self, node)

Write function calls, associated with the given 'node'. Sequences of calls are generated in the following form:

IGNORE(f1(args)) || IGNORE(f2(args)) || IGNORE(f3(args))

get_generator(self)

Return the generator according to the output status attributes.

type_of(self, operand, ref)

Write a TYPEOF test for the 'operand' compared to the given 'ref'.

visitCallFunc(self, node)

Translate this...

expr(x, y, z)

...into this:

(_tmp = expr) ? (TYPEOF(_tmp) == C) ? new(C, 3) : (TYPEOF(_tmp) == D) ? new(D, 4) : None : None

...or this:

(_tmp = expr) ? (FNAME(_tmp) == FNAME(f)) ? f(x, y, z) : (FNAME(_tmp) == FNAME(g)) ? g(x, y, z) : None : None

visitModule(self, node)

Visit the module 'node', producing the top-level declarations and
initialisations. The module is constructed from the contents of the
generators written in the following order:

  * generator (the main one), producing globals and constants
    * top-level, producing class and object definitions, and function
      declarations
    * function, producing function definitions
  * generator, producing the main function
    * main, producing the main function code

write_attr(self, node, obj, attr, attrname, write_case=0)

For the given 'node' expressing an attribute lookup, Write a reference to the attribute of the given object or class 'obj' using the suggested 'attr' and having the given 'attrname'.

write_locals(self, node, prefix=None, include_parameters=1, declaration_mode=None)

Write the locals for the given block 'node'.

write_name(self, node)

Write the name for the given 'node' according to scope and style of access.

write_new(self, node)

Write a reference to a new object instantiated by the given 'node'.

write_parameters(self, node, args, refcontext)

Write the parameters associated with the given function call 'node' using the given call 'args' and a 'refcontext' used to indicate how reference objects used in the call are to be represented.

write_target_test(self, node, args, refcontext, target)

Write the test which selects a particular function call.

write_target_test_end(self, node, args, refcontext, target)

Write the end of the function call selection test.

Class Variable Details

constant_start

Type:
int
Value:
0                                                                     

FUNCTION

Type:
int
Value:
3                                                                     

FUNCTION_BODY

Type:
int
Value:
4                                                                     

magic_number

Type:
int
Value:
100                                                                   

MAIN

Type:
int
Value:
0                                                                     

TOP_LEVEL_DECLARATIONS

Type:
int
Value:
2                                                                     

TOP_LEVEL_DEFINITIONS

Type:
int
Value:
1                                                                     

Generated by Epydoc 2.1 on Tue Dec 20 00:05:45 2005 http://epydoc.sf.net