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

unpackdev / solgo / 6289363215

24 Sep 2023 09:58AM UTC coverage: 88.84% (-0.2%) from 89.03%
6289363215

Pull #110

github

0x19
Bumping protos
Pull Request #110: Resolving unparsed `returns` in Try AST statement and OverrideSpecifier.

75 of 130 new or added lines in 6 files covered. (57.69%)

36 existing lines in 3 files now uncovered.

11829 of 13315 relevant lines covered (88.84%)

0.96 hits per line

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

92.0
/ir/function.go
1
package ir
2

3
import (
4
        ast_pb "github.com/unpackdev/protos/dist/go/ast"
5
        ir_pb "github.com/unpackdev/protos/dist/go/ir"
6
        "github.com/unpackdev/solgo/ast"
7
)
8

9
// Function represents a function declaration in the IR.
10
type Function struct {
11
        unit                    *ast.Function
12
        Id                      int64             `json:"id"`
13
        NodeType                ast_pb.NodeType   `json:"node_type"`
14
        Kind                    ast_pb.NodeType   `json:"kind"`
15
        Name                    string            `json:"name"`
16
        Implemented             bool              `json:"implemented"`
17
        Visibility              ast_pb.Visibility `json:"visibility"`
18
        StateMutability         ast_pb.Mutability `json:"state_mutability"`
19
        Virtual                 bool              `json:"virtual"`
20
        ReferencedDeclarationId int64             `json:"referenced_declaration_id"`
21
        Modifiers               []*Modifier       `json:"modifiers"`
22
        Overrides               []*Override       `json:"overrides"`
23
        Parameters              []*Parameter      `json:"parameters"`
24
        Body                    *Body             `json:"body"`
25
        ReturnStatements        []*Parameter      `json:"return"`
26
}
27

28
// GetAST returns the AST (Abstract Syntax Tree) for the function declaration.
29
func (f *Function) GetAST() *ast.Function {
1✔
30
        return f.unit
1✔
31
}
1✔
32

33
// GetId returns the ID of the function declaration.
34
func (f *Function) GetId() int64 {
1✔
35
        return f.Id
1✔
36
}
1✔
37

38
// GetNodeType returns the NodeType of the function declaration.
39
func (f *Function) GetNodeType() ast_pb.NodeType {
1✔
40
        return f.NodeType
1✔
41
}
1✔
42

43
// GetName returns the name of the function declaration.
44
func (f *Function) GetName() string {
1✔
45
        return f.Name
1✔
46
}
1✔
47

48
// GetKind returns the kind of the function declaration.
49
func (f *Function) GetKind() ast_pb.NodeType {
1✔
50
        return f.Kind
1✔
51
}
1✔
52

53
// IsImplemented returns whether the function is implemented or not.
54
func (f *Function) IsImplemented() bool {
1✔
55
        return f.Implemented
1✔
56
}
1✔
57

58
// GetVisibility returns the visibility of the function.
59
func (f *Function) GetVisibility() ast_pb.Visibility {
1✔
60
        return f.Visibility
1✔
61
}
1✔
62

63
// GetStateMutability returns the state mutability of the function.
64
func (f *Function) GetStateMutability() ast_pb.Mutability {
1✔
65
        return f.StateMutability
1✔
66
}
1✔
67

68
// IsVirtual returns whether the function is virtual or not.
69
func (f *Function) IsVirtual() bool {
1✔
70
        return f.Virtual
1✔
71
}
1✔
72

73
// GetModifiers returns the modifiers of the function.
74
func (f *Function) GetModifiers() []*Modifier {
1✔
75
        return f.Modifiers
1✔
76
}
1✔
77

78
// GetOverrides returns the overrides of the function.
79
func (f *Function) GetOverrides() []*Override {
1✔
80
        return f.Overrides
1✔
81
}
1✔
82

83
// GetParameters returns the parameters of the function.
84
func (f *Function) GetParameters() []*Parameter {
1✔
85
        return f.Parameters
1✔
86
}
1✔
87

88
// GetReturnStatements returns the return statements of the function.
89
func (f *Function) GetReturnStatements() []*Parameter {
1✔
90
        return f.ReturnStatements
1✔
91
}
1✔
92

93
// GetReferencedDeclarationId returns the referenced declaration id of the function.
94
func (f *Function) GetReferencedDeclarationId() int64 {
1✔
95
        return f.ReferencedDeclarationId
1✔
96
}
1✔
97

98
// GetBody returns the body of the function.
99
func (f *Function) GetBody() *Body {
1✔
100
        return f.Body
1✔
101
}
1✔
102

103
// GetSrc returns the source code of the function.
104
func (f *Function) GetSrc() ast.SrcNode {
1✔
105
        return f.unit.GetSrc()
1✔
106
}
1✔
107

