girgen

package
v0.0.0-...-2cf96cb Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLinkMode = types.DynamicLinkMode // types.RuntimeLinkMode

DefaultLinkMode is the default link mode to be used for all constructed Generators.

View Source
var DefaultOpts = Opts{
	LogLevel: logger.Skip,
}

DefaultOpts contains default options.

Functions

This section is empty.

Types

type CFileGenerator

type CFileGenerator struct {
	*NamespaceGenerator
	// contains filtered or unexported fields
}

CFileGenerator creates a new C file generator.

func NewCFileGenerator

func NewCFileGenerator(n *NamespaceGenerator, name string) *CFileGenerator

NewCFileGenerator creates as new C file generator.

func (*CFileGenerator) CIncludes

func (f *CFileGenerator) CIncludes() []string

CIncludes returns the list of C includes at the top of the file.

func (*CFileGenerator) Generate

func (f *CFileGenerator) Generate() ([]byte, error)

Generate implements FileGenerator.

func (*CFileGenerator) Header

func (f *CFileGenerator) Header() *file.Header

Header returns the C file generator's headers.

func (*CFileGenerator) IsEmpty

func (f *CFileGenerator) IsEmpty() bool

IsEmpty returns true if the file is empty.

func (*CFileGenerator) Name

func (f *CFileGenerator) Name() string

Name returns the file's name.

func (*CFileGenerator) Pen

func (f *CFileGenerator) Pen() *pen.Pen

Pen returns the C file generator's writer.

type FileGenerator

type FileGenerator interface {
	generators.FileGenerator
	generators.FileWriter
	Generate() ([]byte, error)
	IsEmpty() bool
	Name() string
}

FileGenerator describes any file that can be generated.

type Generator

type Generator struct {
	Logger *log.Logger
	Opts   Opts
	// contains filtered or unexported fields
}

Generator is a big generator that manages multiple repositories.

func NewGenerator

func NewGenerator(repos gir.Repositories, modPath types.ModulePathFunc) *Generator

NewGenerator creates a new generator with sane defaults.

func NewGeneratorOpts

func NewGeneratorOpts(repos gir.Repositories, modPath types.ModulePathFunc, opts Opts) *Generator

NewGeneratorOpts creates a new generator with options.

func (*Generator) AddFilters

func (g *Generator) AddFilters(filters []types.FilterMatcher)

AddFilters adds the given list of filters.

func (*Generator) AddPostprocessors

func (g *Generator) AddPostprocessors(ppMap map[string][]Postprocessor)

AddPostprocessor registers the given postprocessors inside a map that has keys matching the namespace.

func (*Generator) AddProcessConverters

func (g *Generator) AddProcessConverters(processors []typeconv.ConversionProcessor)

AddProcessConverters adds the given list of conversion processors.

func (*Generator) ApplyPreprocessors

func (g *Generator) ApplyPreprocessors(preprocs []types.Preprocessor)

AddPreprocessors applies the given list of preprocessors.

func (*Generator) DynamicLinkNamespaces

func (g *Generator) DynamicLinkNamespaces(versionedNamespaces []string)

DynamicLinkNamespaces overrides the default link mode for the given namespaces to be DynamicLinkMode. If an unknown versioned namespace is given, then the function panics.

func (*Generator) Filters

func (g *Generator) Filters() []types.FilterMatcher

Filters returns the generator's list of type filters.

func (*Generator) Logln

func (g *Generator) Logln(lvl logger.Level, v ...interface{})

Logln writes a log line into the internal logger.

func (*Generator) ModPath

func (g *Generator) ModPath(n *gir.Namespace) string

ModPath creates an import path from the user's ModulePathFunc given into the constructor.

func (*Generator) NamespaceLinkMode

func (g *Generator) NamespaceLinkMode(namespace *gir.Namespace) types.LinkMode

NamespaceLinkMode returns the link mode for the given namespace.

func (*Generator) ProcessConverter

func (g *Generator) ProcessConverter(converter *typeconv.Converter)

ProcessConverter satisfies the typeconv.ConversionProcessor interface.

func (*Generator) Repositories

func (g *Generator) Repositories() gir.Repositories

Repositories returns the generator's repositories.

func (*Generator) SetDefaultLinkMode

func (g *Generator) SetDefaultLinkMode(linkMode types.LinkMode)

SetDefaultLinkMode sets the default link mode.

func (*Generator) UseNamespace

func (g *Generator) UseNamespace(namespace, version string) *NamespaceGenerator

UseNamespace creates a new namespace generator using the given namespace.

type GoFileGenerator

type GoFileGenerator struct {
	*NamespaceGenerator
	BuildTags []string // go:build lines, joined by AND (&&)
	Packages  []string // extra
	// contains filtered or unexported fields
}

GoFileGenerator is a file generator.

func NewGoFileGenerator

func NewGoFileGenerator(n *NamespaceGenerator, name string, isRoot bool) *GoFileGenerator

NewGoFileGenerator creates a new empty GoFileGenerator instance.

func (*GoFileGenerator) CIncludes

func (f *GoFileGenerator) CIncludes() []string

CIncludes returns this file's sorted C includes, including the repository's C includes.

func (*GoFileGenerator) Generate

func (f *GoFileGenerator) Generate() ([]byte, error)

Generate generates the final file content, completed with gofmt.

