Performance improvements (do not parse addresses or locations unless
location tracking is enabled). Allow profiling option. Add some comments and clean-ups to types/*.go.
This commit is contained in:
+5
-1
@@ -8,6 +8,8 @@ import (
|
||||
"github.com/elliotchance/c2go/util"
|
||||
)
|
||||
|
||||
var TrackPositions bool = false
|
||||
|
||||
// Node represents any node in the AST.
|
||||
type Node interface {
|
||||
Address() Address
|
||||
@@ -27,6 +29,9 @@ type Address uint64
|
||||
// ParseAddress returns the integer representation of the hexadecimal address
|
||||
// (like 0x7f8a1d8ccfd0). If the address cannot be parsed, 0 is returned.
|
||||
func ParseAddress(address string) Address {
|
||||
if !TrackPositions {
|
||||
return 0
|
||||
}
|
||||
addr, _ := strconv.ParseUint(address, 0, 64)
|
||||
|
||||
return Address(addr)
|
||||
@@ -318,7 +323,6 @@ func groupsFromRegex(rx, line string) map[string]string {
|
||||
rx = fullRegexp + "[\\s]*$"
|
||||
|
||||
re := util.GetRegex(rx)
|
||||
|
||||
match := re.FindStringSubmatch(line)
|
||||
if len(match) == 0 {
|
||||
panic("could not match regexp with string\n" + rx + "\n" + line + "\n")
|
||||
|
||||
@@ -20,7 +20,7 @@ func parseBinaryOperator(line string) *BinaryOperator {
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Type: groups["type1"],
|
||||
Type2: groups["type2"],
|
||||
//Type2: groups["type2"],
|
||||
Operator: groups["operator"],
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func parseCStyleCastExpr(line string) *CStyleCastExpr {
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Type: groups["type1"],
|
||||
Type2: groups["type2"],
|
||||
//Type2: groups["type2"],
|
||||
Kind: groups["kind"],
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -27,19 +27,19 @@ func parseEnumConstantDecl(line string) *EnumConstantDecl {
|
||||
line,
|
||||
)
|
||||
|
||||
type2 := groups["type2"]
|
||||
/*type2 := groups["type2"]
|
||||
if type2 != "" {
|
||||
type2 = type2[2 : len(type2)-1]
|
||||
}
|
||||
}*/
|
||||
|
||||
return &EnumConstantDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: groups["position2"],
|
||||
//Position2: groups["position2"],
|
||||
Referenced: len(groups["referenced"]) > 0,
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Type: removeQuotes(groups["type"]),
|
||||
Type2: type2,
|
||||
//Type2: type2,
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -26,18 +26,18 @@ func parseEnumDecl(line string) *EnumDecl {
|
||||
line,
|
||||
)
|
||||
|
||||
type2 := groups["type2"]
|
||||
/*type2 := groups["type2"]
|
||||
if type2 != "" {
|
||||
type2 = type2[2 : len(type2)-1]
|
||||
}
|
||||
}*/
|
||||
|
||||
return &EnumDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: groups["position2"],
|
||||
//Position2: groups["position2"],
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Type: removeQuotes(groups["type"]),
|
||||
Type2: type2,
|
||||
//Type2: type2,
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func parseObjCCategoryDecl(line string) *ObjCCategoryDecl {
|
||||
return &ObjCCategoryDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -25,17 +25,10 @@ func parseObjCInterfaceDecl(line string) *ObjCInterfaceDecl {
|
||||
line,
|
||||
)
|
||||
|
||||
/*fmt.Println(line)
|
||||
fmt.Println("prev = ",groups["prev"])
|
||||
fmt.Println("position = ",groups["position"])
|
||||
fmt.Println("position2 = ",groups["position2"])
|
||||
fmt.Println("implicit = ",len(groups["implicit"])>0)
|
||||
fmt.Println("name = ",groups["name"])*/
|
||||
|
||||
return &ObjCInterfaceDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Implicit: len(groups["implicit"])>0,
|
||||
ChildNodes: []Node{},
|
||||
|
||||
@@ -42,13 +42,13 @@ func parseObjCMethodDecl(line string) *ObjCMethodDecl {
|
||||
return &ObjCMethodDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
Implicit: len(groups["implicit"])>0,
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Implicit: len(groups["implicit"]) > 0,
|
||||
ClassMethod: groups["methodtype"] == " +",
|
||||
Name: parts[0],
|
||||
Parameters: params,
|
||||
Type: strings.TrimSpace(groups["type"]),
|
||||
Type2: strings.TrimSpace(groups["type2"]),
|
||||
//Type2: strings.TrimSpace(groups["type2"]),
|
||||
Attr: strings.TrimSpace(groups["attr"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ func parseObjCPropertyDecl(line string) *ObjCPropertyDecl {
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Type: strings.TrimSpace(groups["type"]),
|
||||
Type2: strings.TrimSpace(groups["type2"]),
|
||||
Type: groups["type"],
|
||||
//Type2: strings.TrimSpace(groups["type2"]),
|
||||
Attr: strings.TrimSpace(groups["attr"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func parseObjCProtocolDecl(line string) *ObjCProtocolDecl {
|
||||
return &ObjCProtocolDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ func parseObjCTypeParamDecl(line string) *ObjCTypeParamDecl {
|
||||
line,
|
||||
)
|
||||
|
||||
type2 := groups["type2"]
|
||||
/*type2 := groups["type2"]
|
||||
if type2 != "" {
|
||||
type2 = type2[2 : len(type2)-1]
|
||||
}
|
||||
}*/
|
||||
|
||||
if strings.Index(groups["position"], "<invalid sloc>") > -1 {
|
||||
groups["position"] = "<invalid sloc>"
|
||||
@@ -45,10 +45,10 @@ func parseObjCTypeParamDecl(line string) *ObjCTypeParamDecl {
|
||||
return &ObjCTypeParamDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Type: groups["type"],
|
||||
Type2: type2,
|
||||
//Type2: type2,
|
||||
IsReferenced: len(groups["referenced"]) > 0,
|
||||
IsCovariant: len(groups["covariant"]) > 0,
|
||||
IsBounded : len(groups["bounded"]) > 0,
|
||||
|
||||
@@ -32,23 +32,23 @@ func parseParmVarDecl(line string) *ParmVarDecl {
|
||||
line,
|
||||
)
|
||||
|
||||
type2 := groups["type2"]
|
||||
/*type2 := groups["type2"]
|
||||
if type2 != "" {
|
||||
type2 = type2[2 : len(type2)-1]
|
||||
}
|
||||
}*/
|
||||
|
||||
if strings.Index(groups["position"], "<invalid sloc>") > -1 {
|
||||
/*if strings.Index(groups["position"], "<invalid sloc>") > -1 {
|
||||
groups["position"] = "<invalid sloc>"
|
||||
groups["position2"] = "<invalid sloc>"
|
||||
}
|
||||
}*/
|
||||
|
||||
return &ParmVarDecl{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Name: strings.TrimSpace(groups["name"]),
|
||||
Type: groups["type"],
|
||||
Type2: type2,
|
||||
//Type2: type2,
|
||||
IsUsed: len(groups["used"]) > 0,
|
||||
IsReferenced: len(groups["referenced"]) > 0,
|
||||
IsRegister: len(groups["register"]) > 0,
|
||||
|
||||
@@ -33,6 +33,9 @@ func (p Position) GetSimpleLocation() (loc string) {
|
||||
}
|
||||
|
||||
func NewPositionFromString(s string) Position {
|
||||
if !TrackPositions {
|
||||
return Position{}
|
||||
}
|
||||
re := util.GetRegex(`<invalid sloc>|<scratch space>|<built-in>`)
|
||||
if re.MatchString(s) || s == "" {
|
||||
return Position{}
|
||||
|
||||
@@ -25,7 +25,7 @@ func parseUnavailableAttr(line string) *UnavailableAttr {
|
||||
return &UnavailableAttr{
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Content: strings.TrimSpace(groups["content"]),
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"strings"
|
||||
//"strings"
|
||||
)
|
||||
|
||||
// Unknown is node represents an unknown node.
|
||||
@@ -30,7 +30,7 @@ func parseUnknown(name, line string) *Unknown {
|
||||
Name: name,
|
||||
Addr: ParseAddress(groups["address"]),
|
||||
Pos: NewPositionFromString(groups["position"]),
|
||||
Position2: strings.TrimSpace(groups["position2"]),
|
||||
//Position2: strings.TrimSpace(groups["position2"]),
|
||||
Content: groups["content"],
|
||||
ChildNodes: []Node{},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user