Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST Bugfix: correctly parsing TypeNameContext - slice of types #183

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ast/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ast

import (
"github.com/goccy/go-json"

ast_pb "github.com/unpackdev/protos/dist/go/ast"
"github.com/unpackdev/solgo/parser"
)
Expand Down
1 change: 0 additions & 1 deletion ast/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func (r *Resolver) Resolve() []error {
uNode := r.UnprocessedNodes[nodeId]
uNode.ErrUpdateRef = true
r.UnprocessedNodes[nodeId] = uNode

}
} else {
uNode := r.UnprocessedNodes[nodeId]
Expand Down
3 changes: 3 additions & 0 deletions ast/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func elementaryTypeSizeInBits(typeName string) (int64, bool) {
// `bytes` with a fixed size, and dynamically sized types like `string` and `bytes`.
// Returns the size and a boolean indicating if the type is recognized.
func getTypeSizeInBits(typeName string) (int64, bool) {
// TODO: Make this actually work better... Figure out dynamically what is the size of an array
typeName = strings.TrimSuffix(typeName, "[]")

switch {
case typeName == "bool":
return 8, true
Expand Down
4 changes: 0 additions & 4 deletions ast/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func (t *Tree) UpdateNodeReferenceById(nodeId int64, nodeRefId int64, typeRef *T
return false
}

/* if nodeId == 4186 || nodeRefId == 4186 {
panic("WHY?")
} */

for _, child := range t.astRoot.GetGlobalNodes() {
if n := t.byRecursiveReferenceUpdate(child, nodeId, nodeRefId, typeRef); n {
return n
Expand Down
11 changes: 8 additions & 3 deletions ast/type_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ func (t *TypeName) parseElementaryTypeName(unit *SourceUnit[Node[ast_pb.SourceUn
t.TypeDescription = refTypeDescription
}
}

}

// parseIdentifierPath parses the IdentifierPath from the given IdentifierPathContext.
Expand Down Expand Up @@ -596,10 +597,12 @@ func (t *TypeName) parseMappingTypeName(unit *SourceUnit[Node[ast_pb.SourceUnit]
func (t *TypeName) generateTypeName(sourceUnit *SourceUnit[Node[ast_pb.SourceUnit]], ctx any, parentNode *TypeName, typeNameNode *TypeName) *TypeName {
typeName := &TypeName{
ASTBuilder: t.ASTBuilder,
Id: t.GetNextID(),
Id: t.GetId(),
NodeType: ast_pb.NodeType_ELEMENTARY_TYPE_NAME,
}

t.NodeType = ast_pb.NodeType_ELEMENTARY_TYPE_NAME

switch specificCtx := ctx.(type) {
case parser.IMappingKeyTypeContext:
typeName.Name = specificCtx.GetText()
Expand Down Expand Up @@ -764,7 +767,9 @@ func (t *TypeName) Parse(unit *SourceUnit[Node[ast_pb.SourceUnit]], fnNode Node[
case *parser.IdentifierPathContext:
t.parseIdentifierPath(unit, parentNodeId, childCtx)
case *parser.TypeNameContext:
t.parseTypeName(unit, parentNodeId, childCtx)
// We cannot pass only the child as it may be broken to the core...
// For example for address[] if we pass childCtx, we are going to get address only!
t.parseTypeName(unit, parentNodeId, ctx.(*parser.TypeNameContext))
case *parser.FunctionTypeNameContext:
t.parseFunctionTypeName(unit, parentNodeId, childCtx)
case *parser.PrimaryExpressionContext:
Expand Down Expand Up @@ -798,7 +803,6 @@ func (t *TypeName) Parse(unit *SourceUnit[Node[ast_pb.SourceUnit]], fnNode Node[
}
}
}

}

// ParseMul parses the TypeName from the given TermalNode.
Expand Down Expand Up @@ -854,6 +858,7 @@ func (t *TypeName) ParseElementaryType(unit *SourceUnit[Node[ast_pb.SourceUnit]]
TypeIdentifier: normalizedTypeIdentifier,
TypeString: normalizedTypeName,
}

}

// PathNode represents a path node within a TypeName.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0x4e9e3aee8b09786dd93dc24ac46f9f591f4478f7",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0x4e9e3aee8b09786dd93dc24ac46f9f591f4478f7",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-01T12-49-26.451694370Z--4e9e3aee8b09786dd93dc24ac46f9f591f4478f7"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0x7da04980bb21239e0ed5577bdbc565fdd775e393",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0x7da04980bb21239e0ed5577bdbc565fdd775e393",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-01T13-41-23.944195606Z--7da04980bb21239e0ed5577bdbc565fdd775e393"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0xaab0071867e35b48ad354db6ded8087f32987b7e",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0xaab0071867e35b48ad354db6ded8087f32987b7e",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-01T15-58-25.428738958Z--aab0071867e35b48ad354db6ded8087f32987b7e"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0xf607b8599bb76adc171984f09038cc2c1bfc2933",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0xf607b8599bb76adc171984f09038cc2c1bfc2933",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-01T13-00-17.796549185Z--f607b8599bb76adc171984f09038cc2c1bfc2933"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
2 changes: 1 addition & 1 deletion data/solc/releases/releases.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions data/tests/abi/Lottery.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"inputs": [],
"outputs": [
{
"internalType": "address",
"internalType": "address[]",
"name": "",
"type": "address"
"type": "address[]"
}
],
"name": "playerAddresses",
Expand Down
4 changes: 2 additions & 2 deletions data/tests/abi/Lottery.abi.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
{
"outputs": [
{
"internalType": "address",
"type": "address"
"internalType": "address[]",
"type": "address[]"
}
],
"name": "playerAddresses",
Expand Down
Loading
Loading