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
6 changes: 3 additions & 3 deletions parser/src/main/kotlin/tools/samt/parser/Nodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RecordFieldNode(
val name: IdentifierNode,
val type: ExpressionNode,
override val annotations: List<AnnotationNode>,
) : Node, AnnotatedNode
) : AnnotatedNode

class EnumDeclarationNode(
override val location: Location,
Expand All @@ -81,7 +81,7 @@ class ServiceDeclarationNode(
override val annotations: List<AnnotationNode>,
) : NamedDeclarationNode, AnnotatedNode

sealed interface OperationNode : Node, AnnotatedNode {
sealed interface OperationNode : AnnotatedNode {
val name: IdentifierNode
val parameters: List<OperationParameterNode>
}
Expand All @@ -91,7 +91,7 @@ class OperationParameterNode(
val name: IdentifierNode,
val type: ExpressionNode,
override val annotations: List<AnnotationNode>,
) : Node, AnnotatedNode
) : AnnotatedNode

class RequestResponseOperationNode(
override val location: Location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ internal class ConstraintBuilder(private val controller: DiagnosticController) {
private fun validateConstraintMatches(constraint: ResolvedTypeReference.Constraint, baseType: Type): Boolean {
return when (constraint) {
is ResolvedTypeReference.Constraint.Pattern -> baseType is StringType
is ResolvedTypeReference.Constraint.Range -> baseType is NumberType
is ResolvedTypeReference.Constraint.Range -> baseType is LiteralNumberType
is ResolvedTypeReference.Constraint.Size -> baseType is StringType || baseType is ListType || baseType is MapType
is ResolvedTypeReference.Constraint.Value -> when (constraint.value) {
is String -> baseType is StringType
is Number -> baseType is NumberType
is Number -> baseType is LiteralNumberType
is Boolean -> baseType is BooleanType
else -> false
}
Expand All @@ -260,7 +260,7 @@ internal class ConstraintBuilder(private val controller: DiagnosticController) {

val applicableConstraints = when (baseType) {
is StringType -> "pattern, size or value"
is NumberType -> "range or value"
is LiteralNumberType -> "range or value"
is BooleanType -> "value"
is ListType -> "size"
is MapType -> "size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class SemanticModelAnnotationProcessor(
return UserMetadata(descriptions, deprecations)
}

private fun Package.getAnnotatedElements(): List<Annotated> = buildList {
private fun Package.getAnnotatedElements(): List<UserAnnotated> = buildList {
this@getAnnotatedElements.allSubPackages.forEach {
addAll(it.records)
it.records.flatMapTo(this, RecordType::fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ internal class SemanticModelPreProcessor(private val controller: DiagnosticContr
)
}
parentPackage += RecordType(
name = statement.name.name,
fields = fields,
declaration = statement
)
Expand All @@ -82,7 +81,7 @@ internal class SemanticModelPreProcessor(private val controller: DiagnosticContr
reportDuplicateDeclaration(parentPackage, statement)
reportDuplicates(statement.values, "Enum value") { it }
val values = statement.values.map { it.name }
parentPackage += EnumType(statement.name.name, values, statement)
parentPackage += EnumType(values, statement)
}

is ServiceDeclarationNode -> {
Expand Down Expand Up @@ -124,7 +123,7 @@ internal class SemanticModelPreProcessor(private val controller: DiagnosticContr
}
}
}
parentPackage += ServiceType(statement.name.name, operations, statement)
parentPackage += ServiceType(operations, statement)
}

is ProviderDeclarationNode -> {
Expand All @@ -140,7 +139,7 @@ internal class SemanticModelPreProcessor(private val controller: DiagnosticContr
name = statement.transport.protocolName.name,
configuration = statement.transport.configuration
)
parentPackage += ProviderType(statement.name.name, implements, transport, statement)
parentPackage += ProviderType(implements, transport, statement)
}

is ConsumerDeclarationNode -> {
Expand All @@ -160,7 +159,6 @@ internal class SemanticModelPreProcessor(private val controller: DiagnosticContr
is TypeAliasNode -> {
reportDuplicateDeclaration(parentPackage, statement)
parentPackage += AliasType(
name = statement.name.name,
aliasedType = UnresolvedTypeReference(statement.type),
declaration = statement
)
Expand Down
58 changes: 24 additions & 34 deletions semantic/src/main/kotlin/tools/samt/semantic/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,44 @@ object UnknownType : Type {

sealed interface LiteralType : Type

sealed interface NumberType : Type
sealed interface LiteralNumberType : LiteralType

/**
* 32-bit whole number, signed
*/
object IntType : LiteralType, NumberType {
object IntType : LiteralNumberType {
override val humanReadableName: String
get() = "Int"
}

/**
* 64-bit whole number, signed
*/
object LongType : LiteralType, NumberType {
object LongType : LiteralNumberType {
override val humanReadableName: String
get() = "Long"
}

/**
* 32-bit floating point number, signed
*/
object FloatType : LiteralType, NumberType {
object FloatType : LiteralNumberType {
override val humanReadableName: String
get() = "Float"
}

/**
* 64-bit floating point number, signed
*/
object DoubleType : LiteralType, NumberType {
object DoubleType : LiteralNumberType {
override val humanReadableName: String
get() = "Double"
}

/**
* Arbitrary precision number, fixed amount of digits before and after decimal point
*/
object DecimalType : LiteralType, NumberType {
object DecimalType : LiteralNumberType {
override val humanReadableName: String
get() = "Decimal"
}
Expand Down Expand Up @@ -110,79 +110,74 @@ object DurationType : LiteralType {
get() = "Duration"
}

sealed interface CompoundType : Type
sealed interface UserDeclaredNamedType : UserDeclared, Type {
override val humanReadableName: String get() = name
override val declaration: NamedDeclarationNode
val name: String get() = declaration.name.name
}

sealed interface UserDeclared {
val declaration: Node
}

sealed interface Annotated : UserDeclared {
sealed interface UserAnnotated : UserDeclared {
override val declaration: AnnotatedNode
val annotations: List<AnnotationNode> get() = declaration.annotations
}

data class ListType(
val elementType: TypeReference,
val node: GenericSpecializationNode,
) : CompoundType {
) : Type {
override val humanReadableName: String = "List<${elementType.humanReadableName}>"
}

data class MapType(
val keyType: TypeReference,
val valueType: TypeReference,
val node: GenericSpecializationNode,
) : CompoundType {
) : Type {
override val humanReadableName: String = "Map<${keyType.humanReadableName}, ${valueType.humanReadableName}>"
}

class AliasType(
val name: String,
/** The type this alias stands for, could be another alias */
var aliasedType: TypeReference,
/** The fully resolved type, will not contain any type aliases anymore, just the underlying merged type */
var fullyResolvedType: ResolvedTypeReference? = null,
override val declaration: TypeAliasNode,
) : CompoundType, Annotated {
override val humanReadableName: String = name
}
) : UserDeclaredNamedType, UserAnnotated

class RecordType(
val name: String,
val fields: List<Field>,
override val declaration: RecordDeclarationNode,
) : CompoundType, Annotated {
) : UserDeclaredNamedType, UserAnnotated {
class Field(
val name: String,
var type: TypeReference,
override val declaration: RecordFieldNode,
) : Annotated

override val humanReadableName: String = name
) : UserAnnotated
}

class EnumType(
val name: String,
val values: List<String>,
override val declaration: EnumDeclarationNode,
) : CompoundType, Annotated {
override val humanReadableName: String = name
}
) : UserDeclaredNamedType, UserAnnotated

class ServiceType(
val name: String,
val operations: List<Operation>,
override val declaration: ServiceDeclarationNode,
) : CompoundType, Annotated {
sealed interface Operation : Annotated {
) : UserDeclaredNamedType, UserAnnotated {
sealed interface Operation : UserAnnotated {
val name: String
val parameters: List<Parameter>
override val declaration: OperationNode

class Parameter(
val name: String,
var type: TypeReference,
override val declaration: OperationParameterNode,
): UserDeclared, Annotated
) : UserDeclared, UserAnnotated
}

class RequestResponseOperation(
Expand All @@ -199,16 +194,13 @@ class ServiceType(
override val parameters: List<Operation.Parameter>,
override val declaration: OnewayOperationNode,
) : Operation

override val humanReadableName: String = name
}

class ProviderType(
val name: String,
val implements: List<Implements>,
@Suppress("unused") val transport: Transport,
override val declaration: ProviderDeclarationNode,
) : CompoundType, UserDeclared {
) : UserDeclaredNamedType {
class Implements(
var service: TypeReference,
var operations: List<ServiceType.Operation>,
Expand All @@ -219,15 +211,13 @@ class ProviderType(
val name: String,
@Suppress("unused") val configuration: Any?,
)

override val humanReadableName: String = name
}

class ConsumerType(
var provider: TypeReference,
var uses: List<Uses>,
override val declaration: ConsumerDeclarationNode,
) : CompoundType, UserDeclared {
) : Type, UserDeclared {
class Uses(
var service: TypeReference,
var operations: List<ServiceType.Operation>,
Expand Down