5255N/ADescription : Static analysis for the Edinburgh Logical Framework
5255N/ACopyright : (c) Kristina Sojakova, DFKI Bremen 2010
5255N/AMaintainer : k.sojakova@jacobs-university.de
5255N/AnumSuf :: String -> Int -> String
5255N/AnumSuf s i = s ++ "_" ++ show i
5255N/AwrapInSig :: String -> String -> String
5255N/AwrapInSig sn cont = "%sig " ++ sn ++ " = {\n" ++ cont ++ "}."
5255N/AwrapInIncl :: String -> String
5255N/AwrapInIncl sn = "%include " ++ sn ++ " %open."
5255N/AgetSentenceAnnos :: [Annoted BASIC_ITEM] ->
5255N/A-----------------------------------------------------------------
-----------------------------------------------------------------
basicAnalysis :: (BASIC_SPEC, Sign, GlobalAnnos) ->
Result (BASIC_SPEC, ExtSign Sign Symbol, [Named EXP])
basicAnalysis (bs, initsig, _) =
then error "Structuring for LF nyi."
else do makeTwelfFile gen_file gen_sig bs
(sig,sen) <- getSigSen gen_file
let syms = getAllSymbols sig
let fs = makeNamedFormulas sen
return $ Just $ (bs, ExtSign sig syms, fs)
makeNamedFormulas :: Sign -> [Named EXP]
makeNamedFormulas (Sign _ _ ds) =
makeNamedFormula :: DEF -> Named EXP
makeNamedFormula (Def s t _) =
let isImplies = or $ map isImplies annos
isImplied = or $ map isImplied annos
isTheorem = isImplies || isImplied
-- converts the basic spec into a Twelf file
makeTwelfFile :: FilePath -> String -> BASIC_SPEC -> IO ()
makeTwelfFile file sn (Basic_spec items) = do
let sig = wrapInSig sn $ printSigItems items
let sen = wrapInSig (senSuf sn) $
wrapInIncl sn ++ printSenItems items
writeFile file $ sig ++ "\n\n" ++ sen
printSigItems :: [Annoted BASIC_ITEM] -> String
Annoted (Decl d) _ _ _ -> d ++ ".\n" ++ printSigItems is
printSenItems :: [Annoted BASIC_ITEM] -> String
printSenItems items = printSenItemsH 0 items
printSenItemsH :: Int -> [Annoted BASIC_ITEM] -> String
printSenItemsH num (i:is) =
Annoted (Form f) _ _ _ ->
nam = if null label then numSuf gen_ax num else label
num' = if null label then num + 1 else num
in nam ++ " : " ++ f ++ ".\n" ++ printSenItemsH num' is
_ -> printSenItemsH num is
-- retrieves the signatures containing basic spec declarations and sentences
getSigSen :: FilePath -> String -> IO (Sign,Sign)
(_,_,(sigmap,_)) <- buildGraph file (emptyLibEnv,emptyGrMap)
let base = dropExtension file