• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

unpackdev / solgo / 6288940170

24 Sep 2023 08:15AM UTC coverage: 89.03% (+0.3%) from 88.733%
6288940170

push

github

web-flow
AST Fix - Introducing BitAndOperation, ast.ToProto(), Global Definitions (#109)

* Just base broken source code
* Adding support for BitAndOperation
* Papa test data update
* Adding support for magic transaction and origin
* Fixing ToProto() in AST
* Introducing ast global declarations
* Proto bump + proto global nodes

180 of 197 new or added lines in 13 files covered. (91.37%)

1 existing line in 1 file now uncovered.

11816 of 13272 relevant lines covered (89.03%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.32
/ast/root_node.go
1
package ast
2

3
import (
4
        v3 "github.com/cncf/xds/go/xds/type/v3"
5
        ast_pb "github.com/unpackdev/protos/dist/go/ast"
6
)
7

8
// RootNode is the root node of the AST.
9
type RootNode struct {
10
        // Id is the unique identifier of the root node.
11
        Id int64 `json:"id"`
12

13
        // NodeType is the type of the AST node.
14
        NodeType ast_pb.NodeType `json:"node_type"`
15

16
        // EntrySourceUnit is the entry source unit of the root node.
17
        EntrySourceUnit int64 `json:"entry_source_unit"`
18

19
        // Globals is the list of global nodes.
20
        Globals []Node[NodeType] `json:"globals"`
21

22
        // SourceUnits is the list of source units.
23
        SourceUnits []*SourceUnit[Node[ast_pb.SourceUnit]] `json:"root"`
24

25
        // Comments is the list of comments.
26
        Comments []*Comment `json:"comments"`
27
}
28

29
// NewRootNode creates a new RootNode with the provided ASTBuilder, entry source unit, source units, and comments.
30
func NewRootNode(builder *ASTBuilder, entrySourceUnit int64, sourceUnits []*SourceUnit[Node[ast_pb.SourceUnit]], comments []*Comment) *RootNode {
1✔
31
        return &RootNode{
1✔
32
                Id:              builder.GetNextID(),
1✔
33
                EntrySourceUnit: entrySourceUnit,
1✔
34
                NodeType:        ast_pb.NodeType_ROOT_SOURCE_UNIT,
1✔
35
                Comments:        comments,
1✔
36
                SourceUnits:     sourceUnits,
1✔
37
                Globals:         make([]Node[NodeType], 0),
1✔
38
        }
1✔
39
}
1✔
40

41
// GetId returns the id of the RootNode node.
42
func (r *RootNode) GetId() int64 {
1✔
43
        return r.Id
1✔
44
}
1✔
45

46
// GetType returns the type of the RootNode node.
47
func (r *RootNode) GetType() ast_pb.NodeType {
1✔
48
        return r.NodeType
1✔
49
}
1✔
50

51
// GetSrc returns the source code location of the RootNode node.
52
func (r *RootNode) GetSrc() SrcNode {
1✔
53
        return SrcNode{}
1✔
54
}
1✔
55

56
// GetTypeDescription returns the type description of the RootNode node.
57
// RootNode nodes do not have type descriptions.
58
func (r *RootNode) GetTypeDescription() *TypeDescription {
1✔
59
        return &TypeDescription{
1✔
60
                TypeString:     "root",
1✔
61
                TypeIdentifier: "t_root",
1✔
62
        }
1✔
63
}
1✔
64

65
// SetReferenceDescriptor sets the reference descriptions of the RootNode node.
66
func (r *RootNode) SetReferenceDescriptor(refId int64, refDesc *TypeDescription) bool {
1✔
67
        return false
1✔
68
}
1✔
69

70
// GetSourceUnits returns the source units of the root node.
71
func (r *RootNode) GetSourceUnits() []*SourceUnit[Node[ast_pb.SourceUnit]] {
1✔
72
        return r.SourceUnits
1✔
73
}
1✔
74

75
// GetSourceUnitByName returns the source unit with the provided name.
76
func (r *RootNode) GetSourceUnitByName(name string) *SourceUnit[Node[ast_pb.SourceUnit]] {
1✔
77
        for _, sourceUnit := range r.SourceUnits {
2✔
78
                if sourceUnit.Name == name {
2✔
79
                        return sourceUnit
1✔
80
                }
1✔
81
        }
82

83
        return nil
×
84
}
85

86
// GetSourceUnitById returns the source unit with the provided id.
87
func (r *RootNode) GetSourceUnitById(id int64) *SourceUnit[Node[ast_pb.SourceUnit]] {
1✔
88
        for _, sourceUnit := range r.SourceUnits {
2✔
89
                if sourceUnit.Id == id {
2✔
90
                        return sourceUnit
1✔
91
                }
1✔
92
        }
93

94
        return nil
×
95
}
96

97
// HasSourceUnits returns true if the root node has source units.
98
func (r *RootNode) HasSourceUnits() bool {
1✔
99
        return len(r.SourceUnits) > 0
1✔
100
}
1✔
101

102
// GetSourceUnitCount returns the number of source units of the root node.
103
func (r *RootNode) GetSourceUnitCount() int32 {
1✔
104
        return int32(len(r.SourceUnits))
1✔
105
}
1✔
106

107
// GetEntrySourceUnit returns the entry source unit of the root node.
108
func (r *RootNode) GetEntrySourceUnit() int64 {
1✔
109
        return r.EntrySourceUnit
1✔
110
}
1✔
111

112
// SetEntrySourceUnit sets the entry source unit of the root node.
113
func (r *RootNode) SetEntrySourceUnit(entrySourceUnit int64) {
1✔
114
        r.EntrySourceUnit = entrySourceUnit
1✔
115
}
1✔
116

117
// GetComments returns the comments of the root node.
118
func (r *RootNode) GetComments() []*Comment {
1✔
119
        return r.Comments
1✔
120
}
1✔
121

122
// GetNodes returns the nodes of the root node.
123
func (r *RootNode) GetNodes() []Node[NodeType] {
1✔
124
        toReturn := make([]Node[NodeType], 0)
1✔
125
        for _, sourceUnit := range r.SourceUnits {
2✔
126
                toReturn = append(toReturn, sourceUnit)
1✔
127
        }
1✔
128
        return toReturn
1✔
129
}
130

131
// GetGlobalNodes returns the global nodes of the root node.
NEW
132
func (r *RootNode) GetGlobalNodes() []Node[NodeType] {
×
NEW
133
        return r.Globals
×
NEW
134
}
×
135

136
// ToProto returns the protobuf representation of the root node.
137
func (r *RootNode) ToProto() *ast_pb.RootSourceUnit {
1✔
138
        sourceUnits := []*ast_pb.SourceUnit{}
1✔
139
        for _, sourceUnit := range r.SourceUnits {
2✔
140
                sourceUnits = append(sourceUnits, sourceUnit.ToProto().(*ast_pb.SourceUnit))
1✔
141
        }
1✔
142

143
        comments := []*ast_pb.Comment{}
1✔
144
        for _, comment := range r.Comments {
2✔
145
                comments = append(comments, comment.ToProto())
1✔
146
        }
1✔
147

148
        globals := []*v3.TypedStruct{}
1✔
149
        for _, global := range r.Globals {
2✔
150
                globals = append(globals, global.ToProto().(*v3.TypedStruct))
1✔
151
        }
1✔
152

153
        return &ast_pb.RootSourceUnit{
1✔
154
                Id:              r.GetId(),
1✔
155
                NodeType:        r.GetType(),
1✔
156
                EntrySourceUnit: r.GetEntrySourceUnit(),
1✔
157
                GlobalNodes:     globals,
1✔
158
                SourceUnits:     sourceUnits,
1✔
159
                Comments:        comments,
1✔
160
        }
1✔
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc