analyser

package
v0.0.0-...-6ac6f58 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAnalyserInvalidParam            = fmt.Errorf("invalid param")
	ErrAnalyserFileNotFound            = fmt.Errorf("file not found")
	ErrAnalyserNodeTypeNoSupport       = fmt.Errorf("node type no support")
	ErrAnalyserGiveUpAnalysing         = fmt.Errorf("give up analysing")
	ErrAnalyserSystemIncludeDirUnknown = fmt.Errorf("system include dir unknown")
)
View Source
var (
	ReBackSlash     = regexp.MustCompile(`\\\n`)
	ReMark          = regexp.MustCompile(`include|define|import`)
	RePairedComment = regexp.MustCompile(`(/[*](.|\n)*?[*]/)`)
	ReMacroExpr     = regexp.MustCompile(`(?P<symbol>\w+)(?P<outer>\s*[(]\s*(?P<args>([^(),])*([,]([^(),])*)*)[)])?`)
	ReContent       = regexp.MustCompile(`^[ \t]*([*][/])?[ \t]*([/][*][^\n]*[*][/])*[ \t]*(?P<directive>[#][ \t]*(define|include_next|include|import)\b(.|\n)*?(([^\\]\n)|$))`)
	ReDirective     = regexp.MustCompile(`^[ \t]*[#][ \t]*(((?P<include>include_next|include|import)\s*("(?P<quote>(\w|[_/.,+-])*)"|<(?P<angle>(\w|[_/.,+-])*)>|(?P<expr>.*?)))|(?P<define>define\s+(?P<lhs>(?P<symbol>\w+)(\s*[(]\s*(?P<args>([^(),])*([,]([^(),])*)*)[)])?)\s*(?P<rhs>.*?)))\s*((/[*]|//)(.|\n)*)?$`)
	ReSystemSearch  = regexp.MustCompile(`#include <...> search starts here:\n((.|\n)*?)\nEnd of search list`)
	ReMacroSymbol   = regexp.MustCompile(`\b\w+\b`)
	ReSinglePound   = regexp.MustCompile(`\B#\s*(\S*)`)
	ReDoublePound   = regexp.MustCompile(`\s*##\s*`)
	ReIncludes      = regexp.MustCompile(`^\s*("\s*(?P<quote>(\w|[\\_/.,+-])*)\s*"|<\s*(?P<angle>(\w|[\\_/.,+-])*)\s*>)\s*$`)
)
View Source
var FlagHandleNothing = func(stat *ParseStat, arg string) error {
	return nil
}

FlagHandleNothing 代表该参数无需任何处理

View Source
var OptionAlwaysTwoWords = map[string]FlagHandleFunc{
	"-Xpreprocessor": func(stat *ParseStat, arg string) error {
		return fmt.Errorf("argument -Xpreprocessor is no implement")
	},

	"-aux-info":   FlagHandleNothing,
	"--param":     FlagHandleNothing,
	"-Xassembler": FlagHandleNothing,
	"-Xlinker":    FlagHandleNothing,
}

参数含多个字母, 且一定是分为两个部分(参数, 值)的处理规则

View Source
var OptionAppearingAsAssignments = map[string]FlagHandleFunc{
	"--sysroot": func(stat *ParseStat, arg string) error {
		stat.SysRoot = arg
		return nil
	},
}

含多个字母, 且包含=号连接参数和值的处理规则

