-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,28 @@ module Language.Drasil.Code.Imperative.ConceptMatch ( | |
chooseConcept, conceptToGOOL | ||
) where | ||
|
||
import Language.Drasil.Choices (Choices(..), CodeConcept(..), MatchedConceptMap) | ||
import Language.Drasil.Choices (Choices(..), CodeConcept(..), ConceptMatchMap, | ||
MatchedConceptMap, showChs) | ||
|
||
import GOOL.Drasil (SValue, OOProg, MathConstant(..)) | ||
|
||
import Prelude hiding (pi) | ||
import qualified Data.Map as Map (map) | ||
import Control.Monad.State (State) | ||
import Text.PrettyPrint.HughesPJ (Doc) | ||
import qualified Data.Map as Map (map, keys) | ||
import Control.Monad.State (State, modify) | ||
import Text.PrettyPrint.HughesPJ (Doc, text, ($$)) | ||
|
||
-- | Concretizes the ConceptMatchMap in Choices to a MatchedConceptMap. | ||
-- Currently we don't have any Choices that would prevent a CodeConcept from | ||
-- being mapped, so we just take the head of the list of CodeConcepts | ||
chooseConcept :: Choices -> State Doc MatchedConceptMap | ||
chooseConcept chs = sequence $ Map.map (chooseConcept' chs) (conceptMatch chs) | ||
where chooseConcept' _ [] = error $ "Empty list of CodeConcepts in the " ++ | ||
chooseConcept chs = sequence $ Map.map (chooseConcept' chs $ conceptMatch chs) (conceptMatch chs) | ||
where chooseConcept' :: Choices -> ConceptMatchMap-> [CodeConcept] -> State Doc CodeConcept | ||
chooseConcept' _ _ [] = error $ "Empty list of CodeConcepts in the " ++ | ||
"ConceptMatchMap" | ||
chooseConcept' _ cs = return $ head cs | ||
chooseConcept' _ cmm cs = do | ||
let uid = (head . Map.keys) cmm | ||
modify ($$ (text $ "Code Concept "++ uid ++" selected as " ++ showChs (head cs))) | ||
return $ head cs | ||
This comment has been minimized.
Sorry, something went wrong.
muhammadaliog3
Author
Collaborator
|
||
|
||
-- | Maps CodeConcepts to corresponding GOOL values | ||
conceptToGOOL :: (OOProg r) => CodeConcept -> SValue r | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import Language.Drasil.Data.ODEInfo (ODEInfo) | |
import Language.Drasil.Data.ODELibPckg (ODELibPckg(..)) | ||
|
||
import Control.Monad.State (State, modify) | ||
import Text.PrettyPrint.HughesPJ (Doc, ($$), text) | ||
import Text.PrettyPrint.HughesPJ (Doc, ($$), text, empty) | ||
|
||
type ODEGenInfo = (Maybe FilePath, [(Name, ExtLibState)], (Name,Version)) | ||
|
||
|
@@ -22,18 +22,25 @@ type ODEGenInfo = (Maybe FilePath, [(Name, ExtLibState)], (Name,Version)) | |
-- ODELibPckg by concretizing the ExternalLibraryCall with each of the ODEInfos | ||
chooseODELib :: Lang -> [ODELibPckg] -> [ODEInfo] -> State Doc ODEGenInfo | ||
chooseODELib _ _ [] = return (Nothing, [], ("","")) | ||
chooseODELib l olps odes = chooseODELib' olps | ||
where chooseODELib' :: [ODELibPckg] -> State Doc ODEGenInfo | ||
chooseODELib' [] = error $ "None of the chosen ODE libraries are " ++ | ||
chooseODELib l olps odes = chooseODELib' olps olps | ||
where chooseODELib' :: [ODELibPckg] -> [ODELibPckg]->State Doc ODEGenInfo | ||
chooseODELib' _ [] = error $ "None of the chosen ODE libraries are " ++ | ||
"compatible with " ++ show l | ||
chooseODELib' (o:os) = if l `elem` compatibleLangs o | ||
then return (libPath o, map (\ode -> (codeName $ odeDef ode, | ||
genExternalLibraryCall (libSpec o) $ libCall o ode)) odes, | ||
chooseODELib' initLib (o:os) = if l `elem` compatibleLangs o | ||
then do | ||
modify ($$ firstChoiceODELib initLib o) | ||
return (libPath o, map (\ode -> (codeName $ odeDef ode, | ||
genExternalLibraryCall (libSpec o) $ libCall o ode)) odes, | ||
This comment has been minimized.
Sorry, something went wrong.
muhammadaliog3
Author
Collaborator
|
||
(libName o, libVers o)) | ||
else modify ($$ incompatibleLib l o) >> chooseODELib' os | ||
else modify ($$ incompatibleLib l o) >> chooseODELib' initLib os | ||
|
||
-- Defines a design log message based on an incompatibility between the given | ||
-- Lang and chosen ODELibPckg. | ||
incompatibleLib :: Lang -> ODELibPckg -> Doc | ||
incompatibleLib lng lib = text $ "Language " ++ show lng ++ " is not " ++ | ||
"compatible with chosen library " ++ libName lib ++ ", trying next choice." | ||
"compatible with chosen library " ++ libName lib ++ ", trying next choice." | ||
|
||
firstChoiceODELib :: [ODELibPckg] -> ODELibPckg -> Doc | ||
firstChoiceODELib prefer olp = if libName (head prefer) == libName olp then | ||
text $ "Successfully " ++"selected first choice ODELibPckg "++ | ||
libName olp else empty |
I wasn't sure if I should omit both "ODE Libraries" and ODE's so I removed them both.