forked from GitHub/gf-core
checking name conflicts; some RGs don't work now
This commit is contained in:
@@ -39,6 +39,7 @@ import GF.Compile.Extend
|
|||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Data.List (nub)
|
||||||
|
|
||||||
renameGrammar :: SourceGrammar -> Err SourceGrammar
|
renameGrammar :: SourceGrammar -> Err SourceGrammar
|
||||||
renameGrammar g = liftM (MGrammar . reverse) $ foldM renameModule [] (modules g)
|
renameGrammar g = liftM (MGrammar . reverse) $ foldM renameModule [] (modules g)
|
||||||
@@ -69,12 +70,22 @@ renameIdentTerm :: Status -> Term -> Err Term
|
|||||||
renameIdentTerm env@(act,imps) t =
|
renameIdentTerm env@(act,imps) t =
|
||||||
errIn ("atomic term" +++ prt t +++ "given" +++ unwords (map (prt . fst) qualifs)) $
|
errIn ("atomic term" +++ prt t +++ "given" +++ unwords (map (prt . fst) qualifs)) $
|
||||||
case t of
|
case t of
|
||||||
Vr c -> do
|
Vr c -> case lookupTree prt c act of
|
||||||
f <- err (predefAbs c) return $ lookupTreeMany prt opens c
|
Ok f -> return $ f c
|
||||||
return $ f c
|
_ -> case lookupTreeManyAll prt opens c of
|
||||||
Cn c -> do
|
[f] -> return $ f c
|
||||||
f <- lookupTreeMany prt opens c
|
[] -> predefAbs c ("constant not found:" +++ prt c)
|
||||||
return $ f c
|
fs -> case nub [f c | f <- fs] of
|
||||||
|
[tr] -> return tr
|
||||||
|
ts -> Bad $ "conflicting imports:" +++ unwords (map prt ts)
|
||||||
|
Cn c -> case lookupTree prt c act of
|
||||||
|
Ok f -> return $ f c
|
||||||
|
_ -> case lookupTreeManyAll prt opens c of
|
||||||
|
[f] -> return $ f c
|
||||||
|
[] -> Bad ("constant not found:" +++ prt c)
|
||||||
|
fs -> case nub [f c | f <- fs] of
|
||||||
|
[tr] -> return tr
|
||||||
|
ts -> Bad $ "conflicting imports:" +++ unwords (map prt ts)
|
||||||
Q m' c | m' == cPredef {- && isInPredefined c -} -> return t
|
Q m' c | m' == cPredef {- && isInPredefined c -} -> return t
|
||||||
Q m' c -> do
|
Q m' c -> do
|
||||||
m <- lookupErr m' qualifs
|
m <- lookupErr m' qualifs
|
||||||
@@ -87,15 +98,15 @@ renameIdentTerm env@(act,imps) t =
|
|||||||
return $ f c
|
return $ f c
|
||||||
_ -> return t
|
_ -> return t
|
||||||
where
|
where
|
||||||
opens = act : [st | (OSimple _ _,st) <- imps]
|
opens = [st | (OSimple _ _,st) <- imps]
|
||||||
qualifs = [(m, st) | (OQualif _ m _, st) <- imps] ++
|
qualifs = [(m, st) | (OQualif _ m _, st) <- imps] ++
|
||||||
[(m, st) | (OSimple _ m, st) <- imps] -- qualif is always possible
|
[(m, st) | (OSimple _ m, st) <- imps] -- qualif is always possible
|
||||||
|
|
||||||
-- this facility is mainly for BWC with GF1: you need not import PredefAbs
|
-- this facility is mainly for BWC with GF1: you need not import PredefAbs
|
||||||
predefAbs c s = case c of
|
predefAbs c s = case c of
|
||||||
IC "Int" -> return $ const $ Q cPredefAbs cInt
|
IC "Int" -> return $ Q cPredefAbs cInt
|
||||||
IC "Float" -> return $ const $ Q cPredefAbs cFloat
|
IC "Float" -> return $ Q cPredefAbs cFloat
|
||||||
IC "String" -> return $ const $ Q cPredefAbs cString
|
IC "String" -> return $ Q cPredefAbs cString
|
||||||
_ -> Bad s
|
_ -> Bad s
|
||||||
|
|
||||||
--- | would it make sense to optimize this by inlining?
|
--- | would it make sense to optimize this by inlining?
|
||||||
@@ -124,7 +135,7 @@ buildStatus :: SourceGrammar -> Ident -> SourceModInfo -> Err Status
|
|||||||
buildStatus gr c mo = let mo' = self2status c mo in case mo of
|
buildStatus gr c mo = let mo' = self2status c mo in case mo of
|
||||||
ModMod m -> do
|
ModMod m -> do
|
||||||
let gr1 = MGrammar $ (c,mo) : modules gr
|
let gr1 = MGrammar $ (c,mo) : modules gr
|
||||||
ops = [OSimple OQNormal e | e <- allExtendsPlus gr1 c] ++ allOpens m
|
ops = [OSimple OQNormal e | e <- allExtends gr1 c] ++ allOpens m
|
||||||
mods <- mapM (lookupModule gr1 . openedModule) ops
|
mods <- mapM (lookupModule gr1 . openedModule) ops
|
||||||
let sts = map modInfo2status $ zip ops mods
|
let sts = map modInfo2status $ zip ops mods
|
||||||
return $ if isModCnc m
|
return $ if isModCnc m
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ module GF.Data.Operations (-- * misc functions
|
|||||||
|
|
||||||
-- * binary search trees; now with FiniteMap
|
-- * binary search trees; now with FiniteMap
|
||||||
BinTree, emptyBinTree, isInBinTree, justLookupTree,
|
BinTree, emptyBinTree, isInBinTree, justLookupTree,
|
||||||
lookupTree, lookupTreeMany, updateTree,
|
lookupTree, lookupTreeMany, lookupTreeManyAll, updateTree,
|
||||||
buildTree, filterBinTree,
|
buildTree, filterBinTree,
|
||||||
sorted2tree, mapTree, mapMTree, tree2list,
|
sorted2tree, mapTree, mapMTree, tree2list,
|
||||||
|
|
||||||
@@ -318,6 +318,12 @@ lookupTreeMany pr (t:ts) x = case lookupTree pr x t of
|
|||||||
_ -> lookupTreeMany pr ts x
|
_ -> lookupTreeMany pr ts x
|
||||||
lookupTreeMany pr [] x = Bad $ "failed to find" +++ pr x
|
lookupTreeMany pr [] x = Bad $ "failed to find" +++ pr x
|
||||||
|
|
||||||
|
lookupTreeManyAll :: Ord a => (a -> String) -> [BinTree a b] -> a -> [b]
|
||||||
|
lookupTreeManyAll pr (t:ts) x = case lookupTree pr x t of
|
||||||
|
Ok v -> v : lookupTreeManyAll pr ts x
|
||||||
|
_ -> lookupTreeManyAll pr ts x
|
||||||
|
lookupTreeManyAll pr [] x = []
|
||||||
|
|
||||||
-- | destructive update
|
-- | destructive update
|
||||||
updateTree :: (Ord a) => (a,b) -> BinTree a b -> BinTree a b
|
updateTree :: (Ord a) => (a,b) -> BinTree a b -> BinTree a b
|
||||||
-- updateTree (a,b) tr = addToFM tr a b
|
-- updateTree (a,b) tr = addToFM tr a b
|
||||||
|
|||||||
Reference in New Issue
Block a user