mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
found and temporarily solved the bug in LangGer gfcc generation
This commit is contained in:
@@ -177,16 +177,20 @@ reorder abs cg = M.MGrammar $
|
|||||||
finfo <- tree2list (M.jments mo)]
|
finfo <- tree2list (M.jments mo)]
|
||||||
predefADefs =
|
predefADefs =
|
||||||
[(IC c, AbsCat (Yes []) Nope) | c <- ["Float","Int","String"]]
|
[(IC c, AbsCat (Yes []) Nope) | c <- ["Float","Int","String"]]
|
||||||
aflags = nubFlags $ concat [M.flags mo | (_,mo) <- M.allModMod cg, M.isModAbs mo]
|
aflags = nubFlags $
|
||||||
|
concat [M.flags mo | (_,mo) <- M.allModMod cg, M.isModAbs mo]
|
||||||
|
|
||||||
cncs = sortIds [(lang, concr lang) | lang <- M.allConcretes cg abs]
|
cncs = sortIds [(lang, concr lang) | lang <- M.allConcretes cg abs]
|
||||||
concr la = (nubFlags (concat flags), sortIds (predefCDefs ++ concat jments)) where
|
concr la = (nubFlags flags,
|
||||||
(flags,jments) = unzip $ cdata la
|
sortIds (predefCDefs ++ jments)) where
|
||||||
cdata la = [(M.flags mo, tree2list (M.jments mo)) |
|
jments = Look.allOrigInfos cg la
|
||||||
(i,mo) <- mos, M.isModCnc mo, elem i (M.allExtends cg la)]
|
flags = concat [M.flags mo |
|
||||||
predefCDefs =
|
(i,mo) <- mos, M.isModCnc mo,
|
||||||
[(IC c, CncCat (Yes GM.defLinType) Nope Nope) | ---- lindef,printname
|
Just r <- [lookup i (M.allExtendSpecs cg la)]]
|
||||||
c <- ["Float","Int","String"]]
|
|
||||||
|
predefCDefs = [(IC c, CncCat (Yes GM.defLinType) Nope Nope) |
|
||||||
|
---- lindef,printname
|
||||||
|
c <- ["Float","Int","String"]]
|
||||||
|
|
||||||
sortIds = sortBy (\ (f,_) (g,_) -> compare f g)
|
sortIds = sortBy (\ (f,_) (g,_) -> compare f g)
|
||||||
nubFlags = nubBy (\ (Opt (f,_)) (Opt (g,_)) -> f == g)
|
nubFlags = nubBy (\ (Opt (f,_)) (Opt (g,_)) -> f == g)
|
||||||
@@ -301,7 +305,9 @@ paramValues cgr = (labels,untyps,typs) where
|
|||||||
Map.fromList $ concatMap Map.toList [typ | (_,typ) <- Map.toList typs]
|
Map.fromList $ concatMap Map.toList [typ | (_,typ) <- Map.toList typs]
|
||||||
lincats =
|
lincats =
|
||||||
[(IC cat,[(LIdent "s",GM.typeStr)]) | cat <- ["Int", "Float", "String"]] ++
|
[(IC cat,[(LIdent "s",GM.typeStr)]) | cat <- ["Int", "Float", "String"]] ++
|
||||||
[(cat,(unlockTyp ls)) | (_,(cat,CncCat (Yes (RecType ls)) _ _)) <- jments]
|
reverse ---- TODO: really those lincats that are reached
|
||||||
|
---- reverse is enough to expel overshadowed ones...
|
||||||
|
[(cat,(unlockTyp ls)) | (_,(cat,CncCat (Yes (RecType ls)) _ _)) <- jments]
|
||||||
labels = Map.fromList $ concat
|
labels = Map.fromList $ concat
|
||||||
[((cat,[lab]),(typ,i)):
|
[((cat,[lab]),(typ,i)):
|
||||||
[((cat,[lab,lab2]),(ty,j)) |
|
[((cat,[lab,lab2]),(ty,j)) |
|
||||||
@@ -400,13 +406,7 @@ term2term cgr env@(labels,untyps,typs) tr = case tr of
|
|||||||
|
|
||||||
valNum tr = maybe (tryPerm tr) EInt $ Map.lookup tr untyps
|
valNum tr = maybe (tryPerm tr) EInt $ Map.lookup tr untyps
|
||||||
where
|
where
|
||||||
tryPerm tr = case tr of
|
tryPerm tr = valNumFV $ tryVar tr
|
||||||
{- obsolete ----
|
|
||||||
R rs -> case Map.lookup (R rs) untyps of
|
|
||||||
Just v -> EInt v
|
|
||||||
_ -> valNumFV $ tryVar tr
|
|
||||||
-}
|
|
||||||
_ -> valNumFV $ tryVar tr
|
|
||||||
tryVar tr = case GM.appForm tr of
|
tryVar tr = case GM.appForm tr of
|
||||||
(c@(QC _ _), ts) -> [GM.mkApp c ts' | ts' <- combinations (map tryVar ts)]
|
(c@(QC _ _), ts) -> [GM.mkApp c ts' | ts' <- combinations (map tryVar ts)]
|
||||||
(FV ts,_) -> ts
|
(FV ts,_) -> ts
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import GF.GFCC.AbsGFCC
|
|||||||
import Data.Map
|
import Data.Map
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
-- linearization and computation of concrete GFCC Terms
|
-- linearization and computation of concrete GFCC Terms
|
||||||
|
|
||||||
linearize :: GFCC -> CId -> Exp -> String
|
linearize :: GFCC -> CId -> Exp -> String
|
||||||
@@ -53,7 +55,7 @@ compute mcfg lang args = comp where
|
|||||||
look = lookOper mcfg lang
|
look = lookOper mcfg lang
|
||||||
|
|
||||||
idx xs i = if i > length xs - 1
|
idx xs i = if i > length xs - 1
|
||||||
then error
|
then trace
|
||||||
("too large " ++ show i ++ " for\n" ++ unlines (lmap prt xs) ++ "\n") TM
|
("too large " ++ show i ++ " for\n" ++ unlines (lmap prt xs) ++ "\n") TM
|
||||||
else xs !! i
|
else xs !! i
|
||||||
|
|
||||||
@@ -71,7 +73,7 @@ compute mcfg lang args = comp where
|
|||||||
C i -> i
|
C i -> i
|
||||||
RP p _ -> getIndex p ---- DEPREC
|
RP p _ -> getIndex p ---- DEPREC
|
||||||
TM -> 0 -- default value for parameter
|
TM -> 0 -- default value for parameter
|
||||||
_ -> error ("ERROR in grammar compiler: index from " ++ show t) 0
|
_ -> trace ("ERROR in grammar compiler: index from " ++ show t) 666
|
||||||
|
|
||||||
getField t i = case t of
|
getField t i = case t of
|
||||||
R rs -> idx rs i
|
R rs -> idx rs i
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ module GF.Grammar.Lookup (
|
|||||||
lookupFirstTag,
|
lookupFirstTag,
|
||||||
lookupValueIndex,
|
lookupValueIndex,
|
||||||
lookupIndexValue,
|
lookupIndexValue,
|
||||||
|
allOrigInfos,
|
||||||
allParamValues,
|
allParamValues,
|
||||||
lookupAbsDef,
|
lookupAbsDef,
|
||||||
lookupLincat,
|
lookupLincat,
|
||||||
@@ -121,6 +122,17 @@ lookupOverload gr m c = do
|
|||||||
_ -> Bad $ prt c +++ "is not an overloaded operation"
|
_ -> Bad $ prt c +++ "is not an overloaded operation"
|
||||||
_ -> Bad $ prt m +++ "is not a resource"
|
_ -> Bad $ prt m +++ "is not a resource"
|
||||||
|
|
||||||
|
lookupOrigInfo :: SourceGrammar -> Ident -> Ident -> Err Info
|
||||||
|
lookupOrigInfo gr m c = do
|
||||||
|
mi <- lookupModule gr m
|
||||||
|
case mi of
|
||||||
|
ModMod mo -> do
|
||||||
|
info <- lookupIdentInfo mo c
|
||||||
|
case info of
|
||||||
|
AnyInd _ n -> lookupOrigInfo gr n c
|
||||||
|
i -> return i
|
||||||
|
_ -> Bad $ prt m +++ "is not run-time module"
|
||||||
|
|
||||||
lookupParams :: SourceGrammar -> Ident -> Ident -> Err ([Param],Maybe PValues)
|
lookupParams :: SourceGrammar -> Ident -> Ident -> Err ([Param],Maybe PValues)
|
||||||
lookupParams gr = look True where
|
lookupParams gr = look True where
|
||||||
look isTop m c = do
|
look isTop m c = do
|
||||||
@@ -169,6 +181,14 @@ lookupIndexValue gr ty i = do
|
|||||||
then return $ ts !! i
|
then return $ ts !! i
|
||||||
else Bad $ "no value for index" +++ show i +++ "in" +++ prt ty
|
else Bad $ "no value for index" +++ show i +++ "in" +++ prt ty
|
||||||
|
|
||||||
|
allOrigInfos :: SourceGrammar -> Ident -> [(Ident,Info)]
|
||||||
|
allOrigInfos gr m = errVal [] $ do
|
||||||
|
mi <- lookupModule gr m
|
||||||
|
case mi of
|
||||||
|
ModMod mo -> return [(c,i) | (c,_) <- tree2list (jments mo), Ok i <- [look c]]
|
||||||
|
where
|
||||||
|
look = lookupOrigInfo gr m
|
||||||
|
|
||||||
allParamValues :: SourceGrammar -> Type -> Err [Term]
|
allParamValues :: SourceGrammar -> Type -> Err [Term]
|
||||||
allParamValues cnc ptyp = case ptyp of
|
allParamValues cnc ptyp = case ptyp of
|
||||||
App (Q (IC "Predef") (IC "Ints")) (EInt n) ->
|
App (Q (IC "Predef") (IC "Ints")) (EInt n) ->
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ module GF.Infra.Modules (
|
|||||||
oSimple, oQualif,
|
oSimple, oQualif,
|
||||||
ModuleStatus(..),
|
ModuleStatus(..),
|
||||||
openedModule, allOpens, depPathModule, allDepsModule, partOfGrammar,
|
openedModule, allOpens, depPathModule, allDepsModule, partOfGrammar,
|
||||||
allExtends, allExtendsPlus, allExtensions, searchPathModule, addModule,
|
allExtends, allExtendSpecs, allExtendsPlus, allExtensions,
|
||||||
|
searchPathModule, addModule,
|
||||||
emptyMGrammar, emptyModInfo, emptyModule,
|
emptyMGrammar, emptyModInfo, emptyModule,
|
||||||
IdentM(..),
|
IdentM(..),
|
||||||
typeOfModule, abstractOfConcrete, abstractModOfConcrete,
|
typeOfModule, abstractOfConcrete, abstractModOfConcrete,
|
||||||
@@ -216,8 +217,7 @@ partOfGrammar gr (i,m) = MGrammar [mo | mo@(j,_) <- mods, elem j modsFor]
|
|||||||
---- ModWith n i os -> i : map openedModule os ++ partOfGrammar (ModMod n) ----
|
---- ModWith n i os -> i : map openedModule os ++ partOfGrammar (ModMod n) ----
|
||||||
_ -> [i]
|
_ -> [i]
|
||||||
|
|
||||||
|
-- | all modules that a module extends, directly or indirectly, without restricts
|
||||||
-- | all modules that a module extends, directly or indirectly
|
|
||||||
allExtends :: (Show i,Ord i) => MGrammar i f a -> i -> [i]
|
allExtends :: (Show i,Ord i) => MGrammar i f a -> i -> [i]
|
||||||
allExtends gr i = case lookupModule gr i of
|
allExtends gr i = case lookupModule gr i of
|
||||||
Ok (ModMod m) -> case extends m of
|
Ok (ModMod m) -> case extends m of
|
||||||
@@ -225,6 +225,14 @@ allExtends gr i = case lookupModule gr i of
|
|||||||
is -> i : concatMap (allExtends gr) is
|
is -> i : concatMap (allExtends gr) is
|
||||||
_ -> []
|
_ -> []
|
||||||
|
|
||||||
|
-- | all modules that a module extends, directly or indirectly, with restricts
|
||||||
|
allExtendSpecs :: (Show i,Ord i) => MGrammar i f a -> i -> [(i,MInclude i)]
|
||||||
|
allExtendSpecs gr i = case lookupModule gr i of
|
||||||
|
Ok (ModMod m) -> case extend m of
|
||||||
|
[] -> [(i,MIAll)]
|
||||||
|
is -> (i,MIAll) : concatMap (allExtendSpecs gr . fst) is
|
||||||
|
_ -> []
|
||||||
|
|
||||||
-- | this plus that an instance extends its interface
|
-- | this plus that an instance extends its interface
|
||||||
allExtendsPlus :: (Show i,Ord i) => MGrammar i f a -> i -> [i]
|
allExtendsPlus :: (Show i,Ord i) => MGrammar i f a -> i -> [i]
|
||||||
allExtendsPlus gr i = case lookupModule gr i of
|
allExtendsPlus gr i = case lookupModule gr i of
|
||||||
|
|||||||
Reference in New Issue
Block a user