diff --git a/ast/aligned_attr.go b/ast/aligned_attr.go index 64c05d3..928e19c 100644 --- a/ast/aligned_attr.go +++ b/ast/aligned_attr.go @@ -9,11 +9,14 @@ type AlignedAttr struct { ChildNodes []Node } -func parseAlignedAttr(line string) *AlignedAttr { +func parseAlignedAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>(?P aligned)?", line, ) + if groups == nil { + return &Unknown{} + } return &AlignedAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/alloc_size_attr.go b/ast/alloc_size_attr.go index 0439eeb..2e053db 100644 --- a/ast/alloc_size_attr.go +++ b/ast/alloc_size_attr.go @@ -17,11 +17,14 @@ type AllocSizeAttr struct { ChildNodes []Node } -func parseAllocSizeAttr(line string) *AllocSizeAttr { +func parseAllocSizeAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)>(?P Inherited)?(?P \d+)(?P \d+)?`, line, ) + if groups == nil { + return &Unknown{} + } return &AllocSizeAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/always_inline_attr.go b/ast/always_inline_attr.go index d01c565..fc30a3e 100644 --- a/ast/always_inline_attr.go +++ b/ast/always_inline_attr.go @@ -8,11 +8,14 @@ type AlwaysInlineAttr struct { ChildNodes []Node } -func parseAlwaysInlineAttr(line string) *AlwaysInlineAttr { +func parseAlwaysInlineAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)> always_inline", line, ) + if groups == nil { + return &Unknown{} + } return &AlwaysInlineAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/arc_weakref_unavailable_attr.go b/ast/arc_weakref_unavailable_attr.go new file mode 100644 index 0000000..b55c88d --- /dev/null +++ b/ast/arc_weakref_unavailable_attr.go @@ -0,0 +1,47 @@ +package ast + +// ArcWeakrefUnavailableAttr +type ArcWeakrefUnavailableAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseArcWeakrefUnavailableAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ArcWeakrefUnavailableAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ArcWeakrefUnavailableAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ArcWeakrefUnavailableAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ArcWeakrefUnavailableAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ArcWeakrefUnavailableAttr) Position() Position { + return n.Pos +} diff --git a/ast/array_subscript_expr.go b/ast/array_subscript_expr.go index 03c818b..47bf07d 100644 --- a/ast/array_subscript_expr.go +++ b/ast/array_subscript_expr.go @@ -11,13 +11,16 @@ type ArraySubscriptExpr struct { ChildNodes []Node } -func parseArraySubscriptExpr(line string) *ArraySubscriptExpr { +func parseArraySubscriptExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'(:'(?P.*?)')? (?P lvalue)? (?P vectorcomponent)?`, line, ) + if groups == nil { + return &Unknown{} + } return &ArraySubscriptExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/asm_label_attr.go b/ast/asm_label_attr.go index 81566d5..26c599a 100644 --- a/ast/asm_label_attr.go +++ b/ast/asm_label_attr.go @@ -9,13 +9,16 @@ type AsmLabelAttr struct { ChildNodes []Node } -func parseAsmLabelAttr(line string) *AsmLabelAttr { +func parseAsmLabelAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? "(?P.+)"`, line, ) + if groups == nil { + return &Unknown{} + } return &AsmLabelAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/ast.go b/ast/ast.go index 1e92fb5..e2fc139 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -2,6 +2,7 @@ package ast import ( + "fmt" "strconv" "strings" @@ -69,6 +70,8 @@ func Parse(fullline string) Node { return parseAlwaysInlineAttr(line) case "ArraySubscriptExpr": return parseArraySubscriptExpr(line) + case "ArcWeakrefUnavailableAttr": + return parseArcWeakrefUnavailableAttr(line) case "AsmLabelAttr": return parseAsmLabelAttr(line) case "AttributedType": @@ -87,8 +90,18 @@ func Parse(fullline string) Node { return parseBuiltinType(line) case "CallExpr": return parseCallExpr(line) + case "ConvertVectorExpr": + return parseConvertVectorExpr(line) case "CaseStmt": return parseCaseStmt(line) + case "CFAuditedTransferAttr": + return parseCFAuditedTransferAttr(line) + case "CFConsumedAttr": + return parseCFConsumedAttr(line) + case "CFReturnsRetainedAttr": + return parseCFReturnsRetainedAttr(line) + case "CFReturnsNotRetainedAttr": + return parseCFReturnsNotRetainedAttr(line) case "CharacterLiteral": return parseCharacterLiteral(line) case "CompoundLiteralExpr": @@ -129,12 +142,16 @@ func Parse(fullline string) Node { return parseEnumConstantDecl(line) case "EnumDecl": return parseEnumDecl(line) + case "EnumExtensibilityAttr": + return parseEnumExtensibilityAttr(line) case "EnumType": return parseEnumType(line) case "Field": return parseField(line) case "FieldDecl": return parseFieldDecl(line) + case "FlagEnumAttr": + return parseFlagEnumAttr(line) case "FloatingLiteral": return parseFloatingLiteral(line) case "FormatAttr": @@ -157,6 +174,10 @@ func Parse(fullline string) Node { return parseGCCAsmStmt(line) case "GotoStmt": return parseGotoStmt(line) + case "IBActionAttr": + return parseIBActionAttr(line) + case "IBOutletAttr": + return parseIBOutletAttr(line) case "IfStmt": return parseIfStmt(line) case "ImplicitCastExpr": @@ -179,10 +200,18 @@ func Parse(fullline string) Node { return parseMallocAttr(line) case "MaxFieldAlignmentAttr": return parseMaxFieldAlignmentAttr(line) + case "MayAliasAttr": + return parseMayAliasAttr(line) case "MemberExpr": return parseMemberExpr(line) + case "MinVectorWidthAttr": + return parseMinVectorWidthAttr(line) case "ModeAttr": return parseModeAttr(line) + case "NoDebugAttr": + return parseNoDebugAttr(line) + case "NoEscapeAttr": + return parseNoEscapeAttr(line) case "NoInlineAttr": return parseNoInlineAttr(line) case "NoThrowAttr": @@ -191,8 +220,34 @@ func Parse(fullline string) Node { return parseNonNullAttr(line) case "NotTailCalledAttr": return parseNotTailCalledAttr(line) + case "NSConsumedAttr": + return parseNSConsumedAttr(line) + case "NSConsumesSelfAttr": + return parseNSConsumesSelfAttr(line) + case "NSErrorDomainAttr": + return parseNSErrorDomainAttr(line) + case "NSReturnsRetainedAttr": + return parseNSReturnsRetainedAttr(line) + case "ObjCBoolLiteralExpr": + return parseObjCBoolLiteralExpr(line) + case "ObjCBoxableAttr": + return parseObjCBoxableAttr(line) + case "ObjCBridgeAttr": + return parseObjCBridgeAttr(line) + case "ObjCBridgeRelatedAttr": + return parseObjCBridgeRelatedAttr(line) + case "ObjCBridgeMutableAttr": + return parseObjCBridgeMutableAttr(line) case "ObjCCategoryDecl": return parseObjCCategoryDecl(line) + case "ObjCDesignatedInitializerAttr": + return parseObjCDesignatedInitializerAttr(line) + case "ObjCExceptionAttr": + return parseObjCExceptionAttr(line) + case "ObjCExplicitProtocolImplAttr": + return parseObjCExplicitProtocolImplAttr(line) + case "ObjCIndependentClassAttr": + return parseObjCIndependentClassAttr(line) case "ObjCInterface": return parseObjCInterface(line,false) case "super ObjCInterface": @@ -201,10 +256,14 @@ func Parse(fullline string) Node { return parseObjCInterfaceDecl(line) case "ObjCInterfaceType": return parseObjCInterfaceType(line) + case "ObjCIvarDecl": + return parseObjCIvarDecl(line) case "getter ObjCMethod": return parseObjCMethod(line) case "ObjCMethod": return parseObjCMethod(line) + case "ObjCMessageExpr": + return parseObjCMessageExpr(line) case "ObjCMethodDecl": return parseObjCMethodDecl(line) case "ObjCObjectType": @@ -213,8 +272,14 @@ func Parse(fullline string) Node { return parseObjCObjectPointerType(line) case "ObjCProtocol": return parseObjCProtocol(line) + case "ObjCReturnsInnerPointerAttr": + return parseObjCReturnsInnerPointerAttr(line) + case "ObjCRequiresSuperAttr": + return parseObjCRequiresSuperAttr(line) case "ObjCProtocolDecl": return parseObjCProtocolDecl(line) + case "ObjCRootClassAttr": + return parseObjCRootClassAttr(line) case "ObjCPropertyDecl": return parseObjCPropertyDecl(line) case "ObjCTypeParamDecl": @@ -257,12 +322,26 @@ func Parse(fullline string) Node { return parseReturnsTwiceAttr(line) case "SentinelAttr": return parseSentinelAttr(line) + case "ShuffleVectorExpr": + return parseShuffleVectorExpr(line) case "StmtExpr": return parseStmtExpr(line) case "StringLiteral": return parseStringLiteral(line) + case "SwiftBridgedTypedefAttr": + return parseSwiftBridgedTypedefAttr(line) + case "SwiftErrorAttr": + return parseSwiftErrorAttr(line) + case "SwiftNameAttr": + return parseSwiftNameAttr(line) + case "SwiftNewtypeAttr": + return parseSwiftNewtypeAttr(line) + case "SwiftPrivateAttr": + return parseSwiftPrivateAttr(line) case "SwitchStmt": return parseSwitchStmt(line) + case "TargetAttr": + return parseTargetAttr(line) case "TextComment": return parseTextComment(line) case "TranslationUnitDecl": @@ -281,6 +360,8 @@ func Parse(fullline string) Node { return parseUnaryOperator(line) case "UnavailableAttr": return parseUnavailableAttr(line) + case "UsedAttr": + return parseUsedAttr(line) case "UnusedAttr": return parseUnusedAttr(line) case "VAArgExpr": @@ -301,6 +382,8 @@ func Parse(fullline string) Node { return parseWarnUnusedResultAttr(line) case "WeakAttr": return parseWeakAttr(line) + case "WeakImportAttr": + return parseWeakImportAttr(line) case "WhileStmt": return parseWhileStmt(line) case "...": @@ -323,7 +406,8 @@ func groupsFromRegex(rx, line string) map[string]string { re := util.GetRegex(rx) match := re.FindStringSubmatch(line) if len(match) == 0 { - panic("could not match regexp with string\n" + rx + "\n" + line + "\n") + fmt.Printf("AST parser: could not match regexp with string. Regexp:\n" + rx + "\nOriginal line:\n" + line + "\n\n") + return nil } result := make(map[string]string) diff --git a/ast/attributed_type.go b/ast/attributed_type.go index c8e6ff4..abb3f7a 100644 --- a/ast/attributed_type.go +++ b/ast/attributed_type.go @@ -8,12 +8,15 @@ type AttributedType struct { ChildNodes []Node } -func parseAttributedType(line string) *AttributedType { +func parseAttributedType(line string) Node { groups := groupsFromRegex( `'(?P.*)' (?P sugar)?`, line, ) + if groups == nil { + return &Unknown{} + } return &AttributedType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/availability_attr.go b/ast/availability_attr.go index 37b09f0..961d78e 100644 --- a/ast/availability_attr.go +++ b/ast/availability_attr.go @@ -16,7 +16,7 @@ type AvailabilityAttr struct { ChildNodes []Node } -func parseAvailabilityAttr(line string) *AvailabilityAttr { +func parseAvailabilityAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? @@ -29,6 +29,9 @@ func parseAvailabilityAttr(line string) *AvailabilityAttr { (?P ".*?")?`, line, ) + if groups == nil { + return &Unknown{} + } return &AvailabilityAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/binary_operator.go b/ast/binary_operator.go index 49f750d..2cd938d 100644 --- a/ast/binary_operator.go +++ b/ast/binary_operator.go @@ -10,11 +10,14 @@ type BinaryOperator struct { ChildNodes []Node } -func parseBinaryOperator(line string) *BinaryOperator { +func parseBinaryOperator(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)'(:'(?P.*?)')? '(?P.*?)'", line, ) + if groups == nil { + return &Unknown{} + } return &BinaryOperator{ Addr: ParseAddress(groups["address"]), diff --git a/ast/block_command_comment.go b/ast/block_command_comment.go index 557517e..328c921 100644 --- a/ast/block_command_comment.go +++ b/ast/block_command_comment.go @@ -8,11 +8,14 @@ type BlockCommandComment struct { ChildNodes []Node } -func parseBlockCommandComment(line string) *BlockCommandComment { +func parseBlockCommandComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Name="(?P.*)"`, line, ) + if groups == nil { + return &Unknown{} + } return &BlockCommandComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/block_pointer_type.go b/ast/block_pointer_type.go index 0a66c1b..90b4a5a 100644 --- a/ast/block_pointer_type.go +++ b/ast/block_pointer_type.go @@ -7,11 +7,14 @@ type BlockPointerType struct { ChildNodes []Node } -func parseBlockPointerType(line string) *BlockPointerType { +func parseBlockPointerType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &BlockPointerType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/break_stmt.go b/ast/break_stmt.go index bf99971..8b2300e 100644 --- a/ast/break_stmt.go +++ b/ast/break_stmt.go @@ -7,11 +7,14 @@ type BreakStmt struct { ChildNodes []Node } -func parseBreakStmt(line string) *BreakStmt { +func parseBreakStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &BreakStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/builtin_type.go b/ast/builtin_type.go index 6bd4cbd..2eec547 100644 --- a/ast/builtin_type.go +++ b/ast/builtin_type.go @@ -7,11 +7,14 @@ type BuiltinType struct { ChildNodes []Node } -func parseBuiltinType(line string) *BuiltinType { +func parseBuiltinType(line string) Node { groups := groupsFromRegex( "'(?P.*?)'", line, ) + if groups == nil { + return &Unknown{} + } return &BuiltinType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/c_style_cast_expr.go b/ast/c_style_cast_expr.go index 6519f2c..d828e0e 100644 --- a/ast/c_style_cast_expr.go +++ b/ast/c_style_cast_expr.go @@ -16,11 +16,14 @@ var CStyleCastExprNullToPointer = "NullToPointer" // CStyleCastExprToVoid - string of kind ToVoid var CStyleCastExprToVoid = "ToVoid" -func parseCStyleCastExpr(line string) *CStyleCastExpr { +func parseCStyleCastExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)'(:'(?P.*?)')? <(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &CStyleCastExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/call_expr.go b/ast/call_expr.go index c71d684..0108744 100644 --- a/ast/call_expr.go +++ b/ast/call_expr.go @@ -8,11 +8,14 @@ type CallExpr struct { ChildNodes []Node } -func parseCallExpr(line string) *CallExpr { +func parseCallExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)'", line, ) + if groups == nil { + return &Unknown{} + } return &CallExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/case_stmt.go b/ast/case_stmt.go index ba86c42..203761e 100644 --- a/ast/case_stmt.go +++ b/ast/case_stmt.go @@ -7,8 +7,11 @@ type CaseStmt struct { ChildNodes []Node } -func parseCaseStmt(line string) *CaseStmt { +func parseCaseStmt(line string) Node { groups := groupsFromRegex(`<(?P.*)>`, line) + if groups == nil { + return &Unknown{} + } return &CaseStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/cf_audited_transfer_attr.go b/ast/cf_audited_transfer_attr.go new file mode 100644 index 0000000..0e0e9f8 --- /dev/null +++ b/ast/cf_audited_transfer_attr.go @@ -0,0 +1,49 @@ +package ast + +// CFAuditedTransferAttr +type CFAuditedTransferAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseCFAuditedTransferAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &CFAuditedTransferAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *CFAuditedTransferAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *CFAuditedTransferAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *CFAuditedTransferAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *CFAuditedTransferAttr) Position() Position { + return n.Pos +} diff --git a/ast/cf_consumed_attr.go b/ast/cf_consumed_attr.go new file mode 100644 index 0000000..b1b2fa8 --- /dev/null +++ b/ast/cf_consumed_attr.go @@ -0,0 +1,49 @@ +package ast + +// CFConsumedAttr +type CFConsumedAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseCFConsumedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &CFConsumedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *CFConsumedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *CFConsumedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *CFConsumedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *CFConsumedAttr) Position() Position { + return n.Pos +} diff --git a/ast/cf_returns_not_retained_attr.go b/ast/cf_returns_not_retained_attr.go new file mode 100644 index 0000000..4226aa8 --- /dev/null +++ b/ast/cf_returns_not_retained_attr.go @@ -0,0 +1,47 @@ +package ast + +// CFReturnsNotRetainedAttr +type CFReturnsNotRetainedAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseCFReturnsNotRetainedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &CFReturnsNotRetainedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *CFReturnsNotRetainedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *CFReturnsNotRetainedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *CFReturnsNotRetainedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *CFReturnsNotRetainedAttr) Position() Position { + return n.Pos +} diff --git a/ast/cf_returns_retained_attr.go b/ast/cf_returns_retained_attr.go new file mode 100644 index 0000000..7db9e1a --- /dev/null +++ b/ast/cf_returns_retained_attr.go @@ -0,0 +1,47 @@ +package ast + +// CFReturnsRetainedAttr +type CFReturnsRetainedAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseCFReturnsRetainedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &CFReturnsRetainedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *CFReturnsRetainedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *CFReturnsRetainedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *CFReturnsRetainedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *CFReturnsRetainedAttr) Position() Position { + return n.Pos +} diff --git a/ast/character_literal.go b/ast/character_literal.go index fe4d052..3420355 100644 --- a/ast/character_literal.go +++ b/ast/character_literal.go @@ -13,11 +13,14 @@ type CharacterLiteral struct { ChildNodes []Node } -func parseCharacterLiteral(line string) *CharacterLiteral { +func parseCharacterLiteral(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)' (?P\\d+)", line, ) + if groups == nil { + return &Unknown{} + } return &CharacterLiteral{ Addr: ParseAddress(groups["address"]), diff --git a/ast/compound_assign_operator.go b/ast/compound_assign_operator.go index d8e35ce..1c3904f 100644 --- a/ast/compound_assign_operator.go +++ b/ast/compound_assign_operator.go @@ -11,7 +11,7 @@ type CompoundAssignOperator struct { ChildNodes []Node } -func parseCompoundAssignOperator(line string) *CompoundAssignOperator { +func parseCompoundAssignOperator(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.+?)' @@ -20,6 +20,9 @@ func parseCompoundAssignOperator(line string) *CompoundAssignOperator { ComputeResultTy='(?P.+?)'`, line, ) + if groups == nil { + return &Unknown{} + } return &CompoundAssignOperator{ Addr: ParseAddress(groups["address"]), diff --git a/ast/compound_literal_expr.go b/ast/compound_literal_expr.go index ad86be3..c142699 100644 --- a/ast/compound_literal_expr.go +++ b/ast/compound_literal_expr.go @@ -9,11 +9,14 @@ type CompoundLiteralExpr struct { ChildNodes []Node } -func parseCompoundLiteralExpr(line string) *CompoundLiteralExpr { +func parseCompoundLiteralExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'(:'(?P.*?)')? lvalue`, line, ) + if groups == nil { + return &Unknown{} + } return &CompoundLiteralExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/compound_stmt.go b/ast/compound_stmt.go index c588bcc..e964a92 100644 --- a/ast/compound_stmt.go +++ b/ast/compound_stmt.go @@ -10,11 +10,14 @@ type CompoundStmt struct { BelongsToSwitch bool } -func parseCompoundStmt(line string) *CompoundStmt { +func parseCompoundStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &CompoundStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/conditional_operator.go b/ast/conditional_operator.go index 7b097e0..65bbaf0 100644 --- a/ast/conditional_operator.go +++ b/ast/conditional_operator.go @@ -8,11 +8,14 @@ type ConditionalOperator struct { ChildNodes []Node } -func parseConditionalOperator(line string) *ConditionalOperator { +func parseConditionalOperator(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'`, line, ) + if groups == nil { + return &Unknown{} + } return &ConditionalOperator{ Addr: ParseAddress(groups["address"]), diff --git a/ast/const_attr.go b/ast/const_attr.go index 54509fd..9bed561 100644 --- a/ast/const_attr.go +++ b/ast/const_attr.go @@ -9,11 +9,14 @@ type ConstAttr struct { ChildNodes []Node } -func parseConstAttr(line string) *ConstAttr { +func parseConstAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>(?P.*)", line, ) + if groups == nil { + return &Unknown{} + } return &ConstAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/constant_array_type.go b/ast/constant_array_type.go index f13bf18..35e2fef 100644 --- a/ast/constant_array_type.go +++ b/ast/constant_array_type.go @@ -12,11 +12,14 @@ type ConstantArrayType struct { ChildNodes []Node } -func parseConstantArrayType(line string) *ConstantArrayType { +func parseConstantArrayType(line string) Node { groups := groupsFromRegex( "'(?P.*)' (?P\\d+)", line, ) + if groups == nil { + return &Unknown{} + } return &ConstantArrayType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/continue_stmt.go b/ast/continue_stmt.go index 4a3decb..27a4175 100644 --- a/ast/continue_stmt.go +++ b/ast/continue_stmt.go @@ -7,11 +7,14 @@ type ContinueStmt struct { ChildNodes []Node } -func parseContinueStmt(line string) *ContinueStmt { +func parseContinueStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &ContinueStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/convert_vector_expr.go b/ast/convert_vector_expr.go new file mode 100644 index 0000000..1e92496 --- /dev/null +++ b/ast/convert_vector_expr.go @@ -0,0 +1,53 @@ +package ast + +// ConvertVectorExpr +type ConvertVectorExpr struct { + Addr Address + Pos Position + Type string + Type2 string + ChildNodes []Node +} + +func parseConvertVectorExpr(line string) Node { + groups := groupsFromRegex( + `<(?P|.*?)> + (?P '.*?')? + (?P:'.*?')?`, + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ConvertVectorExpr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Type: removeQuotes(groups["type"]), + Type2: groups["type2"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ConvertVectorExpr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ConvertVectorExpr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ConvertVectorExpr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ConvertVectorExpr) Position() Position { + return n.Pos +} diff --git a/ast/decayed_type.go b/ast/decayed_type.go index a19cfab..5301fb7 100644 --- a/ast/decayed_type.go +++ b/ast/decayed_type.go @@ -7,11 +7,14 @@ type DecayedType struct { ChildNodes []Node } -func parseDecayedType(line string) *DecayedType { +func parseDecayedType(line string) Node { groups := groupsFromRegex( "'(?P.*)' sugar", line, ) + if groups == nil { + return &Unknown{} + } return &DecayedType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/decl_ref_expr.go b/ast/decl_ref_expr.go index ffdeee3..200351d 100644 --- a/ast/decl_ref_expr.go +++ b/ast/decl_ref_expr.go @@ -15,7 +15,7 @@ type DeclRefExpr struct { ChildNodes []Node } -func parseDeclRefExpr(line string) *DeclRefExpr { +func parseDeclRefExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'(:'(?P.*?)')? @@ -28,6 +28,9 @@ func parseDeclRefExpr(line string) *DeclRefExpr { `, line, ) + if groups == nil { + return &Unknown{} + } return &DeclRefExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/decl_stmt.go b/ast/decl_stmt.go index 1312f34..5e3e0e5 100644 --- a/ast/decl_stmt.go +++ b/ast/decl_stmt.go @@ -7,11 +7,14 @@ type DeclStmt struct { ChildNodes []Node } -func parseDeclStmt(line string) *DeclStmt { +func parseDeclStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &DeclStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/default_stmt.go b/ast/default_stmt.go index e848852..60c8464 100644 --- a/ast/default_stmt.go +++ b/ast/default_stmt.go @@ -7,8 +7,11 @@ type DefaultStmt struct { ChildNodes []Node } -func parseDefaultStmt(line string) *DefaultStmt { +func parseDefaultStmt(line string) Node { groups := groupsFromRegex(`<(?P.*)>`, line) + if groups == nil { + return &Unknown{} + } return &DefaultStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/deprecated_attr.go b/ast/deprecated_attr.go index d86f2cd..3451c09 100644 --- a/ast/deprecated_attr.go +++ b/ast/deprecated_attr.go @@ -11,11 +11,14 @@ type DeprecatedAttr struct { ChildNodes []Node } -func parseDeprecatedAttr(line string) *DeprecatedAttr { +func parseDeprecatedAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)>(?P Inherited)? "(?P.*?)"(?P ".*?")?`, line, ) + if groups == nil { + return &Unknown{} + } return &DeprecatedAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/disable_tail_calls_attr.go b/ast/disable_tail_calls_attr.go index 86007a1..0d278ef 100644 --- a/ast/disable_tail_calls_attr.go +++ b/ast/disable_tail_calls_attr.go @@ -8,11 +8,14 @@ type DisableTailCallsAttr struct { ChildNodes []Node } -func parseDisableTailCallsAttr(line string) *DisableTailCallsAttr { +func parseDisableTailCallsAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &DisableTailCallsAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/do_stmt.go b/ast/do_stmt.go index 09e18dd..7d888f2 100644 --- a/ast/do_stmt.go +++ b/ast/do_stmt.go @@ -7,11 +7,14 @@ type DoStmt struct { ChildNodes []Node } -func parseDoStmt(line string) *DoStmt { +func parseDoStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &DoStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/elaborated_type.go b/ast/elaborated_type.go index b1fe6f9..729b3c4 100644 --- a/ast/elaborated_type.go +++ b/ast/elaborated_type.go @@ -8,11 +8,14 @@ type ElaboratedType struct { ChildNodes []Node } -func parseElaboratedType(line string) *ElaboratedType { +func parseElaboratedType(line string) Node { groups := groupsFromRegex( "'(?P.*?)' (?P.+)", line, ) + if groups == nil { + return &Unknown{} + } return &ElaboratedType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/empty_decl.go b/ast/empty_decl.go index 84b319f..a47d103 100644 --- a/ast/empty_decl.go +++ b/ast/empty_decl.go @@ -8,12 +8,15 @@ type EmptyDecl struct { ChildNodes []Node } -func parseEmptyDecl(line string) *EmptyDecl { +func parseEmptyDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> ( (?P.*))?`, line, ) + if groups == nil { + return &Unknown{} + } return &EmptyDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/enum.go b/ast/enum.go index 0d5c965..af6c99f 100644 --- a/ast/enum.go +++ b/ast/enum.go @@ -7,11 +7,14 @@ type Enum struct { ChildNodes []Node } -func parseEnum(line string) *Enum { +func parseEnum(line string) Node { groups := groupsFromRegex( "'(?P.*?)'", line, ) + if groups == nil { + return &Unknown{} + } return &Enum{ Addr: ParseAddress(groups["address"]), diff --git a/ast/enum_constant_decl.go b/ast/enum_constant_decl.go index 74eede2..edcbe4a 100644 --- a/ast/enum_constant_decl.go +++ b/ast/enum_constant_decl.go @@ -16,7 +16,7 @@ type EnumConstantDecl struct { ChildNodes []Node } -func parseEnumConstantDecl(line string) *EnumConstantDecl { +func parseEnumConstantDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> ( (?P[^ ]+))? @@ -26,6 +26,9 @@ func parseEnumConstantDecl(line string) *EnumConstantDecl { (?P:'.*?')?`, line, ) + if groups == nil { + return &Unknown{} + } /*type2 := groups["type2"] if type2 != "" { diff --git a/ast/enum_decl.go b/ast/enum_decl.go index adfdc94..35e9f7b 100644 --- a/ast/enum_decl.go +++ b/ast/enum_decl.go @@ -15,7 +15,7 @@ type EnumDecl struct { ChildNodes []Node } -func parseEnumDecl(line string) *EnumDecl { +func parseEnumDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P.*)> @@ -25,6 +25,9 @@ func parseEnumDecl(line string) *EnumDecl { (?P:'.*')?`, line, ) + if groups == nil { + return &Unknown{} + } /*type2 := groups["type2"] if type2 != "" { diff --git a/ast/enum_extensibility_attr.go b/ast/enum_extensibility_attr.go new file mode 100644 index 0000000..f3bf17d --- /dev/null +++ b/ast/enum_extensibility_attr.go @@ -0,0 +1,49 @@ +package ast + +// EnumExtensibilityAttr +type EnumExtensibilityAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseEnumExtensibilityAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &EnumExtensibilityAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *EnumExtensibilityAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *EnumExtensibilityAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *EnumExtensibilityAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *EnumExtensibilityAttr) Position() Position { + return n.Pos +} diff --git a/ast/enum_type.go b/ast/enum_type.go index e21fb7e..6c22ed3 100644 --- a/ast/enum_type.go +++ b/ast/enum_type.go @@ -7,11 +7,14 @@ type EnumType struct { ChildNodes []Node } -func parseEnumType(line string) *EnumType { +func parseEnumType(line string) Node { groups := groupsFromRegex( "'(?P.*?)'", line, ) + if groups == nil { + return &Unknown{} + } return &EnumType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/field.go b/ast/field.go index 8630d1f..04d9ef4 100644 --- a/ast/field.go +++ b/ast/field.go @@ -8,11 +8,14 @@ type Field struct { ChildNodes []Node } -func parseField(line string) *Field { +func parseField(line string) Node { groups := groupsFromRegex( `'(?P.*?)' '(?P.*?)'`, line, ) + if groups == nil { + return &Unknown{} + } return &Field{ Addr: ParseAddress(groups["address"]), diff --git a/ast/field_decl.go b/ast/field_decl.go index 0c28334..fb5049d 100644 --- a/ast/field_decl.go +++ b/ast/field_decl.go @@ -17,7 +17,7 @@ type FieldDecl struct { ChildNodes []Node } -func parseFieldDecl(line string) *FieldDecl { +func parseFieldDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P col:\d+| line:\d+:\d+)? @@ -29,6 +29,9 @@ func parseFieldDecl(line string) *FieldDecl { `, line, ) + if groups == nil { + return &Unknown{} + } return &FieldDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/flag_enum_attr.go b/ast/flag_enum_attr.go new file mode 100644 index 0000000..5616cc6 --- /dev/null +++ b/ast/flag_enum_attr.go @@ -0,0 +1,49 @@ +package ast + +// FlagEnumAttr +type FlagEnumAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseFlagEnumAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &FlagEnumAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *FlagEnumAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *FlagEnumAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *FlagEnumAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *FlagEnumAttr) Position() Position { + return n.Pos +} diff --git a/ast/floating_literal.go b/ast/floating_literal.go index a90b1ef..b2db39a 100644 --- a/ast/floating_literal.go +++ b/ast/floating_literal.go @@ -17,11 +17,14 @@ type FloatingLiteral struct { ChildNodes []Node } -func parseFloatingLiteral(line string) *FloatingLiteral { +func parseFloatingLiteral(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)' (?P.+)", line, ) + if groups == nil { + return &Unknown{} + } return &FloatingLiteral{ Addr: ParseAddress(groups["address"]), diff --git a/ast/for_stmt.go b/ast/for_stmt.go index f5f6ea4..f362e6e 100644 --- a/ast/for_stmt.go +++ b/ast/for_stmt.go @@ -7,11 +7,14 @@ type ForStmt struct { ChildNodes []Node } -func parseForStmt(line string) *ForStmt { +func parseForStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &ForStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/format_arg_attr.go b/ast/format_arg_attr.go index fd62282..44df8ea 100644 --- a/ast/format_arg_attr.go +++ b/ast/format_arg_attr.go @@ -9,12 +9,15 @@ type FormatArgAttr struct { ChildNodes []Node } -func parseFormatArgAttr(line string) *FormatArgAttr { +func parseFormatArgAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> *(?P\d+)`, line, ) + if groups == nil { + return &Unknown{} + } return &FormatArgAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/format_attr.go b/ast/format_attr.go index b56a48c..8638a2d 100644 --- a/ast/format_attr.go +++ b/ast/format_attr.go @@ -17,7 +17,7 @@ type FormatAttr struct { ChildNodes []Node } -func parseFormatAttr(line string) *FormatAttr { +func parseFormatAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Implicit)? @@ -27,6 +27,9 @@ func parseFormatAttr(line string) *FormatAttr { (?P\d+)`, line, ) + if groups == nil { + return &Unknown{} + } return &FormatAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/full_comment.go b/ast/full_comment.go index fcbaa8b..ff6b98c 100644 --- a/ast/full_comment.go +++ b/ast/full_comment.go @@ -7,11 +7,14 @@ type FullComment struct { ChildNodes []Node } -func parseFullComment(line string) *FullComment { +func parseFullComment(line string) Node { groups := groupsFromRegex( `<(?P.*)>`, line, ) + if groups == nil { + return &Unknown{} + } return &FullComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/function_decl.go b/ast/function_decl.go index c99727f..dffb858 100644 --- a/ast/function_decl.go +++ b/ast/function_decl.go @@ -23,7 +23,7 @@ type FunctionDecl struct { ChildNodes []Node } -func parseFunctionDecl(line string) *FunctionDecl { +func parseFunctionDecl(line string) Node { groups := groupsFromRegex( `(?:parent (?P0x[0-9a-f]+) )? (?:prev (?P0x[0-9a-f]+) )? @@ -41,6 +41,9 @@ func parseFunctionDecl(line string) *FunctionDecl { `, line, ) + if groups == nil { + return &Unknown{} + } return &FunctionDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/function_proto_type.go b/ast/function_proto_type.go index b84abd7..0216dcb 100644 --- a/ast/function_proto_type.go +++ b/ast/function_proto_type.go @@ -8,11 +8,14 @@ type FunctionProtoType struct { ChildNodes []Node } -func parseFunctionProtoType(line string) *FunctionProtoType { +func parseFunctionProtoType(line string) Node { groups := groupsFromRegex( "'(?P.*?)' (?P.*)", line, ) + if groups == nil { + return &Unknown{} + } return &FunctionProtoType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/gcc_asm_stmt.go b/ast/gcc_asm_stmt.go index c5d4a6f..6880652 100644 --- a/ast/gcc_asm_stmt.go +++ b/ast/gcc_asm_stmt.go @@ -7,11 +7,14 @@ type GCCAsmStmt struct { ChildNodes []Node } -func parseGCCAsmStmt(line string) *GCCAsmStmt { +func parseGCCAsmStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &GCCAsmStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/go_stmt.go b/ast/go_stmt.go index f96dea2..2120115 100644 --- a/ast/go_stmt.go +++ b/ast/go_stmt.go @@ -9,11 +9,14 @@ type GotoStmt struct { ChildNodes []Node } -func parseGotoStmt(line string) *GotoStmt { +func parseGotoStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)' (?P.*)", line, ) + if groups == nil { + return &Unknown{} + } return &GotoStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/html_end_tag_comment.go b/ast/html_end_tag_comment.go index d29235e..bf7dfe9 100644 --- a/ast/html_end_tag_comment.go +++ b/ast/html_end_tag_comment.go @@ -8,11 +8,14 @@ type HTMLEndTagComment struct { ChildNodes []Node } -func parseHTMLEndTagComment(line string) *HTMLEndTagComment { +func parseHTMLEndTagComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Name="(?P.*)"`, line, ) + if groups == nil { + return &Unknown{} + } return &HTMLEndTagComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/html_start_tag_comment.go b/ast/html_start_tag_comment.go index 0590e94..02583a9 100644 --- a/ast/html_start_tag_comment.go +++ b/ast/html_start_tag_comment.go @@ -8,11 +8,14 @@ type HTMLStartTagComment struct { ChildNodes []Node } -func parseHTMLStartTagComment(line string) *HTMLStartTagComment { +func parseHTMLStartTagComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Name="(?P.*)"`, line, ) + if groups == nil { + return &Unknown{} + } return &HTMLStartTagComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/ib_action_attr.go b/ast/ib_action_attr.go new file mode 100644 index 0000000..1cb68ea --- /dev/null +++ b/ast/ib_action_attr.go @@ -0,0 +1,47 @@ +package ast + +// IBActionAttr +type IBActionAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseIBActionAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &IBActionAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *IBActionAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *IBActionAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *IBActionAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *IBActionAttr) Position() Position { + return n.Pos +} diff --git a/ast/ib_outlet_attr.go b/ast/ib_outlet_attr.go new file mode 100644 index 0000000..6dd5b36 --- /dev/null +++ b/ast/ib_outlet_attr.go @@ -0,0 +1,47 @@ +package ast + +// IBOutletAttr +type IBOutletAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseIBOutletAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &IBOutletAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *IBOutletAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *IBOutletAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *IBOutletAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *IBOutletAttr) Position() Position { + return n.Pos +} diff --git a/ast/if_stmt.go b/ast/if_stmt.go index 38f2120..c400da0 100644 --- a/ast/if_stmt.go +++ b/ast/if_stmt.go @@ -7,11 +7,14 @@ type IfStmt struct { ChildNodes []Node } -func parseIfStmt(line string) *IfStmt { +func parseIfStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &IfStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/implicit_cast_expr.go b/ast/implicit_cast_expr.go index f6d6fc1..f2324d2 100644 --- a/ast/implicit_cast_expr.go +++ b/ast/implicit_cast_expr.go @@ -13,7 +13,7 @@ type ImplicitCastExpr struct { // ImplicitCastExprArrayToPointerDecay - constant const ImplicitCastExprArrayToPointerDecay = "ArrayToPointerDecay" -func parseImplicitCastExpr(line string) *ImplicitCastExpr { +func parseImplicitCastExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)' @@ -22,6 +22,9 @@ func parseImplicitCastExpr(line string) *ImplicitCastExpr { ( part_of_explicit_cast)?`, line, ) + if groups == nil { + return &Unknown{} + } return &ImplicitCastExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/implicit_value_init_expr.go b/ast/implicit_value_init_expr.go index abe3e7e..400a3e9 100644 --- a/ast/implicit_value_init_expr.go +++ b/ast/implicit_value_init_expr.go @@ -9,11 +9,14 @@ type ImplicitValueInitExpr struct { ChildNodes []Node } -func parseImplicitValueInitExpr(line string) *ImplicitValueInitExpr { +func parseImplicitValueInitExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)'(:'(?P.*)')?", line, ) + if groups == nil { + return &Unknown{} + } return &ImplicitValueInitExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/incomplete_array_type.go b/ast/incomplete_array_type.go index 7cbbb7a..6a0fc8c 100644 --- a/ast/incomplete_array_type.go +++ b/ast/incomplete_array_type.go @@ -7,11 +7,14 @@ type IncompleteArrayType struct { ChildNodes []Node } -func parseIncompleteArrayType(line string) *IncompleteArrayType { +func parseIncompleteArrayType(line string) Node { groups := groupsFromRegex( "'(?P.*)' ", line, ) + if groups == nil { + return &Unknown{} + } return &IncompleteArrayType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/indirect_field_decl.go b/ast/indirect_field_decl.go index 5dc03a3..ada387d 100644 --- a/ast/indirect_field_decl.go +++ b/ast/indirect_field_decl.go @@ -13,7 +13,7 @@ type IndirectFieldDecl struct { ChildNodes []Node } -func parseIndirectFieldDecl(line string) *IndirectFieldDecl { +func parseIndirectFieldDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P [^ ]+:[\d:]+)? @@ -22,6 +22,9 @@ func parseIndirectFieldDecl(line string) *IndirectFieldDecl { '(?P.+?)'`, line, ) + if groups == nil { + return &Unknown{} + } return &IndirectFieldDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/init_list_expr.go b/ast/init_list_expr.go index 7ad116a..44a04e4 100644 --- a/ast/init_list_expr.go +++ b/ast/init_list_expr.go @@ -9,11 +9,14 @@ type InitListExpr struct { ChildNodes []Node } -func parseInitListExpr(line string) *InitListExpr { +func parseInitListExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)'(:'(?P.*)')?", line, ) + if groups == nil { + return &Unknown{} + } return &InitListExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/inline_command_comment.go b/ast/inline_command_comment.go index 6cdd2e0..b99c4c4 100644 --- a/ast/inline_command_comment.go +++ b/ast/inline_command_comment.go @@ -8,11 +8,14 @@ type InlineCommandComment struct { ChildNodes []Node } -func parseInlineCommandComment(line string) *InlineCommandComment { +func parseInlineCommandComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P.*)`, line, ) + if groups == nil { + return &Unknown{} + } return &InlineCommandComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/integer_literal.go b/ast/integer_literal.go index 0f22abd..1d57727 100644 --- a/ast/integer_literal.go +++ b/ast/integer_literal.go @@ -9,11 +9,14 @@ type IntegerLiteral struct { ChildNodes []Node } -func parseIntegerLiteral(line string) *IntegerLiteral { +func parseIntegerLiteral(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*?)' (?P\\d+)", line, ) + if groups == nil { + return &Unknown{} + } return &IntegerLiteral{ Addr: ParseAddress(groups["address"]), diff --git a/ast/label_stmt.go b/ast/label_stmt.go index 58fb88f..de5ae51 100644 --- a/ast/label_stmt.go +++ b/ast/label_stmt.go @@ -8,11 +8,14 @@ type LabelStmt struct { ChildNodes []Node } -func parseLabelStmt(line string) *LabelStmt { +func parseLabelStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &LabelStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/malloc_attr.go b/ast/malloc_attr.go index c38cc4f..09b5de2 100644 --- a/ast/malloc_attr.go +++ b/ast/malloc_attr.go @@ -8,11 +8,14 @@ type MallocAttr struct { ChildNodes []Node } -func parseMallocAttr(line string) *MallocAttr { +func parseMallocAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &MallocAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/max_field_alignment_attr.go b/ast/max_field_alignment_attr.go index 0b89f25..89aeebd 100644 --- a/ast/max_field_alignment_attr.go +++ b/ast/max_field_alignment_attr.go @@ -11,11 +11,14 @@ type MaxFieldAlignmentAttr struct { ChildNodes []Node } -func parseMaxFieldAlignmentAttr(line string) *MaxFieldAlignmentAttr { +func parseMaxFieldAlignmentAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> Implicit (?P\d*)`, line, ) + if groups == nil { + return &Unknown{} + } return &MaxFieldAlignmentAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/may_alias_attr.go b/ast/may_alias_attr.go new file mode 100644 index 0000000..dee6f9a --- /dev/null +++ b/ast/may_alias_attr.go @@ -0,0 +1,47 @@ +package ast + +// MayAliasAttr +type MayAliasAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseMayAliasAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &MayAliasAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *MayAliasAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *MayAliasAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *MayAliasAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *MayAliasAttr) Position() Position { + return n.Pos +} diff --git a/ast/member_expr.go b/ast/member_expr.go index 34506d1..83875e3 100644 --- a/ast/member_expr.go +++ b/ast/member_expr.go @@ -14,7 +14,7 @@ type MemberExpr struct { ChildNodes []Node } -func parseMemberExpr(line string) *MemberExpr { +func parseMemberExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)' @@ -26,6 +26,9 @@ func parseMemberExpr(line string) *MemberExpr { (?P[0-9a-fx]+)`, line, ) + if groups == nil { + return &Unknown{} + } type2 := groups["type2"] if type2 != "" { diff --git a/ast/min_vector_width_attr.go b/ast/min_vector_width_attr.go new file mode 100644 index 0000000..1332f30 --- /dev/null +++ b/ast/min_vector_width_attr.go @@ -0,0 +1,49 @@ +package ast + +// MinVectorWidthAttr +type MinVectorWidthAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseMinVectorWidthAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &MinVectorWidthAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *MinVectorWidthAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *MinVectorWidthAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *MinVectorWidthAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *MinVectorWidthAttr) Position() Position { + return n.Pos +} diff --git a/ast/mode_attr.go b/ast/mode_attr.go index d41469d..6642908 100644 --- a/ast/mode_attr.go +++ b/ast/mode_attr.go @@ -9,11 +9,14 @@ type ModeAttr struct { ChildNodes []Node } -func parseModeAttr(line string) *ModeAttr { +func parseModeAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)> (?P.+)", line, ) + if groups == nil { + return &Unknown{} + } return &ModeAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/no_debug_attr.go b/ast/no_debug_attr.go new file mode 100644 index 0000000..b4e05a3 --- /dev/null +++ b/ast/no_debug_attr.go @@ -0,0 +1,47 @@ +package ast + +// NoDebugAttr +type NoDebugAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseNoDebugAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NoDebugAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NoDebugAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NoDebugAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NoDebugAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NoDebugAttr) Position() Position { + return n.Pos +} diff --git a/ast/no_escape_attr.go b/ast/no_escape_attr.go new file mode 100644 index 0000000..a3ee461 --- /dev/null +++ b/ast/no_escape_attr.go @@ -0,0 +1,47 @@ +package ast + +// NoEscapeAttr +type NoEscapeAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseNoEscapeAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NoEscapeAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NoEscapeAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NoEscapeAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NoEscapeAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NoEscapeAttr) Position() Position { + return n.Pos +} diff --git a/ast/no_inline_attr.go b/ast/no_inline_attr.go index 936dc55..b75cee6 100644 --- a/ast/no_inline_attr.go +++ b/ast/no_inline_attr.go @@ -8,11 +8,14 @@ type NoInlineAttr struct { ChildNodes []Node } -func parseNoInlineAttr(line string) *NoInlineAttr { +func parseNoInlineAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &NoInlineAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/no_throw_attr.go b/ast/no_throw_attr.go index 6222c0d..546cfd3 100644 --- a/ast/no_throw_attr.go +++ b/ast/no_throw_attr.go @@ -10,7 +10,7 @@ type NoThrowAttr struct { Inherited bool } -func parseNoThrowAttr(line string) *NoThrowAttr { +func parseNoThrowAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? @@ -18,6 +18,9 @@ func parseNoThrowAttr(line string) *NoThrowAttr { `, line, ) + if groups == nil { + return &Unknown{} + } return &NoThrowAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/non_null_attr.go b/ast/non_null_attr.go index a81b066..202c28f 100644 --- a/ast/non_null_attr.go +++ b/ast/non_null_attr.go @@ -19,13 +19,16 @@ type NonNullAttr struct { ChildNodes []Node } -func parseNonNullAttr(line string) *NonNullAttr { +func parseNonNullAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? (?P \d+)?(?P \d+)?(?P \d+)?(?P \d+)?`, line, ) + if groups == nil { + return &Unknown{} + } a := 0 if groups["a"] != "" { diff --git a/ast/not_tail_called_attr.go b/ast/not_tail_called_attr.go index 1829c32..63d7730 100644 --- a/ast/not_tail_called_attr.go +++ b/ast/not_tail_called_attr.go @@ -8,11 +8,14 @@ type NotTailCalledAttr struct { ChildNodes []Node } -func parseNotTailCalledAttr(line string) *NotTailCalledAttr { +func parseNotTailCalledAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &NotTailCalledAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/ns_consumed_attr.go b/ast/ns_consumed_attr.go new file mode 100644 index 0000000..54d84e8 --- /dev/null +++ b/ast/ns_consumed_attr.go @@ -0,0 +1,49 @@ +package ast + +// NSConsumedAttr +type NSConsumedAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseNSConsumedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NSConsumedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NSConsumedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NSConsumedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NSConsumedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NSConsumedAttr) Position() Position { + return n.Pos +} diff --git a/ast/ns_consumes_self_attr.go b/ast/ns_consumes_self_attr.go new file mode 100644 index 0000000..ea7d007 --- /dev/null +++ b/ast/ns_consumes_self_attr.go @@ -0,0 +1,47 @@ +package ast + +// NSConsumesSelfAttr +type NSConsumesSelfAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseNSConsumesSelfAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NSConsumesSelfAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NSConsumesSelfAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NSConsumesSelfAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NSConsumesSelfAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NSConsumesSelfAttr) Position() Position { + return n.Pos +} diff --git a/ast/ns_error_domain_attr.go b/ast/ns_error_domain_attr.go new file mode 100644 index 0000000..695b564 --- /dev/null +++ b/ast/ns_error_domain_attr.go @@ -0,0 +1,49 @@ +package ast + +// NSErrorDomainAttr +type NSErrorDomainAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseNSErrorDomainAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NSErrorDomainAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NSErrorDomainAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NSErrorDomainAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NSErrorDomainAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NSErrorDomainAttr) Position() Position { + return n.Pos +} diff --git a/ast/ns_returns_retained_attr.go b/ast/ns_returns_retained_attr.go new file mode 100644 index 0000000..0b3eca4 --- /dev/null +++ b/ast/ns_returns_retained_attr.go @@ -0,0 +1,47 @@ +package ast + +// NSReturnsRetainedAttr +type NSReturnsRetainedAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseNSReturnsRetainedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &NSReturnsRetainedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NSReturnsRetainedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *NSReturnsRetainedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *NSReturnsRetainedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NSReturnsRetainedAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_bool_literal_expr.go b/ast/objc_bool_literal_expr.go new file mode 100644 index 0000000..662c34d --- /dev/null +++ b/ast/objc_bool_literal_expr.go @@ -0,0 +1,56 @@ +package ast + +// ObjCBoolLiteralExpr +type ObjCBoolLiteralExpr struct { + Addr Address + Pos Position + Type string + Type2 string + Attr string + ChildNodes []Node +} + +func parseObjCBoolLiteralExpr(line string) Node { + groups := groupsFromRegex( + `<(?P|.*?)> + (?P '.*?')? + (?P:'.*?')? + (?P.*)`, + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCBoolLiteralExpr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Type: removeQuotes(groups["type"]), + Type2: groups["type2"], + Attr: groups["attr"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCBoolLiteralExpr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCBoolLiteralExpr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCBoolLiteralExpr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCBoolLiteralExpr) Position() Position { + return n.Pos +} diff --git a/ast/objc_boxable_attr.go b/ast/objc_boxable_attr.go new file mode 100644 index 0000000..7a9fd18 --- /dev/null +++ b/ast/objc_boxable_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCBoxableAttr +type ObjCBoxableAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCBoxableAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCBoxableAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCBoxableAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCBoxableAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCBoxableAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCBoxableAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_bridge_attr.go b/ast/objc_bridge_attr.go new file mode 100644 index 0000000..0452396 --- /dev/null +++ b/ast/objc_bridge_attr.go @@ -0,0 +1,49 @@ +package ast + +// ObjCBridgeAttr +type ObjCBridgeAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseObjCBridgeAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCBridgeAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCBridgeAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCBridgeAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCBridgeAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCBridgeAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_bridge_mutable_attr.go b/ast/objc_bridge_mutable_attr.go new file mode 100644 index 0000000..2154b6a --- /dev/null +++ b/ast/objc_bridge_mutable_attr.go @@ -0,0 +1,49 @@ +package ast + +// ObjCBridgeMutableAttr +type ObjCBridgeMutableAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseObjCBridgeMutableAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCBridgeMutableAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCBridgeMutableAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCBridgeMutableAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCBridgeMutableAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCBridgeMutableAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_bridge_related_attr.go b/ast/objc_bridge_related_attr.go new file mode 100644 index 0000000..b6b0e67 --- /dev/null +++ b/ast/objc_bridge_related_attr.go @@ -0,0 +1,49 @@ +package ast + +// ObjCBridgeRelatedAttr +type ObjCBridgeRelatedAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseObjCBridgeRelatedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCBridgeRelatedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCBridgeRelatedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCBridgeRelatedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCBridgeRelatedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCBridgeRelatedAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_category_decl.go b/ast/objc_category_decl.go index cff80bf..7f1011f 100644 --- a/ast/objc_category_decl.go +++ b/ast/objc_category_decl.go @@ -14,7 +14,7 @@ type ObjCCategoryDecl struct { ChildNodes []Node } -func parseObjCCategoryDecl(line string) *ObjCCategoryDecl { +func parseObjCCategoryDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P|.*)> @@ -22,6 +22,9 @@ func parseObjCCategoryDecl(line string) *ObjCCategoryDecl { (?P \w+)?`, line, ) + if groups == nil { + return &Unknown{} + } return &ObjCCategoryDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_designated_initializer_attr.go b/ast/objc_designated_initializer_attr.go new file mode 100644 index 0000000..75085fc --- /dev/null +++ b/ast/objc_designated_initializer_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCDesignatedInitializerAttr +type ObjCDesignatedInitializerAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCDesignatedInitializerAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCDesignatedInitializerAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCDesignatedInitializerAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCDesignatedInitializerAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCDesignatedInitializerAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCDesignatedInitializerAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_exception_attr.go b/ast/objc_exception_attr.go new file mode 100644 index 0000000..a987d29 --- /dev/null +++ b/ast/objc_exception_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCExceptionAttr +type ObjCExceptionAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCExceptionAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCExceptionAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCExceptionAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCExceptionAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCExceptionAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCExceptionAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_explicit_protocol_impl_attr.go b/ast/objc_explicit_protocol_impl_attr.go new file mode 100644 index 0000000..4385bae --- /dev/null +++ b/ast/objc_explicit_protocol_impl_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCExplicitProtocolImplAttr +type ObjCExplicitProtocolImplAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCExplicitProtocolImplAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCExplicitProtocolImplAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCExplicitProtocolImplAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCExplicitProtocolImplAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCExplicitProtocolImplAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCExplicitProtocolImplAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_independent_class_attr.go b/ast/objc_independent_class_attr.go new file mode 100644 index 0000000..ea682d8 --- /dev/null +++ b/ast/objc_independent_class_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCIndependentClassAttr +type ObjCIndependentClassAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCIndependentClassAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCIndependentClassAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCIndependentClassAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCIndependentClassAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCIndependentClassAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCIndependentClassAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_interface.go b/ast/objc_interface.go index 57a69a8..906e564 100644 --- a/ast/objc_interface.go +++ b/ast/objc_interface.go @@ -8,11 +8,14 @@ type ObjCInterface struct { ChildNodes []Node } -func parseObjCInterface(line string, super bool) *ObjCInterface { +func parseObjCInterface(line string, super bool) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCInterface{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_interface_decl.go b/ast/objc_interface_decl.go index 5999fda..540827d 100644 --- a/ast/objc_interface_decl.go +++ b/ast/objc_interface_decl.go @@ -5,7 +5,7 @@ import ( "strings" ) -// ObjCInterfaceDecl is node represents a typedef declaration. +// ObjCInterfaceDecl type ObjCInterfaceDecl struct { Addr Address Pos Position @@ -15,7 +15,7 @@ type ObjCInterfaceDecl struct { ChildNodes []Node } -func parseObjCInterfaceDecl(line string) *ObjCInterfaceDecl { +func parseObjCInterfaceDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P|.*)> @@ -24,6 +24,9 @@ func parseObjCInterfaceDecl(line string) *ObjCInterfaceDecl { (?P \w+)?`, line, ) + if groups == nil { + return &Unknown{} + } return &ObjCInterfaceDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_interface_type.go b/ast/objc_interface_type.go index 669406a..04f901d 100644 --- a/ast/objc_interface_type.go +++ b/ast/objc_interface_type.go @@ -7,11 +7,14 @@ type ObjCInterfaceType struct { ChildNodes []Node } -func parseObjCInterfaceType(line string) *ObjCInterfaceType { +func parseObjCInterfaceType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCInterfaceType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_ivar_decl.go b/ast/objc_ivar_decl.go new file mode 100644 index 0000000..28ddc2a --- /dev/null +++ b/ast/objc_ivar_decl.go @@ -0,0 +1,66 @@ +package ast + +import ( + "strings" +) + +// ObjCIvarDecl is node represents an Objective-C property declaration +type ObjCIvarDecl struct { + Addr Address + Pos Position + Position2 string + Name string + Type string + Type2 string + Attr string + ChildNodes []Node +} + +func parseObjCIvarDecl(line string) Node { + groups := groupsFromRegex( + `<(?P.*)> + (?P col:\d+)? + (?P.*?) + '(?P[^']*?)' + (:'(?P.*?)')? + (?P .*)?`, + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCIvarDecl{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Position2: strings.TrimSpace(groups["position2"]), + Name: strings.TrimSpace(groups["name"]), + Type: groups["type"], + //Type2: strings.TrimSpace(groups["type2"]), + Attr: strings.TrimSpace(groups["attr"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCIvarDecl) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCIvarDecl) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCIvarDecl) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCIvarDecl) Position() Position { + return n.Pos +} diff --git a/ast/objc_message_expr.go b/ast/objc_message_expr.go new file mode 100644 index 0000000..7a6da7d --- /dev/null +++ b/ast/objc_message_expr.go @@ -0,0 +1,49 @@ +package ast + +// ObjCMessageExpr +type ObjCMessageExpr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseObjCMessageExpr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCMessageExpr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCMessageExpr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCMessageExpr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCMessageExpr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCMessageExpr) Position() Position { + return n.Pos +} diff --git a/ast/objc_method.go b/ast/objc_method.go index 74d79ac..36e0d97 100644 --- a/ast/objc_method.go +++ b/ast/objc_method.go @@ -7,11 +7,14 @@ type ObjCMethod struct { ChildNodes []Node } -func parseObjCMethod(line string) *ObjCMethod { +func parseObjCMethod(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCMethod{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_method_decl.go b/ast/objc_method_decl.go index 42e2e7a..ed31b60 100644 --- a/ast/objc_method_decl.go +++ b/ast/objc_method_decl.go @@ -19,7 +19,7 @@ type ObjCMethodDecl struct { ChildNodes []Node } -func parseObjCMethodDecl(line string) *ObjCMethodDecl { +func parseObjCMethodDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P.*.*?|.*.*?|.*|.*?)> @@ -32,6 +32,10 @@ func parseObjCMethodDecl(line string) *ObjCMethodDecl { (?P .*)?`, line, ) + if groups == nil { + return &Unknown{} + } + names := strings.TrimSpace(groups["names"]) parts := strings.Split(strings.TrimSpace(groups["names"]),":") params := []string{} diff --git a/ast/objc_object_pointer_type.go b/ast/objc_object_pointer_type.go index 0607928..a217fd2 100644 --- a/ast/objc_object_pointer_type.go +++ b/ast/objc_object_pointer_type.go @@ -7,11 +7,14 @@ type ObjCObjectPointerType struct { ChildNodes []Node } -func parseObjCObjectPointerType(line string) *ObjCObjectPointerType { +func parseObjCObjectPointerType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCObjectPointerType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_object_type.go b/ast/objc_object_type.go index 3ec9c83..521792c 100644 --- a/ast/objc_object_type.go +++ b/ast/objc_object_type.go @@ -7,11 +7,14 @@ type ObjCObjectType struct { ChildNodes []Node } -func parseObjCObjectType(line string) *ObjCObjectType { +func parseObjCObjectType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCObjectType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_property_decl.go b/ast/objc_property_decl.go index 05c925d..964af5e 100644 --- a/ast/objc_property_decl.go +++ b/ast/objc_property_decl.go @@ -16,7 +16,7 @@ type ObjCPropertyDecl struct { ChildNodes []Node } -func parseObjCPropertyDecl(line string) *ObjCPropertyDecl { +func parseObjCPropertyDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P.*.*?|.*.*?|.*|.*?)> @@ -27,6 +27,9 @@ func parseObjCPropertyDecl(line string) *ObjCPropertyDecl { (?P .*)?`, line, ) + if groups == nil { + return &Unknown{} + } return &ObjCPropertyDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_protocol.go b/ast/objc_protocol.go index 05119e5..d848800 100644 --- a/ast/objc_protocol.go +++ b/ast/objc_protocol.go @@ -7,11 +7,14 @@ type ObjCProtocol struct { ChildNodes []Node } -func parseObjCProtocol(line string) *ObjCProtocol { +func parseObjCProtocol(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &ObjCProtocol{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_protocol_decl.go b/ast/objc_protocol_decl.go index 746454f..190e617 100644 --- a/ast/objc_protocol_decl.go +++ b/ast/objc_protocol_decl.go @@ -13,7 +13,7 @@ type ObjCProtocolDecl struct { ChildNodes []Node } -func parseObjCProtocolDecl(line string) *ObjCProtocolDecl { +func parseObjCProtocolDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P.*.*?|.*.*?|.*|.*?)> @@ -21,6 +21,9 @@ func parseObjCProtocolDecl(line string) *ObjCProtocolDecl { (?P.*?)`, line, ) + if groups == nil { + return &Unknown{} + } return &ObjCProtocolDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/objc_requires_super_attr.go b/ast/objc_requires_super_attr.go new file mode 100644 index 0000000..87c254c --- /dev/null +++ b/ast/objc_requires_super_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCRequiresSuperAttr +type ObjCRequiresSuperAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCRequiresSuperAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCRequiresSuperAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCRequiresSuperAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCRequiresSuperAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCRequiresSuperAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCRequiresSuperAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_returns_inner_pointer_attr.go b/ast/objc_returns_inner_pointer_attr.go new file mode 100644 index 0000000..f202dd4 --- /dev/null +++ b/ast/objc_returns_inner_pointer_attr.go @@ -0,0 +1,49 @@ +package ast + +// ObjCReturnsInnerPointerAttr +type ObjCReturnsInnerPointerAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseObjCReturnsInnerPointerAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)?", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCReturnsInnerPointerAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCReturnsInnerPointerAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCReturnsInnerPointerAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCReturnsInnerPointerAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCReturnsInnerPointerAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_root_class_attr.go b/ast/objc_root_class_attr.go new file mode 100644 index 0000000..5e35797 --- /dev/null +++ b/ast/objc_root_class_attr.go @@ -0,0 +1,47 @@ +package ast + +// ObjCRootClassAttr +type ObjCRootClassAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseObjCRootClassAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ObjCRootClassAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ObjCRootClassAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ObjCRootClassAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ObjCRootClassAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ObjCRootClassAttr) Position() Position { + return n.Pos +} diff --git a/ast/objc_type_param_decl.go b/ast/objc_type_param_decl.go index bd1412d..fa53c5a 100644 --- a/ast/objc_type_param_decl.go +++ b/ast/objc_type_param_decl.go @@ -18,7 +18,7 @@ type ObjCTypeParamDecl struct { ChildNodes []Node } -func parseObjCTypeParamDecl(line string) *ObjCTypeParamDecl { +func parseObjCTypeParamDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P [^ ]+:[\d:]+)? @@ -31,6 +31,9 @@ func parseObjCTypeParamDecl(line string) *ObjCTypeParamDecl { `, line, ) + if groups == nil { + return &Unknown{} + } /*type2 := groups["type2"] if type2 != "" { diff --git a/ast/offset_of_expr.go b/ast/offset_of_expr.go index a149369..fa4799b 100644 --- a/ast/offset_of_expr.go +++ b/ast/offset_of_expr.go @@ -8,11 +8,14 @@ type OffsetOfExpr struct { ChildNodes []Node } -func parseOffsetOfExpr(line string) *OffsetOfExpr { +func parseOffsetOfExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &OffsetOfExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/packed_attr.go b/ast/packed_attr.go index d9d8481..56b3e24 100644 --- a/ast/packed_attr.go +++ b/ast/packed_attr.go @@ -8,11 +8,14 @@ type PackedAttr struct { ChildNodes []Node } -func parsePackedAttr(line string) *PackedAttr { +func parsePackedAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &PackedAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/paragraph_comment.go b/ast/paragraph_comment.go index 4fe5c82..1d9ea54 100644 --- a/ast/paragraph_comment.go +++ b/ast/paragraph_comment.go @@ -7,11 +7,14 @@ type ParagraphComment struct { ChildNodes []Node } -func parseParagraphComment(line string) *ParagraphComment { +func parseParagraphComment(line string) Node { groups := groupsFromRegex( `<(?P.*)>`, line, ) + if groups == nil { + return &Unknown{} + } return &ParagraphComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/param_command_comment.go b/ast/param_command_comment.go index 8c2e019..8b59c68 100644 --- a/ast/param_command_comment.go +++ b/ast/param_command_comment.go @@ -8,11 +8,14 @@ type ParamCommandComment struct { ChildNodes []Node } -func parseParamCommandComment(line string) *ParamCommandComment { +func parseParamCommandComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P.*)`, line, ) + if groups == nil { + return &Unknown{} + } return &ParamCommandComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/paren_expr.go b/ast/paren_expr.go index ad46530..d4e7b79 100644 --- a/ast/paren_expr.go +++ b/ast/paren_expr.go @@ -11,7 +11,7 @@ type ParenExpr struct { ChildNodes []Node } -func parseParenExpr(line string) *ParenExpr { +func parseParenExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'(:'(?P.*)')? (?P lvalue)? @@ -19,6 +19,9 @@ func parseParenExpr(line string) *ParenExpr { `, line, ) + if groups == nil { + return &Unknown{} + } return &ParenExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/paren_type.go b/ast/paren_type.go index 4492935..927e6c7 100644 --- a/ast/paren_type.go +++ b/ast/paren_type.go @@ -8,8 +8,11 @@ type ParenType struct { ChildNodes []Node } -func parseParenType(line string) *ParenType { +func parseParenType(line string) Node { groups := groupsFromRegex(`'(?P.*?)' sugar`, line) + if groups == nil { + return &Unknown{} + } return &ParenType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/parm_var_decl.go b/ast/parm_var_decl.go index fac1a7b..66eaf65 100644 --- a/ast/parm_var_decl.go +++ b/ast/parm_var_decl.go @@ -18,7 +18,7 @@ type ParmVarDecl struct { ChildNodes []Node } -func parseParmVarDecl(line string) *ParmVarDecl { +func parseParmVarDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P [^ ]+:[\d:]+)? @@ -31,6 +31,9 @@ func parseParmVarDecl(line string) *ParmVarDecl { `, line, ) + if groups == nil { + return &Unknown{} + } /*type2 := groups["type2"] if type2 != "" { diff --git a/ast/pointer_type.go b/ast/pointer_type.go index 2c8c2e4..66cad39 100644 --- a/ast/pointer_type.go +++ b/ast/pointer_type.go @@ -7,11 +7,14 @@ type PointerType struct { ChildNodes []Node } -func parsePointerType(line string) *PointerType { +func parsePointerType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &PointerType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/predefined_expr.go b/ast/predefined_expr.go index 4499562..5ebc7fc 100644 --- a/ast/predefined_expr.go +++ b/ast/predefined_expr.go @@ -10,11 +10,14 @@ type PredefinedExpr struct { ChildNodes []Node } -func parsePredefinedExpr(line string) *PredefinedExpr { +func parsePredefinedExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)' lvalue (?P.*)", line, ) + if groups == nil { + return &Unknown{} + } return &PredefinedExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/pure_attr.go b/ast/pure_attr.go index 6b7bc57..407c7f8 100644 --- a/ast/pure_attr.go +++ b/ast/pure_attr.go @@ -10,13 +10,16 @@ type PureAttr struct { ChildNodes []Node } -func parsePureAttr(line string) *PureAttr { +func parsePureAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? (?P Implicit)?`, line, ) + if groups == nil { + return &Unknown{} + } return &PureAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/qual_type.go b/ast/qual_type.go index e53b44a..800ae83 100644 --- a/ast/qual_type.go +++ b/ast/qual_type.go @@ -8,11 +8,14 @@ type QualType struct { ChildNodes []Node } -func parseQualType(line string) *QualType { +func parseQualType(line string) Node { groups := groupsFromRegex( "'(?P.*)' (?P.*)", line, ) + if groups == nil { + return &Unknown{} + } return &QualType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/record.go b/ast/record.go index 4f29018..000ecd2 100644 --- a/ast/record.go +++ b/ast/record.go @@ -7,11 +7,14 @@ type Record struct { ChildNodes []Node } -func parseRecord(line string) *Record { +func parseRecord(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &Record{ Addr: ParseAddress(groups["address"]), diff --git a/ast/record_decl.go b/ast/record_decl.go index 8ce85ac..fd334ff 100644 --- a/ast/record_decl.go +++ b/ast/record_decl.go @@ -16,7 +16,7 @@ type RecordDecl struct { ChildNodes []Node } -func parseRecordDecl(line string) *RecordDecl { +func parseRecordDecl(line string) Node { groups := groupsFromRegex( `(?:parent (?P0x[0-9a-f]+) )? (?:prev (?P0x[0-9a-f]+) )? @@ -26,6 +26,9 @@ func parseRecordDecl(line string) *RecordDecl { (?P.*)`, line, ) + if groups == nil { + return &Unknown{} + } definition := false name := strings.TrimSpace(groups["name"]) diff --git a/ast/record_type.go b/ast/record_type.go index 41d442b..af9416e 100644 --- a/ast/record_type.go +++ b/ast/record_type.go @@ -7,11 +7,14 @@ type RecordType struct { ChildNodes []Node } -func parseRecordType(line string) *RecordType { +func parseRecordType(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &RecordType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/restrict_attr.go b/ast/restrict_attr.go index 18463f0..3c5c30b 100644 --- a/ast/restrict_attr.go +++ b/ast/restrict_attr.go @@ -9,11 +9,14 @@ type RestrictAttr struct { ChildNodes []Node } -func parseRestrictAttr(line string) *RestrictAttr { +func parseRestrictAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)> (?P.+)", line, ) + if groups == nil { + return &Unknown{} + } return &RestrictAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/return_stmt.go b/ast/return_stmt.go index da9d11b..9474329 100644 --- a/ast/return_stmt.go +++ b/ast/return_stmt.go @@ -7,11 +7,14 @@ type ReturnStmt struct { ChildNodes []Node } -func parseReturnStmt(line string) *ReturnStmt { +func parseReturnStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &ReturnStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/returns_twice_attr.go b/ast/returns_twice_attr.go index 8266440..f37cee4 100644 --- a/ast/returns_twice_attr.go +++ b/ast/returns_twice_attr.go @@ -10,7 +10,7 @@ type ReturnsTwiceAttr struct { Implicit bool } -func parseReturnsTwiceAttr(line string) *ReturnsTwiceAttr { +func parseReturnsTwiceAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? @@ -18,6 +18,9 @@ func parseReturnsTwiceAttr(line string) *ReturnsTwiceAttr { `, line, ) + if groups == nil { + return &Unknown{} + } return &ReturnsTwiceAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/sentinel_attr.go b/ast/sentinel_attr.go index b2e9b73..8016e56 100644 --- a/ast/sentinel_attr.go +++ b/ast/sentinel_attr.go @@ -16,11 +16,14 @@ type SentinelAttr struct { ChildNodes []Node } -func parseSentinelAttr(line string) *SentinelAttr { +func parseSentinelAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)>(?P \d+)(?P \d+)?`, line, ) + if groups == nil { + return &Unknown{} + } b := 0 if groups["b"] != "" { diff --git a/ast/shuffle_vector_expr.go b/ast/shuffle_vector_expr.go new file mode 100644 index 0000000..baa71f6 --- /dev/null +++ b/ast/shuffle_vector_expr.go @@ -0,0 +1,53 @@ +package ast + +// ShuffleVectorExpr +type ShuffleVectorExpr struct { + Addr Address + Pos Position + Type string + Type2 string + ChildNodes []Node +} + +func parseShuffleVectorExpr(line string) Node { + groups := groupsFromRegex( + `<(?P|.*?)> + (?P '.*?')? + (?P:'.*?')?`, + line, + ) + if groups == nil { + return &Unknown{} + } + + return &ShuffleVectorExpr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Type: removeQuotes(groups["type"]), + Type2: groups["type2"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *ShuffleVectorExpr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *ShuffleVectorExpr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *ShuffleVectorExpr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *ShuffleVectorExpr) Position() Position { + return n.Pos +} diff --git a/ast/stmt_expr.go b/ast/stmt_expr.go index 5b40a40..0cf71b9 100644 --- a/ast/stmt_expr.go +++ b/ast/stmt_expr.go @@ -8,11 +8,14 @@ type StmtExpr struct { ChildNodes []Node } -func parseStmtExpr(line string) *StmtExpr { +func parseStmtExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &StmtExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/string_literal.go b/ast/string_literal.go index 8b9eef5..e327fe8 100644 --- a/ast/string_literal.go +++ b/ast/string_literal.go @@ -15,11 +15,14 @@ type StringLiteral struct { ChildNodes []Node } -func parseStringLiteral(line string) *StringLiteral { +func parseStringLiteral(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*)' lvalue (?P".*")`, line, ) + if groups == nil { + return &Unknown{} + } s, err := strconv.Unquote(groups["value"]) if err != nil { diff --git a/ast/swift_bridged_typedef_attr.go b/ast/swift_bridged_typedef_attr.go new file mode 100644 index 0000000..5a00194 --- /dev/null +++ b/ast/swift_bridged_typedef_attr.go @@ -0,0 +1,47 @@ +package ast + +// SwiftBridgedTypedefAttr +type SwiftBridgedTypedefAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseSwiftBridgedTypedefAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &SwiftBridgedTypedefAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *SwiftBridgedTypedefAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *SwiftBridgedTypedefAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *SwiftBridgedTypedefAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *SwiftBridgedTypedefAttr) Position() Position { + return n.Pos +} diff --git a/ast/swift_error_attr.go b/ast/swift_error_attr.go new file mode 100644 index 0000000..9c67fd8 --- /dev/null +++ b/ast/swift_error_attr.go @@ -0,0 +1,49 @@ +package ast + +// SwiftErrorAttr +type SwiftErrorAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseSwiftErrorAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &SwiftErrorAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *SwiftErrorAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *SwiftErrorAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *SwiftErrorAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *SwiftErrorAttr) Position() Position { + return n.Pos +} diff --git a/ast/swift_name_attr.go b/ast/swift_name_attr.go new file mode 100644 index 0000000..81646fc --- /dev/null +++ b/ast/swift_name_attr.go @@ -0,0 +1,49 @@ +package ast + +// SwiftNameAttr +type SwiftNameAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseSwiftNameAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &SwiftNameAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *SwiftNameAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *SwiftNameAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *SwiftNameAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *SwiftNameAttr) Position() Position { + return n.Pos +} diff --git a/ast/swift_newtype_attr.go b/ast/swift_newtype_attr.go new file mode 100644 index 0000000..953b0fc --- /dev/null +++ b/ast/swift_newtype_attr.go @@ -0,0 +1,50 @@ +package ast + +// SwiftNewtypeAttr +type SwiftNewtypeAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseSwiftNewtypeAttr(line string) Node { + groups := groupsFromRegex( + `<(?P.*)> + (?P.*)`, + line, + ) + if groups == nil { + return &Unknown{} + } + + return &SwiftNewtypeAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *SwiftNewtypeAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *SwiftNewtypeAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *SwiftNewtypeAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *SwiftNewtypeAttr) Position() Position { + return n.Pos +} diff --git a/ast/swift_private_attr.go b/ast/swift_private_attr.go new file mode 100644 index 0000000..d3319cd --- /dev/null +++ b/ast/swift_private_attr.go @@ -0,0 +1,47 @@ +package ast + +// SwiftPrivateAttr +type SwiftPrivateAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseSwiftPrivateAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &SwiftPrivateAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *SwiftPrivateAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *SwiftPrivateAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *SwiftPrivateAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *SwiftPrivateAttr) Position() Position { + return n.Pos +} diff --git a/ast/switch_stmt.go b/ast/switch_stmt.go index b89ac29..819edbc 100644 --- a/ast/switch_stmt.go +++ b/ast/switch_stmt.go @@ -7,8 +7,11 @@ type SwitchStmt struct { ChildNodes []Node } -func parseSwitchStmt(line string) *SwitchStmt { +func parseSwitchStmt(line string) Node { groups := groupsFromRegex(`<(?P.*)>`, line) + if groups == nil { + return &Unknown{} + } return &SwitchStmt{ Addr: ParseAddress(groups["address"]), diff --git a/ast/target_attr.go b/ast/target_attr.go new file mode 100644 index 0000000..25b5070 --- /dev/null +++ b/ast/target_attr.go @@ -0,0 +1,49 @@ +package ast + +// TargetAttr +type TargetAttr struct { + Addr Address + Pos Position + Content string + ChildNodes []Node +} + +func parseTargetAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &TargetAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *TargetAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *TargetAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *TargetAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *TargetAttr) Position() Position { + return n.Pos +} diff --git a/ast/text_comment.go b/ast/text_comment.go index 1187946..ec33590 100644 --- a/ast/text_comment.go +++ b/ast/text_comment.go @@ -8,11 +8,14 @@ type TextComment struct { ChildNodes []Node } -func parseTextComment(line string) *TextComment { +func parseTextComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Text="(?P.*)"`, line, ) + if groups == nil { + return &Unknown{} + } return &TextComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/translation_unit_decl.go b/ast/translation_unit_decl.go index 4656327..0bccda3 100644 --- a/ast/translation_unit_decl.go +++ b/ast/translation_unit_decl.go @@ -6,8 +6,11 @@ type TranslationUnitDecl struct { ChildNodes []Node } -func parseTranslationUnitDecl(line string) *TranslationUnitDecl { +func parseTranslationUnitDecl(line string) Node { groups := groupsFromRegex("<(?P.*)> <(?P.*)>", line) + if groups == nil { + return &Unknown{} + } return &TranslationUnitDecl{ Addr: ParseAddress(groups["address"]), diff --git a/ast/transparent_union_attr.go b/ast/transparent_union_attr.go index 2a419f1..01de6eb 100644 --- a/ast/transparent_union_attr.go +++ b/ast/transparent_union_attr.go @@ -8,8 +8,11 @@ type TransparentUnionAttr struct { ChildNodes []Node } -func parseTransparentUnionAttr(line string) *TransparentUnionAttr { +func parseTransparentUnionAttr(line string) Node { groups := groupsFromRegex(`<(?P.*)>`, line) + if groups == nil { + return &Unknown{} + } return &TransparentUnionAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/typedef.go b/ast/typedef.go index 1f760ad..93cfb97 100644 --- a/ast/typedef.go +++ b/ast/typedef.go @@ -7,11 +7,14 @@ type Typedef struct { ChildNodes []Node } -func parseTypedef(line string) *Typedef { +func parseTypedef(line string) Node { groups := groupsFromRegex( "'(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &Typedef{ Addr: ParseAddress(groups["address"]), diff --git a/ast/typedef_decl.go b/ast/typedef_decl.go index 2561a1c..4dccf82 100644 --- a/ast/typedef_decl.go +++ b/ast/typedef_decl.go @@ -17,7 +17,7 @@ type TypedefDecl struct { ChildNodes []Node } -func parseTypedefDecl(line string) *TypedefDecl { +func parseTypedefDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P|.*?)> @@ -29,6 +29,9 @@ func parseTypedefDecl(line string) *TypedefDecl { (?P:'.*?')?`, line, ) + if groups == nil { + return &Unknown{} + } type2 := groups["type2"] if type2 != "" { diff --git a/ast/typedef_type.go b/ast/typedef_type.go index d8f03ec..6491e4e 100644 --- a/ast/typedef_type.go +++ b/ast/typedef_type.go @@ -8,11 +8,14 @@ type TypedefType struct { ChildNodes []Node } -func parseTypedefType(line string) *TypedefType { +func parseTypedefType(line string) Node { groups := groupsFromRegex( "'(?P.*)' (?P.+)", line, ) + if groups == nil { + return &Unknown{} + } return &TypedefType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/unary_expr_or_type_trait_expr.go b/ast/unary_expr_or_type_trait_expr.go index 15f5256..dce4462 100644 --- a/ast/unary_expr_or_type_trait_expr.go +++ b/ast/unary_expr_or_type_trait_expr.go @@ -11,7 +11,7 @@ type UnaryExprOrTypeTraitExpr struct { ChildNodes []Node } -func parseUnaryExprOrTypeTraitExpr(line string) *UnaryExprOrTypeTraitExpr { +func parseUnaryExprOrTypeTraitExpr(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.+?)' @@ -21,6 +21,9 @@ func parseUnaryExprOrTypeTraitExpr(line string) *UnaryExprOrTypeTraitExpr { `, line, ) + if groups == nil { + return &Unknown{} + } return &UnaryExprOrTypeTraitExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/unary_operator.go b/ast/unary_operator.go index 6308f27..cbc0c6d 100644 --- a/ast/unary_operator.go +++ b/ast/unary_operator.go @@ -12,7 +12,7 @@ type UnaryOperator struct { ChildNodes []Node } -func parseUnaryOperator(line string) *UnaryOperator { +func parseUnaryOperator(line string) Node { groups := groupsFromRegex( `<(?P.*)> '(?P.*?)'(:'(?P.*)')? @@ -23,6 +23,9 @@ func parseUnaryOperator(line string) *UnaryOperator { ( .*)?`, line, ) + if groups == nil { + return &Unknown{} + } return &UnaryOperator{ Addr: ParseAddress(groups["address"]), diff --git a/ast/unavailable_attr.go b/ast/unavailable_attr.go index 85c7fd4..3c46630 100644 --- a/ast/unavailable_attr.go +++ b/ast/unavailable_attr.go @@ -13,7 +13,7 @@ type UnavailableAttr struct { ChildNodes []Node } -func parseUnavailableAttr(line string) *UnavailableAttr { +func parseUnavailableAttr(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P|.*?)> @@ -21,6 +21,9 @@ func parseUnavailableAttr(line string) *UnavailableAttr { (?P.*)`, line, ) + if groups == nil { + return &Unknown{} + } return &UnavailableAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/unknown.go b/ast/unknown.go index 3e33e9b..3688e50 100644 --- a/ast/unknown.go +++ b/ast/unknown.go @@ -9,7 +9,6 @@ type Unknown struct { Name string Addr Address Pos Position - Position2 string Content string ChildNodes []Node } @@ -18,19 +17,14 @@ func parseUnknown(name, line string) *Unknown { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? <(?P.*.*?|.*.*?|.*|.*?)> - (?P | col:\d+| line:\d+:\d+)? (?P.*)`, line, ) -/* - (?P | col:\d+| line:\d+:\d+)? -*/ return &Unknown{ Name: name, Addr: ParseAddress(groups["address"]), Pos: NewPositionFromString(groups["position"]), - //Position2: strings.TrimSpace(groups["position2"]), Content: groups["content"], ChildNodes: []Node{}, } diff --git a/ast/unused_attr.go b/ast/unused_attr.go index dbf79c9..3932add 100644 --- a/ast/unused_attr.go +++ b/ast/unused_attr.go @@ -9,11 +9,14 @@ type UnusedAttr struct { IsUnused bool } -func parseUnusedAttr(line string) *UnusedAttr { +func parseUnusedAttr(line string) Node { groups := groupsFromRegex( "<(?P.*)>(?P unused)?", line, ) + if groups == nil { + return &Unknown{} + } return &UnusedAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/used_attr.go b/ast/used_attr.go new file mode 100644 index 0000000..a06d7bb --- /dev/null +++ b/ast/used_attr.go @@ -0,0 +1,47 @@ +package ast + +// UsedAttr +type UsedAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseUsedAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &UsedAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *UsedAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *UsedAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *UsedAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *UsedAttr) Position() Position { + return n.Pos +} diff --git a/ast/va_arg_expr.go b/ast/va_arg_expr.go index 7cc07da..fb9d041 100644 --- a/ast/va_arg_expr.go +++ b/ast/va_arg_expr.go @@ -8,11 +8,14 @@ type VAArgExpr struct { ChildNodes []Node } -func parseVAArgExpr(line string) *VAArgExpr { +func parseVAArgExpr(line string) Node { groups := groupsFromRegex( "<(?P.*)> '(?P.*)'", line, ) + if groups == nil { + return &Unknown{} + } return &VAArgExpr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/var_decl.go b/ast/var_decl.go index fa6011a..cb8a448 100644 --- a/ast/var_decl.go +++ b/ast/var_decl.go @@ -23,7 +23,7 @@ type VarDecl struct { ChildNodes []Node } -func parseVarDecl(line string) *VarDecl { +func parseVarDecl(line string) Node { groups := groupsFromRegex( `(?:prev (?P0x[0-9a-f]+) )? (?:parent (?P0x[0-9a-f]+) )? @@ -43,6 +43,10 @@ func parseVarDecl(line string) *VarDecl { line, ) + if groups == nil { + return &Unknown{} + } + type2 := groups["type2"] if type2 != "" { type2 = type2[2 : len(type2)-1] diff --git a/ast/vector_type.go b/ast/vector_type.go index 3b3c883..a092489 100644 --- a/ast/vector_type.go +++ b/ast/vector_type.go @@ -12,12 +12,15 @@ type VectorType struct { ChildNodes []Node } -func parseVectorType(line string) *VectorType { +func parseVectorType(line string) Node { groups := groupsFromRegex( `'(?P.*)' (?P[\d]+)`, line, ) + if groups == nil { + return &Unknown{} + } return &VectorType{ Addr: ParseAddress(groups["address"]), diff --git a/ast/verbatim_block_comment.go b/ast/verbatim_block_comment.go index a7b41a1..c0686f4 100644 --- a/ast/verbatim_block_comment.go +++ b/ast/verbatim_block_comment.go @@ -9,13 +9,16 @@ type VerbatimBlockComment struct { ChildNodes []Node } -func parseVerbatimBlockComment(line string) *VerbatimBlockComment { +func parseVerbatimBlockComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Name="(?P.*?)" CloseName="(?P.*?)"`, line, ) + if groups == nil { + return &Unknown{} + } return &VerbatimBlockComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/verbatim_block_line_comment.go b/ast/verbatim_block_line_comment.go index 72474b6..2ece548 100644 --- a/ast/verbatim_block_line_comment.go +++ b/ast/verbatim_block_line_comment.go @@ -8,11 +8,14 @@ type VerbatimBlockLineComment struct { ChildNodes []Node } -func parseVerbatimBlockLineComment(line string) *VerbatimBlockLineComment { +func parseVerbatimBlockLineComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Text="(?P.*?)"`, line, ) + if groups == nil { + return &Unknown{} + } return &VerbatimBlockLineComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/verbatim_line_comment.go b/ast/verbatim_line_comment.go index b7ebe4d..d091b53 100644 --- a/ast/verbatim_line_comment.go +++ b/ast/verbatim_line_comment.go @@ -8,11 +8,14 @@ type VerbatimLineComment struct { ChildNodes []Node } -func parseVerbatimLineComment(line string) *VerbatimLineComment { +func parseVerbatimLineComment(line string) Node { groups := groupsFromRegex( `<(?P.*)> Text="(?P.*)"`, line, ) + if groups == nil { + return &Unknown{} + } return &VerbatimLineComment{ Addr: ParseAddress(groups["address"]), diff --git a/ast/visibility_attr.go b/ast/visibility_attr.go index 7549d48..e5217a4 100644 --- a/ast/visibility_attr.go +++ b/ast/visibility_attr.go @@ -10,7 +10,7 @@ type VisibilityAttr struct { IsHidden bool } -func parseVisibilityAttr(line string) *VisibilityAttr { +func parseVisibilityAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)> (?P Inherited)? @@ -19,6 +19,9 @@ func parseVisibilityAttr(line string) *VisibilityAttr { `, line, ) + if groups == nil { + return &Unknown{} + } return &VisibilityAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/warn_unused_result_attr.go b/ast/warn_unused_result_attr.go index 8ea63b1..fcd12de 100644 --- a/ast/warn_unused_result_attr.go +++ b/ast/warn_unused_result_attr.go @@ -8,8 +8,11 @@ type WarnUnusedResultAttr struct { ChildNodes []Node } -func parseWarnUnusedResultAttr(line string) *WarnUnusedResultAttr { +func parseWarnUnusedResultAttr(line string) Node { groups := groupsFromRegex(`<(?P.*)>( warn_unused_result)?`, line) + if groups == nil { + return &Unknown{} + } return &WarnUnusedResultAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/weak_attr.go b/ast/weak_attr.go index d1c8f74..9c0863e 100644 --- a/ast/weak_attr.go +++ b/ast/weak_attr.go @@ -7,11 +7,14 @@ type WeakAttr struct { ChildNodes []Node } -func parseWeakAttr(line string) *WeakAttr { +func parseWeakAttr(line string) Node { groups := groupsFromRegex( `<(?P.*)>`, line, ) + if groups == nil { + return &Unknown{} + } return &WeakAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/weak_import_attr.go b/ast/weak_import_attr.go new file mode 100644 index 0000000..517f578 --- /dev/null +++ b/ast/weak_import_attr.go @@ -0,0 +1,47 @@ +package ast + +// WeakImportAttr +type WeakImportAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseWeakImportAttr(line string) Node { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + if groups == nil { + return &Unknown{} + } + + return &WeakImportAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *WeakImportAttr) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *WeakImportAttr) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *WeakImportAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *WeakImportAttr) Position() Position { + return n.Pos +} diff --git a/ast/while_stmt.go b/ast/while_stmt.go index 0adf0fe..6acb39d 100644 --- a/ast/while_stmt.go +++ b/ast/while_stmt.go @@ -7,11 +7,14 @@ type WhileStmt struct { ChildNodes []Node } -func parseWhileStmt(line string) *WhileStmt { +func parseWhileStmt(line string) Node { groups := groupsFromRegex( "<(?P.*)>", line, ) + if groups == nil { + return &Unknown{} + } return &WhileStmt{ Addr: ParseAddress(groups["address"]), diff --git a/main.go b/main.go index 1bc78ca..e1da232 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ type conf struct { Package string Inputfiles []string Astfile string + Debugast bool Classes []string Functions []string Enums []string @@ -49,10 +50,25 @@ type treeNode struct { node ast.Node } +func printLinesWithContext(lines []string,i int) { + b := i - 3 + if b < 0 { b = 0 } + var flag string + for x := b; (x < b + 6) && (x < len(lines)); x++ { + if x == i { + flag = "--> " + } else { + flag = " " + } + fmt.Printf("%s%s\n",flag,lines[x]) + } +} + func convertLinesToNodes(lines []string) []treeNode { nodes := make([]treeNode, len(lines)) var counter int - for _, line := range lines { + unknowns := 0 + for i, line := range lines { if strings.TrimSpace(line) == "" { continue } @@ -66,9 +82,27 @@ func convertLinesToNodes(lines []string) []treeNode { indentLevel := (len(line) - len(trimmed)) / 2 nodes[counter] = treeNode{indentLevel, node} counter++ + if !Config.Debugast { + continue + } + switch node.(type) { + case *ast.Unknown: + fmt.Printf("Unrecognized node:\n") + printLinesWithContext(lines,i) + fmt.Printf("\n") + unknowns++ + if unknowns > 5 { + fmt.Printf("nswrap failed due to unrecognized nodes.\n") + os.Exit(-1) + } + } } nodes = nodes[0:counter] + if Config.Debugast && unknowns > 0 { + fmt.Printf("\nswrap failed due to unrecognized nodes.\n") + os.Exit(-1) + } return nodes } @@ -281,12 +315,10 @@ func main() { fmt.Printf("%s\n\nFATAL ERROR: Configuration file must be present in directory where nswrap\nis invoked.\n",err) os.Exit(-1) } - if err = yaml.Unmarshal(confbytes,&Config); err != nil { + if err = yaml.UnmarshalStrict(confbytes,&Config); err != nil { 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)