View Source
var OptionMaybeTwoWords = map[string]FlagHandleFunc{
	"-MF":     FlagHandleNothing,
	"-MT":     FlagHandleNothing,
	"-MQ":     FlagHandleNothing,
	"-arch":   FlagHandleNothing,
	"-target": FlagHandleNothing,
	"-include": func(stat *ParseStat, arg string) error {
		stat.IncludeFiles = append(stat.IncludeFiles, arg)
		return nil
	},
	"-imacros": func(stat *ParseStat, arg string) error {
		stat.IncludeFiles = append(stat.IncludeFiles, arg)
		return nil
	},
	"-idirafter": func(stat *ParseStat, arg string) error {
		stat.AfterSystemDirs = append(stat.AfterSystemDirs, arg)
		return nil
	},
	"-iprefix": func(stat *ParseStat, arg string) error {
		stat.IPrefix = arg
		return nil
	},
	"-iwithprefixbefore": func(stat *ParseStat, arg string) error {
		stat.IDirs = append(stat.IDirs, filepath.Join(stat.IPrefix, arg))
		return nil
	},
	"-isysroot": func(stat *ParseStat, arg string) error {
		stat.SysRoot = arg
		return nil
	},
	"-imultilib": func(stat *ParseStat, arg string) error {
		return fmt.Errorf("argument -imultilib is no implement")
	},
	"-isystem": func(stat *ParseStat, arg string) error {
		stat.BeforeSystemDirs = append(stat.BeforeSystemDirs, arg)
		return nil
	},
	"-iquote": func(stat *ParseStat, arg string) error {
		stat.QuoteDirs = append(stat.QuoteDirs, arg)
		return nil
	},
}

参数含多个字母, 且可能分为两个部分(参数, 值), 也可能合在一起的处理规则, 如: -MF a.d -MFfoo

View Source
var OptionOneLetter = map[string]FlagHandleFunc{
	"-D": func(stat *ParseStat, arg string) error {
		stat.DOpts = append(stat.DOpts, strings.Split(arg, "="))
		return nil
	},
	"-I": func(stat *ParseStat, arg string) error {
		stat.IDirs = append(stat.IDirs, arg)
		return nil
	},
	"-o": func(stat *ParseStat, arg string) error {
		stat.OutputFile = arg
		return nil
	},
	"-x": func(stat *ParseStat, arg string) error {
		stat.Language = arg
		return nil
	},

	"-U": FlagHandleNothing,
	"-A": FlagHandleNothing,
	"-l": FlagHandleNothing,
	"-F": func(stat *ParseStat, arg string) error {
		dirs, err := filepath.Glob(filepath.Join(arg, "*", "Headers"))
		if err != nil {
			return err
		}

		stat.IDirs = append(stat.IDirs, dirs...)
		return nil
	},
	"-u": FlagHandleNothing,
	"-L": FlagHandleNothing,
	"-B": FlagHandleNothing,
	"-V": FlagHandleNothing,
	"-b": FlagHandleNothing,
}

只有1个字母的flag的处理规则

View Source
var OptionOneWord = map[string]FlagHandleFunc{
	"-undef": FlagHandleNothing,
	"-nostdinc": func(stat *ParseStat, arg string) error {
		stat.NoDistinc = true
		return nil
	},
}

含多个字母, 但只有参数, 没有值的处理规则

View Source
var OptionTwoWords = map[string]FlagHandleFunc{}

含多个字母, 且可能分为两个部分(参数, 值), 由OptionMaybeTwoWords和OptionAlwaysTwoWords组成

Functions

This section is empty.

Types

type Analyser

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

Analyser provide a manager of task dependence analysing

func New

func New() *Analyser

New get an Analyser with new file cache and root cache

func NewWithCache

func NewWithCache(fileCache *FileCache, rootCache *RootCache) *Analyser

NewWithCache get an Analyser with specific file cache and root cache

func (*Analyser) Do

func (a *Analyser) Do(runDir string, cmd []string, environ *env.Sandbox,
	includeSystemHeader, disableMacro bool) (*Result, error)

Do 执行对一个命令的分析. includeSystemHeader 决定了是否要将system header包含在dependentFile中, 若为false, 则system header都会被过滤掉 disableMacro 决定了是否要彻底禁止macro, 若为true, 则该命令涉及的整颗依赖树, 一旦出现include macro, 则整颗树的所有节点都会被禁用

