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

Opcode functions and instruction tree + JSON normalization #210

Merged
merged 3 commits into from
May 5, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions ast/and_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type AndOperation struct {
*ASTBuilder

Id int64 `json:"id"`
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
Src SrcNode `json:"src"`
Expressions []Node[NodeType] `json:"expressions"`
TypeDescriptions []*TypeDescription `json:"type_descriptions"`
TypeDescriptions []*TypeDescription `json:"typeDescriptions"`
}

// NewAndOperationExpression creates a new AndOperation instance.
Expand Down Expand Up @@ -83,7 +83,7 @@ func (f *AndOperation) UnmarshalJSON(data []byte) error {
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &f.NodeType); err != nil {
return err
}
Expand All @@ -108,7 +108,7 @@ func (f *AndOperation) UnmarshalJSON(data []byte) error {
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -120,7 +120,7 @@ func (f *AndOperation) UnmarshalJSON(data []byte) error {
}
}

if typeDescriptions, ok := tempMap["type_descriptions"]; ok {
if typeDescriptions, ok := tempMap["typeDescriptions"]; ok {
if err := json.Unmarshal(typeDescriptions, &f.TypeDescriptions); err != nil {
return err
}
Expand Down
36 changes: 18 additions & 18 deletions ast/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (
type Assignment struct {
*ASTBuilder

Id int64 `json:"id"` // Unique identifier for the Assignment node.
NodeType ast_pb.NodeType `json:"node_type"` // Type of the AST node.
Src SrcNode `json:"src"` // Source location information.
Expression Node[NodeType] `json:"expression,omitempty"` // Expression for the assignment (if used).
Operator ast_pb.Operator `json:"operator,omitempty"` // Operator used in the assignment.
LeftExpression Node[NodeType] `json:"left_expression,omitempty"` // Left-hand side expression.
RightExpression Node[NodeType] `json:"right_expression,omitempty"` // Right-hand side expression.
ReferencedDeclaration int64 `json:"referenced_declaration,omitempty"` // Referenced declaration identifier (if used).
TypeDescription *TypeDescription `json:"type_description,omitempty"` // Type description associated with the Assignment node.
Text string `json:"text,omitempty"` // Text of the Assignment node.
Id int64 `json:"id"` // Unique identifier for the Assignment node.
NodeType ast_pb.NodeType `json:"nodeType"` // Type of the AST node.
Src SrcNode `json:"src"` // Source location information.
Expression Node[NodeType] `json:"expression,omitempty"` // Expression for the assignment (if used).
Operator ast_pb.Operator `json:"operator,omitempty"` // Operator used in the assignment.
LeftExpression Node[NodeType] `json:"leftExpression,omitempty"` // Left-hand side expression.
RightExpression Node[NodeType] `json:"rightExpression,omitempty"` // Right-hand side expression.
ReferencedDeclaration int64 `json:"referencedDeclaration,omitempty"` // Referenced declaration identifier (if used).
TypeDescription *TypeDescription `json:"typeDescription,omitempty"` // Type description associated with the Assignment node.
Text string `json:"text,omitempty"` // Text of the Assignment node.
}

// NewAssignment creates a new Assignment node with a given ASTBuilder.
Expand Down Expand Up @@ -131,7 +131,7 @@ func (a *Assignment) UnmarshalJSON(data []byte) error {
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &a.NodeType); err != nil {
return err
}
Expand All @@ -143,13 +143,13 @@ func (a *Assignment) UnmarshalJSON(data []byte) error {
}
}

if referencedDeclaration, ok := tempMap["referenced_declaration"]; ok {
if referencedDeclaration, ok := tempMap["referencedDeclaration"]; ok {
if err := json.Unmarshal(referencedDeclaration, &a.ReferencedDeclaration); err != nil {
return err
}
}

if typeDescription, ok := tempMap["type_description"]; ok {
if typeDescription, ok := tempMap["typeDescription"]; ok {
if err := json.Unmarshal(typeDescription, &a.TypeDescription); err != nil {
return err
}
Expand All @@ -161,15 +161,15 @@ func (a *Assignment) UnmarshalJSON(data []byte) error {
}
}

if leftExpression, ok := tempMap["left_expression"]; ok {
if leftExpression, ok := tempMap["leftExpression"]; ok {
if err := json.Unmarshal(leftExpression, &a.LeftExpression); err != nil {
var tempNodeMap map[string]json.RawMessage
if err := json.Unmarshal(leftExpression, &tempNodeMap); err != nil {
return err
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -181,15 +181,15 @@ func (a *Assignment) UnmarshalJSON(data []byte) error {
}
}

if rightExpression, ok := tempMap["right_expression"]; ok {
if rightExpression, ok := tempMap["rightExpression"]; ok {
if err := json.Unmarshal(rightExpression, &a.RightExpression); err != nil {
var tempNodeMap map[string]json.RawMessage
if err := json.Unmarshal(rightExpression, &tempNodeMap); err != nil {
return err
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -209,7 +209,7 @@ func (a *Assignment) UnmarshalJSON(data []byte) error {
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions ast/base_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type BaseContract struct {
Id int64 `json:"id"`
// NodeType is the type of the node.
// For a BaseContract, this is always NodeType_BASE_CONTRACT.
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
// Src contains source information about the node, such as its line and column numbers in the source file.
Src SrcNode `json:"src"`
// BaseName is the name of the base contract.
BaseName *BaseContractName `json:"base_name"`
BaseName *BaseContractName `json:"baseName"`
}

// GetId returns the unique identifier of the base contract.
Expand Down Expand Up @@ -55,15 +55,15 @@ type BaseContractName struct {
Id int64 `json:"id"`
// NodeType is the type of the node.
// For a BaseContractName, this is always NodeType_BASE_CONTRACT_NAME.
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
// Src contains source information about the node, such as its line and column numbers in the source file.
Src SrcNode `json:"src"`
// Name is the name of the base contract.
Name string `json:"name"`
// ReferencedDeclaration is the unique identifier of the source unit declaration that this name references.
ReferencedDeclaration int64 `json:"referenced_declaration"`
ReferencedDeclaration int64 `json:"referencedDeclaration"`
// ContractReferencedDeclaration is the unique identifier of the source unit contract declaration that this name references.
ContractReferencedDeclaration int64 `json:"contract_referenced_declaration"`
ContractReferencedDeclaration int64 `json:"contractReferencedDeclaration"`
}

// GetId returns the unique identifier of the base contract name.
Expand Down
28 changes: 14 additions & 14 deletions ast/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ type BinaryOperation struct {
// Id is the unique identifier of the binary operation.
Id int64 `json:"id"`
// IsConstant indicates whether the binary operation is a constant.
Constant bool `json:"is_constant"`
Constant bool `json:"isConstant"`
// IsPure indicates whether the binary operation is pure (i.e., it does not read or modify state).
Pure bool `json:"is_pure"`
Pure bool `json:"isPure"`
// NodeType is the type of the node.
// For a BinaryOperation, this is always NodeType_BINARY_OPERATION.
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
// Src contains source information about the node, such as its line and column numbers in the source file.
Src SrcNode `json:"src"`
// Operator is the operator of the binary operation.
Operator ast_pb.Operator `json:"operator"`
// LeftExpression is the left operand of the binary operation.
LeftExpression Node[NodeType] `json:"left_expression"`
LeftExpression Node[NodeType] `json:"leftExpression"`
// RightExpression is the right operand of the binary operation.
RightExpression Node[NodeType] `json:"right_expression"`
RightExpression Node[NodeType] `json:"rightExpression"`
// TypeDescription is the type description of the binary operation.
TypeDescription *TypeDescription `json:"type_description"`
TypeDescription *TypeDescription `json:"typeDescription"`
}

// NewBinaryOperationExpression is a constructor function that initializes a new BinaryOperation with a unique ID and the NodeType set to NodeType_BINARY_OPERATION.
Expand Down Expand Up @@ -121,19 +121,19 @@ func (a *BinaryOperation) UnmarshalJSON(data []byte) error {
}
}

if isConstant, ok := tempMap["is_constant"]; ok {
if isConstant, ok := tempMap["isConstant"]; ok {
if err := json.Unmarshal(isConstant, &a.Constant); err != nil {
return err
}
}

if isPure, ok := tempMap["is_pure"]; ok {
if isPure, ok := tempMap["isPure"]; ok {
if err := json.Unmarshal(isPure, &a.Pure); err != nil {
return err
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &a.NodeType); err != nil {
return err
}
Expand All @@ -145,7 +145,7 @@ func (a *BinaryOperation) UnmarshalJSON(data []byte) error {
}
}

if typeDescription, ok := tempMap["type_description"]; ok {
if typeDescription, ok := tempMap["typeDescription"]; ok {
if err := json.Unmarshal(typeDescription, &a.TypeDescription); err != nil {
return err
}
Expand All @@ -157,15 +157,15 @@ func (a *BinaryOperation) UnmarshalJSON(data []byte) error {
}
}

if leftExpression, ok := tempMap["left_expression"]; ok {
if leftExpression, ok := tempMap["leftExpression"]; ok {
if err := json.Unmarshal(leftExpression, &a.LeftExpression); err != nil {
var tempNodeMap map[string]json.RawMessage
if err := json.Unmarshal(leftExpression, &tempNodeMap); err != nil {
return err
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -177,15 +177,15 @@ func (a *BinaryOperation) UnmarshalJSON(data []byte) error {
}
}

if rightExpression, ok := tempMap["right_expression"]; ok {
if rightExpression, ok := tempMap["rightExpression"]; ok {
if err := json.Unmarshal(rightExpression, &a.RightExpression); err != nil {
var tempNodeMap map[string]json.RawMessage
if err := json.Unmarshal(rightExpression, &tempNodeMap); err != nil {
return err
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions ast/bit_and_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type BitAndOperation struct {
*ASTBuilder

Id int64 `json:"id"`
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
Src SrcNode `json:"src"`
Expressions []Node[NodeType] `json:"expressions"`
TypeDescriptions []*TypeDescription `json:"type_descriptions"`
TypeDescriptions []*TypeDescription `json:"typeDescriptions"`
}

// NewBitAndOperationExpression creates a new BitAndOperation instance.
Expand Down Expand Up @@ -80,7 +80,7 @@ func (b *BitAndOperation) UnmarshalJSON(data []byte) error {
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &b.NodeType); err != nil {
return err
}
Expand All @@ -105,7 +105,7 @@ func (b *BitAndOperation) UnmarshalJSON(data []byte) error {
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -117,7 +117,7 @@ func (b *BitAndOperation) UnmarshalJSON(data []byte) error {
}
}

if typeDescriptions, ok := tempMap["type_descriptions"]; ok {
if typeDescriptions, ok := tempMap["typeDescriptions"]; ok {
if err := json.Unmarshal(typeDescriptions, &b.TypeDescriptions); err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions ast/bit_or_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type BitOrOperation struct {
*ASTBuilder

Id int64 `json:"id"`
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
Src SrcNode `json:"src"`
Expressions []Node[NodeType] `json:"expressions"`
TypeDescriptions []*TypeDescription `json:"type_descriptions"`
TypeDescriptions []*TypeDescription `json:"typeDescriptions"`
}

// NewBitOrOperationExpression creates a new BitOrOperation instance.
Expand Down Expand Up @@ -80,7 +80,7 @@ func (b *BitOrOperation) UnmarshalJSON(data []byte) error {
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &b.NodeType); err != nil {
return err
}
Expand All @@ -105,7 +105,7 @@ func (b *BitOrOperation) UnmarshalJSON(data []byte) error {
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -117,7 +117,7 @@ func (b *BitOrOperation) UnmarshalJSON(data []byte) error {
}
}

if typeDescriptions, ok := tempMap["type_descriptions"]; ok {
if typeDescriptions, ok := tempMap["typeDescriptions"]; ok {
if err := json.Unmarshal(typeDescriptions, &b.TypeDescriptions); err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions ast/bit_xor_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type BitXorOperation struct {
*ASTBuilder

Id int64 `json:"id"`
NodeType ast_pb.NodeType `json:"node_type"`
NodeType ast_pb.NodeType `json:"nodeType"`
Src SrcNode `json:"src"`
Expressions []Node[NodeType] `json:"expressions"`
TypeDescriptions []*TypeDescription `json:"type_descriptions"`
TypeDescription *TypeDescription `json:"type_description"`
TypeDescriptions []*TypeDescription `json:"typeDescriptions"`
TypeDescription *TypeDescription `json:"typeDescription"`
}

// NewBitXorOperationExpression creates a new BitXorOperation instance.
Expand Down Expand Up @@ -92,7 +92,7 @@ func (b *BitXorOperation) UnmarshalJSON(data []byte) error {
}
}

if nodeType, ok := tempMap["node_type"]; ok {
if nodeType, ok := tempMap["nodeType"]; ok {
if err := json.Unmarshal(nodeType, &b.NodeType); err != nil {
return err
}
Expand All @@ -117,7 +117,7 @@ func (b *BitXorOperation) UnmarshalJSON(data []byte) error {
}

var tempNodeType ast_pb.NodeType
if err := json.Unmarshal(tempNodeMap["node_type"], &tempNodeType); err != nil {
if err := json.Unmarshal(tempNodeMap["nodeType"], &tempNodeType); err != nil {
return err
}

Expand All @@ -129,7 +129,7 @@ func (b *BitXorOperation) UnmarshalJSON(data []byte) error {
}
}

if typeDescriptions, ok := tempMap["type_descriptions"]; ok {
if typeDescriptions, ok := tempMap["typeDescriptions"]; ok {
if err := json.Unmarshal(typeDescriptions, &b.TypeDescriptions); err != nil {
return err
}
Expand Down
Loading
Loading