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

unpackdev / solgo / 6533905795

16 Oct 2023 12:54PM UTC coverage: 82.079% (-1.1%) from 83.146%
6533905795

push

github

web-flow
Grouped fixes No.1 (#123)

* InlineArray support + function fixes + other fixes

* Some fixes and notice about solidity versions < 6.0

* IR Unit is now public and written into json

* Utils semantic version parser from string

* Adding support for global struct definition

* Changes to local sources (ability to disable), fixing interface type of contract, version and verifier updates

* Bump github.com/consensys/gnark-crypto from 0.11.2 to 0.12.0 (#121)

Bumps [github.com/consensys/gnark-crypto](https://github.com/consensys/gnark-crypto) from 0.11.2 to 0.12.0.
- [Release notes](https://github.com/consensys/gnark-crypto/releases)
- [Changelog](https://github.com/Consensys/gnark-crypto/blob/master/CHANGELOG.md)
- [Commits](https://github.com/consensys/gnark-crypto/compare/v0.11.2...v0.12.0)

---
updated-dependencies:
- dependency-name: github.com/consensys/gnark-crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Merging dependabot

* Bunch of reference resolutions

* Import proto extension for As and Aliases



---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

407 of 606 new or added lines in 38 files covered. (67.16%)

111 existing lines in 5 files now uncovered.

14033 of 17097 relevant lines covered (82.08%)

0.91 hits per line

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

92.31
/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     `json:"ast"`
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
        Signature               string            `json:"signature"`
22
        Modifiers               []*Modifier       `json:"modifiers"`
23
        Overrides               []*Override       `json:"overrides"`
24
        Parameters              []*Parameter      `json:"parameters"`
25
        Body                    *Body             `json:"body"`
26
        ReturnStatements        []*Parameter      `json:"return"`
27
        Src                     ast.SrcNode       `json:"src"`
28
}
29

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

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

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

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

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

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

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

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

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

75
// GetSignature returns the keccak signature of the function.
76
func (f *Function) GetSignature() string {
1✔
77
        return f.Signature
1✔
78
}
1✔
79

80
// GetModifiers returns the modifiers of the function.
81
func (f *Function) GetModifiers() []*Modifier {
1✔
82
        return f.Modifiers
1✔
83
}
1✔
84

85
// GetOverrides returns the overrides of the function.
86
func (f *Function) GetOverrides() []*Override {
1✔
87
        return f.Overrides
1✔
88
}
1✔
89

90
// GetParameters returns the parameters of the function.
91
func (f *Function) GetParameters() []*Parameter {
1✔
92
        return f.Parameters
1✔
93
}
1✔
94

95
// GetReturnStatements returns the return statements of the function.
96
func (f *Function) GetReturnStatements() []*Parameter {
1✔
97
        return f.ReturnStatements
1✔
98
}
1✔
99

100
// GetReferencedDeclarationId returns the referenced declaration id of the function.
101
func (f *Function) GetReferencedDeclarationId() int64 {
1✔
102
        return f.ReferencedDeclarationId
1✔
103
}
1✔
104

105
// GetBody returns the body of the function.
106
func (f *Function) GetBody() *Body {
1✔
107
        return f.Body
1✔
108
}
1✔
109

110
// GetSrc returns the source code of the function.
111
func (f *Function) GetSrc() ast.SrcNode {
1✔
112
        return f.Src
1✔
113
}
1✔
114

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

1✔
135
        for _, modifier := range f.GetModifiers() {
2✔
136
                proto.Modifiers = append(proto.Modifiers, modifier.ToProto())
1✔
137
        }
1✔
138

139
        for _, overrides := range f.GetOverrides() {
1✔
140
                proto.Overrides = append(proto.Overrides, overrides.ToProto())
×
141
        }
×
142

143
        for _, parameter := range f.GetParameters() {
2✔
144
                proto.Parameters = append(proto.Parameters, parameter.ToProto())
1✔
145
        }
1✔
146

147
        for _, returnStatement := range f.GetReturnStatements() {
2✔
148
                proto.Return = append(proto.Return, returnStatement.ToProto())
1✔
149
        }
1✔
150

151
        return proto
1✔
152
}
153

154
// processFunction processes the function declaration and returns the Function.
155
func (b *Builder) processFunction(unit *ast.Function, parseBody bool) *Function {
1✔
156
        toReturn := &Function{
1✔
157
                Unit:                    unit,
1✔
158
                Id:                      unit.GetId(),
1✔
159
                NodeType:                unit.GetType(),
1✔
160
                Kind:                    unit.GetKind(),
1✔
161
                Name:                    unit.GetName(),
1✔
162
                Implemented:             unit.IsImplemented(),
1✔
163
                Visibility:              unit.GetVisibility(),
1✔
164
                StateMutability:         unit.GetStateMutability(),
1✔
165
                Virtual:                 unit.IsVirtual(),
1✔
166
                ReferencedDeclarationId: unit.GetReferencedDeclaration(),
1✔
167
                Signature:               unit.GetSignature(),
1✔
168
                Modifiers:               make([]*Modifier, 0),
1✔
169
                Overrides:               make([]*Override, 0),
1✔
170
                Parameters:              make([]*Parameter, 0),
1✔
171
                ReturnStatements:        make([]*Parameter, 0),
1✔
172
                Src:                     unit.GetSrc(),
1✔
173
        }
1✔
174

1✔
175
        for _, modifier := range unit.GetModifiers() {
2✔
176
                toReturn.Modifiers = append(toReturn.Modifiers, &Modifier{
1✔
177
                        Unit:          modifier,
1✔
178
                        Id:            modifier.GetId(),
1✔
179
                        NodeType:      modifier.GetType(),
1✔
180
                        Name:          modifier.GetName(),
1✔
181
                        ArgumentTypes: modifier.GetArgumentTypes(),
1✔
182
                })
1✔
183
        }
1✔
184

185
        for _, oride := range unit.GetOverrides() {
2✔
186
                for _, overrideParameter := range oride.GetOverrides() {
1✔
187
                        override := &Override{
×
NEW
188
                                Unit:                    oride,
×
189
                                Id:                      overrideParameter.GetId(),
×
190
                                NodeType:                overrideParameter.GetType(),
×
191
                                Name:                    overrideParameter.GetName(),
×
192
                                ReferencedDeclarationId: overrideParameter.GetReferencedDeclaration(),
×
193
                                TypeDescription:         overrideParameter.GetTypeDescription(),
×
194
                        }
×
195
                        toReturn.Overrides = append(toReturn.Overrides, override)
×
196
                }
×
197
        }
198

199
        for _, parameter := range unit.GetParameters().GetParameters() {
2✔
200
                param := &Parameter{
1✔
201
                        Unit:            parameter,
1✔
202
                        Id:              parameter.GetId(),
1✔
203
                        NodeType:        parameter.GetType(),
1✔
204
                        Name:            parameter.GetName(),
1✔
205
                        Type:            parameter.GetTypeName().GetName(),
1✔
206
                        TypeDescription: parameter.GetTypeDescription(),
1✔
207
                }
1✔
208

1✔
209
                if param.GetType() == "" && parameter.GetTypeName().GetPathNode() != nil {
2✔
210
                        param.Type = parameter.GetTypeName().GetPathNode().Name
1✔
211
                }
1✔
212

213
                toReturn.Parameters = append(toReturn.Parameters, param)
1✔
214
        }
215

216
        if parseBody {
2✔
217
                toReturn.Body = b.processFunctionBody(toReturn, unit.GetBody())
1✔
218
        }
1✔
219

220
        for _, returnStatement := range unit.GetReturnParameters().GetParameters() {
2✔
221
                param := &Parameter{
1✔
222
                        Unit:            returnStatement,
1✔
223
                        Id:              returnStatement.GetId(),
1✔
224
                        NodeType:        returnStatement.GetType(),
1✔
225
                        Name:            returnStatement.GetName(),
1✔
226
                        Type:            returnStatement.GetTypeName().GetName(),
1✔
227
                        TypeDescription: returnStatement.GetTypeDescription(),
1✔
228
                }
1✔
229

1✔
230
                if param.GetType() == "" && returnStatement.GetTypeName().GetPathNode() != nil {
2✔
231
                        param.Type = returnStatement.GetTypeName().GetPathNode().Name
1✔
232
                }
1✔
233

234
                toReturn.ReturnStatements = append(toReturn.ReturnStatements, param)
1✔
235
        }
236

237
        return toReturn
1✔
238
}
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