func (*Analyser) FindNode

func (a *Analyser) FindNode(
	kind NodeType,
	searchDir, filePath, lastFileDir, lastFile *File,
	r *FileSolveResult) (*NodeCacheValue, error)

FindNode 针对每一个搜索节点做分析, 根据不同的类型, 分析得到实际文件, 和该文件的父依赖, 并组织下一个深度的搜索

func (*Analyser) ParseCommand

func (a *Analyser) ParseCommand(currentDir string, args []string, environ *env.Sandbox) (*ParseStat, error)

ParseCommand 解析任务的命令, 获得命令参数相关信息

func (*Analyser) ParseFile

func (a *Analyser) ParseFile(filePath *File) (*FileResult, error)

ParseFile 分析单个文件的include信息, 并得到其依赖关系

func (*Analyser) Run

func (a *Analyser) Run(filePath *File, searchDirList []*File) (*CalculateResult, error)

Run 通过分析起始文件, 生成搜索树, 并最终从搜索树中计算出所有依赖项

type CacheCanonicalPath

type CacheCanonicalPath struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CacheCanonicalPath 提供了一个根据给定路径来获取其真实绝对路径的办法. 同时内部包含了一个简易的缓存, 用来减少对filepath库的调用

func NewCacheCanonicalPath

func NewCacheCanonicalPath() *CacheCanonicalPath

NewCacheCanonicalPath 提供一个全新的CacheCanonicalPath对象

func (*CacheCanonicalPath) GetCanonicalPath

func (ccp *CacheCanonicalPath) GetCanonicalPath(path string) (string, error)

GetCanonicalPath 根据给定路径, 若真实存在, 则返回目标的真实绝对路径. 所谓真实绝对路径, 首先是一个绝对路径, 并且该路径所包含的所有软链都会被解析到目标.

type CacheDirName

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

CacheDirName 提供查询目录索引, 和目录绝对路径索引的办法和缓存 包含了relativeMap, directoryMap和canonicalMap, 用于在查询时做必要的查询/插入操作

func (*CacheDirName) LookUp

func (cdn *CacheDirName) LookUp(currentDirIdx, searchDirIdx, includePathIdx int) (dirIdx, dirRealPathIdx int)

LookUp 提供了一个方法, 给定: 当前执行目录 + 搜索目录 + 目标路径, 获得该文件所在的目录(相对于当前执行目录)索引, 和目录绝对路径的索引 * 该文件所在的目录为: 搜索目录 + 目标目录, 从directoryMap中拿到索引 * 该文件所在的目录绝对路径为: 当前执行目录 + 该文件所在目录, 从canonicalMap中拿到索引 同时提供了一个简易的三级缓存, 用于缓存对相同参数的查询结果

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

CacheSymlink 提供软链接的信息缓存, 防止重复的调用syscall来查询

func NewCacheSymlink() *CacheSymlink

NewCacheSymlink provide an empty CacheSymlink

func (cs *CacheSymlink) GetLinks(f *File) []*dcSDK.FileDesc

GetLinks 获取一个文件f的所在路径上, 所有的软链接信息 例如/foo/bar/hello/world.cpp 依次查询/foo, /foo/bar, /foo/bar/hello, /foo/bar/hello/world.cpp是否为软链接, 若是则依次加入返回队列中

type CacheSystemDir

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

CacheSystemDir 提供对系统头文件所在目录的缓存 用户提供compiler(编译器), sysRoot(编译指令中指定的sysRoot), language(编译指令中指定的语言) 则可以获取对饮过的系统头文件所在目录

func NewCacheSystemDir

func NewCacheSystemDir() *CacheSystemDir

NewCacheSystemDir get an empty CacheSystemDir

func (*CacheSystemDir) GetSystemDir

func (csd *CacheSystemDir) GetSystemDir(compiler, sysRoot, language string) ([]string, error)

