RefactorScript – Data Model

This page describes the data model used by RefactorScript. Each C/C++ entity (e.g. a class or a function) is represented by a single RefactorScript object of one of the types shown below:

RefactorScript objects automatically inherit properties from the base object types. E.g. an instance of the Field type will inherit all properties of Variable and Entity. You can check whether the object belongs to a particular type using the “is” operator, e.g.:

if (obj is Function)
{
    //...
}

The properties of all object types are described below:

Entity

Entity is a base type for all C/C++ entities (e.g. classes, functions, variables, etc.). It always defines the properties shown below:

Property Type Meaning
QualifiedName string Specifies the fully qualified name of the entity (e.g. std::string::c_str)
ShortName string Specifies the name of the entity without its cope (e.g. c_str)
Location CodeLocation Specifies the location in the source file where the entity is defined or declared
Range CodeRange Refers to the part of the source file containing the entity

Typedef

The Typedef object represents a single C/C++ typedef. It inherits the Entity and TypeRef types and does not define any additional properties on top of them.

Enum

The Enum object represents a single enum declaration. It inherits the Entity type.

Property Type Meaning
IsScoped bool Specifies whether it’s a scoped “enum class” declaration.
UnderlyingType TypeRef Specifies the underlying type of the enum (normally “int”)
Values Value[] Specifies all enum values as defined in the declaration

Record

The Record object represents a single struct/class/union declaration. It inherits the Entity type.

Property Type Meaning
IsClass bool Specifies whether this is a class declaration
IsStruct bool Specifies whether this is a struct declaration
IsUnion bool Specifies whether this is a union declaration
Bases Base[] Contains the list of base classes of a C++ class/struct
Fields Field[] Contains the list of all fields of a record (but not from the base classes)
Methods Function[] Contains the list of all methods of a class (but not from the base classes)

Value

The Value object represents a single enum constant. It inherits the Entity type.

Property Type Meaning
HasValue bool Specifies whether the integral value of the enum constant is known (even if not set explicitly).
Value int Specifies the exact integral value of the enum constant.
HasInitializer bool Specifies whether the value of the enum constant was explicitly set via the ‘=’ operator.
Initializer SourceRange Refers to the part of the source file defining the value of the enum constant.

Variable

The Variable object represents a single variable (see also Field and FunctionArgument). It inherits the Entity type.

Property Type Meaning
Type TypeRef Specifies the type of the variable.
HasInitializer bool Specifies whether the variable is explicitly initialized at declaration using the ‘=’ operator.
Initializer bool Refers to the part of the source file defining the initial value of the variable.
IsStatic bool Specifies whether it is a static field or a static variable.

Field

The Field object represents a single field. It inherits the Variable type.

Property Type Meaning
Access string Specifies the access class of the field (public/private/protected).
ContainingType Record Specifies the class/struct/union containing the field.

FunctionArgument

The FunctionArgument object represents a single function argument. It inherits the Variable type.

Function

The Function object represents a single function, method, constructor, destructor or an operator. It inherits from the Entity type.

Property Type Meaning
ReturnType TypeRef Specifies the return type of the function
IsInline bool Specifies whether this is an inline function/method
IsMethod bool Specifies whether this is a C++ method, operator, constructor or destructor
IsStatic bool Specifies whether this is a static function/method

The following properties are only available with IsMethod == true:

Property Type Meaning
IsVirtual bool Specifies whether this is a virtual method
IsPure bool Specifies whether this is a pure virtual (i.e. abstract) method
IsConst bool Specifies whether this is a const method
IsImplicit bool Specifies whether this is a compiler-generated constructor, destructor or operator
IsDeleted bool Specifies whether this method is declared as “=delete”;
IsDefault bool Specifies whether this method is declared as “=default”;
Access string Contains the access class of the method (private/protected/public).

TypeRef

A TypeRef object represents a reference to a C/C++ type. It is typically exposed as a part of the Typedef object, or via the Type property of the Variable object.

Because C/C++ types can be referenced via typedefs or preprocessor macros, simply finding out the actual type of the variable might not be always sufficient (e.g. in many cases you would like to use “string” instead of “std::basic_string<…>“. The TypeRef object contains multiple levels of information about a type, allowing the scripts to pick what works the best in a particular scenario.

Property Type Meaning
Literal SourceRange Refers to the exact syntax that was used to reference the type in the variable declaration or typedef. It includes the preprocessor macros, spaces before the “*” symbol for pointers, etc. It does not include the suffix (e.g. “[]” for arrays).
LiteralSuffix SourceRange Contains the part of the type that follows the variable name. E.g. for “int array[5]” LiteralSuffix will resolve to “[5]”.
Referenced ResolvedType Specifies the type of the declaration, without resolving any typedefs, but after substituting preprocessor macros.
Resolved ResolvedType Specifies the type of the declaration after resolving all typedefs.
IsValid bool Specifies whether the type reference has been resolved to a valid C/C++ type.

Typically, the fields of TypeRef should be used as follows:

  • Use $decl.Type.Literal to copy the exact syntax that was used by an existing declaration to reference a type.
  • Use $decl.Type.Referenced.Name to get the fully qualified type name (with the parent classes or namespaces) useful in generating method implementations.
  • Check fields of decl.Type.Resolved to test whether the type is a pointer, array, or another special case.

FunctionPrototype

A FunctionPrototype object is a special case of TypeRef. It represents the type of a field or typedef that is declared as a function pointer, e.g.:

struct Foo
{
    int (*bar)(int x, int y, int z);
};

This allows programmatically generating implementations for function pointer fields.

Property Type Meaning
ReturnType TypeRef Specifies the return type of the Function object.
Arguments FunctionArgument[] Contains the arguments of the function similar to the Function object.

Base

A Base object represents a reference to a single base class of a C++ class/struct.

Property Type Meaning
Access string Contains the access class of the base (private/protected/public).
IsVirtual bool Specifies whether this is a virtual base.
Type TypeRef Specifies the base type. Note that it is an instance of TypeRef and not Record. This allows tracking the exact name used in the class declaration, or resolving typedefs if needed.

ResolvedType

A ResolvedType object represents a single C/C++ type.

Property Type Meaning
IsValid bool Specifies whether the type has been resolved to a valid C/C++ type.
Name bool Specifies the full name of the type.
IsConst bool Specifies whether the variable having this type has a ‘const’ modifier.
IsVolatile bool Specifies whether the variable having this type has a ‘volatile’ modifier.
IsPointerOrReference bool Specifies whether this type is a pointer or a reference. Use the PointerSymbol property to distinguish them.
PointerSymbol string Contains “*”, “&” or “&&” based on the type of the pointer.
IsRecord bool Specifies whether this type is a class/struct/union.
IsBuiltin bool Specifies whether this is a built-in type like “int”.
IsTypedef bool Specifies whether this is a typedefed type.
IsArray bool Specifies whether this is an array.
ArraySize int Specifies the size of array in elements.
PointedType ResolvedType Specifies the pointed type (also for references, arrays and rvalue references).
Declaration Record/Typedef Points to the Record/Typedef declaration if IsRecord or IsTypedef is true.