108
// ToProto returns the protocol buffer version of the function.
109
func (f *Function) ToProto() *ir_pb.Function {
1✔
110
        proto := &ir_pb.Function{
1✔
111
                Id:                      f.GetId(),
1✔
112
                NodeType:                f.GetNodeType(),
1✔
113
                Kind:                    f.GetKind(),
1✔
114
                Name:                    f.GetName(),
1✔
115
                Implemented:             f.IsImplemented(),
1✔
116
                Visibility:              f.GetVisibility(),
1✔
117
                StateMutability:         f.GetStateMutability(),
1✔
118
                Virtual:                 f.IsVirtual(),
1✔
119
                ReferencedDeclarationId: f.GetReferencedDeclarationId(),
1✔
120
                Modifiers:               make([]*ir_pb.Modifier, 0),
1✔
121
                Overrides:               make([]*ir_pb.Override, 0),
1✔
122
                Parameters:              make([]*ir_pb.Parameter, 0),
1✔
123
                Body:                    f.GetBody().ToProto(),
1✔
124
                Return:                  make([]*ir_pb.Parameter, 0),
1✔
125
        }
1✔
126

1✔
127
        for _, modifier := range f.GetModifiers() {
2✔
128
                proto.Modifiers = append(proto.Modifiers, modifier.ToProto())
1✔
129
        }
1✔
130

131
        for _, overrides := range f.GetOverrides() {
1✔
UNCOV
132
                proto.Overrides = append(proto.Overrides, overrides.ToProto())
×
UNCOV
133
        }
×
134

135
        for _, parameter := range f.GetParameters() {
2✔
136
                proto.Parameters = append(proto.Parameters, parameter.ToProto())
1✔
137
        }
1✔
138

139
        for _, returnStatement := range f.GetReturnStatements() {
2✔
140
                proto.Return = append(proto.Return, returnStatement.ToProto())
1✔
141
        }
1✔
142

143
        return proto
1✔
144
}
145

146
// processFunction processes the function declaration and returns the Function.
147
func (b *Builder) processFunction(unit *ast.Function, parseBody bool) *Function {
1✔
148
        toReturn := &Function{
1✔
149
                unit:                    unit,
1✔
150
                Id:                      unit.GetId(),
1✔
151
                NodeType:                unit.GetType(),
1✔
152
                Kind:                    unit.GetKind(),
1✔
153
                Name:                    unit.GetName(),
1✔
154
                Implemented:             unit.IsImplemented(),
1✔
155
                Visibility:              unit.GetVisibility(),
1✔
156
                StateMutability:         unit.GetStateMutability(),
1✔
157
                Virtual:                 unit.IsVirtual(),
1✔
158
                ReferencedDeclarationId: unit.GetReferencedDeclaration(),
1✔
159
                Modifiers:               make([]*Modifier, 0),
1✔
160
                Overrides:               make([]*Override, 0),
1✔
161
                Parameters:              make([]*Parameter, 0),
1✔
162
                ReturnStatements:        make([]*Parameter, 0),
1✔
163
        }
1✔
164

1✔
165
        for _, modifier := range unit.GetModifiers() {
2✔
166
                toReturn.Modifiers = append(toReturn.Modifiers, &Modifier{
1✔
167
                        unit:          modifier,
1✔
168
                        Id:            modifier.GetId(),
1✔
169
                        NodeType:      modifier.GetType(),
1✔
170
                        Name:          modifier.GetName(),
1✔
171
                        ArgumentTypes: modifier.GetArgumentTypes(),
1✔
172
                })
1✔
173
        }
1✔
174

175
        for _, oride := range unit.GetOverrides() {
2✔
176
                for _, overrideParameter := range oride.GetOverrides() {
1✔
NEW
177
                        override := &Override{
×
NEW
178
                                unit:                    oride,
×
NEW
179
                                Id:                      overrideParameter.GetId(),
×
NEW
180
                                NodeType:                overrideParameter.GetType(),
×
NEW
181
                                Name:                    overrideParameter.GetName(),
×
NEW
182
                                ReferencedDeclarationId: overrideParameter.GetReferencedDeclaration(),
×
NEW
183
                                TypeDescription:         overrideParameter.GetTypeDescription(),
×
UNCOV
184
                        }
×
NEW
185
                        toReturn.Overrides = append(toReturn.Overrides, override)
×
NEW
186
                }
×
187
        }
188

189
        for _, parameter := range unit.GetParameters().GetParameters() {
2✔
190
                param := &Parameter{
1✔
191
                        unit:            parameter,
1✔
192
                        Id:              parameter.GetId(),
1✔
193
                        NodeType:        parameter.GetType(),
1✔
194
                        Name:            parameter.GetName(),
1✔
195
                        Type:            parameter.GetTypeName().GetName(),
1✔
196
                        TypeDescription: parameter.GetTypeDescription(),
1✔
197
                }
1✔
198

1✔
199
                if param.GetType() == "" && parameter.GetTypeName().GetPathNode() != nil {
2✔
200
                        param.Type = parameter.GetTypeName().GetPathNode().Name
1✔
201
                }
1✔
202

203
                toReturn.Parameters = append(toReturn.Parameters, param)
1✔
204
        }
205

206
        if parseBody {
2✔
207
                toReturn.Body = b.processFunctionBody(toReturn, unit.GetBody())
1✔
208
        }
1✔
209

210
        for _, returnStatement := range unit.GetReturnParameters().GetParameters() {
2✔
211
                param := &Parameter{
1✔
212
                        unit:            returnStatement,
1✔
213
                        Id:              returnStatement.GetId(),
1✔
214
                        NodeType:        returnStatement.GetType(),
1✔
215
                        Name:            returnStatement.GetName(),
1✔
216
                        Type:            returnStatement.GetTypeName().GetName(),
1✔
217
                        TypeDescription: returnStatement.GetTypeDescription(),
1✔
218
                }
1✔
219

1✔
220
                if param.GetType() == "" && returnStatement.GetTypeName().GetPathNode() != nil {
2✔
221
                        param.Type = returnStatement.GetTypeName().GetPathNode().Name
1✔
222
                }
1✔
223

224
                toReturn.ReturnStatements = append(toReturn.ReturnStatements, param)
1✔
225
        }
226

227
        return toReturn
1✔
228
}
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