GetSystemDir 获取系统头文件所在目录列表, 按搜索优先级高到低排序

func (*CacheSystemDir) StartWithSystemDir

func (csd *CacheSystemDir) StartWithSystemDir(compiler, sysRoot, language string, f *File) (bool, error)

StartWithSystemDir 判断一个文件f是否在系统头文件所在目录中

type CalculateResult

type CalculateResult struct {
	Files    []*CalculateResultItem
	Symlinks []*dcSDK.FileDesc
}

CalculateResult provide the result of CalculateNodes Includes the dependent files and the dependent symlinks

func CalculateNodes

func CalculateNodes(node *NodeCacheValue) (*CalculateResult, error)

CalculateNode 使用广度优先搜索, 根据提供的node作为跟节点, 搜索整个关系树并返回所依赖的全部路径

type CalculateResultItem

type CalculateResultItem struct {
	Desc      *dcSDK.FileDesc
	Canonical *File
}

CalculateResultItem provide the item in CalculateResult Includes every single dependent file

type File

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

File 作为文件的实体, 提供从字符串到数字一一对应的索引, 用于在后续的缓存中更方便地进行hash和比较 该文件不一定存在, 只是一个内存中的索引, 是否真的存在还需要另外检测

func NewFileWithCache

func NewFileWithCache(cache *FileCache, fileType FileType, str string) *File

NewFileWithCache 给定cache主体, 获取对应type和str的文件实体

func (*File) Dir

func (f *File) Dir() *File

Dir 获取文件的所在目录

func (*File) Equal

func (f *File) Equal(t *File) bool

Equal 判断文件是否与t文件是同一个文件

func (*File) Index

func (f *File) Index() int

Index 获取文件在缓存中对应的索引

func (*File) String

func (f *File) String() string

String 获取文件原始的名字

type FileCache

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

FileCache 提供了一个一体化的依赖文件搜索缓存方案

func NewFileCache

func NewFileCache() *FileCache

NewFileCache get and init an empty file cache

func (*FileCache) CheckBlackList

func (fc *FileCache) CheckBlackList(f *File) bool

CheckBlackList 测试一个Canonical文件是否在黑名单中, 若不是Canonical文件则返回false

func (*FileCache) EmptyCanonicalFile

func (fc *FileCache) EmptyCanonicalFile() *File

EmptyCanonicalFile 提供一个空Canonical File对象

func (*FileCache) EmptyDirectory

func (fc *FileCache) EmptyDirectory() *File

EmptyDirectory 提供一个空Directory File对象

func (*FileCache) EmptyRelativeFile

func (fc *FileCache) EmptyRelativeFile() *File

EmptyRelativeFile 提供一个空Relative File对象

func (*FileCache) GetCanonicalFile

func (fc *FileCache) GetCanonicalFile(path string) *File

GetCanonicalFile 提供一个由给定path生成的canonical类型的File对象

func (*FileCache) GetCanonicalFileList

func (fc *FileCache) GetCanonicalFileList(s []string) []*File

GetCanonicalFileList 提供一个由给定path-list生成的canonical类型的File对象组成的列表

func (*FileCache) GetDirectoryFile

func (fc *FileCache) GetDirectoryFile(path string) *File

GetDirectoryFile 提供一个由给定path生成的directory类型的File对象

func (*FileCache) GetDirectoryFileList

func (fc *FileCache) GetDirectoryFileList(s []string) []*File

GetDirectoryFileList 提供一个由给定path-list生成的directory类型的File对象组成的列表

func (*FileCache) GetFileParse

func (fc *FileCache) GetFileParse(f *File) *FileResult

GetFileParse 提供一个缓存, 用于查询文件正则解析的缓存

func (*FileCache) GetRelativeFile

func (fc *FileCache) GetRelativeFile(path string) *File

GetRelativeFile 提供一个由给定path生成的relative类型的File对象

func (*FileCache) GetRelativeFileList

