base

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package base provides shared helpers for language analyzers.

These helpers eliminate copy-paste boilerplate that was duplicated across all 11 language analyzers (php, javascript, typescript, python, golang, java, ruby, c, cpp, csharp, rust).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeMethodBody

func AnalyzeMethodBody(
	method *types.MethodDef,
	state *types.AnalysisState,
	paramPrefix string,
	inputSources map[string]types.SourceType,
	propertyPattern PropertyAssignPatternFunc,
) *analyzer.MethodFlowAnalysis

AnalyzeMethodBody is a shared implementation of the LanguageAnalyzer AnalyzeMethodBody method. It covers the logic that is structurally identical across all language analyzers:

  • Initialises MethodFlowAnalysis with empty slices/maps.
  • Skips analysis when BodySource is empty.
  • Checks whether each parameter flows to a return statement.
  • Optionally checks whether each parameter flows to an object property via the language-specific propertyPattern callback.
  • Checks whether the method returns a known input source directly.

Parameters:

  • method: the method definition to analyse.
  • source: raw source bytes (unused here, kept for interface alignment).
  • state: analysis state (unused here, kept for interface alignment).
  • paramPrefix: the sigil prepended to parameters in the body (e.g. "$" for PHP, "" for Python/Go/JS/Ruby).
  • inputSources: the language's input-source map. If the body contains "return" and any key from this map, ReturnsInput is set to true.
  • propertyPattern: optional; when non-nil it is called with each "paramPrefix+param.Name" value and the returned regexp is applied to the body to detect property assignments.

func RegisterFrameworkPatterns

func RegisterFrameworkPatterns(ba *analyzer.BaseAnalyzer, patterns []*common.FrameworkPattern, languageOverride string)

RegisterFrameworkPatterns loads a slice of common.FrameworkPattern into a BaseAnalyzer. This is the body that was copy-pasted verbatim across six language analyzers (php, javascript, typescript, python, golang, java) — the only difference between them was which GetAllPatterns() call was made and (for typescript) an optional language override.

Call it from your language analyzer's init/constructor like:

base.RegisterFrameworkPatterns(a.BaseAnalyzer, jsPatterns.GetAllPatterns(), "")
base.RegisterFrameworkPatterns(a.BaseAnalyzer, jsPatterns.GetAllPatterns(), "typescript") // override

Types

type PropertyAssignPatternFunc

type PropertyAssignPatternFunc func(paramName string) *regexp.Regexp

PropertyAssignPatternFunc is a function that, given a parameter name, returns a compiled *regexp.Regexp that matches assignments of that parameter to an object property (e.g. $this->prop = $param in PHP, self.prop = param in Python, this.prop = param in JavaScript/TypeScript/Go).

If the language has no such property-assignment convention, pass nil.

Jump to

Keyboard shortcuts

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