compilerutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 23 Imported by: 19

Documentation

Overview

compilerutil package defines utility methods.

Index

Constants

View Source
const INDENTATION = "  "
View Source
const RECURSIVE_PATTERN = "/..."

RECURSIVE_PATTERN defines the pattern for recursively searching for files.

Variables

View Source
var (
	InfoColor       = color.New(color.FgBlue, color.Bold)
	SuccessColor    = color.New(color.FgGreen, color.Bold)
	WarningColor    = color.New(color.FgYellow, color.Bold)
	ErrorColor      = color.New(color.FgRed, color.Bold)
	BoldWhiteColor  = color.New(color.FgWhite, color.Bold)
	FaintWhiteColor = color.New(color.FgWhite, color.Faint)
	MessageColor    = color.New(color.FgHiWhite)
)
View Source
var RunningUnderTest = false

Functions

func DCHECK

func DCHECK(checker checkFn, failMessage string, args ...interface{})

DCHECK executes the checker function only if the DEBUG environment variable is set. If the function returns false, the compiler will panic with the formatted message.

func DetectGoroutineLeak added in v0.3.1

func DetectGoroutineLeak(t *testing.T, grCount int)

DetectGoroutineLeak detects if there is a leak of goroutines over the life of a test.

func DownloadURLToFileWithProgress added in v0.3.0

func DownloadURLToFileWithProgress(url *url.URL, filePath string, callback ProgressCallback) error

DownloadURLToFileWithProgress downloads the contents of the given URL to the given file path on disk, invoking the callback function to report progress.

func IsId

func IsId(possibleId string) bool

IsId returns whether the given string is a possible ID as returned by NewUniqueId.

func LatestSemanticVersion

func LatestSemanticVersion(availableVersions []string) (string, bool)

LatestSemanticVersion returns the latest non-patch semantic version found in the list of available versions, if any.

func LogMessageToConsole added in v0.2.0

func LogMessageToConsole(prefixColor *color.Color, prefixText string, sourceRange compilercommon.SourceRange, message string, args ...interface{})

LogMessageToConsole logs a message to the console, with the given level and range.

func LogToConsole

func LogToConsole(level ConsoleLogLevel, sourceRange compilercommon.SourceRange, message string, args ...interface{})

LogToConsole logs a message to the console, with the given level and range.

func NewUniqueId

func NewUniqueId() string

NewUniqueId returns a new unique ID.

func NextSemanticVersion added in v0.2.0

func NextSemanticVersion(currentVersionString string, option NextVersionOption) (string, error)

NextSemanticVersion returns the next logic semantic version from the current version, given the update option.

func ParseFloat

func ParseFloat(strValue string) float64

ParseFloat parses the given string value into a float64, panicing on failure.

func Queue

func Queue() *orderedWorkQueue

Queue returns a new ordered work queue.

func SemanticUpdateVersion

func SemanticUpdateVersion(currentVersionString string, availableVersions []string, option UpdateVersionOption) (string, error)

SemanticUpdateVersion finds the semver in the available versions list that is newer than the current version.

func WalkSourcePath

func WalkSourcePath(path string, handler PathHandler, skipDirectories ...string) (uint, error)

WalkSourcePath walks the given source path, invoking the given handler for each file found. Returns the number of files walked and the error that occurred, if any.

Types

type CancelFunction added in v0.3.0

type CancelFunction func()

CancelFunction is a function that can be invoked to cancel the operation.

type CancelationHandle added in v0.3.0

type CancelationHandle interface {
	// Cancel marks the operation as canceled.
	Cancel()

	// WasCanceled returns whether the operation was canceled.
	WasCanceled() bool
}

CancelationHandle defines a handle for the cancelation of operations.

func GetCancelationHandle added in v0.3.0

func GetCancelationHandle(existing CancelationHandle) CancelationHandle

GetCancelationHandle returns either the existing cancelation handle (if not nil) or a new no-op handle.

func NewCancelationHandle added in v0.3.0

func NewCancelationHandle() CancelationHandle

NewCancelationHandle returns a new handle for canceling an operation.

func NoopCancelationHandle added in v0.3.0

func NoopCancelationHandle() CancelationHandle

NoopCancelationHandle returns a cancelation handle that cannot be canceled.

type ConsoleLogLevel