func (fc *FileCache) GetRelativeFileList(s []string) []*File

GetRelativeFileList 提供一个由给定path-list生成的relative类型的File对象组成的列表

func (*FileCache) GetSystemDir

func (fc *FileCache) GetSystemDir(compiler, sysRoot, language string) ([]string, error)

GetSystemDir 提供一个缓存, 用于查询给定参数下的系统头文件目录

func (*FileCache) PutFileParse

func (fc *FileCache) PutFileParse(f *File, r *FileResult)

PutFileParse 提供一个缓存, 用于插入文件正则解析的缓存

func (*FileCache) Resolve

func (fc *FileCache) Resolve(param *FileResolveParam, skipper resolveSkipFunc) (*FileSolveResult, error)

Resolve 接收给定的搜索参数, 在缓存中直接获取, 或按优先级搜索目标文件是否存在 入参为:

  1. filePath, 需要搜索的文件名, 如#include<foo/bar.h>中的foo/bar.h, 或-c /data/src/hello.c里的hello.c 必须为相对路径, 若为绝对路径则无需搜索, 并默认前把绝对路径拆分为searchDir和filePath, 同时清空searchDirList
  2. runDir, 当前执行目录, 用于标定绝对路径, 是所有相对路径的默认前缀
  3. searchDir, 优先搜索目录, 应该被置于searchDirList的最前面
  4. searchDirList, 搜索目录, 按优先级排序, 应依次搜索这些目录下是否存在指定的目标文件

结果为: 1. searchDir, 找到目标文件的searchDir 2. filePath, 目标文件 3. canonicalPath, 目标文件真实路径

func (*FileCache) SetBlackList

func (fc *FileCache) SetBlackList(f *File)

SetBlackList 将一个Canonical文件放进全局黑名单中

func (*FileCache) StartWithSystemDir

func (fc *FileCache) StartWithSystemDir(compiler, sysRoot, language string, f *File) (bool, error)

StartWithSystemDir 提供一个缓存, 用于查询给定的参数下, 该文件是否在系统头文件目录里

type FileResolveParam

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

FileResolveParam 作为提供给FileCache.Resolve的参数

type FileResult

type FileResult struct {
	QuoteIncludes []*File
	AngleIncludes []*File
	ExprIncludes  []string
	NextIncludes  []*File
	// contains filtered or unexported fields
}

FileResult provide a result of ParseFile Includes the files's include information

type FileSolveResult

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

FileSolveResult 作为FileCache.Resolve返回的数据

type FileType

type FileType int

FileType 作为File文件实体的类型, 提供多个不同种类 用于在插入/查询索引时, 对不同的类型做不同的定制操作

const (
	FileTypeDir FileType = iota
	FileTypeRelative
	FileTypeCanonical
)

type FlagHandleFunc

type FlagHandleFunc func(stat *ParseStat, arg string) error

FlagHandleFunc 用来规范当解析到每个参数时对应的处理函数

type Map2Index

type Map2Index struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Map2Index 提供一个简易的str到int的一一对应的关系, 通过对str按插入顺序排序, 用其在队列中的位置作为索引, 同时保存在map中方便快速获取.

func NewMap2Index

func NewMap2Index() *Map2Index

NewMap2Index 提供一个全新的Map2Index对象

func (*Map2Index) Index

func (mi *Map2Index) Index(path string) int

Index 获取给定str在该关系中的索引, 若不存在则插入

func (*Map2Index) Length

func (mi *Map2Index) Length() int

Length 获取该关系中的队列长度

func (*Map2Index) String

func (mi *Map2Index) String(idx int) string

String 获取给定索引对应的str, 若不存在则返回空字符串

type MapCanonicalPath

type MapCanonicalPath struct {
	Map2Index
	// contains filtered or unexported fields
}

MapCanonicalPath 通过组合Map2Index, 一般用于处理绝对路径的关系索引. 其中, 保证路径str中不会含有任何软链接

