headalyzer

package
v0.0.0-...-1667554 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package headalyzer contains the core logic for the headalyzer tool

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFile

func LoadFile(path string) ([]Constant, []Option, []Hint, error)

LoadFile is a wrapper around LoadString() which reads the input from disk.

func LoadString

func LoadString(text, apparantPath string) ([]Constant, []Option, []Hint, error)

LoadString reads a headalyzer definition file which is stored as a string and returns the list of constants.

apparantPath may be empty to use the default value.

func ResolveHint

func ResolveHint(hints []Hint, symbol Symbol, section, key, defaultval string) (string, bool)

ResolveHint can be used to find a hint which matches a specific symbol, section, and key, and returns the appropriate value. If the hint is found, the bool return value will be 'true', otherwise it will be 'false' and the returned string will be the given defaultval.

If multiple hints match, the one with the highest index is used.

func ResolveOption

func ResolveOption(opts []Option, section, key string, defaults []Option) (string, bool)

ResolveOption can be used to resolve the value of a given section, key tuple. Non-default options always have precedence. The defaults parameter may be nil.

If an option is defined more than once in an option list, the most recent one (iterating from index 0) takes precedence.

Types

type Case

type Case string

Case represents one of several ways of casing a collection of symbol components.

const (
	// CamelCase indicates that Symbol.CamelCase() should be used
	CamelCase Case = "CamelCase"

	// UpperCamelCase indicates that Symbol.UpperCamelCase() should be used
	UpperCamelCase Case = "UpperCamelCase"

	// LowerCamelCase indicates that Symbol.LowerCamelCase() should be used
	LowerCamelCase Case = "LowerCamelCase"

	// SnakeCase indicates that Symbol.SnakeCase() should be used
	SnakeCase Case = "SnakeCase"

	// CapitalSnakeCase indicates that Symbol.CapitalSnakeCase() should be
	// used
	CapitalSnakeCase Case = "CapitalSnakeCase"
)

func (Case) ApplyCase

func (c Case) ApplyCase(s Symbol) (string, error)

ApplyCase applies a casing to a symbol dynamically (based on the case).

type Constant

type Constant interface {
	// Return this constant's type
	GetType() Type

	String() string

	// The name of the constant
	Symbol() Symbol

	// What should be generated as text
	Text() string
}

A Constant represents any constant that Headalyzer understands.

func CreateConstant

func CreateConstant(s Symbol, t Type, v string) (Constant, error)

CreateConstant creates a new constant of the given type and value.

type Hint

type Hint struct {
	Symbol Symbol
	Option Option
}

A Hint is an option that is associated with a specific symbol.

type IntConstant

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

IntConstant represents a constant of type Int

func (IntConstant) GetType

func (i IntConstant) GetType() Type

GetType always returns Int

func (IntConstant) String

func (i IntConstant) String() string

func (IntConstant) Symbol

func (i IntConstant) Symbol() Symbol

Symbol returns the symbol for this int constant

func (IntConstant) Text

func (i IntConstant) Text() string

type Option

type Option struct {
	Section string
	Key     string
	Value   string
}

Option is used to represent generator-specific options, it's meaning is entirely defined by the generator in question.

By convention, the Section should be the generator name to which the option applies, the Key a configuration key, and the Value the set value. The generator may cast the Value to another type (such as a number) internally if it wishes.

type StringConstant

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

StringConstant represents a constant of type String

func (StringConstant) GetType

func (s StringConstant) GetType() Type

GetType always returns String

func (StringConstant) String

func (s StringConstant) String() string

func (StringConstant) Symbol

func (s StringConstant) Symbol() Symbol

Symbol returns the symbol for this string constant

func (StringConstant) Text

func (s StringConstant) Text() string

Text returns the generated text for the string constant

type Symbol

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

A Symbol represents what how a Constant is referred to. It is a list of components which may be joined in one of several ways. For example, the symbol ["My", "Cool", "Constant"] might be generated ad "MY_COOL_CONSTANT" in a C macro definition, and "MyCoolConstant" in a Go constant definition.

func MakeSymbol

func MakeSymbol(c ...string) Symbol

MakeSymbol creates a Symbol from a list of components.

func (Symbol) CamelCase

func (s Symbol) CamelCase() string

CamelCase applies camel-case to the symbol without modifying the case of the first component.

My Cool Constant -> MyCoolConstant my cool constant -> myCoolConstant

func (Symbol) CapitalSnakeCase

func (s Symbol) CapitalSnakeCase() string

CapitalSnakeCase applies snake-case to the symbol and makes all letters upper case.

My Cool Constant -> MY_COOL_CONSTANT

my cool constant -> MY_COOL_CONSTANT

my Cool Constant -> MY_COOL_CONSTANT

func (Symbol) Compare

func (s1 Symbol) Compare(s2 Symbol) bool

func (Symbol) LowerCamelCase

func (s Symbol) LowerCamelCase() string

LowerCamelCase applies camel-case to the symbol, explicitly guaranteeing the first component starts with a lower case letter.

My Cool Constant -> myCoolConstant my cool constant -> myCoolConstant

func (Symbol) SnakeCase

func (s Symbol) SnakeCase() string

SnakeCase applies snake-case to the symbol without modifying the case of the components.

My Cool Constant -> My_Cool_Constant

my cool constant -> my_cool_constant

my Cool Constant -> my_Cool_Constant

func (Symbol) String

func (s Symbol) String() string

func (Symbol) UpperCamelCase

func (s Symbol) UpperCamelCase() string

UpperCamelCase applies camel-case to the symbol, explicitly guaranteeing the first component starts with an upper case letter.

My Cool Constant -> MyCoolConstant my cool constant -> MyCoolConstant

type Type

type Type string

Type is used to distinguish types that Headalyzer knows about.

const (
	// Int represents signed integer values of unspecified length, no
	// guarantees will be made about storage size
	Int Type = "int"

	// Int64 represents signed 64 bit integers
	Int64 Type = "int64"

	// Int32 represents signed 32 bit integers
	Int32 Type = "int32"

	// Int16 represents signed 16 bit integers
	Int16 Type = "int16"

	// Int8 represents signed 8 bit integers
	Int8 Type = "int8"

	// Uint represents unsigned integer values of unspecified length, no
	// guarantees will be
	// made about storage size
	Uint Type = "uint"

	// Uint64 represents unsigned 64 bit integers
	Uint64 Type = "uint64"

	// Uint32 represents unsigned 32 bit integers
	Uint32 Type = "uint32"

	// Uint16 represents unsigned 16 bit integers
	Uint16 Type = "uint16"

	// Uint8 represents unsigned 8 bit integers
	Uint8 Type = "uint8"

	// String represents string constants
	String Type = "string"

	// Untyped represents constants which are not typed
	Untyped Type = "untyped"
)

type UnrepresentableError

type UnrepresentableError struct {

	// Human-readable representation of the constant
	Constant string

	// Reason why the generator cannot represent the value
	Reason string
}

UnrepresentableError indicates that the generator cannot represent the constant value.

func (*UnrepresentableError) Error

func (e *UnrepresentableError) Error() string

Directories

Path Synopsis
c
Package c implement the C header file generator for Headalyzer.
Package c implement the C header file generator for Headalyzer.
Package shell implement the make generator for Headalyzer
Package shell implement the make generator for Headalyzer
Package shell implement the shell generator for Headalyzer
Package shell implement the shell generator for Headalyzer
Package systemverilog implement the systemverilog header file generator for Headalyzer.
Package systemverilog implement the systemverilog header file generator for Headalyzer.

Jump to

Keyboard shortcuts

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