func (*GoFileGenerator) Header

func (f *GoFileGenerator) Header() *file.Header

Header returns the current file's header.

func (*GoFileGenerator) IsEmpty

func (f *GoFileGenerator) IsEmpty() bool

IsEmpty returns true if the file is empty.

func (*GoFileGenerator) Logln

func (f *GoFileGenerator) Logln(lvl logger.Level, v ...interface{})

func (*GoFileGenerator) Name

func (f *GoFileGenerator) Name() string

Name returns the current file's name.

func (*GoFileGenerator) Pen

func (f *GoFileGenerator) Pen() *pen.Pen

Pen returns the current file's writing pen.

func (*GoFileGenerator) Pkgconfig

func (f *GoFileGenerator) Pkgconfig() []string

Pkgconfig returns the current repository's pkg-config names.

type NamespaceGenerator

type NamespaceGenerator struct {
	*Generator
	PkgPath    string
	PkgName    string
	PkgVersion string

	Files map[string]FileGenerator
	// contains filtered or unexported fields
}

NamespaceGenerator manages generation of a namespace. A namespace contains various files, which are created using the FileWriter method.

func NewNamespaceGenerator

func NewNamespaceGenerator(g *Generator, n *gir.NamespaceFindResult) *NamespaceGenerator

NewNamespaceGenerator creates a new NamespaceGenerator from the given generator and namespace.

func (*NamespaceGenerator) AddPostprocessors

func (n *NamespaceGenerator) AddPostprocessors(pps []Postprocessor)

AddPostprocessors adds the given list of postprocessors.

func (*NamespaceGenerator) CanGenerate

func (n *NamespaceGenerator) CanGenerate(r *types.Resolved) bool

CanGenerate checks if a type can be generated or not.

func (*NamespaceGenerator) File

func (n *NamespaceGenerator) File(filename string) (*GoFileGenerator, bool)

File gets an existing Go file but returns false if no such file exists. It's useful for postprocessors to check if generation is working as intended. If SingleFile is true, then File will always return the same file.

func (*NamespaceGenerator) FileWriter

func (n *NamespaceGenerator) FileWriter(info cmt.InfoFields, export bool) generators.FileWriter

FileWriter returns the respective file writer from the given InfoFields.

func (*NamespaceGenerator) Generate

func (n *NamespaceGenerator) Generate() (map[string][]byte, error)

Generate generates everything in the current namespace into files. The returned map maps the filename to the raw file content.

func (*NamespaceGenerator) LinkMode

func (n *NamespaceGenerator) LinkMode() types.LinkMode

LinkMode implements FileGenerator.

func (*NamespaceGenerator) Logln

func (n *NamespaceGenerator) Logln(lvl logger.Level, v ...interface{})

func (*NamespaceGenerator) MakeFile

func (n *NamespaceGenerator) MakeFile(filename string) *GoFileGenerator

MakeFile makes a new GoFileGenerator for the given filename or returns an existing one.

func (*NamespaceGenerator) Namespace

func (n *NamespaceGenerator) Namespace() *gir.NamespaceFindResult

Namespace returns the generator's namespace that includes the repository it's in.

func (*NamespaceGenerator) Pkgconfig

func (n *NamespaceGenerator) Pkgconfig() []string

Pkgconfig returns the current repository's pkg-config names.

func (*NamespaceGenerator) Rename

func (n *NamespaceGenerator) Rename(src, dst string) error

Rename renames a file from src to dst. If src does not exist, then it will return an error.

func (*NamespaceGenerator) SetLinkMode

func (n *NamespaceGenerator) SetLinkMode(mode types.LinkMode)

SetLinkMode sets the link mode for the current namespace and all its files. The default is RuntimeLinkMode.

type Opts

type Opts struct {
	// LogLevel is defaulted to Skip, unless GIR_VERBOSE=1, then it's Debug.
	LogLevel logger.Level
	// SingleFile, if true, will make all NamespaceGenerators generate a single
	// output file per package instead of correlating it to the source file.
	SingleFile bool
}

Opts contains generator options.

type Postprocessor

type Postprocessor func(n *NamespaceGenerator) error

Postprocessor describes a processor function that modifies a namespace. It is called right before files are finalized within the namespace generator.

Directories

Path Synopsis
Package cmt provides functions that parse and render GIR comments into nice and conventional Go comments.
Package cmt provides functions that parse and render GIR comments into nice and conventional Go comments.
Package file provides per-file state helpers, such as for tracking imports.
Package file provides per-file state helpers, such as for tracking imports.
callable
Package callable provides a generic callable generator.
Package callable provides a generic callable generator.
iface
Package iface provides an interface generator.
Package iface provides an interface generator.
Package gotmpl provides abstractions around text/template to better generate Go files.
Package gotmpl provides abstractions around text/template to better generate Go files.
Package logger provides abstractions over girgen's logging.
Package logger provides abstractions over girgen's logging.
Package strcases provides helper functions to convert between string cases, such as Pascal Case, snake_case and Go's Mixed Caps, along with various special cases.
Package strcases provides helper functions to convert between string cases, such as Pascal Case, snake_case and Go's Mixed Caps, along with various special cases.
typeconv
Package typeconv provides conversions between C and Go types.
Package typeconv provides conversions between C and Go types.

Jump to

Keyboard shortcuts

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