Skip to content

Commit

Permalink
Added IsInherited to DeprecatedAttr. Fixes #205 and #184 (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin8105 authored and elliotchance committed Nov 2, 2017
1 parent 8f5bd37 commit 22f50f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
24 changes: 13 additions & 11 deletions ast/deprecated_attr.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package ast

type DeprecatedAttr struct {
Addr Address
Pos Position
Message1 string
Message2 string
ChildNodes []Node
Addr Address
Pos Position
Message1 string
Message2 string
IsInherited bool
ChildNodes []Node
}

func parseDeprecatedAttr(line string) *DeprecatedAttr {
groups := groupsFromRegex(
`<(?P<position>.*)> "(?P<message1>.*?)"(?P<message2> ".*?")?`,
`<(?P<position>.*)>(?P<inherited> Inherited)? "(?P<message1>.*?)"(?P<message2> ".*?")?`,
line,
)

return &DeprecatedAttr{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Message1: removeQuotes(groups["message1"]),
Message2: removeQuotes(groups["message2"]),
ChildNodes: []Node{},
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Message1: removeQuotes(groups["message1"]),
Message2: removeQuotes(groups["message2"]),
IsInherited: len(groups["inherited"]) > 0,
ChildNodes: []Node{},
}
}

Expand Down
27 changes: 22 additions & 5 deletions ast/deprecated_attr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@ import (
func TestDeprecatedAttr(t *testing.T) {
nodes := map[string]Node{
`0x7fec4b0ab9c0 <line:180:48, col:63> "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ""`: &DeprecatedAttr{
Addr: 0x7fec4b0ab9c0,
Pos: NewPositionFromString("line:180:48, col:63"),
Message1: "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead.",
Message2: "",
ChildNodes: []Node{},
Addr: 0x7fec4b0ab9c0,
Pos: NewPositionFromString("line:180:48, col:63"),
Message1: "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead.",
Message2: "",
IsInherited: false,
ChildNodes: []Node{},
},
`0xb75d00 <line:1107:12> "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: &DeprecatedAttr{
Addr: 0xb75d00,
Pos: NewPositionFromString("line:1107:12"),
Message1: "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.",
Message2: "",
IsInherited: false,
ChildNodes: []Node{},
},
`0xb75d00 <line:1107:12> Inherited "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: &DeprecatedAttr{
Addr: 0xb75d00,
Pos: NewPositionFromString("line:1107:12"),
Message1: "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.",
Message2: "",
IsInherited: true,
ChildNodes: []Node{},
},
}

Expand Down

0 comments on commit 22f50f9

Please sign in to comment.