Skip to content

Commit

Permalink
AST Bugfix: correctly parsing TypeNameContext - slice of types (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x19 authored Apr 1, 2024
1 parent a1afab5 commit a8fd6b4
Show file tree
Hide file tree
Showing 191 changed files with 278,893 additions and 278,368 deletions.
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

0 comments on commit a8fd6b4

Please sign in to comment.