CodeQL library for C#
codeql/csharp-all 0.4.4 (changelog, source)
Search

Module PrintAst

Provides queries to pretty-print a C# AST as a graph.

By default, this will print the AST for all elements in the database. To change this behavior, extend PrintAstConfiguration and override shouldPrint to hold for only the elements you wish to view the AST for.

Import path

import semmle.code.csharp.PrintAst

Imports

csharp

The default C# QL library.

Predicates

edges

Holds if target is a child of source in the AST, and property key of the edge has the given value.

graphProperties

Holds if property key of the graph has the given value.

nodes

Holds if node belongs to the output tree, and its property key has the given value.

Classes

AssignmentNode

A node representing an Assignment. Left and right children are shown in this order.

AttributeNode

A node representing an Attribute.

AttributesNode

A node representing the attributes of an Attributable. Only rendered if there’s at least one attribute.

BaseTypesNode

A node representing the base types of a ValueOrRefType.

CallableNode

A node representing a Callable, such as method declaration.

CastExprNode

A node representing a CastExpr. Type access and casted expression children are shown in this order.

ControlFlowElementNode

A node representing a ControlFlowElement (Expr or Stmt).

DeclarationWithAccessorsNode

A node representing a DeclarationWithAccessors, such as property declaration.

ElementNode

A node representing an AST node with an underlying Element.

FieldNode

A node representing a Field declaration.

LocalFunctionStmtNode

A node representing a LocalFunctionStmt. Each LocalFunction is displayed below its corresponding LocalFunctionStmt.

NamespaceNode

A node representing a NamespaceDeclaration.

ParameterNode

A node representing a Parameter declaration.

ParametersNode

A node representing the parameters of a Parameterizable. Only rendered if there’s at least one parameter and if the Parameterizable is not compiler generated or is of type Accessor.

PrintAstConfiguration

The query can extend this class to control which elements are printed.

PrintAstNode

A node in the output tree.

TopLevelPrintAstNode

A top-level AST node.

TypeMentionNode

A node representing an AST node with an underlying TypeMention.

TypeNode

A node representing a ValueOrRefType.

TypeParameterNode

A node representing a TypeParameter.

TypeParametersNode

A node representing the type parameters of an UnboundGeneric.