func NewMapCanonicalPath

func NewMapCanonicalPath(canonical *CacheCanonicalPath) *MapCanonicalPath

NewMapCanonicalPath 提供一个全新的MapCanonicalPath关系

func (*MapCanonicalPath) Index

func (mcp *MapCanonicalPath) Index(path string) int

Index 通过Map2Index获取关系索引, 在查询/插入之前会将str中的所有软链接展开, 并取绝对路径

type MapDirectory

type MapDirectory struct {
	Map2Index
}

MapDirectory 通过组合Map2Index, 一般用于处理目录的关系索引. 其中, 保证目录str的末尾不会有后置的/

func NewMapDirectory

func NewMapDirectory() *MapDirectory

NewMapDirectory 获取一个MapDirectory关系

func (*MapDirectory) Index

func (md *MapDirectory) Index(directory string) int

Index 通过Map2Index获取关系索引, 在查询/插入前会去除str中所有的后置/

type MapRelativePath

type MapRelativePath struct {
	Map2Index
}

MapRelativePath 通过组合Map2Index, 一般用于处理相对路径(也可以为绝对路径)的关系索引. 其中, 保证路径str的开头不会有前置的./

func NewMapRelativePath

func NewMapRelativePath() *MapRelativePath

NewMapRelativePath 提供一个全新的MapRelativePath关系

func (*MapRelativePath) Index

func (mrp *MapRelativePath) Index(relativePath string) int

Index 通过Map2Index获取关系索引, 在查询/插入之前会去除str中所有的前置./

type NodeCache

type NodeCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NodeCache 提供了RootCache下的二级缓存, 缓存了搜索节点,提供一级缓存前提下的继续匹配

func NewNodeCache

func NewNodeCache(root *RootCache) *NodeCache

NewNodeCache provide an empty NodeCache

func (*NodeCache) MatchOrInsert

func (n *NodeCache) MatchOrInsert(searchDir, filePath, lastFileDir *File, nodeType NodeType) (*NodeCacheValue, bool)

MatchOrInsert 接收一级缓存, 根据给定的searchDir, filePath, lastFileDir, nodeType 匹配或插入一条二级缓存, 并把该缓存对应的最终结果返回给调用者

type NodeCacheValue

type NodeCacheValue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NodeCacheValue 主要处理对搜索节点的缓存, 在保证正确性的情况下尽量减少搜索分支 cache的key是 searchDir+filePath, lastFileDir, nodeType * 当nodeType为NodeTypeResolved时, searchDir+filePath为找到的文件的位置, lastFileDir为空 * 当nodeType为NodeTypeQuote时, searchDir为空, 已知的只有filePath, lastFileDir为上一个文件的所在目录 * 当nodeType为NodeTypeAngle时, searchDir为空, 已知的只有filePath, lastFileDir为空

func (*NodeCacheValue) CanonicalPath

func (nv *NodeCacheValue) CanonicalPath() *File

CanonicalPath get node's canonical path

func (*NodeCacheValue) Children

func (nv *NodeCacheValue) Children() []*NodeCacheValue

Children 获取该节点的所有儿子节点

func (*NodeCacheValue) Disable

func (nv *NodeCacheValue) Disable()

Disable means set the node disabled, every one meet this node should ignore it.

func (*NodeCacheValue) Enable

func (nv *NodeCacheValue) Enable(r *FileSolveResult, children []*NodeCacheValue)

Enable 标记该搜索节点为"已处理"且有效的 没有被Enable的搜索节点, 只能作为拓扑节点, 而不能作为计算节点 并行的拓扑搜索, 能够在多任务之间, 快速构建多颗相互交叉的搜索树; 但一个任务只有等到它的所有搜索节点都被Enable之后, 才能完成最终的依赖计算

func (*NodeCacheValue) InBlackList

func (nv *NodeCacheValue) InBlackList() bool

