Synopsys logo

Coverity® 2020.12 CodeXM

Go Library Reference

Introduction

Specifying the Target Language

Class Definitions

‘enum’ Kinds

‘globalset’ Sets

Code Patterns

Records

Functions

Hide/show Contents

Coverity® 2020.12 CodeXM

Go Library Reference

Introduction

CodeXM is a domain-specific language that allows you to create custom code checkers. CodeXM checkers analyze source code for specific coding patterns, and report these defects with messages that you provide. Like other Coverity checkers, the defects are displayed in Coverity Connect. They can be archived with the cov-commit-defect feature.

The CodeXM Go library provides access to Go coding constructs.

This document provides information about the patterns and functions provided by the Go library. To learn how to get started with CodeXM, please see Learning to Write CodeXM Checkers.

Typographic Conventions

Describing CodeXM is a bit different from describing other languages. Most programming books talk about one language only. To describe CodeXM, we have to talk about CodeXM code itself, and the code of the language it is inspecting—the target language.

This reference shows all code in monospace type.

CodeXM code appears in shades of green.

Target code (whatever the language) appears in shades of orange.

Reminder: By default, many browsers do not print out background colors.

Nullable Types

The type of certain pattern properties is said to be nullable. This means that the property might return a value, or it might not. If it does not, its value matches the CodeXM keyword null. In the CodeXM documents, a nullable type is indicated by the name of the type the property might return, followed by a question mark; for example, int?.

In checker code, a nullable type requires some special handling in order to avoid the error of referencing the null. The Handling Null Values section of Learning to Write CodeXM Checkers describes how to do this.

Specifying the Target Language

In your CodeXM source, begin with an include declaration that names the library target language: include `Go`.

Specifying the target language makes the library’s special patterns and functions available within this CodeXM file. These patterns and functions are the subject of this reference.

The language specification also causes the checkers defined in your CodeXM file to be applied only to the target source code in your code base.

Class Definitions

Class definitions match class entities in the abstract representation of the target code, and provide properties that describe the classes that the library supports.

astnode (class)

Every target-code object that Coverity inspects is a node in an abstract syntax tree. For a brief overview of how Coverity uses these syntax trees, see How Does Coverity Analysis Work?.

Properties

Every astnode has the following properties:

Name Type Description
location sourceloc The location of this code construct in the source files
children list<astnode> A list of child nodes that are sub-parts of this code construct
parent astnode? This node’s parent node, if there is one; null if there is no parent.
macrosExpandedFrom list<macroinfo> If the code is produced by macro expansion, this list contains the macros that generated that expansion. Otherwise, this list is empty.
implicit bool Indicates whether the node is the result of compiler intervention, as opposed to being explicitly stated in the source code. For example, if ( x ) in the source code is interpreted as if ( x != 0 ) by the compiler. The not-equals binary operator and the literal constant zero are implicit.

The astnode elements are further classified as statement, expression, initializer and ctorinit (constructor initializer), and declaration elements (declaration elements declare symbols). Certain kinds of elements have their own set of properties in addition to the astnode properties shown here.

classDefinition (class)

Describes a Go struct or interface.

Properties

classDefinition produces a record that contains the following properties:

Name Type Description
declaredType classType The type of the class.
fieldList list<fieldSymbol> A list of fieldSymbols, one for each non-static field in the class
location sourceloc The location of this class in the source code
memberFunctionList list<functionSymbol> A list of functionSymbols, one for each non-static member function

functionDefinition (class)

Describes a function definition.

Properties

functionDefinition produces a record that contains the following properties:

Name Type Description
body statement A blockStatement that is the function’s body.
formalParameterLists list<symbol> A list of parameterSymbol objects, one for each parameter to the function.
functionSymbol symbol The functionSymbol object that represents this function.

Inherits properties from:

functionOrStaticVariableDefinition

functionOrStaticVariableDefinition (class)

Describes a function or a statically declared variable.

Properties

functionOrStaticVariableDefinition produces a record that contains the following properties:

Name Type Description
allCode set<astnode> A list of all the nodes within the function. For a variable, this is usually just the variable’s initialization.
location sourceloc The function’s location in the code. This value is used in error reports.
paths executionPaths The execution paths used for path-sensitive analysis.

staticVariableDefinition (class)

Matches symbols for variables that are declared as const.

Properties

staticVariableDefinition produces a record that contains the following property:

Name Type Description
initializer initializer? The initializer for this variable; null if no initializer exists.
variable symbol A staticVariableSymbol that represents this variable.

Inherits properties from:

functionOrStaticVariableDefinition

‘enum’ Kinds

These are enumerations that are used by the language library, and that are available to your own CodeXM code.

assignKind (enum)

Specifies whether an assignment is simple (assignment only) or compound (incorporating an additional operation such as plus, +, or minus, -).

Details

The following values are defined:

Name Description
`simple` A simple assignment; for example, a = b
`compound` A compound assignment; for example, a += b

See Also

assignmentOperator, assignmentOperatorCompound, assignmentOperatorSimple

castKind (enum)

Represents the various kinds of type casts in Go.

Details

The following values are defined:

Name Description
`dynamic` A dynamic cast
`explicit` An explicit cast
`implicit` An implicit cast

Example

In Go an explicit type cast, or conversion, appears similar to a function call. For example, consider the following declarations:

Go code follows
var sum int = 17
var count int = 5
var mean float32

... then to obtain a value for mean based on sum and count, the Go code would first have to convert the integers to 32-bit floating-point values, as follows:

Go code follows
mean = float32(sum) / float32(count)

See Also

castOperator

floatKind (enum)

Represents whether a floating-point value is real or complex.

Details

The following values are defined:

Name Description
`float` A real number, in floating-point format
`complex` The imaginary component of a complex number, in floating-point format

See Also

floatType

ForLoopKind (enum)

Represents either a simple or an enhanced for loop.

Details

A simple for loop is of the form:

Go code follows
for (int i; i < 10; i++) {
// ...
}

An enhanced for loop is of the form:

Go code follows
for (i := mySet) {
// ...
};

The following values are defined:

Name Description
`enhanced` An enhanced for loop
`simple` A simple for loop

See Also

forLoop, forLoopSimple

intKind (enum)

Represents various kinds of integer values.

Details

The following values are defined:

