Summary of Perl 5 AST nodes

P5AST01 - scope

Abstract

The scope node is used for every new scope in the code. It delimits the lifespan of variables and pragmas. If a pragma is defined a new scope is open, if a variable is redeclared, a new scope is open. An optimizer can reuse the scope for pragma declarations in the start of the code. But it cannot rename the re-declared variable, as the stash can be manipulated, just emit a warning.

Elements

scoped_declarations
a list of nodes containing scoped_variable_declaration, and pragma_declaration. The list is ordered according to the source code.

outer_references
A list of nodes containing variables accessed by this scope that are defined by the parent scope, or outer_referenced by the parent scope.

children
A list of statements to be run inside this scope.

Example

  block_decl
  helloworld

P5AST02 - package

Abstract

The package node is the root node of a Perl5 AST. It can declare subroutines, global variables. It inherits the ``scope'' node as every package defines a new scope.

Elements

name
The name of the package, default to 'main'.

package_declarations
A list of nodes containing global_variable_declaration, subroutine_declaration and use_declaration.

Example

  block_decl
  helloworld

P5AST03 - block

A block is a scope (inherits scope) defined explicitly. It tell us that it is ok to redeclare a variable, and no warning is necessary. It is also the boundary for closures.

Example

  block_decl

P5AST04 - variable_declaration

Abstract

The variable_declaration is the super-class for scoped and global variable declaration. It defines how a variable can be declared.

Elements

variable_type
One of SCALAR, ARRAY, HASH or GLOB. GLOBs can only be scoped with local, and they're always global. Even if they're scoped.

variable_name
An expression that defines the name of the variable. This expression should be evaluated every time the variable is used. It can reference another variable in this expression. An outer_references entry should be added if the referenced variable is from the parent scope.

alias
Alias to be used inside the AST when referencing this variable. For optimizing performance, it should be unique in this AST.

P5AST05 - scoped_variable_declaration

Abstract

Defines a variable with a limited visibility, either by name or by value. Inherits variable_declaration.

Elements

variable_visibility
One of ``my'' or ``local''. If ``local'', it should also declare a ``global'' variable.

P5AST06 - global_variable_declaration

Abstract

This node causes the same effect of the ``our'' declaration, but appears here even if the declaration didn't appears in the original code.