Introduction
C++ has a rich type systems and Dehydra is designed to distill that type system to the minimum such that it can be easy to match on. It is recommended to explore C++ types using JavaScript's introspection features. In fact, by default Dehydra set's Object.toString to call uneval to encourage learning the type system in an interactive fashion. Additionally, Dehydra never sets boolean values to false, if a boolean is false, then the property is simply not attached to the object. This helps reduce verbosity when objects are print()ed.
Common Properties
Note that properties will not be set when they aren't applicable. For example, class types, typedefs, etc have .loc, but primitives do not.
The following properties are common to all object types.
- loc: Source location of the object
Variable Object
Dehydra presents AST nodes as variables. These types are used to represent variables, functions, assignments, etc. The following properties are available:
- name: The function name.
- type: The a type object describing this variable
- isStatic: True if the node is static
Variables can identified by their DehydraDecl() prototype.
Variable Flags
Variables can have flags describing the context they are used in:
- .isReturn: the variable is being returned
- .isDecl: the variable is being declared (local variables only)
- .assign: variable is an LHS, the value of the property is an array of #Variable Objects being assigned
- .isFcall: the variable is being used as a function call.
- .arguments: refers to an array of #Variable Objects used as arguments to make a function call
- .fieldOf: is present when the variable is being accessed through another variable (eg. foo->member). It refers to the #Variable Object of the container
Function Variable
Function objects are an extension of #Variable Objects.
The following additional properties are available on methods:
- methodOf: For functions, refers to #Aggregate Type of the class containing the function
- isVirtual: true indicates a virtual function, "pure" indicates a pure virtual
- isConstructor: indicates a constructor. Constructors generally have a .fieldOf attribute unless they are constructing the return value and .isReturn attribute is present.
Type Object
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).
Dehydra Type objects use the DehydraType() prototype.
Aggregate Type
This type object represents aggregate types in GCC.
- kind: One of "class", "struct", "union" or "enum"
- isIncomplete: true if the type was forward-declared and the full declaration has not been processed
- bases: An array of {access:'public'|'protected'|'private' type:(#Aggregate Type base class info)} objects representing inheritance info of the class
- members: An array of member variables(#Variable Object) and functions(#Function Type).
- template: If this class is a template instantiation(#Template Object this property describes it
Typedef Type
- typedef: #Type Object referred to by typedef
- name: Typedef name
Primitive Type
- name: type name, such as "unsigned char"
Function Type
These represent functions and methods in the type system
Attribute Object
.attributes property appears on #Variable Objects and #Type Objects and represents GNU attributes. The format is [{name:string, values: string array]
Template Object
- name is the name of the template. Eg. nsCOMPtr
- arguments is an array where arguments are either strings representing C++ constants or #Type Objects