Repository: Konstantin8105/c4go
Pull request #500 (2021-04-24 14:09:08)

update to clang 12


Patch:
diff --git a/.travis.yml b/.travis.yml
index aab354b..0f1da4d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,5 @@
 language: go
+dist: xenial
 
 go:
   - "1.16"
@@ -47,6 +48,8 @@ matrix:
       os: linux
     - env: SCRIPT=test CLANG=8
       os: linux
+    - env: SCRIPT=test CLANG=12
+      os: linux
 ####### lint checking ########
     - env: SCRIPT=lint CLANG=3.9
       os: linux
@@ -56,7 +59,7 @@ before_install:
       if [ "$TRAVIS_OS_NAME" = "linux" ]; then
         wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
         sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
-        sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-$CLANG main"
+        sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$CLANG main"
         sudo apt-get install lzip ## Added for scripts/ed.sh
         sudo apt-get update
         sudo apt-cache search clang
diff --git a/ast/asm_label_attr.go b/ast/asm_label_attr.go
index dea11a9..5278b22 100644
--- a/ast/asm_label_attr.go
+++ b/ast/asm_label_attr.go
@@ -2,27 +2,30 @@ package ast
 
 // AsmLabelAttr is a type of attribute for assembler label
 type AsmLabelAttr struct {
-	Addr         Address
-	Pos          Position
-	IsInherited  bool
-	FunctionName string
-	ChildNodes   []Node
+	Addr           Address
+	Pos            Position
+	IsInherited    bool
+	IsLiteralLabel bool
+	FunctionName   string
+	ChildNodes     []Node
 }
 
 func parseAsmLabelAttr(line string) *AsmLabelAttr {
 	groups := groupsFromRegex(
 		`<(?P<position>.*)>
 		(?P<inherited> Inherited)?
-		 "(?P<function>.+)"`,
+		 "(?P<function>.+)"
+		(?P<isliterallabel> IsLiteralLabel)?`,
 		line,
 	)
 
 	return &AsmLabelAttr{
-		Addr:         ParseAddress(groups["address"]),
-		Pos:          NewPositionFromString(groups["position"]),
-		IsInherited:  len(groups["inherited"]) > 0,
-		FunctionName: groups["function"],
-		ChildNodes:   []Node{},
+		Addr:           ParseAddress(groups["address"]),
+		Pos:            NewPositionFromString(groups["position"]),
+		IsInherited:    len(groups["inherited"]) > 0,
+		FunctionName:   groups["function"],
+		IsLiteralLabel: len(groups["isliterallabel"]) > 0,
+		ChildNodes:     []Node{},
 	}
 }
 
diff --git a/ast/ast.go b/ast/ast.go
index d690473..24760b3 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -80,6 +80,8 @@ func Parse(fullline string) (returnNode Node, err error) {
 		return parseAttributedType(line), nil
 	case "AvailabilityAttr":
 		return parseAvailabilityAttr(line), nil
+	case "BuiltinAttr":
+		return parseBuiltinAttr(line), nil
 	case "BinaryConditionalOperator":
 		return parseBinaryConditionalOperator(line), nil
 	case "BinaryOperator":
diff --git a/ast/availability_attr.go b/ast/availability_attr.go
index d37e0e9..4a4f24b 100644
--- a/ast/availability_attr.go
+++ b/ast/availability_attr.go
@@ -16,6 +16,7 @@ type AvailabilityAttr struct {
 	IsUnavailable bool
 	Message1      string
 	Message2      string
+	Message3      string
 	IsInherited   bool
 	ChildNodes    []Node
 }
@@ -30,7 +31,9 @@ func parseAvailabilityAttr(line string) *AvailabilityAttr {
 		 (?P<unknown2>[\d.]+)
 		(?P<unavalable> Unavailable)?
 		 "(?P<message1>.*?)"
-		(?P<message2> ".*?")?`,
+		(?P<message2> ".*?")?
+		(?P<message3> .*?)?
+		`,
 		line,
 	)
 
@@ -45,6 +48,7 @@ func parseAvailabilityAttr(line string) *AvailabilityAttr {
 		Message1:      removeQuotes(groups["message1"]),
 		Message2:      removeQuotes(groups["message2"]),
 		IsInherited:   len(groups["inherited"]) > 0,
+		Message3:      removeQuotes(groups["message3"]),
 		ChildNodes:    []Node{},
 	}
 }
diff --git a/ast/builtin_attr.go b/ast/builtin_attr.go
new file mode 100644
index 0000000..66c32dd
--- /dev/null
+++ b/ast/builtin_attr.go
@@ -0,0 +1,57 @@
+package ast
+
+import "strings"
+
+// BuiltinAttr is a type of attribute ...
+type BuiltinAttr struct {
+	Addr        Address
+	Pos         Position
+	IsImplicit  bool
+	IsInherited bool
+	Name        string
+	IsAligned   bool
+	ChildNodes  []Node
+}
+
+func parseBuiltinAttr(line string) *BuiltinAttr {
+	groups := groupsFromRegex(
+		`<(?P<position>.*)>
+		(?P<inherited> Inherited)?
+		(?P<implicit> Implicit)?
+		(?P<name> .*)?
+		`,
+		line,
+	)
+
+	return &BuiltinAttr{
+		Addr:        ParseAddress(groups["address"]),
+		Pos:         NewPositionFromString(groups["position"]),
+		IsImplicit:  len(groups["implicit"]) > 0,
+		IsInherited: len(groups["inherited"]) > 0,
+		Name:        strings.TrimSpace(groups["name"]),
+		ChildNodes:  []Node{},
+	}
+}
+
+// AddChild adds a new child node. Child nodes can then be accessed with the
+// Children attribute.
+func (n *BuiltinAttr) 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 *BuiltinAttr) 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 *BuiltinAttr) Children() []Node {
+	return n.ChildNodes
+}
+
+// Position returns the position in the original source code.
+func (n *BuiltinAttr) Position() Position {
+	return n.Pos
+}
diff --git a/ast/position.go b/ast/position.go
index 16ae010..ffd54e9 100644
--- a/ast/position.go
+++ b/ast/position.go
@@ -248,6 +248,8 @@ func setPosition(node Node, position Position) {
 		n.Pos = position
 	case *AvailabilityAttr:
 		n.Pos = position
+	case *BuiltinAttr:
+		n.Pos = position
 	case *BinaryConditionalOperator:
 		n.Pos = position
 	case *BinaryOperator:


Test patch:
diff --git a/ast/asm_label_attr_test.go b/ast/asm_label_attr_test.go
index e2b9b2a..32e31f2 100644
--- a/ast/asm_label_attr_test.go
+++ b/ast/asm_label_attr_test.go
@@ -20,6 +20,14 @@ func TestAsmLabelAttr(t *testing.T) {
 			FunctionName: "_popen",
 			ChildNodes:   []Node{},
 		},
+		`0x1271fd0 <col:42> "__xpg_sigpause" IsLiteralLabel`: &AsmLabelAttr{
+			Addr:           0x1271fd0,
+			Pos:            NewPositionFromString("col:42"),
+			IsInherited:    false,
+			FunctionName:   "__xpg_sigpause",
+			IsLiteralLabel: true,
+			ChildNodes:     []Node{},
+		},
 	}
 
 	runNodeTests(t, nodes)
diff --git a/ast/availability_attr_test.go b/ast/availability_attr_test.go
index ee37f00..4ea5b29 100644
--- a/ast/availability_attr_test.go
+++ b/ast/availability_attr_test.go
@@ -110,6 +110,34 @@ func TestAvailabilityAttr(t *testing.T) {
 			IsInherited:   true,
 			ChildNodes:    []Node{},
 		},
+		`0x7fca9c806c60 <col:243, col:278> watchos 3.0 0 0 "" "" 0`: &AvailabilityAttr{
+			Addr:          0x7fca9c806c60,
+			Pos:           NewPositionFromString("col:243, col:278"),
+			OS:            "watchos",
+			Version:       "3.0",
+			Unknown1:      0,
+			Unknown2:      0,
+			IsUnavailable: false,
+			Message1:      "",
+			Message2:      "",
+			Message3:      "0",
+			IsInherited:   false,
+			ChildNodes:    []Node{},
+		},
+		`0x7fca9c810880 <line:184:16, col:86> swift 0 0 0 Unavailable "Use mkstemp(3) instead." "" 0`: &AvailabilityAttr{
+			Addr:          0x7fca9c810880,
+			Pos:           NewPositionFromString("line:184:16, col:86"),
+			OS:            "swift",
+			Version:       "0",
+			Unknown1:      0,
+			Unknown2:      0,
+			IsUnavailable: true,
+			Message1:      "Use mkstemp(3) instead.",
+			Message2:      "",
+			Message3:      "0",
+			IsInherited:   false,
+			ChildNodes:    []Node{},
+		},
 	}
 
 	runNodeTests(t, nodes)
diff --git a/ast/builtin_attr_test.go b/ast/builtin_attr_test.go
new file mode 100644
index 0000000..4f98309
--- /dev/null
+++ b/ast/builtin_attr_test.go
@@ -0,0 +1,28 @@
+package ast
+
+import (
+	"testing"
+)
+
+func TestBuiltinAttr(t *testing.T) {
+	nodes := map[string]Node{
+		`0x22e4f60 <<invalid sloc>> Implicit 905`: &BuiltinAttr{
+			Addr:        0x22e4f60,
+			Pos:         NewPositionFromString("<invalid sloc>"),
+			IsImplicit:  true,
+			IsInherited: false,
+			Name:        "905",
+			ChildNodes:  []Node{},
+		},
+		`0x22e51c8 <<invalid sloc>> Inherited Implicit 905`: &BuiltinAttr{
+			Addr:        0x22e51c8,
+			Pos:         NewPositionFromString("<invalid sloc>"),
+			IsImplicit:  true,
+			IsInherited: true,
+			Name:        "905",
+			ChildNodes:  []Node{},
+		},
+	}
+
+	runNodeTests(t, nodes)
+}