AnalysisLibrary.hs revision d5a225e7c58f6a8ab7b5acda22841784a19e261f
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederModule : $Header$
e47d29b522739fbf08aac80c6faa447dde113fbcChristian MaederDescription : static analysis of DOL documents and CASL specification libraries
11d6ec73ee5550e00cb56b221bdbeb709142e779Christian MaederCopyright : (c) Till Mossakowski, Uni Magdeburg 2002-2016
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
f3cd81f98592d1dbf301f48af31677a6a0cc666aChristian MaederMaintainer : till@informatik.uni-bremen.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederPortability : non-portable(Logic)
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederStatic analysis of DOL documents and CASL specification libraries
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder Follows the verification semantics sketched in Chap. IV:6
f3cd81f98592d1dbf301f48af31677a6a0cc666aChristian Maeder of the CASL Reference Manual.
f3cd81f98592d1dbf301f48af31677a6a0cc666aChristian Maeder Follows the semantics of DOL documents, DOL OMG standard, clause 10.2.1
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder ( anaLibFileOrGetEnv
0216a1580abf46ed8981f25e89d6fd99b2944ac2Christian Maeder , anaSourceFile
1c67beb3720d0b84d8d71ee2012166a09be81fbdChristian Maeder , anaViewDefn
e47d29b522739fbf08aac80c6faa447dde113fbcChristian Maederimport Static.ArchDiagram (emptyExtStUnitCtx)
35cd0c10843c2cdbbe29f00a2a5d7e5e4f2d0064Christian Maederimport Common.AS_Annotation hiding (isAxiom, isDef)
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maederimport qualified Common.Unlit as Unlit
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederimport qualified Data.Map as Map
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maederimport qualified Data.Set as Set
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maederimport Data.Either (lefts, rights)
18b709ce961d68328da768318dcc70067f066d86Christian Maeder-- a set of library names to check for cyclic imports
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maedertype LNS = Set.Set LibName
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder{- | parsing and static analysis for files
9c5b1136299d9052e4e995614a3a36a051a2682fChristian MaederParameters: logic graph, default logic, file name -}
0216a1580abf46ed8981f25e89d6fd99b2944ac2Christian MaederanaSourceFile :: LogicGraph -> HetcatsOpts -> LNS -> LibEnv -> DGraph
0216a1580abf46ed8981f25e89d6fd99b2944ac2Christian Maeder -> FilePath -> ResultT IO (LibName, LibEnv)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian MaederanaSourceFile = anaSource Nothing
9c5b1136299d9052e4e995614a3a36a051a2682fChristian MaederanaSource :: Maybe LibName -- ^ suggested library name
9c5b1136299d9052e4e995614a3a36a051a2682fChristian Maeder -> LogicGraph -> HetcatsOpts -> LNS -> LibEnv -> DGraph
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder -> FilePath -> ResultT IO (LibName, LibEnv)
0216a1580abf46ed8981f25e89d6fd99b2944ac2Christian MaederanaSource mln lg opts topLns libenv initDG origName = ResultT $ do
797f811e57952d59e73b8cd03b667eef276db972Christian Maeder let mName = useCatalogURL opts origName
11d6ec73ee5550e00cb56b221bdbeb709142e779Christian Maeder fname = fromMaybe mName $ stripPrefix "file://" mName
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian Maeder syn = case defSyntax opts of
797f811e57952d59e73b8cd03b667eef276db972Christian Maeder "" -> Nothing
797f811e57952d59e73b8cd03b667eef276db972Christian Maeder s -> Just $ simpleIdToIRI $ mkSimpleId s
18b709ce961d68328da768318dcc70067f066d86Christian Maeder lgraph = setSyntax syn $ setCurLogic (defLogic opts) lg
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski fname' <- getContentAndFileType opts fname
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian Maeder case fname' of
b52ad1aed6b1eb8b8416aaf100695f54ea59aea0Christian Maeder Left err -> return $ fail err
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder Right (mr, _, file, inputLit) ->
18b709ce961d68328da768318dcc70067f066d86Christian Maeder if any (`isSuffixOf` file) [envSuffix, prfSuffix] then
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder return . fail $ "no matching source file for '" ++ fname ++ "' found."
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder input = (if unlit opts then Unlit.unlit else id) inputLit
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder libStr = if isAbsolute fname
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder then convertFileToLibStr fname
3daa82a175c7cfabf22455aa77c4beda327404e4Christian Maeder else dropExtensions fname
e9490701e16d1e8abd995ef876d6f937da93b412Christian Maeder nLn = case mln of
e9490701e16d1e8abd995ef876d6f937da93b412Christian Maeder Nothing | useLibPos opts && not (checkUri fname) ->
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder Just $ emptyLibName libStr
d5c415f6373274fed04d83b9322891f3b82e9c26Christian Maeder fn2 = keepOrigClifName opts origName file
22fc8a1bd14dc53c5c7f482d2e0c04eb5ee4beb4Christian Maeder if runMMT opts then mmtRes fname else
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder if takeExtension file /= ('.' : show TwelfIn)
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder then runResultT $
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder anaString nLn lgraph opts topLns libenv initDG input fn2 mr
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder res <- anaTwelfFile opts file
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder return $ case res of
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder Nothing -> fail $ "failed to analyse file: " ++ file
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder Just (lname, lenv) -> return (lname, Map.union lenv libenv)
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder-- | parsing of input string (content of file)
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian MaederanaString :: Maybe LibName -- ^ suggested library name
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder -> LogicGraph -> HetcatsOpts -> LNS -> LibEnv -> DGraph -> String
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder -> FilePath -> Maybe String -- ^ mime-type of file
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder -> ResultT IO (LibName, LibEnv)
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian MaederanaString mln lgraph opts topLns libenv initDG input file mr = do
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder curDir <- lift getCurrentDirectory -- get full path for parser positions
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder let realFileName = curDir </> file
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder posFileName = case mln of
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder Just gLn | useLibPos opts -> libToFileName gLn
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder _ -> if checkUri file then file else realFileName
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian Maeder lift $ putIfVerbose opts 2 $ "Reading file " ++ file
11d6ec73ee5550e00cb56b221bdbeb709142e779Christian Maeder libdefns <- readLibDefn lgraph opts mr file posFileName input
9c5b1136299d9052e4e995614a3a36a051a2682fChristian Maeder when (null libdefns) . fail $ "failed to read contents of file: " ++ file
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder foldM (anaStringAux mln lgraph opts topLns initDG mr file posFileName)
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder (error "Static.AnalysisLibrary.anaString", libenv)
fcec1ffa4a95dbc47cf23f75e6843ceff93a925eChristian Maeder $ case analysis opts of
fcec1ffa4a95dbc47cf23f75e6843ceff93a925eChristian Maeder Skip -> [last libdefns]
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder _ -> libdefns
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder-- | calling static analysis for parsed library-defn
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian MaederanaStringAux :: Maybe LibName -- ^ suggested library name
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder -> LogicGraph -> HetcatsOpts -> LNS -> DGraph -> Maybe String -> FilePath
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder -> FilePath -> (LibName, LibEnv) -> LIB_DEFN -> ResultT IO (LibName, LibEnv)
fcec1ffa4a95dbc47cf23f75e6843ceff93a925eChristian MaederanaStringAux mln lgraph opts topLns initDG mt file posFileName (_, libenv)
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder (Lib_defn pln is' ps ans) = do
f454c20b6c126bea7d31d400cc8824b9ee8cc6eaChristian Maeder let pm = fst $ partPrefixes ans
b52ad1aed6b1eb8b8416aaf100695f54ea59aea0Christian Maeder expnd i = fromMaybe i $ expandCurie pm i
65835942d66905c377fa503e0d577df5aade58feChristian Maeder spNs = Set.unions . map (Set.map expnd . getSpecNames)
65835942d66905c377fa503e0d577df5aade58feChristian Maeder $ concatMap (getSpecDef . item) is'
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder declNs = Set.fromList . map expnd
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder $ concatMap (getDeclSpecNames . item) is'
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder missNames = Set.toList $ spNs Set.\\ declNs
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder unDecls = map (addDownload True) $ filter
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder (isNothing . (`lookupGlobalEnvDG` initDG)) missNames
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder is = unDecls ++ is'
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder spN = convertFileToLibStr file
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder noLibName = getLibId pln == nullIRI
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder nIs = case is of
fcec1ffa4a95dbc47cf23f75e6843ceff93a925eChristian Maeder [Annoted (Spec_defn spn gn as qs) rs [] []]
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder | noLibName && null (iriToStringUnsecure spn)
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder -> [Annoted (Spec_defn (simpleIdToIRI $ mkSimpleId spN)
case Map.lookup lnFinal lenv of
let lnstr = show ln in case find (== ln) $ Map.keys libenv of
(Set.insert ln topLns) libenv initDG (Just ln) $ libNameToFile ln
if Map.member ln2 p_libEnv then
(return $ Map.insert ln gc libenv)
, lgraph, Map.empty) (map item alibItems)
return (ln, newLD, globalAnnos dg2, Map.insert ln dg2 libenv')
| Set.notMember n spNs && null (getThSens locTh) && isGlobalDef lt
{ prefix_map = Map.singleton ""
if Map.member spn genv
, dg'' { globalEnv = Map.insert spn (SpecEntry
if Map.member asn genv
Map.insert aName diag
{ globalEnv = Map.insert asn
if Map.member usn genv
{ globalEnv = Map.insert usn (UnitEntry unitSig) genv },
if Map.member rn genv
{ globalEnv = Map.insert rn (ArchOrRefEntry False rsig) genv }
if Set.member ln topLns then
$ Set.map getLibId topLns
case Map.lookup ln' libenv' of
++ show ln' ++ " available: " ++ show (Map.keys libenv')
let is = Map.keys $ globalEnv dg'
additionalEo = Map.fromList $ map (\ o -> (o, fn)) origItems
eo' = Map.unionWith (\ _ p2 -> p2) eo additionalEo
-> Result (Set.Set (G_symbol, G_symbol))
[] -> return Set.empty
return $ Set.union sPs1 sPs2
([r1], [r2]) -> -- trace (show r1 ++ " " ++ show (Set.toList sys1)) $
( filter (\ sy -> matches l1 sy r1) $ Set.toList sys1
, filter (\ sy -> matches l2 sy r2) $ Set.toList sys2) of
Set.toList sys1
return $ Set.insert p ps
if Map.member vn genv
{ globalEnv = Map.insert vn (ViewOrStructEntry True vsig) genv }
let leftList = map fst $ Set.toList pairsSet
rightList = map snd $ Set.toList pairsSet
isTotal gsig sList = Set.fromList sList == symsOfGsign gsig
in Map.insert s1' s2' f
dg'' = dg' { globalEnv = Map.insert an (AlignEntry asign)
let s' = Set.insert csym s
f1' = Map.insert
f2' = Map.insert
$ Set.toList pairsSet
(empty_signature lid1) $ Set.toList pairedSymSet
return dg4 { globalEnv = Map.insert an (AlignEntry asign)
return dg7 {globalEnv = Map.insert an (AlignEntry asign)
if Map.member an $ globalEnv dg
phi1 = Map.empty
phi2 = Map.empty
let p1' = Map.union cmap1 p1
p2' = Map.union cmap2 p2
let p1' = Map.union eMap1 p1
p2' = Map.union eMap2 p2
rsMap1 = Map.mapKeys (symbol_to_raw lid1) $
Map.map (symbol_to_raw lid1) sMap1
rsMap2 = Map.mapKeys (symbol_to_raw lid1) $
Map.map (symbol_to_raw lid1) sMap2
$ case Map.lookup new genv of
genv1 = Map.insert new (ViewOrStructEntry b vsig1) genv
genv1 = Map.insert new (SpecEntry extsig1) genv