Skip to content

Commit

Permalink
cs bullshit
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Oct 20, 2023
1 parent 49350c0 commit ebe443a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/io/septimalmind/baboon/BaboonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.septimalmind.baboon
import distage.{DIKey, ModuleDef}
import io.septimalmind.baboon.BaboonCompiler.CompilerOptions
import io.septimalmind.baboon.parser.BaboonParser
import io.septimalmind.baboon.translator.AbstractBaboonTranslator
import io.septimalmind.baboon.translator.BaboonAbstractTranslator
import io.septimalmind.baboon.translator.csharp.CSValue.CSPackageId
import io.septimalmind.baboon.translator.csharp.{
CSBaboonTranslator,
Expand Down Expand Up @@ -38,7 +38,7 @@ class BaboonModule(options: CompilerOptions) extends ModuleDef {

make[BLogger].from[BLogger.BLoggerImpl]

many[AbstractBaboonTranslator].ref[CSBaboonTranslator]
many[BaboonAbstractTranslator].ref[CSBaboonTranslator]
make[CSBaboonTranslator]
make[CSDefnTools].from[CSDefnTools.CSDefnToolsImpl]
make[CSDefnTranslator].from[CSDefnTranslator.CSDefnTranslatorImpl]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import izumi.fundamentals.collections.nonempty.NEList
case class Sources(files: Map[String, String])
case class DomainSources(domain: Domain, files: Map[String, String])

trait AbstractBaboonTranslator {
trait BaboonAbstractTranslator {
def translate(
family: BaboonFamily
): Either[NEList[BaboonIssue.TranslationIssue], Sources]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.septimalmind.baboon.RuntimeGenOpt
import io.septimalmind.baboon.parser.model.issues.BaboonIssue
import io.septimalmind.baboon.translator.csharp.CSBaboonTranslator.*
import io.septimalmind.baboon.translator.csharp.CSValue.{CSPackageId, CSType}
import io.septimalmind.baboon.translator.{AbstractBaboonTranslator, Sources}
import io.septimalmind.baboon.translator.{BaboonAbstractTranslator, Sources}
import io.septimalmind.baboon.typer.model.*
import izumi.distage.LocalContext
import izumi.functional.IzEither.*
Expand All @@ -23,7 +23,7 @@ class CSBaboonTranslator(
options: CompilerOptions,
codecs: Set[CSCodecTranslator],
tools: CSDefnTools,
) extends AbstractBaboonTranslator {
) extends BaboonAbstractTranslator {

type Out[T] = Either[NEList[BaboonIssue.TranslationIssue], T]

Expand Down Expand Up @@ -184,12 +184,17 @@ class CSBaboonTranslator(
| public $csTpe TypeTo();
|}
|
|public interface IBaboonGeneratedConversion : IConversion
|{
| public IBaboonGenerated Convert<C>(C? context, AbstractBaboonConversions conversions, IBaboonGenerated from);
|}
|
|public interface IDynamicConversion<To> : IConversion
|{
| public To Convert<C>(C? context, AbstractBaboonConversions conversions, dynamic from);
|}
|
|public abstract class AbstractConversion<From, To> : IDynamicConversion<To>
|public abstract class AbstractConversion<From, To> : IDynamicConversion<To>, IBaboonGeneratedConversion
|{
| public abstract To Convert<C>(C? context, AbstractBaboonConversions conversions, From from);
|
Expand All @@ -198,6 +203,23 @@ class CSBaboonTranslator(
| return Convert<C>(context, conversions, (From)from);
| }
|
| IBaboonGenerated IBaboonGeneratedConversion.Convert<C>(C? context, $abstractBaboonConversions conversions, $iBaboonGenerated from) where C : default
| {
| if (from is not From fr)
| {
| throw new Exception(
| $"Can't use IBaboonGeneratedConversion interface when from is not of type {typeof(To).FullName}");
| }
| var res = Convert(context, conversions, fr);
|
| if (res is not $iBaboonGenerated bg)
| {
| throw new $csArgumentException(
| $$"Can't use IBaboonGeneratedConversion interface for non IBaboonGenerated return type To = {typeof(To).FullName}");
| }
| return bg;
| }
|
| public $csTpe TypeFrom() {
| return typeof(From);
| }
Expand Down Expand Up @@ -332,13 +354,13 @@ class CSBaboonTranslator(
|
| public IBaboonGenerated ConvertWithContext<C>(C? c, IBaboonGenerated from, IConversion conversion)
| {
| var tconv = ((IDynamicConversion<IBaboonGenerated>)conversion);
| var tconv = (IBaboonGeneratedConversion)conversion;
| return tconv.Convert<C>(c, this, from);
| }
|
| public IBaboonGenerated Convert(IBaboonGenerated from, IConversion conversion)
| {
| var tconv = ((IDynamicConversion<IBaboonGenerated>)conversion);
| var tconv = (IBaboonGeneratedConversion)conversion;
| return tconv.Convert<Object>(null, this, from);
| }
|
Expand Down

0 comments on commit ebe443a

Please sign in to comment.