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

Namespaces cleanup #20

Merged
merged 14 commits into from
Sep 18, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions src/main/scala/io/septimalmind/baboon/BaboonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import distage.{DIKey, ModuleDef}
import io.septimalmind.baboon.BaboonCompiler.CompilerOptions
import io.septimalmind.baboon.parser.BaboonParser
import io.septimalmind.baboon.translator.BaboonAbstractTranslator
import io.septimalmind.baboon.translator.csharp.CSValue.CSPackageId
import io.septimalmind.baboon.translator.csharp.*
import io.septimalmind.baboon.translator.csharp.CSValue.CSPackageId
import io.septimalmind.baboon.typer.*
import io.septimalmind.baboon.typer.BaboonTyper.FullRawDefn
import io.septimalmind.baboon.typer.model.*
import io.septimalmind.baboon.typer.model.Scope.NestedScope
import io.septimalmind.baboon.util.BLogger
import io.septimalmind.baboon.validator.BaboonValidator
import izumi.fundamentals.collections.nonempty.NEList

import java.nio.file.Path

Expand Down Expand Up @@ -47,7 +46,7 @@ class BaboonModule(options: CompilerOptions,
.localDependencies(
List(
DIKey[Pkg],
DIKey[NEList[Scope[FullRawDefn]]],
DIKey[NestedScope[ExtendedRawDefn]],
DIKey[Map[TypeId, DomainMember]]
)
)
Expand All @@ -57,17 +56,6 @@ class BaboonModule(options: CompilerOptions,
.extractWith { (translator: BaboonTranslator) =>
translator
}
// make[LocalContext[Identity, BaboonTranslator]]
// .fromLocalContext(new ModuleDef {
// make[BaboonTranslator]
// }.running { (translator: BaboonTranslator) =>
// translator
// })
// .external(
// DIKey[Pkg],
// DIKey[NEList[Scope[FullRawDefn]]],
// DIKey[Map[TypeId, DomainMember]]
// )

makeSubcontext[IndividualConversionHandler]
.localDependencies(
Expand All @@ -87,20 +75,6 @@ class BaboonModule(options: CompilerOptions,
handler
}

// make[LocalContext[Identity, IndividualConversionHandler]]
// .fromLocalContext(new ModuleDef {
// make[IndividualConversionHandler]
// }.running { (handler: IndividualConversionHandler) =>
// handler
// })
// .external(
// DIKey[CSPackageId],
// DIKey[Version],
// DIKey.get[Domain].named("current"),
// DIKey.get[Domain].named("source"),
// DIKey.get[BaboonRuleset]
// )

many[CSCodecTranslator]
.add[CSNSJsonCodecGenerator]
.add[CSUEBACodecGenerator]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import fastparse.Parsed
import io.septimalmind.baboon.parser.BaboonParser
import io.septimalmind.baboon.parser.model.*
import io.septimalmind.baboon.translator.OutputFile
import io.septimalmind.baboon.typer.BaboonTyper
import io.septimalmind.baboon.typer.BaboonTyper.FullRawDefn
import io.septimalmind.baboon.typer.model.*
import izumi.fundamentals.collections.nonempty.NEList
import izumi.fundamentals.graphs.ToposortError
Expand Down Expand Up @@ -64,7 +62,7 @@ object BaboonIssue {

case class UnexpectedNonBuiltin(name: TypeName,
pkg: Pkg,
path: NEList[Scope[FullRawDefn]],
path: Scope[ExtendedRawDefn],
meta: RawNodeMeta)
extends TyperIssue

Expand Down Expand Up @@ -113,7 +111,8 @@ object BaboonIssue {
meta: RawNodeMeta
) extends TyperIssue

case class UnexpectedScoping(e: List[Scope[FullRawDefn]], meta: RawNodeMeta)
case class UnexpectedScoping(e: List[Scope[ExtendedRawDefn]],
meta: RawNodeMeta)
extends TyperIssue
with BaboonBug

Expand All @@ -128,7 +127,7 @@ object BaboonIssue {
case class BadTypeName(name: String, meta: RawNodeMeta) extends TyperIssue

case class BadInheritance(
bad: Map[TypeId.User, List[(Set[TypeId.User], BaboonTyper.ScopedDefn)]],
bad: Map[TypeId.User, List[(Set[TypeId.User], Scope[ExtendedRawDefn])]],
meta: RawNodeMeta
) extends TyperIssue
with BaboonBug
Expand All @@ -140,11 +139,11 @@ object BaboonIssue {
case class NameNotFound(pkg: Pkg, name: ScopedRef, meta: RawNodeMeta)
extends TyperIssue

case class UnexpectedScopeLookup(b: Scope[FullRawDefn], meta: RawNodeMeta)
case class UnexpectedScopeLookup(b: Scope[ExtendedRawDefn], meta: RawNodeMeta)
extends TyperIssue

case class NamSeqeNotFound(names: Seq[RawTypeName],
scope: Scope.SubScope[FullRawDefn],
scope: Scope.SubScope[ExtendedRawDefn],
meta: RawNodeMeta)
extends TyperIssue

Expand Down
49 changes: 20 additions & 29 deletions src/main/scala/io/septimalmind/baboon/typer/BaboonTranslator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@ package io.septimalmind.baboon.typer

import io.septimalmind.baboon.parser.model.*
import io.septimalmind.baboon.parser.model.issues.BaboonIssue
import io.septimalmind.baboon.parser.model.issues.BaboonIssue.{
MissingContractFields,
ScopedRefToNamespacedGeneric
}
import io.septimalmind.baboon.typer.BaboonTyper.{FullRawDefn, ScopedDefn}
import io.septimalmind.baboon.parser.model.issues.BaboonIssue.{MissingContractFields, ScopedRefToNamespacedGeneric}
import io.septimalmind.baboon.typer.model.*
import io.septimalmind.baboon.typer.model.Scope.NestedScope
import izumi.functional.IzEither.*
import izumi.fundamentals.collections.IzCollections.*
import izumi.fundamentals.collections.nonempty.NEList

class BaboonTranslator(pkg: Pkg,
path: NEList[Scope[FullRawDefn]],
defn: NestedScope[ExtendedRawDefn],
defined: Map[TypeId, DomainMember],
scopeSupport: ScopeSupport) {
def translate(
defn: ScopedDefn
): Either[NEList[BaboonIssue.TyperIssue], List[DomainMember]] = {
def translate()
: Either[NEList[BaboonIssue.TyperIssue], List[DomainMember]] = {

for {
rawDefn <- Right(defn.thisScope.defn)
rawDefn <- Right(defn.defn)
id <- scopeSupport.resolveUserTypeId(
rawDefn.defn.name,
path,
defn,
pkg,
rawDefn.defn.meta
)
members <- convertMember(id, rawDefn, defn.thisScope)
members <- convertMember(id, rawDefn, defn)
} yield {
members.toList
members
}
}

private def convertMember(id: TypeId.User,
defn: FullRawDefn,
thisScope: NestedScope[FullRawDefn],
defn: ExtendedRawDefn,
thisScope: NestedScope[ExtendedRawDefn],
): Either[NEList[BaboonIssue.TyperIssue], List[DomainMember.User]] = {
val root = defn.gcRoot
defn.defn match {
Expand Down Expand Up @@ -117,7 +112,7 @@ class BaboonTranslator(pkg: Pkg,
refMeta: RawNodeMeta
): Either[NEList[BaboonIssue.TyperIssue], Seq[Field]] = {
for {
id <- scopeSupport.resolveScopedRef(parent, path, pkg, refMeta)
id <- scopeSupport.resolveScopedRef(parent, defn, pkg, refMeta)
parentDef = defined(id)
out <- parentDef match {
case DomainMember.User(_, defn: Typedef.Dto, _) =>
Expand Down Expand Up @@ -158,7 +153,7 @@ class BaboonTranslator(pkg: Pkg,
refMeta: RawNodeMeta,
): Either[NEList[BaboonIssue.TyperIssue], List[ContractContent]] = {
for {
id <- scopeSupport.resolveScopedRef(c.contract.tpe, path, pkg, refMeta)
id <- scopeSupport.resolveScopedRef(c.contract.tpe, defn, pkg, refMeta)
content <- readContractContent(id, meta)
} yield {
content
Expand Down Expand Up @@ -256,11 +251,11 @@ class BaboonTranslator(pkg: Pkg,
_ <- finalFields
.map(m => (m.name.name.toLowerCase, m))
.toUniqueMap(e => NEList(BaboonIssue.NonUniqueFields(id, e, dto.meta)))
contractRefs = contracts.flatMap(_.refs).distinct.toList
contractRefs = contracts.flatMap(_.refs).distinct
} yield {
DomainMember.User(
isRoot,
produce(id, finalFields.toList, contractRefs),
produce(id, finalFields, contractRefs),
dto.meta
)
}
Expand All @@ -269,20 +264,15 @@ class BaboonTranslator(pkg: Pkg,
private def convertAdt(id: TypeId.User,
isRoot: Boolean,
adt: RawAdt,
thisScope: NestedScope[FullRawDefn],
thisScope: NestedScope[ExtendedRawDefn],
): Either[NEList[BaboonIssue.TyperIssue], NEList[DomainMember.User]] = {
for {
converted <- adt.members
.collect { case d: RawAdtMember => d }
.map(
member =>
scopeSupport
.resolveUserTypeId(
member.defn.name,
path :+ thisScope,
pkg,
member.meta
)
.resolveUserTypeId(member.defn.name, thisScope, pkg, member.meta)
)
.biSequence
nel <- NEList
Expand All @@ -291,7 +281,8 @@ class BaboonTranslator(pkg: Pkg,
contracts <- adt.contracts
.map(
ref =>
scopeSupport.resolveScopedRef(ref.contract.tpe, path, pkg, ref.meta)
scopeSupport
.resolveScopedRef(ref.contract.tpe, defn, pkg, ref.meta)
)
.biSequence
.map(_.toList)
Expand All @@ -316,7 +307,7 @@ class BaboonTranslator(pkg: Pkg,
tpe match {
case RawTypeRef.Simple(name, prefix) =>
for {
id <- scopeSupport.resolveTypeId(prefix, name, path, pkg, meta)
id <- scopeSupport.resolveTypeId(prefix, name, defn, pkg, meta)
asScalar <- id match {
case scalar: TypeId.Scalar =>
Right(scalar)
Expand All @@ -331,7 +322,7 @@ class BaboonTranslator(pkg: Pkg,
_ <- Either.ifThenFail(prefix.nonEmpty)(
NEList(ScopedRefToNamespacedGeneric(prefix, meta))
)
id <- scopeSupport.resolveTypeId(prefix, name, path, pkg, meta)
id <- scopeSupport.resolveTypeId(prefix, name, defn, pkg, meta)
asCollection <- id match {
case coll: TypeId.BuiltinCollection =>
Right(coll)
Expand Down
Loading