CodeQL library for Go
codeql/go-all 2.1.1-dev (changelog, source)
Search

Class SwitchStmt

A switch statement, that is, either an expression switch or a type switch.

Examples:

switch x := f(); x {
case 0, 1:
  a = 1
  fallthrough
default:
  b = 2
}

switch i := x.(type) {
default:
  printString("don't know the type")
case nil:
  printString("x is nil")
case int:
  printInt(i)
case func(int) float64:
  printFunction(i)
}

Import path

import semmle.go.Stmt

Direct supertypes

Indirect supertypes

Known direct subtypes

Predicates

getACase

Gets a case clause of this switch statement.

getANonDefaultCase

Gets a non-default case clause of this switch statement.

getBody

Gets the body of this switch statement.

getCase

Gets the ith case clause of this switch statement (0-based).

getDefault

Gets the default case clause of this switch statement, if any.

getInit

Gets the init statement of this switch statement, if any.

getNonDefaultCase

Gets the ith non-default case clause of this switch statement (0-based).

getNumCase

Gets the number of case clauses in this switch statement.

getNumNonDefaultCase

Gets the number of non-default case clauses in this switch statement.

Inherited predicates

getAChild

Gets a child node of this node.

from AstNode
getAChildExpr

Gets an expression that is a child node of this node in the AST.

from ExprParent
getAChildStmt

Gets a statement that is a child node of this node in the AST.

from StmtParent
getAPrimaryQlClass

Gets the name of a primary CodeQL class to which this node belongs.

from AstNode
getChild

Gets the ith child node of this node.

from AstNode
getChildExpr

Gets the ith child expression of this node.

from ExprParent
getChildStmt

Gets the ith child statement of this node.

from StmtParent
getEnclosingFunction

Gets the innermost function definition to which this AST node belongs, if any.

from AstNode
getFile

Gets the file this program element comes from.

from Locatable
getFirstControlFlowNode

Gets the first control-flow node in this statement.

from Stmt
getKind

Gets the kind of this statement, which is an integer value representing the statement’s node type.

from Stmt
getLocation

Gets this element’s location.

from Locatable
getNumChild

Gets the number of child nodes of this node.

from AstNode
getNumChildExpr

Gets the number of child expressions of this node.

from ExprParent
getNumChildStmt

Gets the number of child statements of this node.

from StmtParent
getNumLines

Gets the number of lines covered by this element.

from Locatable
getParent

Gets the parent node of this AST node, if any.

from AstNode
getPrimaryQlClasses

Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.

from AstNode
getScope

Gets the scope induced by this node, if any.

from ScopeNode
getUniquelyNumberedChild

Get an AstNode child, ordered by child kind and then by index.

from AstNode
hasLocationInfo

Holds if this element is at the specified location. The location spans column startcolumn of line startline to column endcolumn of line endline in file filepath. For more information, see Locations.

from Locatable
mayHaveSideEffects

Holds if the execution of this statement may produce observable side effects.

from Stmt
toString

Gets a textual representation of this element.

from AstNode