Skip to content

Commit

Permalink
Merge pull request #168 from AttilaMihaly/direct-mapping-to-scala
Browse files Browse the repository at this point in the history
Reverted function to method mapping. #163
  • Loading branch information
AttilaMihaly committed Oct 2, 2020
2 parents 55f2757 + af37fd6 commit a0c3ae0
Showing 1 changed file with 2 additions and 93 deletions.
95 changes: 2 additions & 93 deletions src/Morphir/Scala/Backend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,7 @@ mapModuleDefinition opt distribution currentPackagePath currentModulePath access
)
|> List.singleton
, extends = []
, members =
mapFunctionsToMethods currentPackagePath
currentModulePath
typeName
(accessControlledModuleDef.value.values
|> Dict.toList
|> List.map
(\( valueName, valueDef ) ->
( valueName, valueDef.value |> Value.definitionToSpecification )
)
)
, members = []
}
)
]
Expand Down Expand Up @@ -289,17 +279,7 @@ mapCustomTypeDefinition currentPackagePath currentModulePath moduleDef typeName
, name = typeName |> Name.toTitleCase
, typeArgs = typeParams |> List.map (Name.toTitleCase >> Scala.TypeVar)
, extends = []
, members =
mapFunctionsToMethods currentPackagePath
currentModulePath
typeName
(moduleDef.values
|> Dict.toList
|> List.map
(\( valueName, valueDef ) ->
( valueName, valueDef.value |> Value.definitionToSpecification )
)
)
, members = []
}
]
, accessControlledCtors.value
Expand Down Expand Up @@ -328,77 +308,6 @@ mapCustomTypeDefinition currentPackagePath currentModulePath moduleDef typeName
sealedTraitHierarchy |> List.map Scala.MemberTypeDecl


{-| Collect functions where the last input argument is this type and turn them into methods on the type.
-}
mapFunctionsToMethods : Path -> Path -> Name -> List ( Name, Value.Specification ta ) -> List Scala.MemberDecl
mapFunctionsToMethods currentPackageName currentModuleName currentTypeName valueSpecifications =
valueSpecifications
|> List.filterMap
(\( valueName, valueSpec ) ->
case List.reverse valueSpec.inputs of
[] ->
-- if this is a value (function with no arguments) then we don't turn it into a method
Nothing

( _, lastInputType ) :: restOfInputsReversed ->
-- if the last argument type of the function is
let
inputs =
List.reverse restOfInputsReversed
in
case lastInputType of
Type.Reference _ fQName [] ->
if fQName == FQName currentPackageName currentModuleName currentTypeName then
Just
(FunctionDecl
{ modifiers = []
, name = valueName |> Name.toCamelCase
, typeArgs = []
, args =
if List.isEmpty inputs then
[]

else
[ inputs
|> List.map
(\( argName, argType ) ->
{ modifiers = []
, tpe = mapType argType
, name = argName |> Name.toCamelCase
, defaultValue = Nothing
}
)
]
, returnType =
Just (mapType valueSpec.output)
, body =
let
( path, name ) =
mapFQNameToPathAndName (FQName currentPackageName currentModuleName valueName)
in
Just
(Scala.Apply (Scala.Ref path (name |> Name.toCamelCase))
(List.append
(inputs
|> List.map
(\( argName, _ ) ->
Scala.ArgValue Nothing (Scala.Variable (argName |> Name.toCamelCase))
)
)
[ Scala.ArgValue Nothing Scala.This ]
)
)
}
)

else
Nothing

_ ->
Nothing
)


mapType : Type a -> Scala.Type
mapType tpe =
case tpe of
Expand Down

0 comments on commit a0c3ae0

Please sign in to comment.