|
|
| Line 1: |
Line 1: |
| This is an attempt to document the functions for writing scripts for [[Dehydra GCC]]. It is incomplete, as is dehydra-gcc itself, so things are in constant flux.
| | [http://wiki.mozilla.org/Dehydra_API Dehydra documentation] is now on MDC |
| | |
| == Callback Functions ==
| |
| | |
| Dehydra works by calling functions in your Javascript for elements of the source code file. You are not required to have any of these functions in your script: if a function is not there, Dehydra will know and will not try to call it. Here are the functions Dehydra will call:
| |
| | |
| === process_type(t) ===
| |
| | |
| Dehydra calls this for each class/struct/enum/union. process_class is called ''after'' process_function is called for all the member functions. <var>t</var> is a JS object representing the class, with the following properties:
| |
| | |
| <dl>
| |
| <dt>.kind
| |
| <dd>One of "class", "struct", "union" or "enum"
| |
| | |
| <dt>.bases
| |
| <dd>An array representing the base classes of this class.
| |
| | |
| <dt>.members
| |
| <dd>An array of member variables and functions.
| |
| | |
| <dt>.loc
| |
| <dd> Location in the source
| |
| | |
| <dt>.template
| |
| <dd> If this class is a template instantiation the .template property describes it
| |
| </dl>
| |
| | |
| === process_function(decl, body) ===
| |
| | |
| Dehydra calls this for each top-level function or class member function. | |
| | |
| <dl>
| |
| <dt>.decl
| |
| <dd>The function declaration.
| |
| <dl>
| |
| <dt>.name
| |
| <dd>The function name.
| |
| <dt>.type
| |
| <dd>The function type, including parameter types.
| |
| <dt>.loc
| |
| <dd>Source location of the function
| |
| <dt>.isStatic
| |
| <dd>True if the function is static
| |
| <dt>.memberOf
| |
| <dd>Class containing the function, if any.
| |
| </dl>
| |
| | |
| <dt>.body[_]
| |
| <dd>The function body is an array with an element for each statement.
| |
| <dl>
| |
| <dt>.loc
| |
| <dd>Source location of the statement
| |
| <dt>.statements
| |
| <dd>"Dehydra Items"--each element represents a variable or value referred to in the statement.
| |
| </dl>
| |
| </dl>
| |
| | |
| The API for "Dehydra items" is not fully documented, but here are a few items it has:
| |
| | |
| <dl>
| |
| <dt>.loc
| |
| <dd>Source location of the item.
| |
| <dt>.type
| |
| <dd>Type of the item.
| |
| <dt>.name
| |
| <dd>If the item is a variable, this is its name. If the item is a function/method call, this is the name of the function/method. If the item is a field access, this is the name of the field.
| |
| <dt>.isFcall
| |
| <dd>True if this item represents a function call.
| |
| <dt>.methodOf
| |
| <dd>If the item is a method or method call, this is the type that contains the method.
| |
| <dt>.fieldOf
| |
| <dd>If the item is a field access or method call, this is the subexpression to the left of the dot.
| |
| </dl>
| |
| | |
| === process_var(decl) ===
| |
| | |
| decl is a JS object representing a variable declaration outside of a function body.
| |
| | |
| === process_tree(func, body) ===
| |
| | |
| func is a function declaration. body is a JS object representing the CFG for a function body. NOT YET FULLY IMPLEMENTED
| |
| | |
| === input_end() ===
| |
| | |
| Called once at the end of the C++ source file.
| |
| | |
| == Builtin functions ==
| |
| | |
| The following functions are provided by dehydra and may be called by the user:
| |
| === include("file") ===
| |
| Include a javascript file.
| |
| | |
| === warning(msg, ...) ===
| |
| | |
| Print one or more warning messages using the GCC warning mechanism. If -Werror is specified this will cause compilation to fail.
| |
| | |
| === error(msg, ...) ===
| |
| | |
| Print one or more error messages using the GCC error mechanism. This will cause compilation to fail.
| |
| | |
| === print(msg) ===
| |
| | |
| Print a string to stdout (or stderr if the compiler is piping output). If the current callback is associated with a particular location, the location will be printed first.
| |
| | |
| === _print(msg, ...) ===
| |
| | |
| Like <tt>print()</tt> but the location will not be printed.
| |
| | |
| === read_file(filename) ===
| |
| | |
| Read a file a return it as a string.
| |
| | |
| === write_file(filename, data) ===
| |
| | |
| Write a string to a file.
| |
| | |
| == Variable Objects ==
| |
| Dehydra presents AST nodes as variables. Variables can have flags such as isReturn. Variable type is indicated by the .type attribute.
| |
| | |
| === Methods ===
| |
| Methods have .fieldOf to indicate the variable being acted upon and .methodOf is the type object of the class implementing the method.
| |
| | |
| === Constructors ===
| |
| Like a method, differentiated by presence of .isConstructor attribute. Constructors generally have a .fieldOf attribute unless they are constructing the return value and .isReturn attribute is present.
| |
| | |
| == Type objects ==
| |
| | |
| Dehydra provides detailed type objects. A Dehydra type object can represent a primitive type (with name attribute), a class type (with name, members attributes, etc.), a pointer type (with isPointer=true and a type attribute), a reference type (with isReference=true and a type attribute), or a function pointer type (with parameters attribute, etc).
| |