Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • Base
  • ZendPHP
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo

Class Base

Base class to implement a source code generator.

Direct known subclasses

Peg\Lib\Generator\ZendPHP
Abstract
Namespace: Peg\Lib\Generator
Located at src/Generator/Base.php
Methods summary
public
# __construct( string $templates, string $output, string $generator_name, Peg\Lib\Definitions\Symbols & $symbols )

The symbols object with all definitions required to generate the code.

The symbols object with all definitions required to generate the code.

Parameters

$templates
string
$templates Path where template files reside.
$output
string
$output Path where the generated source code is going to be saved.
$generator_name
string
$generator_name Name of the generator being instantiated. Should be all lower case.
$symbols
Peg\Lib\Definitions\Symbols
$symbols
public string
# Indent( string $code, integer $spaces )

Useful to indent the output of a template.

Useful to indent the output of a template.

Parameters

$code
string
$code Output code of template.
$spaces
integer
$spaces Amount of spaces to indent the code.

Returns

string
Code indented.
public
# GetHeaderDefine( string $name )

Converts a header file name into a suitable flag for the compiler pre-processor. Eg: header.h -> PHP_HEADER_H this can be used for #ifndef checks on the generated code to prevent double inclusions.

Converts a header file name into a suitable flag for the compiler pre-processor. Eg: header.h -> PHP_HEADER_H this can be used for #ifndef checks on the generated code to prevent double inclusions.

Parameters

$name
string
$name
public
# GetHeaderNamePHP( string $name )

Converts a header filename into one that doesn't conflicts with original which can be used to store the generated code. Eg: header.h -> php_header.h or lib/header.h -> php_lib_header.h

Converts a header filename into one that doesn't conflicts with original which can be used to store the generated code. Eg: header.h -> php_header.h or lib/header.h -> php_lib_header.h

Parameters

$name
string
$name
public
# GetSourceNamePHP( string $name )

Converts a header filename into a source file name which can be used to store the generated code. Eg: header.h -> php_header.cpp or lib/header.h -> php_lib_header.cpp

Converts a header filename into a source file name which can be used to store the generated code. Eg: header.h -> php_header.cpp or lib/header.h -> php_lib_header.cpp

Parameters

$name
string
$name
public
# GetCustomSources( )

Gets a list of custom source files on the custom_sources directory that resides in the templates/$generator_name directory with the .php extension stripped out.

Gets a list of custom source files on the custom_sources directory that resides in the templates/$generator_name directory with the .php extension stripped out.

public string
# GetTemplatePath( string $name, string $type, string $subtype, string $dir, string $overrides_prefix = "", string $namespace = "" )

Get a php template file path based on the given parameters.

Get a php template file path based on the given parameters.

Parameters

$name
string
$name Name of element.
$type
string
$type Main type of template.
$subtype
string
$subtype Subtype of template.
$dir
string
$dir Relative dir to templates path where template resides.
$overrides_prefix
string
$overrides_prefix In case $dir is shared with other template types.
$namespace
string
$namespace Namespace of the $name element.

Returns

string
public string
# GetGenericTemplate( string $name, string $subdir = "" )

Get a php template file for a given file name.

Get a php template file for a given file name.

Parameters

$name
string
$name Filename of source file, eg: php_extension.h, config.m4
$subdir
string
$subdir Relative path to the templates_path where the file resides.

Returns

string
Path to template file.
public string
# GetParameterTemplate( Peg\Lib\Definitions\Element\Parameter $parameter, string $namespace = "", string $type = "declare" )

Retrieve the template path for parameters, also checks if a valid override exists and returns that instead.

Retrieve the template path for parameters, also checks if a valid override exists and returns that instead.

Parameters

$parameter
string
$parameter Name of the function.
$namespace
string
$namespace
$type
string
$type Can be declare, parse_string, parse, parse_string_ref, parse_reference or object_validate.

Returns

string
Path to template file.
public string
# GetReturnTemplate( Peg\Lib\Definitions\Element\ReturnType $return, string $namespace = "", string $type = "function" )

Retrieve the template path for return, also checks if a valid override exists and returns that instead.

Retrieve the template path for return, also checks if a valid override exists and returns that instead.

Parameters

$return
string
$return Name of the function.
$namespace
string
$namespace
$type
string
$type Can be function, method or static_method.

Returns

string
Path to template file.
public
# RemoveHeader( string $header_name )

Deletes a generated header declarations file and its source file

Deletes a generated header declarations file and its source file

Parameters

$header_name
string
$header_name Original name of header.
public
# AddHeader( string $header_name, string & $content, string $subdir = "includes" )

Adds or updates a header file if neccessary.

Adds or updates a header file if neccessary.

Parameters

$header_name
string
$header_name Original name of header.
$content
string
$content
$subdir
string
$subdir
public
# AddSource( string $header_name, string & $content, string $subdir = "src" )

Adds or updates a header source file if neccessary.

Adds or updates a header source file if neccessary.

Parameters

$header_name
string
$header_name Original name of header.
$content
string
$content
$subdir
string
$subdir
public
# AddGenericFile( string $file_name, string & $content, string $subdir = "" )

Adds or updates a generic file if neccessary.

Adds or updates a generic file if neccessary.

Parameters

$file_name
string
$file_name Original name of header.
$content
string
$content
$subdir
string
$subdir
abstract public
# Start( )

Generate all the sources.

Generate all the sources.

abstract public string
# GenerateHeader( string $header_name )

Generate the header source of a specific header file.

Generate the header source of a specific header file.

Parameters

$header_name
string
$header_name

Returns

string
Source code.
abstract public string
# GenerateSource( string $header_name )

Generate the source file of a specific header file.

Generate the source file of a specific header file.

Parameters

$header_name
string
$header_name

Returns

string
Source code.
abstract public string
# GenerateFunction( Peg\Lib\Definitions\Element\FunctionElement $function_object )

Generate the wrapping code of a specific C/C++ function.

Generate the wrapping code of a specific C/C++ function.

Parameters

$function_object
Peg\Lib\Definitions\Element\FunctionElement
$function_object

Returns

string
Source code.
Properties summary
public Peg\Lib\Definitions\Symbols $symbols
#

Reference to the symbols object with all definitions required to generate the code.

Reference to the symbols object with all definitions required to generate the code.

public string $templates_path
#

Path where template files reside.

Path where template files reside.

public string $output_path
#

Path where the generated source code is going to be saved.

Path where the generated source code is going to be saved.

public string $generator_name
#

Name of the generator implementing this base class. Useful to determine the directory where generated source code is going to be stored.

Name of the generator implementing this base class. Useful to determine the directory where generated source code is going to be stored.

PEG Api API documentation generated by ApiGen 2.8.0