Dehydra Object Reference


Dehydra represents C++ types and variables as JavaScript objects. The objects are designed to distill that type system to the minimum such that it can be easy to match on.

Often, the best way to become familiar with the Dehydra objects is to print out the objects:

Understanding Properties

Dehydra only sets properties that are applicable. For example, class types and typedefs are declared and will have a .loc property. Intrinsic types such as "int" are not declared and will not have a .loc.

Dehydra only sets boolean flags when they are true. For example, a pointer type will have .isPointer == true, but a class type will not have an .isPointer property.

Common Properties

Property Type Description
.loc location object
Source location of a type or declaration.
.attributes array of objects
Attributes of the type or declaration. Each member of the array has the following properties:
  name: string,
  value: string or number, if applicable
See an example on enforcing final classes. Code can be annotated with arbitrary user attributes: __attribute__((user("customstring"))).

Variable Objects

Dehydra presents AST nodes as variables. These types are used to represent variables, functions, assignments, etc. The following properties are usually available:

Property Type Description
.name string
The function or variable name.
.type type object
The type of this function or variable.
.isStatic boolean flag
.isReturn boolean flag The variable is being returned.
.isDecl boolean flag
The variable is being declared (local variables only).
.assign array of variable objects
This variable is the LHS of an assignment. The value is an array of values that were assigned.
.isFcall boolean flag
The variable is being used as a function call.
.arguments array of variable objects
Arguments used to make a function call.
.parameters array of variable objects
A function definition's parameter names and types
.memberOf aggregate type object
Indicates the aggregate type(class/struct) in the type system that this variable is a member of.
.fieldOf variable object
Provides the object being dereferenced, in the AST system. Applicable when accessing member variables or nonstatic member functions of aggregate types, e.g. the "foo" variable would be a .fieldOf memberVar/Fn in foo->memberVar or foo->memberFn(). Note that when constructing the return value of a function (e.g. return T();), no container variable is available; in this case, .isReturn will be true (see Function Variable).

Variables can identified by their DehydraDecl() prototype.

Function Variable

Function objects are an extension of Variable Objects. The following additional properties are available on functions:

Property Type Description
.isVirtual true or "pure"
true for virtual methods, or "pure" for pure virtuals (e.g. virtual void foo() = 0;).
.isConstructor boolean flag
Constructors generally have a .fieldOf attribute (see Variable Objects).
.isFunction boolean flag true for function variables.

Type Objects

Dehydra provides detailed type objects. Dehydra Type objects use the DehydraType() prototype.

Common Type Properties

Property Type Description
.name string
If applicable, the name of of the type. For typedefs and classes, this is the declared name. For built-in types this is the standard name such as "int". Some types such as bitfields may not have names.
type object
If this is a typedef, the original type.
boolean flag
boolean flag
type object
"const int" and "int" are separate types in GCC; the const version is considered a variant of the normal version. The variantOf property allows access to the original type object.
boolean flag
Applicable to function parameters only. Indicates whether the parameter has a default value, e.g. void foo(int i = 42).

Aggregate Types (class/struct/union/enum)

This type object represents aggregate types in GCC.

Property Type Description
.kind string
One of "class", "struct", "union", or "enum".
.isIncomplete boolean flag
the type was forward-declared and the full declaration has not been processed.
.bases array of objects
Inheritance information about the class. Each member of the array has the following properties:
  access: 'public' | 'protected' | 'private',
  type: type object representing the base class
.members array of variable objects
An array containing all the member variables and methods. Note: the .members will not include static member functions.
.template template object
The template from which this class was instantiated, if applicable.

Pointer and Reference Types

Property Type Description
.isPointer boolean flag
.isReference boolean flag
.type type object
The type this points to or references

Array Type

Property Type Description
.isArray boolean flag
.max integer
or normal fixed-size arrays, the index of the largest element of the array. For example, an int[10] would have .max = 9
.variableLength boolean flag
true if the type represents a C99 variable-length array type

Number Type

Property Type Description
.precision integer
for floating-point types, the precision of the type
.min integer
for integer types, the minimum value capable of being stored
.max integer
for integer types, the maximum value capable of being stored
.isSigned boolean flag
for integer types, true if the type stores signed values
.isUnsigned boolean flag
for integer types, true if the type stores unsigned values
.bitfieldBits integer
if the type represents a bitfield, the number of bits used by the bitfield
.bitfieldOf number type object
if the type represents a bitfield, the base type of the bitfield.

Function Type

These represent the types functions and methods in the type system:

Property Type Description
.type type object
the function return type.
.parameters array of type objects
the parameter types for the function.
.isExplicit boolean flag true for constructors declared using the C++ explicit keyword

Template Objects

Property Type Description
.name string
the name of the template, for example "nsCOMPtr".
.arguments array
an array where arguments are either strings representing C++ constants or type objects.

Location Objects

Location objects are passed to builtin functions such as warning() and error() to specify the location of the message. They convert to a string of the form "file:line:column". They have the following properties:

Property Type
.file string
.line integer
.column integer (optional)