InBlackList check if node is in blacklist

func (*NodeCacheValue) IsDisabled

func (nv *NodeCacheValue) IsDisabled() bool

IsDisabled check if node is disabled

func (*NodeCacheValue) IsValid

func (nv *NodeCacheValue) IsValid() bool

IsValid check if node is valid

func (*NodeCacheValue) Match

func (nv *NodeCacheValue) Match(searchDir, filePath, lastFileDir *File, nodeType NodeType) bool

Match 用于校验该二级缓存是否与查询完全匹配

func (*NodeCacheValue) SetBlackList

func (nv *NodeCacheValue) SetBlackList()

SetBlackList 将该节点标记为黑名单, 所有涉及黑名单的节点所在的搜索树, 都会被放弃

func (*NodeCacheValue) WaitUntilValid

func (nv *NodeCacheValue) WaitUntilValid()

WaitUntilValid 将会阻塞, 直到该节点valid为止

type NodeCacheValueList

type NodeCacheValueList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NodeCacheValueList 提供了NodeCacheValue的冲突队列

func (*NodeCacheValueList) MatchOrInsert

func (nvl *NodeCacheValueList) MatchOrInsert(
	searchDir, filePath, lastFileDir *File,
	nodeType NodeType) (*NodeCacheValue, bool)

MatchOrInsert 在冲突队列NodeCacheValueList中查找完全匹配的缓存, 并返回

type NodeType

type NodeType int

NodeType 定义了当前分析的搜索节点的类型 分为 - RESOLVED: 已经找到具体文件 - QUOTE: 将要从quote include里面找文件 - ANGLE: 将要从angle include里面找文件 - NEXT: 将要从next include里面找文件

const (
	NodeTypeResolved NodeType = iota
	NodeTypeQuote
	NodeTypeAngle
	NodeTypeNext
)

func (NodeType) Int

func (nt NodeType) Int() int

Get NodeType int

func (NodeType) String

func (nt NodeType) String() string

Get NodeType string

type ParseCache

type ParseCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ParseCache 提供文件依赖解析的缓存, 一个文件的静态依赖只与其内容有关系, 因此只需要绝对真实路径为索引即可

func NewParseCache

func NewParseCache() *ParseCache

NewParseCache 提供了一个ParseCache实例

func (*ParseCache) GetFileParse

func (pc *ParseCache) GetFileParse(f *File) *FileResult

GetFileParse 根据提供的File的绝对真实路径, 直接给到解析结果

func (*ParseCache) PutFileParse

func (pc *ParseCache) PutFileParse(f *File, r *FileResult)

PutFileParse 根据给定的File和解析结果, 更新缓存

type ParseStat

type ParseStat struct {
	Compiler         string
	NoDistinc        bool
	FileNames        []string
	QuoteDirs        []string
	IncludeFiles     []string
	IDirs            []string
	BeforeSystemDirs []string
	AfterSystemDirs  []string

	Language   string
	ISysRoot   string
	SysRoot    string
	OutputFile string
	IPrefix    string
	DOpts      [][]string

	SourceFilePrefix string

	SourceFile      *File
	QuoteDirList    []*File
	AngleDirList    []*File
	SystemDirList   []*File
	IncludeFileList []*File
}

ParseStat provide the result of a single task's ParseCommand

func (*ParseStat) IncludeSysRoot

func (ps *ParseStat) IncludeSysRoot() string

IncludeSysRoot get the sys root of this task

type Result

type Result struct {
	DependentFile    []*dcSDK.FileDesc
	DependentSymlink []*dcSDK.FileDesc
}

Result 定义了Analyse Do的结果 对于一个命令的分析结果, 最终得到的是 - DependentFile: 该命令所依赖的文件 - DependentSymlink: 该命令及其所依赖文件所依赖的软链接, 这将被视为在远程复刻该命令的前提条件

type RootCache

type RootCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RootCache 提供了一个搜索树节点缓存方案, 整体为一个二级缓存 - 第一级缓存key为: runDir, quoteDirList, angleDirList - 第二级缓存key为: searchDir, filePath, lastFileDir, nodeType 其中第二级缓存由NodeCache提供

func NewRootCache

func NewRootCache() *RootCache

NewRootCache get an empty root cache

func (*RootCache) MatchOrInsert

func (r *RootCache) MatchOrInsert(runDir *File, quoteDirList, angleDirList []*File) *NodeCache

MatchOrInsert 接收一级缓存, 根据给定的runDir, quoteDirList, angleDirList 匹配或插入一条一级缓存, 并把该缓存对应的NodeCache返回给调用者, 方便其发起对二级缓存的查询

type RootCacheValue

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

RootCacheValue 是RootCache的一级缓存对象, 存放了一些匹配用的字段, 以及缓存对象NodeCache

func (*RootCacheValue) Match

func (rv *RootCacheValue) Match(runDir *File, quoteDirList, angleDirList []*File) bool

Match 用于校验该一级缓存是否与查询完全匹配

type RootCacheValueList

type RootCacheValueList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RootCacheValueList 是RootCache中一级缓存的冲突队列, 当多个一级缓存的key相同时, 放在同一个RootCacheValueList里

func (*RootCacheValueList) MatchOrInsert

func (rvl *RootCacheValueList) MatchOrInsert(runDir *File, quoteDirList, angleDirList []*File) *NodeCache

MatchOrInsert 在冲突队列RootCacheValueList中查找完全匹配的缓存, 并返回

type Stats

type Stats struct {
	TimeTotal time.Duration

	// resolve总数统计
	ResolveCount       int64
	ResolveTimeTotal   time.Duration
	ResolveTimeAvg     time.Duration
	ResolveTimeLongest time.Duration

	// resolve实际执行统计
	ResolveProcessCount       int64
	ResolveProcessTimeTotal   time.Duration
	ResolveProcessTimeAvg     time.Duration
	ResolveProcessTimeLongest time.Duration

	// resolve缓存命中统计
	ResolveHitCount       int64
	ResolveHitTimeTotal   time.Duration
	ResolveHitTimeAvg     time.Duration
	ResolveHitTimeLongest time.Duration

	// parse-file总数统计
	ParseFileCount       int64
	ParseFileTimeTotal   time.Duration
	ParseFileTimeAvg     time.Duration
	ParseFileTimeLongest time.Duration

	// parse-file实际执行统计
	ParseFileProcessCount       int64
	ParseFileProcessTimeTotal   time.Duration
	ParseFileProcessTimeAvg     time.Duration
	ParseFileProcessTimeLongest time.Duration

	// parse-file缓存命中统计
	ParseFileHitCount       int64
	ParseFileHitTimeTotal   time.Duration
	ParseFileHitTimeAvg     time.Duration
	ParseFileHitTimeLongest time.Duration

	// find-node总数统计
	FindNodeCount       int64
	FindNodeTimeTotal   time.Duration
	FindNodeTimeAvg     time.Duration
	FindNodeTimeLongest time.Duration

	// find-node实际执行统计
	FindNodeProcessCount       int64
	FindNodeProcessTimeTotal   time.Duration
	FindNodeProcessTimeAvg     time.Duration
	FindNodeProcessTimeLongest time.Duration

	// find-node缓存命中统计
	FindNodeHitCount       int64
	FindNodeHitTimeTotal   time.Duration
	FindNodeHitTimeAvg     time.Duration
	FindNodeHitTimeLongest time.Duration
}

Stats describe the stats information of analyser

func NewStats

func NewStats() *Stats

NewStats provide an empty Stats

func (*Stats) Calculate

func (s *Stats) Calculate()

Calculate calculate the stats result, such as average time.

Jump to

Keyboard shortcuts

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