type ConsoleLogLevel int
const (
	InfoLogLevel ConsoleLogLevel = iota
	SuccessLogLevel
	WarningLogLevel
	ErrorLogLevel
)

type Element

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

type ImmutableMap added in v0.1.0

type ImmutableMap interface {
	// Get returns the value found at the given key, if any.
	Get(key string) (interface{}, bool)

	// Set returns a new ImmutableMap which is a copy of this map, but with the given key set
	// to the given value.
	Set(key string, value interface{}) ImmutableMap
}

ImmutableMap defines an immutable map struct, where Set-ing a new key returns a new ImmutableMap.

func NewImmutableMap added in v0.1.0

func NewImmutableMap() ImmutableMap

NewImmutableMap creates a new, empty immutable map.

type IntRange

type IntRange struct {
	StartPosition int
	EndPosition   int
}

IntRange defines a range of integer values, inclusive.

type LockMap

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

LockMap defines a concurrent-safe map that returns a sync Mutex for each key. This is useful when multiple resources are being loaded concurrently and locking is needed, but only on a per-resource basis.

func CreateLockMap

func CreateLockMap() LockMap

CreateLockMap returns a new LockMap.

func (LockMap) GetLock

func (lm LockMap) GetLock(key string) *sync.Mutex

GetLock returns a lock for the given key.

type NextVersionOption added in v0.2.0

type NextVersionOption string

NextVersionOption defines the options for the NextSemanticVersion method.

const (
	// NextMajorVersion indicates that the major version field should be incremented.
	NextMajorVersion NextVersionOption = "major"

	// NextMinorVersion indicates that the minor version field should be incremented.
	NextMinorVersion NextVersionOption = "minor"

	// NextPatchVersion indicates that the patch version field should be incremented.
	NextPatchVersion NextVersionOption = "patch"
)

type PathHandler

type PathHandler func(filePath string, info os.FileInfo) (bool, error)

PathHandler defines a handler to be invoked for every file found. Implementations should return false if the file should be skipped.

type ProgressCallback added in v0.3.0

type ProgressCallback func(bytesDownloaded int64, totalBytes int64, startCall bool)

ProgressCallback is a callback for the progress of a file download operation.

type RangeMapTree

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

RangeMapTree defines a helper struct for cached, faster lookup of an int range to an associated piece of data, under a specific key (such as a source file path). Note that the ranges for the data must be explicitly *non-overlapping* under each key, or this data structure will fail to work as intended. Ranges *within* other ranges, on the other hand, are allowed.

This data structure is safe for multi-threaded access.

func NewRangeMapTree

func NewRangeMapTree(calculator RangeMapTreeCalculator) *RangeMapTree

NewRangeMapTree creates a new range map tree.

func (*RangeMapTree) Get

func (rmt *RangeMapTree) Get(key string, current IntRange) interface{}

Get returns the data associated with the given key and range. If the data for that range has not yet been calculated, the calculator method is called to do so lazily.

type RangeMapTreeCalculator

type RangeMapTreeCalculator func(key string, current IntRange) (IntRange, interface{})

RangeMapTreeCalculator returns the calculated value for the given key and range. The range returned should encompass the entire range of the returned value. If no valid value is found for the position and key, the range returned should be the range requested.

type Stack

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

func (*Stack) Len

func (s *Stack) Len() int

Return the stack's length

func (*Stack) Peek

func (s *Stack) Peek() interface{}

Peek returns the element on the top of the list, if any. If the stack is empty, return nil

func (*Stack) PeekSecond

func (s *Stack) PeekSecond() interface{}

PeekSecond returns the element second to the top of the list, if any. If the stack contains less than two elemeents, return nil

func (*Stack) Pop

func (s *Stack) Pop() (value interface{})

Remove the top element from the stack and return it's value If the stack is empty, return nil

func (*Stack) Push

func (s *Stack) Push(value interface{})

Push a new element onto the stack

type UpdateVersionOption

type UpdateVersionOption string

UpdateVersionOption defines the options for the SemanticUpdateVersion method.

const (
	// UpdateVersionMinor indicates that only minor version updates are allowed.
	UpdateVersionMinor UpdateVersionOption = "minor"

	// UpdateVersionMajor indicates the both minor and major version updates are allowed.
	UpdateVersionMajor UpdateVersionOption = "major"
)

Jump to

Keyboard shortcuts

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