Name Description
`bool` A Boolean value
`byte` A single byte
`int` A full integer
`int8` An 8-bit signed integer
`int16` A 16-bit signed integer
`int32` A 32-bit signed integer
`int64` A 64-bit signed integer
`uint8` An 8-bit unsigned integer
`uint16` A 16-bit unsigned integer
`uint32` A 32-bit unsigned integer
`uint64` A 64-bit unsigned integer
`uintptr` An unsigned integer pointer value
`rune` A 32-bit signed integer: Can be used to represent a Unicode character.

See Also

integerType

labelScopeKind (enum)

Represents the scope of a label.

Details

The following values are defined:

Name Description
`unscoped` The label is within a local scope.
`scoped` The label appears with a struct or an interface.

See Also

labelStatement

variableDeclarationKind (enum)

Represents the scope of a variable declaration.

Details

The following values are defined:

Name Description
`local` The declaration is in a local scope.
`static` The declaration appears with a struct or an interface.

See Also

declaration

variableScopeEnum (enum)

Represents the scope of a variable.

Details

The following values are defined:

Name Description
`local` The variable is local to the function, struct, or interface.
`static` The variable is static and is available globally.

See Also

variableReference

‘globalset’ Sets

The sets described in this section can help narrow the search of your checker. Typically they are used in for loop constructions such as the following:

CXM code follows
for code in globalset allFunctionCode where code matches // ... further criteria

allClasses (globalset)

Includes the definitions of all interface and struct types declared in the current Go code.

allFunctionAndStaticVariableCode (globalset)

Includes the Abstract Syntax Tree (AST) nodes in all functions, and all statically declared variables. This set is the union of allFunctionCode and allStaticVariableCode.

allFunctionAndStaticVariableDefinitions (globalset)

Includes all function and staticaly declared variable definitions. This set is the union of allFunctionDefinitions and allStaticVariableDefinitions.

allFunctionCode (globalset)

Includes all the Abstract Syntax Tree (AST) nodes in all the functions of the current Go code.

See Also

allFunctionAndStaticVariableCode

allFunctionDefinitions (globalset)

Includes all function definitions in the current Go code.

See Also

allFunctionAndStaticVariableDefinitions

allStaticVariableCode (globalset)

Includes all statically declared variables in the current Go code.

See Also

allFunctionAndStaticVariableCode

allStaticVariableDefinitions (globalset)

Includes all definitions of statically declared variables in the current Go code.

See Also

allFunctionAndStaticVariableDefinitions

allTextFiles (globalset)

Includes all source files in the current project that are coded in the Go language.

Code Patterns

These patterns, organized by category, match the constructs that might be found in the target source code.

Statements

Patterns in this section belong to the statement class. They match executable statements in the target code.

allLoops (pattern)

Matches all loop kinds.

Details

The pattern matches both simple and enhanced for loops.

This pattern only matches nodes of type statement.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

Example

The following pattern uses allLoops to determine whether the simpleStatement is a loop:

CXM code follows
pattern simpleStatementLoop { simpleStatement { .expression == allLoops } };

See Also

forLoopSimple, forLoop

blockStatement (pattern)

Matches statements contained in curly braces ( { } ).

Details

Block statements contain one or more statements, enclosed in curly braces.

This pattern only matches nodes of type statement.

Properties

blockStatement produces a record that contains the following property:

Name Type Description
containedStatements list<statement> The statements contained in the block

Inherits properties from:

astnode

Example

The following pattern finds blockStatement entities that contain only the empty statement:

CXM code follows
pattern emptyStatementBlock { blockStatement { .containedStatements == emptyStatement } };

See Also

emptyStatement

breakStatement (pattern)

Matches break statements.

Details

This does not match a break that has a label. See labeledBreakStatement.

This pattern only matches nodes of type statement.

Properties

breakStatement produces a record that contains the following property:

Name Type Description
controlStatement statement The flow control statement within which the break occurs; for example, while or switch

Inherits properties from:

astnode

Example

The following example matches break statements within a switch:

CXM code follows
pattern breakFromSwitch { breakStatement { .controlStatement == switchStatement } };

See Also

switchStatement, forLoop, forLoopSimple

caseStatement (pattern)

Matches individual case statements.

Details

This pattern does not match the default statement. See the defaultStatement pattern.

This pattern only matches nodes of type statement.

Properties

caseStatement produces a record that contains the following property:

Name Type Description
valueExpression expression The value associated with the case

Inherits properties from:

astnode

Example

The following CodeXM pattern matches all case statements that have a case for the integer value 1:

CXM code follows
pattern caseOne { caseStatement { .valueExpression == integerLiteral { .value == 1 } } };

See Also

defaultStatement, switchStatement

continueStatement (pattern)

Matches continue statements.

Details

This pattern only matches nodes of type statement.

Properties

continueStatement produces a record that contains the following property:

Name Type Description
controlStatement statement The flow-control statement within which the continue occurs. For example, switch.

Inherits properties from:

astnode

Example

The following example matches continue statements within a switch:

CXM code follows
pattern continueFromSwitch { continueStatement { .controlStatement == switchStatement } };

See Also

labeledContinueStatement, allLoops, forLoop, forLoopSimple

defaultStatement (pattern)

Matches the default case in switch statements.

Details

This pattern only matches nodes of type statement.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

Example

The following pattern matches switch statements that have a default clause:

CXM code follows
pattern switchWithDefault { switchStatement as sw where exists stmt in sw.caseList where stmt matches defaultStatement };

See Also

caseStatement, switchStatement

deferStatement (pattern)

Matches defer statements.

Details

This pattern only matches nodes of type statement.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

See Also

blockStatement, ifStatement

emptyStatement (pattern)

Matches empty statements.

An empty statement can be a line with no executable code that is terminated by a semicolon; non-executable code enclosed by curly braces; or an implied branch of an if statement.

Details

The following are examples of emptyStatement situations:

Go code follows
; // No code here
{
// No code here
}
if (b) {
// ...
}
// No else branch

This pattern only matches nodes of type statement.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

See Also

blockStatement, ifStatement

fallThroughStatement (pattern)

Matches fallthrough statements.

Details

This pattern only matches nodes of type statement.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

forLoop (pattern)

This pattern matches both simple and enhanced for loops.

Details

The condition of a simple for loop is a for clause; for example, i := 0; i < 10; i++.

The condition of an enhanced for loop is either a Boolean expression, or it is a range clause that tells the loop to iterate over all the entries in an object such as an array, a string, a map, and so on.

This pattern only matches nodes of type statement.

Properties

forLoop produces a record that contains the following properties:

