Some AST tweaks and add astfile: config option to read AST from a file
instead of running Clang. Attempt to port to MacOS Mojave.
This commit is contained in:
parent
a7df3a4e71
commit
4f0cdf4d1a
|
@ -3,7 +3,7 @@ package ast
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"git.wow.st/gmp/nswrap/util"
|
||||
//"git.wow.st/gmp/nswrap/util"
|
||||
)
|
||||
|
||||
// AllocSizeAttr is a type of attribute that is optionally attached to a variable
|
||||
|
@ -12,8 +12,8 @@ type AllocSizeAttr struct {
|
|||
Addr Address
|
||||
Pos Position
|
||||
Inherited bool
|
||||
A int
|
||||
B int
|
||||
A string
|
||||
B string
|
||||
ChildNodes []Node
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@ func parseAllocSizeAttr(line string) *AllocSizeAttr {
|
|||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Inherited: len(groups["inherited"]) > 0,
|
||||
A: util.Atoi(strings.TrimSpace(groups["a"])),
|
||||
B: util.Atoi(strings.TrimSpace(groups["b"])),
|
||||
A: strings.TrimSpace(groups["a"]),
|
||||
B: strings.TrimSpace(groups["b"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ func parseImplicitCastExpr(line string) *ImplicitCastExpr {
|
|||
`<(?P<position>.*)>
|
||||
'(?P<type>.*?)'
|
||||
(:'(?P<type2>.*?)')?
|
||||
<(?P<kind>.*)>`,
|
||||
<(?P<kind>.*)>
|
||||
( part_of_explicit_cast)?`,
|
||||
line,
|
||||
)
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ func parseUnaryOperator(line string) *UnaryOperator {
|
|||
(?P<lvalue> lvalue)?
|
||||
(?P<prefix> prefix)?
|
||||
(?P<postfix> postfix)?
|
||||
'(?P<operator>.*?)'`,
|
||||
'(?P<operator>.*?)'
|
||||
( .*)?`,
|
||||
line,
|
||||
)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ type VarDecl struct {
|
|||
Type2 string
|
||||
IsExtern bool
|
||||
IsUsed bool
|
||||
IsRange bool
|
||||
IsCInit bool
|
||||
IsReferenced bool
|
||||
IsStatic bool
|
||||
|
@ -28,6 +29,7 @@ func parseVarDecl(line string) *VarDecl {
|
|||
(?:parent (?P<parent>0x[0-9a-f]+) )?
|
||||
<(?P<position>.*)>(?P<position2> .+:\d+)?
|
||||
(?P<used> used)?
|
||||
(?P<range> range)?
|
||||
(?P<referenced> referenced)?
|
||||
(?P<name> \w+)?
|
||||
'(?P<type>.+?)'
|
||||
|
@ -36,6 +38,7 @@ func parseVarDecl(line string) *VarDecl {
|
|||
(?P<static> static)?
|
||||
(?P<cinit> cinit)?
|
||||
(?P<register> register)?
|
||||
(.*)
|
||||
`,
|
||||
line,
|
||||
)
|
||||
|
@ -55,6 +58,7 @@ func parseVarDecl(line string) *VarDecl {
|
|||
Type2: type2,
|
||||
IsExtern: len(groups["extern"]) > 0,
|
||||
IsUsed: len(groups["used"]) > 0,
|
||||
IsRange: len(groups["range"]) > 0,
|
||||
IsCInit: len(groups["cinit"]) > 0,
|
||||
IsReferenced: len(groups["referenced"]) > 0,
|
||||
IsStatic: len(groups["static"]) > 0,
|
||||
|
|
20
main.go
20
main.go
|
@ -23,6 +23,7 @@ type conf struct {
|
|||
Positions bool
|
||||
Package string
|
||||
Inputfiles []string
|
||||
Astfile string
|
||||
Classes []string
|
||||
Functions []string
|
||||
Enums []string
|
||||
|
@ -157,8 +158,20 @@ func matches(x string, rs []string) bool {
|
|||
|
||||
// Start begins transpiling an input file.
|
||||
func Start() (err error) {
|
||||
astPP := []byte{}
|
||||
if Config.Astfile != "" {
|
||||
fmt.Printf("Reading ast file %s\n",Config.Astfile)
|
||||
_, err = os.Stat(Config.Astfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Input AST file %s not found",Config.Astfile)
|
||||
}
|
||||
astPP, err = ioutil.ReadFile(Config.Astfile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for _, in := range Config.Inputfiles {
|
||||
_, err := os.Stat(in)
|
||||
_, err = os.Stat(in)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Input file %s is not found", in)
|
||||
}
|
||||
|
@ -172,7 +185,7 @@ func Start() (err error) {
|
|||
}
|
||||
cargs = append(cargs,Config.Inputfiles...)
|
||||
fmt.Printf("Generating AST\n")
|
||||
astPP, err := exec.Command("clang",cargs...).Output()
|
||||
astPP, err = exec.Command("clang",cargs...).Output()
|
||||
if err != nil {
|
||||
// If clang fails it still prints out the AST, so we have to run it
|
||||
// again to get the real error.
|
||||
|
@ -187,6 +200,7 @@ func Start() (err error) {
|
|||
fmt.Printf("clang failed:\n%s\n", txt)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
lines := readAST(astPP)
|
||||
|
||||
|
@ -271,6 +285,8 @@ func main() {
|
|||
fmt.Printf("Cannot decode config file nswrap.yaml. %s\n",err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
fmt.Printf("Package = %s\n",Config.Package)
|
||||
fmt.Printf("Astfile = %s\n",Config.Astfile)
|
||||
if err := Start(); err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(-1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user