Skip to content
Draft
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
84 changes: 41 additions & 43 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,12 @@

type BLangNode interface {
model.Node
SetTypeData(ty model.TypeData)
SetDeterminedType(ty semtypes.SemType)
SetPosition(pos Location)
}

type (
BLangNodeBase struct {
ty model.TypeData
bLangNodeBase struct {
DeterminedType semtypes.SemType

parent BLangNode
Expand All @@ -246,27 +244,26 @@
internal bool
}

// TODO: look into what is the difference between the public TypeData fields and ty
BLangAnnotation struct {
BLangNodeBase
bLangNodeBase
Name *BLangIdentifier
AnnAttachments []BLangAnnotationAttachment
MarkdownDocumentationAttachment *BLangMarkdownDocumentation
TypeData model.TypeData
typeDescriptor model.TypeDescriptor
FlagSet common.UnorderedSet[model.Flag]
attachPoints common.UnorderedSet[model.AttachPoint]
}

BLangAnnotationAttachment struct {
BLangNodeBase
bLangNodeBase
Expr BLangExpression
AnnotationName *BLangIdentifier
PkgAlias *BLangIdentifier
AttachPoints common.OrderedSet[model.Point]
}

BLangFunctionBodyBase struct {
BLangNodeBase
bLangNodeBase
}

BLangBlockFunctionBody struct {
Expand All @@ -280,14 +277,14 @@
}

BLangIdentifier struct {
BLangNodeBase
bLangNodeBase
Value string
OriginalValue string
isLiteral bool
}

BLangImportPackage struct {
BLangNodeBase
bLangNodeBase
OrgName *BLangIdentifier
PkgNameComps []BLangIdentifier
Alias *BLangIdentifier
Expand All @@ -296,7 +293,7 @@
}

BLangClassDefinition struct {
BLangNodeBase
bLangNodeBase
Name *BLangIdentifier
symbol model.SymbolRef
AnnAttachments []BLangAnnotationAttachment
Expand All @@ -321,7 +318,7 @@
}

BLangService struct {
BLangNodeBase
bLangNodeBase
symbol model.SymbolRef
ServiceVariable *BLangSimpleVariable
AttachedExprs []BLangExpression
Expand All @@ -338,15 +335,15 @@
}

BLangCompilationUnit struct {
BLangNodeBase
bLangNodeBase
TopLevelNodes []model.TopLevelNode
Name string
packageID *model.PackageID
sourceKind SourceKind
}

BLangPackage struct {
BLangNodeBase
bLangNodeBase
CompUnits []BLangCompilationUnit
Imports []BLangImportPackage
XmlnsList []BLangXMLNS
Expand Down Expand Up @@ -378,7 +375,7 @@
isLegacyMockingMap map[string]bool
}
BLangXMLNS struct {
BLangNodeBase
bLangNodeBase
namespaceURI BLangExpression
prefix *BLangIdentifier
CompUnit *BLangIdentifier
Expand All @@ -390,7 +387,7 @@
BLangXMLNS
}
BLangMarkdownDocumentation struct {
BLangNodeBase
bLangNodeBase
DocumentationLines []BLangMarkdownDocumentationLine
Parameters []BLangMarkdownParameterDocumentation
References []BLangMarkdownReferenceDocumentation
Expand All @@ -399,7 +396,7 @@
DeprecatedParametersDocumentation *BLangMarkDownDeprecatedParametersDocumentation
}
BLangMarkdownReferenceDocumentation struct {
BLangNodeBase
bLangNodeBase
Qualifier string
TypeName string
Identifier string
Expand All @@ -409,7 +406,10 @@
}

BLangVariableBase struct {
BLangNodeBase
bLangNodeBase
// We are using variable for function paramets and record td fields so we need to have
// type descriptors here. Not sure this is the best way to do this.
typeNode BType
AnnAttachments []model.AnnotationAttachmentNode
MarkdownDocumentationAttachment model.MarkdownDocumentationNode
Expr model.ExpressionNode
Expand All @@ -434,14 +434,14 @@
}

BLangInvokableNodeBase struct {
BLangNodeBase
bLangNodeBase
Name *BLangIdentifier
symbol model.SymbolRef
AnnAttachments []model.AnnotationAttachmentNode
MarkdownDocumentationAttachment *BLangMarkdownDocumentation
RequiredParams []BLangSimpleVariable
RestParam model.SimpleVariableNode
ReturnTypeData model.TypeData
returnTypeDescriptor model.TypeDescriptor
ReturnTypeAnnAttachments []model.AnnotationAttachmentNode
Body model.FunctionBodyNode
DefaultWorkerName model.IdentifierNode
Expand All @@ -463,7 +463,7 @@
}

BLangTypeDefinition struct {
BLangNodeBase
bLangNodeBase
Name *BLangIdentifier
symbol model.SymbolRef
typeData model.TypeData
Expand All @@ -478,27 +478,19 @@
}
)

func (this *BLangNodeBase) SetTypeData(ty model.TypeData) {
this.ty = ty
}

func (this *BLangNodeBase) GetTypeData() model.TypeData {
return this.ty
}

func (this *BLangNodeBase) SetDeterminedType(ty semtypes.SemType) {
func (this *bLangNodeBase) SetDeterminedType(ty semtypes.SemType) {
this.DeterminedType = ty
}

func (this *BLangNodeBase) GetDeterminedType() semtypes.SemType {
func (this *bLangNodeBase) GetDeterminedType() semtypes.SemType {
return this.DeterminedType
}

func (this *BLangNodeBase) GetPosition() Location {
func (this *bLangNodeBase) GetPosition() Location {
return this.pos
}

func (this *BLangNodeBase) SetPosition(pos Location) {
func (this *bLangNodeBase) SetPosition(pos Location) {
this.pos = pos
}

Expand Down Expand Up @@ -526,6 +518,14 @@
n.symbol = symbolRef
}

func (n *BLangVariableBase) TypeNode() BType {
return n.typeNode
}

func (n *BLangVariableBase) SetTypeNode(bt BType) {
n.typeNode = bt
}

func (n *BLangInvokableNodeBase) Symbol() model.SymbolRef {
return n.symbol
}
Expand Down Expand Up @@ -655,14 +655,12 @@
panic("name is not a BLangIdentifier")
}

func (this *BLangAnnotation) GetTypeData() model.TypeData {
// migrated from BLangAnnotation.java:70:5
return this.TypeData
func (this *BLangAnnotation) GetTypeDescriptor() model.TypeDescriptor {
return this.typeDescriptor

Check warning on line 659 in ast/ast.go

View check run for this annotation

Codecov / codecov/patch

ast/ast.go#L658-L659

Added lines #L658 - L659 were not covered by tests
}

func (this *BLangAnnotation) SetTypeData(typeData model.TypeData) {
// migrated from BLangAnnotation.java:75:5
this.TypeData = typeData
func (this *BLangAnnotation) SetTypeDescriptor(typeDescriptor model.TypeDescriptor) {
this.typeDescriptor = typeDescriptor

Check warning on line 663 in ast/ast.go

View check run for this annotation

Codecov / codecov/patch

ast/ast.go#L662-L663

Added lines #L662 - L663 were not covered by tests
}

func (this *BLangAnnotation) GetFlags() common.Set[model.Flag] {
Expand Down Expand Up @@ -1382,12 +1380,12 @@
return b.Body != nil
}

func (b *BLangInvokableNodeBase) GetReturnTypeData() model.TypeData {
return b.ReturnTypeData
func (b *BLangInvokableNodeBase) GetReturnTypeDescriptor() model.TypeDescriptor {
return b.returnTypeDescriptor
}

func (b *BLangInvokableNodeBase) SetReturnTypeData(returnTypeData model.TypeData) {
b.ReturnTypeData = returnTypeData
func (b *BLangInvokableNodeBase) SetReturnTypeDescriptor(typeDescriptor model.TypeDescriptor) {
b.returnTypeDescriptor = typeDescriptor
}

func (b *BLangInvokableNodeBase) GetReturnTypeAnnotationAttachments() []model.AnnotationAttachmentNode {
Expand Down
2 changes: 1 addition & 1 deletion ast/binding_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "ballerina-lang-go/model"

type (
BLangBindingPatternBase struct {
BLangNodeBase
bLangNodeBase
}

BLangCaptureBindingPattern struct {
Expand Down
6 changes: 3 additions & 3 deletions ast/clauses.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ type TypeParamEntry struct {

type (
BLangCollectClause struct {
BLangNodeBase
bLangNodeBase
Expression model.ExpressionNode
NonGroupingKeys common.Set[string]
}
BLangDoClause struct {
BLangNodeBase
bLangNodeBase
Body *BLangBlockStmt
}
BLangOnFailClause struct {
BLangNodeBase
bLangNodeBase
Body *BLangBlockStmt
VariableDefinitionNode model.VariableDefinitionNode
VarType BType
Expand Down
Loading