NameTypeDescription
body statement The body of the for loop
kind enum ForLoopKind The kind of for loop: either `simple` or `enhanced`. See ForLoopKind.

Inherits properties from:

astnode

Example

Matches any simple for loop:

CXM code follows
pattern anySimpleForLoop { forLoop { .kind == `simple` } };

See Also

allLoops, forLoopSimple

forLoopSimple (pattern)

Matches simple for loops of the form for (int i = 0; i < 10; i++).

Details

This pattern only matches nodes of type statement.

Properties

forLoopSimple produces a record that contains the following properties:

Name Type Description
bodyStatement statement The body of the loop
conditionDeclaration variableDeclaration? If a variable is declared in the second clause of the loop, it is represented here; otherwise this field is null
conditionExpression statement The conditional clause for the loop
initializationStatement statement The initialization clause for the loop
kind enum ForLoopKind Always `simple`. See ForLoopKind.
updateStatement statement The update clause of the loop

Inherits properties from:

astnode

Example

The following pattern matches a simple for loop that uses a postfix increment expression to update its iterations:

CXM code follows
pattern postFixUpdate { forLoopSimple { .updateStatement == simpleStatement { .expression == incrementOperator { .kind == `postfix` } } } };

See Also

allLoops, forLoop

gotoStatement (pattern)

Matches goto statements.

Details

This pattern only matches nodes of type statement.

Properties

goToStatement produces a record that contains the following property:

Name Type Description
labelStatement statement The statement to go to

Inherits properties from:

astnode

ifStatement (pattern)

Matches entire if statements, including their condition expressions and their true and false branches.

Details

This pattern only matches nodes of type statement.

Properties

ifStatement produces a record that contains the following properties:

Name Type Description
conditionDeclaration variableDeclaration? The variable declared in the condition, if one exists; null otherwise
conditionExpression expression The condition of the if statement
falseStatement statement? The false branch of the if statement, or null if no false branch exists
trueStatement statement The true branch of the if statement

Inherits properties from:

astnode

Example

The following pattern matches if statements that have no else clause:

CXM code follows
pattern ifNoElse { ifStatement { .falseStatement == null } };

incDecStatement (pattern)

Matches IncDec statements: that is, statements that use either the incrementOperator, ++, or the decrementOperator, --.

Details

This pattern only matches nodes of type statement.

Properties

incDecStatement produces a record that contains the following property:

Name Type Description
expression expression The expression; for example, a function call, an assignment, or (frequently) a post clause in a simple for loop.

labeledBreakStatement (pattern)

Matches break statements that target a label.

Details

This pattern only matches nodes of type statement.

Properties

labeledBreakStatement produces a record that contains the following properties:

Name Type Description
controlStatement statement The flow-of-control statement within which the break occurs; for example, for or switch
target statement The label to break to

Inherits properties from:

astnode

Example

The following pattern matches a break statement that targets the label outer:

CXM code follows
pattern outerBreak { labeledBreakStatement { .target == labelStatement { .nameString == "outer" } } };

See Also

labelStatement, breakStatement, switchStatement, forLoop, forLoopSimple

labeledContinueStatement (pattern)

Matches continue statements that target a label.

Details

This pattern only matches nodes of type statement.

Properties

labeledContinueStatement produces a record that contains the following properties:

Name Type Description
controlStatement statement The flow-of-control statement within which the continue occurs; for example, while or switch
target statement The label to target

Inherits properties from:

astnode

Example

The following pattern matches a continue statement that targets the label outer:

pattern outerBreak { labeledContinueStatement { .target == labelStatement { .nameString == "outer" } } };

labelStatement (pattern)

Matches statements that have a label.

Details

This pattern only matches nodes of type statement.

Properties

labelStatement produces a record that contains the following properties:

Name Type Description
kind enum labelScopeKind The scope of the label: `unscoped` if the label is inside a local scope; `scoped` if the label appears within a struct or an interface. See labelScopeKind.
nameString string The name of the label
targetStatement statement The statement to which this label is assigned

Inherits properties from:

astnode

Example

The following pattern finds all continue statements that target the label outer:

CXM code follows
pattern continueOuter { labeledContinueStatement { .target == labelStatement { .nameString == "outer" } } };

See Also

labeledContinueStatement, labeledBreakStatement

locallyDeclaredTypeStatement (pattern)

Matches statements that use a locally declared type.

Details

This pattern only matches nodes of type statement.

Properties

locallyDeclaredTypeStatement produces a record that contains the following property:

Name Type Description
declaredClass expression The expression, such as a function call or an assignment.

returnStatement (pattern)

Matches both simple, void return statements, and return <expression> returns.

Details

This pattern only matches nodes of type statement.

Properties

returnStatement produces a record that contains the following properties:

Name Type Description
isVoid bool true if the return does not have an associated expression
returnedExpression expression? The expression returned, if one is specified; null, otherwise

Inherits properties from:

astnode

Example

The following pattern matches return statements that are void (that is, that do not return a value):

CXM code follows
pattern voidReturn { returnStatement { .isVoid == true } };

selectStatement (pattern)

Matches select statements.

Details

This pattern only matches nodes of type statement.

Properties

selectStatement produces a record that contains the following property:

Name Type Description
branchStatement statement The body of the select statement, including all the statements contained in its case and default clauses.

Example

The following pattern matches select statements that have a default clause:

CXM code follows
pattern selectWithDefault { selectStatement as sw where exists stmt in sw.caseList where stmt matches defaultStatement }

See Also

caseStatement, defaultStatement

sendStatement (pattern)

Matches send statements.

Details

This pattern only matches nodes of type statement.

Properties

sendStatement produces a record that contains the following properties:

Name Type Description
lhsExpression expression The left-hand side of the Send expression.
rhsExpression expression The right-hand side of the Send expression.

simpleStatement (pattern)

Matches individual executable statements.

Details

The term simple—as opposed to compound—means that the these statements are not flow-of-control statements. Simple statements include assignments, function calls, and function returns. Variable declarations (variableDeclaration) are not considered statements.

This pattern only matches nodes of type statement.

Properties

simpleStatement produces a record that contains the following property:

Name Type Description
expression expression The expression to match, such as a function call or an assignment

Inherits properties from:

astnode

Example

The following pattern matches a function call:

CXM code follows
pattern simpleStatementFunctionCall { simpleStatement { .expression == functionCall } };

switchStatement (pattern)

Matches entire switch statements, including all the statements contained in their case and default clauses.

Details

This pattern only matches nodes of type statement.

Properties

switchStatement produces a record that contains the following properties:

Name Type Description
bodyStatement statement The body of the switch statement
caseList list<statement> A list of the case names for the switch statement
conditionDeclaration variableDeclaration? If a variable is declared in the conditionExpression, it is identified here; if it is not, this field is null
conditionExpression expression The condition for the switch statement

Inherits properties from:

astnode

Example

The following pattern matches switch statements that have a default clause:

CXM code follows
pattern switchWithDefault { switchStatement as sw where exists stmt in sw.caseList where stmt matches defaultStatement };

See Also

caseStatement, defaultStatement

Declarations

Patterns in this section belong to the declaration class. They match object declarations in the target code.

variableDeclaration (pattern)

Matches all kinds of variable declarations.

Properties

variableDeclaration produces a record that contains the following properties:

Name Type Description
initializer initializer? The initializer of the variable, if it exists
variableDeclarationKind enum Either `unscoped` or `scoped`
variable symbol The identifier of the variable being declared

Inherits properties from:

astnode

Example

The following pattern matches all variables declared with the type int:

CXM code follows
pattern intVariableDeclaration { variableDeclaration { .variable == symbol { .type == integerType } } }

Types

These patterns match various types of values in the target code.

anyType (pattern)

Matches any Go language type.

Details

This pattern only matches nodes of type type.

Properties

This pattern does not expose any new properties.

arrayType (pattern)

Matches all array types.

Details

This pattern only matches nodes of type type.

Properties

arrayType produces a record that contains the following property:

Name Type Description
elementType type The type of the elements in the array

Example

The following pattern finds all arrays whose elements are any type of integer:

CXM code follows
t matches arrayType { .elementType == integerType };

boolType (pattern)

Matches the bool type.

Details

This pattern only matches nodes of type type.

Properties

boolType produces a record that contains the following properties:

Name Type Description
alignmentInBytes int The alignment of the type, in bytes
sizeInBits int The size of the Boolean, in bits
sizeInBytes int The size of the Boolean, in bytes

Example

The following pattern matches any expression of the type bool:

CXM code follows
node matches expression as e where e.type matches boolType;

See Also

integerType

classType (pattern)

Matches all struct and interface types.

Details

This pattern only matches nodes of type type.

Properties

classType produces a record that contains the following properties:

Name Type Description
extra extra Extra information used for defect reporting
extraWithoutScope extra Extra information used for defect reporting. This version of the extra information omits the scope details.
isAnonymous bool true if the class is anonymous
isComplete bool true if the class is complete.
kind enum The kind of class: either `interface` or `struct`
location location The location information of the class
qualifiedName string The name of the class including the class’s package
scopeList list<string> The scope of the class. This is the elements of the qualified name broken up into a list.
simpleName string The name of the class, without the package prefix

Example

The following pattern matches all interface types:

CXM code follows
c matches classType { .kind = `interface` };

floatType (pattern)

Matches the Go types float and complex.

Details

This pattern only matches nodes of type type.

Properties

floatType produces a record that contains the following properties:

Name Type Description
kind enum floatKind The kind of floating-point value: either `float` or `complex`. See floatKind.
alignmentInBytes int The alignment of the type, in bytes
sizeInBits int The total size of the float, in bits
sizeInBytes int The size of the float, in bytes

Note: The representation of floating types is implementation-defined, so CodeXM does not show how bits are apportioned between the exponent and the mantissa.

Example

The following pattern matches any expression that has the type float:

CXM code follows
node matches expression { .type == floatType { .kind == `float`} };

functionType (pattern)

Matches function types.

Details

This pattern only matches nodes of type type.

Properties

functionType produces a record that contains the following properties:

Name Type Description
declaredThrownTypeList list<type> The types the function is declared to throw
hasVariableArity bool true if the function uses variable arity; that is, a variable number of potential arguments
isStatic bool true if the function is declared as static
parameterTypeList list<type> A list of all the parameter types for the function
returnType type The return type of the function

Example

The following pattern matches all function types that return an int:

CXM code follows
pattern returnsInt { functionType { .retunrnType == integertype { .kind == `int` } } };

integerType (pattern)

Matches all integer types that Go recognizes.

Details

This pattern only matches nodes of type type.

Properties

integertype produces a record that contains the following properties:

Name Type Description
alignmentInBytes int The alignment of the type, in bytes
kind enum intKind The kind of integer type: See intKind.
sizeInBits int The size of the type, in bits
sizeInBytes int The size of the type, in bytes

Example

The following pattern uses the kind property to match a uint8 type:

CXM code follows
t matches integertype { .kind == `uint8` };

See Also

boolType

referenceType (pattern)

Matches reference types.

Details

A reference type represents an object being passed by reference; for example, as an argument to a function.

This pattern only matches nodes of type type.

Properties

referenceType produces a record that contains the following property:

Name Type Description
toType type The type the reference refers to

Example

The following pattern matches all references to a structure named MyStruct:

CXM code follows
r matches referenceType { .toType == classType { .simpleName == "MyStruct" } };

stringType (pattern)

Matches the string type.

Details

This pattern only matches nodes of type type.

Properties

This pattern does not expose any new properties.

Example

The following pattern matches an expression whose result is a string type:

CXM code follows
node matches expression as e where e.type matches stringType

Expressions

Patterns in this section belong to the expression class. They match expressions in the target code.

Many statements in Go code contain expressions. The patterns in this section match specific kinds of expressions.

Please be aware: The patterns shown in the “Literals” and “Operators” sections are expressions, too.

Example: Expressions used as if-statement conditions

For example, in the following snippet of target code:

Go code follows
if ( my_boolean ) {
if ( getPropertyValue(a) == v) {
// ... Do something.
}
};

... we see a pair of if statements. As described in the previous section, the ifStatement pattern detects either instance.

But each statement has a condition: namely, the part enclosed by the parentheses that follow the keyword if. Both conditions in this example are expressions. The first is simply a variable reference. The second is more complicated: It is made up of a binary operator (specifically, the equality operator) with operands (which are themselves expressions) appearing on either side. The left-hand operand is a function call, and the right-hand operand is a variable reference.

You could match the first of these conditions by using the expression pattern variableReference (which also matches the right-hand side of the second condition), and you could match the second of these conditions by using the expression pattern binaryOperator.

To inspect a complete condition expression, look at the .conditionExpression property of the ifStatement pattern.

Common Properties of Expressions

