titus.pfaast.FcnDef

class titus.pfaast.FcnDef(paramsPlaceholder, retPlaceholder, body, pos=None)[source]

Bases: titus.pfaast.Argument

Abstract syntax tree for a function definition.

class Context(fcnType, calls, paramNames, params, ret, symbols, exprs)

Bases: titus.pfaast.FcnContext

__init__(fcnType, calls, paramNames, params, ret, symbols, exprs)
FcnDef.__init__(paramsPlaceholder, retPlaceholder, body, pos=None)
FcnDef.collect(pf)

Walk over tree applying a partial function, returning a list of results in its domain.

Parameters:
  • pf (callable with isDefinedAt method) – partial function that takes any titus.pfaast.Ast as an argument, returning anything
  • pf.isDefinedAt (callable) – domain that takes any titus.pfaast.Ast as an argument, returning True if this item is in the domain, False otherwise
Return type:

list of function results

Returns:

a result for each abstract syntax tree node in the pf function’s domain

FcnDef.jsonNode(lineNumbers, memo)

Convert this abstract syntax tree to Pythonized JSON.

Parameters:
  • lineNumbers (bool) – if True, include locator marks in each JSON object
  • memo (set of string) – used to avoid recursion; provide an empty set if unsure
Return type:

Pythonized JSON

Returns:

JSON representation

FcnDef.paramNames

Names of the parameters (list of strings).

FcnDef.params

Resolved parameter types (list of {string: titus.datatype.AvroType} singletons).

FcnDef.paramsDict

Resolved parameter types as an unordered dictionary (dict of titus.datatype.AvroType).

FcnDef.replace(pf)

Walk over tree applying a partial function, returning a transformed copy of the tree.

Parameters:
  • pf (callable with isDefinedAt method) – partial function that takes any titus.pfaast.Ast as an argument, returning a replacement titus.pfaast.Ast
  • pf.isDefinedAt (callable) – domain that takes any titus.pfaast.Ast as an argument, returning True if this item is in the domain, False otherwise
Return type:

new titus.pfaast.Ast tree

Returns:

tree with nodes in the pf function’s domain transformed; everything else left as-is

FcnDef.ret

Resolved return type (titus.datatype.AvroType).

FcnDef.walk(task, symbolTable, functionTable, engineOptions, version)

Walk over tree applying a titus.pfaast.Task while checking for semantic errors.

This is how Python is generated from an abstract syntax tree: the titus.pfaast.Task in that case is titus.genpy.GeneratePython.

Parameters:
Return type:

(titus.pfaast.AstContext, titus.pfaast.TaskResult)

Returns:

(information about this abstract syntax tree node after type-checking, result of the generic task)