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

unpackdev / solgo / 6288337927

24 Sep 2023 05:53AM UTC coverage: 89.033% (+0.3%) from 88.733%
6288337927

Pull #109

github

0x19
Introducing ast global declarations
Pull Request #109: AST Fix - Introducing BitAndOperation, ast.ToProto(), Global Definitions

175 of 192 new or added lines in 13 files covered. (91.15%)

2 existing lines in 1 file now uncovered.

11812 of 13267 relevant lines covered (89.03%)

0.96 hits per line

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

93.98
/ast/root_node.go
1
package ast
2

3
import (
4
        ast_pb "github.com/unpackdev/protos/dist/go/ast"
5
)
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
82
        return nil
×
83
}
84

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

UNCOV
93
        return nil
×
94
}
95

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

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

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

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

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

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

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

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

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

147
        return &ast_pb.RootSourceUnit{
1✔
148
                Id:              r.GetId(),
1✔
149
                NodeType:        r.GetType(),
1✔
150
                EntrySourceUnit: r.GetEntrySourceUnit(),
1✔
151
                SourceUnits:     sourceUnits,
1✔
152
                Comments:        comments,
1✔
153
        }
1✔
154
}
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