In addition to the properties specific to each pattern, and the properties inherited from astnode, all expression patterns have the following properties:

Name Type Description
type type The Go type of the expression
isParenthesized bool Whether there are parenthesis around this expression

anyTypeVariableReference (pattern)

Matches locations where an expression references a variable.

Details

This pattern only matches nodes of type expression.

Properties

anyTypeVariableReference produces a record that contains the following property:

Name Type Description
variable symbol The symbol that represents the variable

Inherits properties from:

astnode

Example

The following pattern matches all references to local variables:

CXM code follows
pattern variableReferenceStaticFinal { variableReference { .scope == `local`; } }

attributeReference (pattern)

Matches expressions that reference an attribute. For example, townStructure.street.

Details

This pattern only matches nodes of type expression.

Properties

attributeReference produces a record that contains the following properties:

Name Type Description
primaryExpression expression The base (the left-hand side) of the attribute-reference expression
propertyExpression expression The property to access (the right-hand side) of the attribute-reference expression

Inherits properties from:

astnode

Example

The following pattern matches an attribute-reference expression that accesses a property named street:

CXM code follows
pattern customAttribute { attributeReference { .primaryExpression == stringLiteral { .valueString == "street" } } }

boxExpression (pattern)

Matches box expressions: both boxing a value and unboxing a reference.

Details

This pattern only matches nodes of type expression.

Properties

boxExpression produces a record that contains the following property:

Name Type Description
expression expression The expression being boxed or unboxed

Inherits properties from:

astnode

Example

The following pattern matches all unboxing expressions:

CXM code follows
pattern unboxingExpression { unboxExpression { .unboxMethod == NonNull } }

builtinFunctionExpression (pattern)

Matches calls to built-in functions.

Details

This pattern only matches nodes of type expression.

Properties

builtinFunctionExpression produces a record that contains the following properties:

Name Type Description
args list<expression> A list that contains the arguments passed to the function
name string The name of the built-in function

Inherits properties from:

astnode

deconstructionExpression (pattern)

Matches deconstruction expressions.

Details

This pattern only matches nodes of type expression.

Properties

deconstructionExpression produces a record that contains the following properties:

Name Type Description
sourceExpression expression The source of the deconstruction
targetStatements list<statement> The targets of the deconstruction

Inherits properties from:

astnode

Example

The following pattern matches the deconstruction of value tuples:

CXM code follows
pattern tupleDeconstruction { deconstructionExpression { .sourceExpression == expression { .type = valueTupleType } } };

dynamicFunctionCall (pattern)

Matches calls to dynamic functions.

Details

This pattern only matches nodes of type expression.

Properties

dynamicFunctionCall produces a record that contains the following properties:

Name Type Description
callKind DynamicFuncKind One of `DFK_METHOD`, `DFK_INVOKE`, `DFK_PROPERTY`, `DFK_INDEXER`, `DFK_OPERATOR`, or `DFK_CONVERSION`
name string The name of the function

Inherits properties from:

astnode

Example

The following pattern matches calls to the dynamic function named example():

CXM code follows
pattern dynamicExampleCall { dynamicFunctionCall { .name == "example" } };

enumReference (pattern)

Matches expressions that reference an enum.

Details

This pattern only matches nodes of type expression.

Properties

enumReference produces a record that contains the following property:

Name Type Description
enumVariableSymbol symbol The symbol that refers to this enum

Inherits properties from:

astnode

Example

The following pattern matches enum instances that have the identifer Example:

CXM code follows
pattern enumReferenceExample { enumReference { .enumVariableSymbol == enumVariableSymbol { .simpleName == "Example" } } };

fieldAccess (pattern)

Matches expressions that access fields.

Details

This pattern only matches nodes of type expression.

Properties

fieldAccess produces a record that contains the following properties:

Name Type Description
field symbol The symbol of the field being accessed
objectExpression expression The object that owns the field being accessed

Inherits properties from:

astnode

Example

Given the following code:

Go code follows
e Example{ MyInt: 35 }
var i = e.MyInt

... the following pattern would match the access to the MyInt field:

CXM code follows
pattern accessToExampleMyInt { fieldAccess { .objectExpression == expression { .type == classType { .simpleName == "Example" } }; .field == symbol { .simpleName == "myInt" } } }

fieldReference (pattern)

Matches expressions that reference fields.

Details

This pattern only matches nodes of type expression.

Properties

fieldReference produces a record that contains the following property:

Name Type Description
fieldSymbol symbol The field symbol

Inherits properties from:

astnode

Example

The following pattern matches when a field example is referenced:

CXM code follows
pattern referringToExample { fieldReference { .fieldSymbol == symbol { .simpleName == "example" } } };

functionCall (pattern)

Matches calls to functions.

Details

This pattern only matches nodes of type expression.

Properties

functionCall a record that contains the following properties:

Name Type Description
argumentList list<expression> A list of the arguments passed to the function
calledExpression expression The expression of the function being called
calledFunction functionSymbol The symbol of the function being called
isNonStaticMethod bool true if the function being called is a non-static method
resolvedCallees list<symbol> A list of the callees

Inherits properties from:

astnode

Example

The following pattern finds function calls whose arguments are not variable references:

CXM code follows
pattern nonReferenceArgument { functionCall as fn where exists a in fn.argumentList where ! (a matches variableReference) };

See Also

functionReference

functionReference (pattern)

Matches expressions that reference functions.

Details

This pattern only matches nodes of type expression.

Properties

functionReference produces a record that contains the following property:

Name Type Description
functionSymbol symbol The symbol that represents the function

Inherits properties from:

astnode

Example

The following pattern matches calls to a function named example():

CXM code follows
pattern callToExample { functionCall { .calledExpression == functionReference { .functionSymbol == functionSymbol { .simpleName == "example" } } } }

See Also

functionCall

functionVariableReference (pattern)

Matches locations where an expression references a variable.

Details

This pattern only matches nodes of type expression.

Properties

functionVariableReference produces a record that contains the following properties:

Name Type Description
qualifiedName string The name of the variable, including any scope information
simpleName string The name of the variable, without scope information
variable symbol The symbol that represents this variable

Inherits properties from:

astnode

Example

The following pattern matches all references to local variables:

CXM code follows
pattern variableReferenceStaticFinal { variableReference { .scope == `local`; } }

referenceDereference (pattern)

Matches locations where a reference-type expression has been dereferenced.

Details

This pattern only matches nodes of type expression.

Properties

referenceDereference produces a record that contains the following property:

Name Type Description
referencedExpression expression The expression being dereferenced

Inherits properties from:

astnode

See Also

referenceType

subscriptReference (pattern)

Matches uses of a subscript to find a value in an array.

Details

This pattern only matches nodes of type expression.

Properties

subscriptReference produces a record that contains the following properties:

Name Type Description
arrayExpression expression The array the subscript is being used on
indexExpression expression The value inside the brackets ( [ ] )

Inherits properties from:

astnode

Example

The following pattern matches where a variable is used as an index to look up a value in an array:

CXM code follows
pattern variableArrayLookup { subscriptReference { .indexExpression == variableReference } };

variableReference (pattern)

Matches where variables are referenced in expressions.

Details

This pattern only matches nodes of type expression.

Properties

variableReference produces a record that contains the following properties by variableReference:

Name Type Description
qualifiedName string The name of the variable, with scope information.
scope enum variableScopeEnum The scope of the variable: either `local` or `static` (available globally). See variableScopeEnum.
simpleName string The name of the variable, without scope information.
variable symbol The symbol that represents this variable

Inherits properties from:

astnode

Example

The following pattern matches all references to local variables:

CXM code follows
pattern variableReferenceStaticFinal { variableReference { .scope == `local`; };

Literals

These patterns match literal values in the target code.

boolLiteral (pattern)

Matches Boolean literals: that is, either true or false.

Details

This pattern only matches nodes of type expression.

Properties

boolLiteral produces a record that contains the following property:

Name Type Description
value enum `true` or `false`

Inherits properties from:

astnode

Example

The following pattern matches all literal true Boolean values:

CXM code follows
pattern trueBooleanLiteral { boolLiteral { .value == `true' } };

compositeLiteral (pattern)

Matches struct literals.

Details

This pattern only matches nodes of type expression.

Properties

compositeLiteral produces a record that contains the following property:

Name Type Description
targetType classType The type of the struct object.

Example

The following pattern matches literal struct objects whose name is Example:

CXM code follows
pattern examplecompositeLiteral { .targetType == classType { .simpleName == "Example" } }

floatLiteral (pattern)

Matches floating-point literals.

Details

This pattern only matches nodes of type expression.

Properties

floatLiteral produces a record that contains the following properties:

Name Type Description
isHexFloat bool true if this float is represented using hexadecimal numerals
suffix enum? The suffix of the literal: either `f` or null.
valueString string The value of the float, represented as a string

Inherits properties from:

astnode

Example

The following pattern:

CXM code follows
f matches floatLiteral { .valueString == "2.5" };

... matches this target-code expression:

Go code follows
f float32 = 2.5;

imaginaryLiteral (pattern)

Matches the imaginary part of a complex number.

Details

This pattern only matches nodes of type expression.

Properties

imaginaryLiteral produces a record that contains the following property:

Name Type Description
valueString string The value of the imaginary component of the complex number, represented as a string.

Inherits properties from:

astnode

Example

Given the following snippet of source code:

Go code follows
33.14i

... the following CodeXM pattern would match it:

CXM code follows
f matches imaginaryLiteral { .valueString == "33.14" }

integerLiteral (pattern)

Matches integer literals; that is, all possible literal integer values.

Details

This pattern only matches nodes of type expression.

Properties

integerLiteral produces a record that contains the following properties:

NameTypeDescription
base enum One of `binary`, `decimal`, `octal`, or `hexadecimal`.
intKind enum The kind of the integer type: See intKind.
value int The value of the integer literal

Inherits properties from:

astnode

Example

The following pattern matches only long integer literals:

CXM code follows
pattern longIntegerLiteral { integerLiteral { .kind == `long` } };

mapLiteral (pattern)

Matches literal map expressions.

Details

This pattern only matches nodes of type expression.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

nilLiteral (pattern)

Matches all nil literals.

Details

This pattern only matches nodes of type expression.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

Example

The following pattern finds all assignments to nil; for example, a = nil:

CXM code follows
pattern assignmentToNil { assignmentOperator { sourceExpression == nilLiteral } };

stringLiteral (pattern)

Matches all string literals.

Details

This pattern only matches nodes of type expression.

Properties

stringLiteral produces a record that contains the following property:

Name Type Description
valueString string The value of the string literal.

Inherits properties from:

astnode

Example

The following pattern finds assignments from the string literal "Example":

CXM code follows
pattern assignmentsToStringLiterals { assignmentOperator { .sourceExpression == stringLiteral { .value == "Example" } } };

Operators

These patterns match operators in the target code.

addressOf(pattern)

Matches address-of operations.

Details

In Go, the address-of operation applies only to integers.

This pattern only matches nodes of type expression.

Properties

addressOf produces a record that contains the following property:

Name Type Description
kind enum Always `int`

Example

The following pattern matches operations that obtain the address of int variables:

CXM code follows
pattern addressOfInt { addressOf { .operandType == integerType { .kind == `int` } } }

assignmentOperator (pattern)

Matches all forms of the assignment operator where it occurs.

Details

This pattern does not match variable declarations where the variable is initialized with a value (see variableDeclaration).

This general pattern matches both simple (a = b) and compound (a += b) forms of assignments.

This pattern only matches nodes of type expression.

Properties

assignmentOperator produces a record that contains the following properties:

NameTypeDescription
kind enum assignKind The kind of assignment: either `simple` or `compound`. See assignKind.
operator enum The operator used: one of `=`, `+=`, `-=`, `*=`, `/=`, `|=`, `&=` `%=`, `^=`, `>>=`, or `<<=`
sourceExpression expression The expression on the right-hand side of the assignment operator
targetExpression expression The expression on the left-hand side of the assignment operator

Inherits properties from:

astnode

Example

The following pattern matches any assignment where the source of the assignment is a cast:

CXM code follows
pattern assignedFromCast { assignmentOperator { .sourceExpression == castOperator } };

See Also

assignmentOperatorCompound, assignmentOperatorSimple

assignmentOperatorCompound (pattern)

Matches only compound assignment operators such as a += b.

Details

This pattern only matches nodes of type expression.

Properties

assignmentOperatorCompound produces a record that contains the following properties:

Name Type Description
kind enum assignmentOperatorCompound Always `compound`. See assignKind.
operator enum The operator used: one of `+=`, `-=`, `*=`, `/=`, `|=`, `&=`, `%=`, `^=`, `>>=`, or `<<=`
sourceExpression expression The expression on the right-hand side of the assignment operator
targetExpression expression The expression on the left-hand side of the assignment operator

Inherits properties from:

astnode

Example

The following pattern matches the += operator:

CXM code follows
pattern addCompoundAssignment { assignmentOperatorCompound { .operator == `+=` } };

See Also

assignmentOperatorSimple, assignmentOperator

assignmentOperatorSimple (pattern)

Matches only simple assignments such as a = 1.

Details

Even though variable declarations look similar to assignment operators, this pattern does not match variable declarations. See variableDeclaration.

This pattern only matches nodes of type expression.

Properties

assignmentOperatorSimple produces a record that contains the following properties:

Name Type Description
kind enum assignKind Always `simple`. See assignKind.
operator enum Always `=`
sourceExpression expression The expression on the right-hand side of the assignment operator
targetExpression expression The expression on the left-hand side of the assignment operator

Inherits properties from:

astnode

Example

The following pattern matches all simple assignments to a nil literal:

CXM code follows
pattern assignmentToNilLiteral { assignmentOperatorSimple { .sourceExpression == nilLiteral } };

See Also

assignmentOperatorCompound, assignmentOperator

binaryOperator (pattern)

Matches all possible binary operations in Go.

Details

This pattern only matches nodes of type expression.

Properties

binaryOperator produces a record that contains the following properties:

Name Type Description
isImplicit bool true if the operator is implicit
lhsExpression expression The expression on the left-hand side of the operator
operator enum The operator this pattern represents: one of `==`, `!=`, `<`, `>`, `<=`, `>=`, `*`, `/`, `%`, `+`, `-`, `<<`, `>>`, `&`, `^`, `|`, `&&`, `||`, `,`, or `=`
rhsExpression expression The expression on the right-hand side of the operator

Inherits properties from:

astnode

Nested Expressions

When pattern matching, be aware that either or both operands of a binary operator can themselves be binary operators that represent operations to be completed before the matched operation is performed.

For example, a + b * c is understood as a + (b * c) due to operator precedence. This is matched as a binary addition that has a right-hand operand of b * c. The value of the subexpression must be computed before the addition is performed.

On the other hand, (a + b) * c is matched as a binary multiplication. The left-hand operand, a + b, must be computed before it is multiplied by c.

The following illustration shows these two situations:

Parsing binary operations

In both these cases, a binaryOperator { .operand == `*` } pattern matches some part of the expression. In the left-hand case, it matches b * c. In the right-hand case, it matches the entire expression.

Example

The following pattern matches only multiplication ( * ):

CXM code follows
pattern multiplicationOperation { binaryOperator { .operator == `*` } };

See Also

unaryOperator

castOperator (pattern)

Matches all kinds of casts.

Details

This pattern only matches nodes of type expression.

Properties

castOperator produces a record that contains the following properties:

Name Type Description
castKind enum The kind of cast represented: `explicit`, `implicit`, or `dynamic`. See castKind.
operandExpression expression The expression being cast

Inherits properties from:

astnode

Example

The following CodeXM pattern matches all kinds of casts (implicit, explicit, dynamic) to type int:

CXM code follows
pattern castToInt { castOperator { .type == integerType { .kind == `int` } } };

decrementOperator (pattern)

Matches all decrement operators.

Details

This pattern only matches nodes of type expression.

Properties

decrementOperator produces a record that contains the following property:

Name Type Description
operandExpression expression The expression the decrement operator is being applied to

Inherits properties from:

astnode

Example

The following pattern matches when a decrement operator is used to update a for loop:

CXM code follows
pattern forLoopPostfixDecrement { forLoop { .updateStatement == simpleStatement { .expression == decrementOperator } } };

See Also

incrementOperator

incrementOperator (pattern)

Matches all increment operators.

Details

This pattern only matches nodes of type expression.

Properties

incrementOperator produces a record that contains the following properties:

Name Type Description
operandExpression expression The expression the increment operator is being applied to

Inherits properties from:

astnode

Example

The following example CodeXM matches when a prefix increment operator is used to update a for loop:

CXM code follows
pattern forLoopPrefixIncrement { forLoop { .updateStatement == simpleStatement { .expression == incrementOperator } } } };

See Also

decrementOperator

newOperator (pattern)

Matches the new operator.

Details

This pattern only matches nodes of type expression.

Properties

newOperator produces a record that contains the following properties:

Name Type Description
initializer initializer The expression evaluated to determine the initial condition
objectType type The type of the object being created

Inherits properties from:

astnode

Example

The following pattern matches all new operations that create an object of type struct Example:

CXM code follows
pattern exampleNew { newOperator { .objectType == classType { .simpleName == "Example" } } };

unaryOperator (pattern)

Matches unary operators—those operators that have only one operand.

Details

This pattern only matches nodes of type expression.

Properties

unaryOperator produces a record that contains the following properties:

Name Type Description
operandExpression expression The expression the operation is performed on
operator enum The unary operator this pattern represents: one of `+`, `-`, `!`, or `~` (tilde for bitwise negation)

Inherits properties from:

astnode

Example

The folowing pattern matches any use of the unary plus ( + ) operator:

CXM code follows
pattern unaryPlus { unaryOperator { .operator == `+` } };

See Also

binaryOperator

Initializers

Patterns in this section belong to the initializer class. They match initializers in the target code.

In many cases, an initializer can appear to be an assigment statement. However, many languages treat initialization as its own, special case. The CodeXM language libraries treat initialization in this way, as well.

arrayInitializer (pattern)

Matches the initializations of linear arrays that use a list enclosed in curly braces.

Details

This pattern only matches nodes of type initializer.

Properties

arrayInitializer produces a record that contains the following property:

Name Type Description
variableInitializerList list<initializer> A list of the elements in the curly braces

Inherits properties from:

astnode

Example

The arrayInitializer pattern matches code such as the following array initialization:

Go code follows
a []int = {0, 1};

expressionInitializer (pattern)

Matches simple expression initializers used to initialize scalar objects.

Details

This pattern only matches nodes of type initializer.

Properties

expressionInitializer produces a record that contains the following property:

Name Type Description
expression expression The expression that evaluates to the value that is used to initialize the scalar object

Inherits properties from:

astnode

Example

This pattern would match the following Go initialization:

Go code follows
var a = x + y

The following pattern matches all initializations done using binary operations:

CXM code follows
pattern binaryOperationInitializer { expressionInitializer { .expression == binaryOperator; } };

zeroInitializer (pattern)

Matches initializations where no value is provided.

Details

This pattern only matches nodes of type initializer.

Properties

This pattern does not expose any new properties.

Inherits properties from:

astnode

Symbols

These patterns match symbols in the target code.

A symbol is an entity that can have an identifier; for example, a symbol might be a variable, a function, or a parameter to a function.

In Coverity Analysis, each symbol in a program is its own node in the abstract syntax tree, and is distinct from the identifier that represents the entity in the source.

Common Properties of Symbols

In addition to the properties that are specific to each pattern, all symbol patterns have the following properties in common:

Name Type Description
identifier string? The string used as an unqualified name for the symbol; null if there is none
mangledName string? The internal “mangled” name used for the symbol (the mangled name includes type and scope information, to disambiguate this instance of the identifier); null if the mangled name is not available
location sourceloc The location where this symbol was declared
type type The Go type declared for this symbol
access enum AccessKeyword The scoping keywords associated with the symbol, such as `public` or `private`
is_file_or_readonly bool true if the symbol has a final specifier
scopeList list<string> A list of the class names and namespaces that enclose the symbol

fieldSymbol (pattern)

Matches field symbols in class declarations.

Details

This pattern only matches nodes of type symbol.

Properties

fieldSymbol produces a record that contains the following properties:

Name Type Description
isTransient bool true if the field is declared transient
isVolatile bool true if the field is declared volatile
ownerClass classType The owner class for the field symbol
qualifiedName string The name of the field, including any scope information
simpleName string The name of the field, excluding scope information

Inherits properties from:

symbol

Example

The following pattern finds the field name Unleaded:

CXM code follows
pattern privateFieldAccess { fieldAccess { .field == fieldSymbol { .simpleName == `Unleaded` } } }

functionSymbol (pattern)

Matches the symbols used to declare functions.

Details

This pattern only matches nodes of type symbol.

Properties

functionSymbol produces a record that contains the following properties:

Name Type Description
explicitParameterCount int The number of explicit parameters this function has
functionType functionType The type of the function
hasThis bool true if the function has the implicit this argument
isClassInitializer bool true if this function is a class initializer
isCompilerGenerated bool true if the function is compiler-generated
isConstructor bool true if the function is a constructor
isStaticMethod bool true if the function is a static method
qualifiedName string The name of the function, including any scope information
simpleName string The name of the function, without scope information

Inherits properties from:

symbol

Example

The following pattern finds all function calls to method functions:

CXM code follows
pattern callToSynchronized { functionCall { .calledFunction == functionSymbol { .hasThus == true } } }

localVariableSymbol (pattern)

Matches the variable symbols used in variable declarations.

Details

This pattern only matches nodes of type symbol.

Properties

localVariableSymbol produces a record that contains the following properties:

Name Type Description
qualifiedName string The name of the variable, including any scope information
simpleName string The name of the variable, without scope information

Inherits properties from:

symbol

Example

The following pattern finds all uses of local variables:

pattern localVariableUse { variableReference { .variable == localVariableSymbol } };

parameterSymbol (pattern)

Matches parameter symbols in function declarations.

Details

This pattern only matches nodes of type symbol.

Properties

parameterSymbol produces a record that contains the following properties:

Name Type Description
extra extra Extra information used for defect reporting
ownerClass classType The owner class for the parameter symbol
position sourceloc The position of the parameter in the function
qualifiedName string The name of the class, including scope information
scopeList list<string> The scope of the parameter. This is the elements of the qualified name broken up into a list.
simpleName string The name of the parameter, without scope information
type type The parameter’s type

Inherits properties from:

symbol

Example

The following pattern finds all uses of parameters whose type is referenceType:

CXM code follows
pattern useOfReferenceType { variableReference { .variable == parameterSymbol { .type == referenceType } } }

staticVariableSymbol (pattern)

Matches symbols for variables declared as const.

Details

This pattern only matches nodes of type symbol.

Properties

staticVariableSymbol produces a record that contains the following properties:

Name Type Description
ownerClass classType The owner class for the static variable symbol
qualifiedName string The name of the variable, including any scope information
simpleName string The name of the variable, without scope information

Inherits properties from:

symbol

Example

The following pattern finds all uses of statically defined variables:

CXM code follows
pattern staticVariableUse { variableReference { .variable == staticVariableSymbol } };

variableSymbol (pattern)

Matches the symbols of all declared variables.

Details

This pattern only matches nodes of type symbol.

Properties

variableSymbol produces a record that contains the following properties:

Name Type Description
qualifiedName string The name of the variable, including any scope information
scope variableScopeKind Either `local` for local variables, or `static` for statically defined variables
simpleName string The name of the variable, without scope information

Inherits properties from:

symbol

See Also

staticVariableSymbol, localVariableSymbol, parameterSymbol

Records

These are records that can be used within CodeXM patterns to match declarations.

declaration (record)

Represents a declaration.

Properties

declaration produces a record that contains the following properties:

Name Type Description
initializer initializer? An initializer; null if there is none
kind enum variableDeclarationKind The kind of declaration: `local` if the scope of the variable is local; `static` if the variable is declared within a struct or an interface. See variableDeclarationKind.
variable symbol The symbol variable

Example

The following pattern matches the declaration of an array whose name is perYear:

CXM code follows
let myTableDeclaration = pattern { declaration { .variable == localVariableSymbol { .simpleName == "perYear" } } }

Functions

The Go library provides a number of functions to help you handle, and analyze, the target source code.

See the Common Library Reference for descriptions of some general-purpose functions that are available to all language libraries.

Definition Functions

Definition functions retrieve definitions of struct, interface, function (func), or static variable objects.

getClassDefinition( classType )

Returns the definition of a specified class type, if that definition is available to analysis.

Name Type Description
classTypeResult classType The type of class whose definition you want to obtain.
return value classDefinition Returns the class definition if one is available; returns null, otherwise.

Pattern Functions

Pattern functions return patterns that you can use in your CodeXM searches, just as you use patterns provided by the language library.

arrayOf( typePattern )

A function that generates a pattern to match arrays of a particular type.

Details

This can be used to construct patterns that match nested structure.

Parameters and Return Value

Name Type Description
typePattern pattern A pattern matching a type
return value pattern A pattern matching an array type

Example

The following CodeXM snippet returns a pattern, intArray, that matches arrays of type int:

CXM code follows
let intArray = arrayOf( pattern integertype { .kind == `int` } ) in for code in globalset allFunctionCode where code matches intArray { // ... };

See Also

arrayType