in tool/instrument/inst_struct.go [32:64]
func (rp *RuleProcessor) applyStructRules(bundle *resource.RuleBundle) error {
for file, struct2Rules := range bundle.File2StructRules {
util.Assert(filepath.IsAbs(file), "file path must be absolute")
// Apply struct rules to the file
astRoot, err := rp.loadAst(file)
if err != nil {
return err
}
for _, decl := range astRoot.Decls {
for structName, rules := range struct2Rules {
if util.MatchStructDecl(decl, structName) {
for _, rule := range rules {
rp.addStructField(rule, decl)
}
}
}
}
// Once all struct rules are applied, we restore AST to file and use it
// in future compilation
newFile, err := rp.restoreAst(file, astRoot)
if err != nil {
return err
}
// Line directive must be placed at the beginning of the line, otherwise
// it will be ignored by the compiler
err = rp.enableLineDirective(newFile)
if err != nil {
return err
}
rp.saveDebugFile(newFile)
}
return nil
}