preprocess

package
v0.0.0-...-ba14292 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package preprocess hosts preprocessing logic for the input (e.g., CFGs etc.) to make it more amenable to analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Preprocessor

type Preprocessor struct {
	// contains filtered or unexported fields
}

Preprocessor handles different preprocessing logic for different types of input.

func New

func New(pass *analysis.Pass) *Preprocessor

New returns a new Preprocessor.

func (*Preprocessor) CFG

func (p *Preprocessor) CFG(graph *cfg.CFG, funcDecl *ast.FuncDecl) *cfg.CFG

CFG performs several passes on the CFG of utility to our analysis and returns a shallow copy of the modified CFG, with the original CFG untouched.

Specifically, it performs the following modifications to the CFG:

Canonicalize conditionals: - replace `if !cond {T} {F}` with `if cond {F} {T}` (swap successors) - replace `if cond1 && cond2 {T} {F}` with `if cond1 {if cond2 {T} else {F}}{F}` (nesting) - replace `if cond1 || cond2 {T} {F}` with `if cond1 {T} else {if cond2 {T} else {F}}` (nesting)

Canonicalize nil comparisons: It also performs the following useful transformation: - replace `if x != nil {T} {F}` with `if x == nil {F} {T}` (swap successors) - replace `nil == x {T} {F}` with `if x == nil {T} {F}` (swap comparison order)

Canonicalize explicit boolean comparisons: - replace `if x == true {T} {F}` with `if x {T} {F}` - replace `if x == false {T} {F}` with `if !x {T} {F}`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL