Package compiler :: Module pycodegen :: Class CodeGenerator
[hide private]
[frames] | no frames]

_ClassType CodeGenerator

Known Subclasses:

Defines basic code generator for Python bytecode

This class is an abstract base class. Concrete subclasses must define an __init__() that defines self.graph and then calls the __init__() defined in this class.

The concrete class must also define the class attributes NameFinder, FunctionGen, and ClassGen. These attributes can be defined in the initClass() method, which is a hook for initializing these methods after all the classes have been defined.

Nested Classes [hide private]
Find local names in scope
Instance Methods [hide private]
This method is called once for each class
Verify that class is constructed correctly
Return a code object
mangle(self, name)
parseSymbols(self, tree)
isLocalName(self, name)
storeName(self, name)
loadName(self, name)
delName(self, name)
_nameOp(self, prefix, name)
_implicitNameOp(self, prefix, name)
Emit name ops for names generated implicitly by for loops
set_lineno(self, node, force=False)
Emit SET_LINENO if necessary.
visitModule(self, node)
visitExpression(self, node)
visitFunction(self, node)
visitLambda(self, node)
_visitFuncOrLambda(self, node, isLambda=0)
visitClass(self, node)
visitIf(self, node)
visitWhile(self, node)
visitFor(self, node)
visitBreak(self, node)
visitContinue(self, node)
visitTest(self, node, jump)
visitAnd(self, node)
visitOr(self, node)
visitIfExp(self, node)
visitCompare(self, node)
visitListComp(self, node)
visitListCompFor(self, node)
visitListCompIf(self, node, branch)
_makeClosure(self, gen, args)
visitGenExpr(self, node)
visitGenExprInner(self, node)
visitGenExprFor(self, node)
visitGenExprIf(self, node, branch)
visitAssert(self, node)
visitRaise(self, node)
visitTryExcept(self, node)
visitTryFinally(self, node)
visitWith(self, node)
visitDiscard(self, node)
visitConst(self, node)
visitKeyword(self, node)
visitGlobal(self, node)
visitName(self, node)
visitPass(self, node)
visitImport(self, node)
visitFrom(self, node)
_resolveDots(self, name)
visitGetattr(self, node)
visitAssign(self, node)
visitAssName(self, node)
visitAssAttr(self, node)
_visitAssSequence(self, node, op='UNPACK_SEQUENCE')
visitAssTuple(self, node, op='UNPACK_SEQUENCE')
visitAssList(self, node, op='UNPACK_SEQUENCE')
visitAugAssign(self, node)
visitAugName(self, node, mode)
visitAugGetattr(self, node, mode)
visitAugSlice(self, node, mode)
visitAugSubscript(self, node, mode)
visitExec(self, node)
visitCallFunc(self, node)
visitPrint(self, node, newline=0)
visitPrintnl(self, node)
visitReturn(self, node)
visitYield(self, node)
visitSlice(self, node, aug_flag=None)
visitSubscript(self, node, aug_flag=None)
binaryOp(self, node, op)
visitAdd(self, node)
visitSub(self, node)
visitMul(self, node)
visitDiv(self, node)
visitFloorDiv(self, node)
visitMod(self, node)
visitPower(self, node)
visitLeftShift(self, node)
visitRightShift(self, node)
unaryOp(self, node, op)
visitInvert(self, node)
visitUnarySub(self, node)
visitUnaryAdd(self, node)
visitUnaryInvert(self, node)
visitNot(self, node)
visitBackquote(self, node)
bitOp(self, nodes, op)
visitBitand(self, node)
visitBitor(self, node)
visitBitxor(self, node)
visitEllipsis(self, node)
visitTuple(self, node)
visitList(self, node)
visitSliceobj(self, node)
visitDict(self, node)
Class Variables [hide private]
  optimized = 0
  __initialized = None
  class_name = None
  FunctionGen = None
  ClassGen = None
  __list_count = 0
  __with_count = 0
  _augmented_opcode = {'%=': 'INPLACE_MODULO', '&=': 'INPLACE_AN...
Method Details [hide private]

_implicitNameOp(self, prefix, name)


Emit name ops for names generated implicitly by for loops

The interpreter generates names that start with a period or dollar sign. The symbol table ignores these names because they aren't present in the program text.

set_lineno(self, node, force=False)


Emit SET_LINENO if necessary.

The instruction is considered necessary if the node has a lineno attribute and it is different than the last lineno emitted.

Returns true if SET_LINENO was emitted.

There are no rules for when an AST node should have a lineno attribute. The transformer and AST code need to be reviewed and a consistent policy implemented and documented. Until then, this method works around missing line numbers.

Class Variable Details [hide private]


 '&=': 'INPLACE_AND',
 '**=': 'INPLACE_POWER',
 '+=': 'INPLACE_ADD',