pass: add textflags.h if required

Closes #12
This commit is contained in:
Michael McLoughlin
2018-12-31 00:23:15 -08:00
parent 4aaf6bc7ed
commit c62e40f8d2
13 changed files with 43 additions and 25 deletions

41
pass/textflag.go Normal file
View File

@@ -0,0 +1,41 @@
package pass
import (
"github.com/mmcloughlin/avo"
)
// IncludeTextFlagHeader includes textflag.h if necessary.
func IncludeTextFlagHeader(f *avo.File) error {
const textflagheader = "textflag.h"
// Check if we already have it.
for _, path := range f.Includes {
if path == textflagheader {
return nil
}
}
// Add it if necessary.
if requirestextflags(f) {
f.Includes = append(f.Includes, textflagheader)
}
return nil
}
// requirestextflags returns whether the file uses flags in the textflags.h header.
func requirestextflags(f *avo.File) bool {
for _, s := range f.Sections {
var a avo.Attribute
switch s := s.(type) {
case *avo.Function:
a = s.Attributes
case *avo.Global:
a = s.Attributes
}
if a.ContainsTextFlags() {
return true
}
}
return false
}