Skip to content
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
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 Location = diagnostics.Location

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 @@ type (
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 @@ type (
}

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 @@ type (
}

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

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

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 @@ type (
isLegacyMockingMap map[string]bool
}
BLangXMLNS struct {
BLangNodeBase
bLangNodeBase
namespaceURI BLangExpression
prefix *BLangIdentifier
CompUnit *BLangIdentifier
Expand All @@ -390,7 +387,7 @@ type (
BLangXMLNS
}
BLangMarkdownDocumentation struct {
BLangNodeBase
bLangNodeBase
DocumentationLines []BLangMarkdownDocumentationLine
Parameters []BLangMarkdownParameterDocumentation
References []BLangMarkdownReferenceDocumentation
Expand All @@ -399,7 +396,7 @@ type (
DeprecatedParametersDocumentation *BLangMarkDownDeprecatedParametersDocumentation
}
BLangMarkdownReferenceDocumentation struct {
BLangNodeBase
bLangNodeBase
Qualifier string
TypeName string
Identifier string
Expand All @@ -409,7 +406,10 @@ type (
}

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 @@ type (
}

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 @@ type (
}

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

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 @@ func (n *BLangVariableBase) SetSymbol(symbolRef model.SymbolRef) {
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 @@ func (this *BLangAnnotation) SetName(name model.IdentifierNode) {
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
}

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
}

func (this *BLangAnnotation) GetFlags() common.Set[model.Flag] {
Expand Down Expand Up @@ -1382,12 +1380,12 @@ func (b *BLangInvokableNodeBase) HasBody() bool {
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
23 changes: 15 additions & 8 deletions ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type (
Parameters []BLangMarkdownParameterDocumentation
}
BLangExpressionBase struct {
BLangNodeBase
bLangNodeBase
// ImpConversionExpr *BLangTypeConversionExpr
ExpectedType BType
}
Expand Down Expand Up @@ -184,6 +184,7 @@ type (
}
BLangLiteral struct {
BLangExpressionBase
valueType BType
Value any
OriginalValue string
IsConstant bool
Expand Down Expand Up @@ -253,7 +254,7 @@ type (

BLangTypedescExpr struct {
BLangExpressionBase
TypeData model.TypeData
typeDescriptor model.TypeDescriptor
}

BLangUnaryExpr struct {
Expand Down Expand Up @@ -394,14 +395,20 @@ func (this *BLangTypedescExpr) GetKind() model.NodeKind {
return model.NodeKind_TYPEDESC_EXPRESSION
}

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

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

func (this *BLangLiteral) GetValueType() BType {
return this.valueType
}

func (this *BLangLiteral) SetValueType(bt BType) {
this.valueType = bt
}

func (this *BLangAlternateWorkerReceive) GetKind() model.NodeKind {
Expand Down
2 changes: 1 addition & 1 deletion ast/match_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "ballerina-lang-go/model"

type (
BLangMatchPatternBase struct {
BLangNodeBase
bLangNodeBase

MatchExpr BLangExpression
MatchGuardIsAvailable bool
Expand Down
Loading