NAME ^

PCT::Node - base class for PAST and POST nodes

DESCRIPTION ^

This file implements the base class for abstract syntax tree (PAST) and opcode syntax tree (POST) nodes in the Parrot Compiler Toolkit.

PCT::Node ^

PCT::Node is the base class for all PAST and POST nodes. It's derived from class Capture, so that it has both array and hash components. The array component is used to maintain a node's children, while the hash component contains the attributes of the node. In general we provide and use accessor methods for a node's attributes, instead of accessing the hash component directly.

Every PAST/POST node has name, source, and pos attributes. The name attribute is the node's name, if any, while source and pos are used to identify the location in the original source code for the node. The source and pos values are generally set by the node method below.

Other node attributes are generally defined by subclasses of PCT::Node.

init([child1, child2, ..., ] [attr1=>val1, attr2=>val2, ... ])

Initialize a node with the given children and attributes. Adds each child to the node (using the push method, below) and calls the appropriate accessor method for each attribute. And returns the node.

new([child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])

Create a new PAST node of initialized with the given children and attributes. Returns the newly created node.

unshift(child)

Add child to the beginning of the invocant's list of children.

shift()

Remove the first child from the invocant's list of children. Returns the child.

push(child)

Add child to the end of the invocant's list of children.

pop()

Remove the last child from the invocant's list of children. Returns the child.

push_new(class, [child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])

(Deprecated.) Creates a new node of type class, initializes it with the given children and attributes, and adds it to the end of the invocant's array of children. Returns the newly created node.

iterator( )

Returns a newly initialized iterator for the invocant's list of children.

node([val])

Sets the invocant's source and pos attributes to those of val. If val is another PAST node, then source and pos are simply copied from that node, otherwise val is assumed to be a Match object and obtains source/position information from that.

name([value])

Accessor method -- sets/returns the name attribute of the invocant.

attr(STR attrname, PMC value, INT has_value)

Helper method for accessors. If has_value is true then set the invocant's value of attrname to value. Returns the (resulting) value of attrname in the invocant.

unique([STR fmt])

Generate a unique number that can be used as an identifier. If fmt is provided, then it will be used as a prefix to the unique number.

AUTHOR ^

Patrick Michaud <pmichaud@pobox.com> is the author and maintainer. Please send patches and suggestions to the Parrot porters or Perl 6 compilers mailing lists.

HISTORY ^

2006-11-20 Patrick Michaud added first draft of POD documentation. 2007-11-21 Re-implementation with pdd26 compliance, compiler toolkit 2007-12-07 Refactor PAST::Node into separate PCT::Node component.

COPYRIGHT ^

Copyright (C) 2006-2008, The Perl Foundation.


parrot