-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,36 +51,60 @@ fromInternal [email protected] {..} = do | |
itab' = Internal.insertInternalModule itab md | ||
table :: Internal.InfoTable | ||
table = Internal.computeCombinedInfoTable itab' | ||
moduleNames :: [Name] | ||
moduleNames = map (^. Internal.internalModuleName) (HashMap.elems (itab' ^. Internal.internalModuleTable)) | ||
comments :: [Comment] | ||
comments = allComments (Internal.getInternalTypedResultComments res) | ||
go onlyTypes comments table _resultModule | ||
go onlyTypes comments moduleNames table _resultModule | ||
where | ||
go :: Bool -> [Comment] -> Internal.InfoTable -> Internal.Module -> Sem r Result | ||
go onlyTypes comments tab md = | ||
go :: Bool -> [Comment] -> [Name] -> Internal.InfoTable -> Internal.Module -> Sem r Result | ||
go onlyTypes comments moduleNames tab md = | ||
return $ | ||
Result | ||
{ _resultTheory = goModule onlyTypes tab md, | ||
{ _resultTheory = goModule onlyTypes moduleNames tab md, | ||
_resultModuleId = md ^. Internal.moduleId, | ||
_resultComments = filter (\c -> c ^. commentInterval . intervalFile == file) comments | ||
} | ||
where | ||
file = getLoc md ^. intervalFile | ||
|
||
goModule :: Bool -> Internal.InfoTable -> Internal.Module -> Theory | ||
goModule onlyTypes infoTable Internal.Module {..} = | ||
goModule :: Bool -> [Name] -> Internal.InfoTable -> Internal.Module -> Theory | ||
goModule onlyTypes moduleNames infoTable Internal.Module {..} = | ||
Theory | ||
{ _theoryName = overNameText toIsabelleName _moduleName, | ||
_theoryImports = map (^. Internal.importModuleName) (_moduleBody ^. Internal.moduleImports), | ||
{ _theoryName = lookupTheoryName _moduleName, | ||
_theoryImports = | ||
map lookupTheoryName $ | ||
map (^. Internal.importModuleName) (_moduleBody ^. Internal.moduleImports), | ||
_theoryStatements = case _modulePragmas ^. pragmasIsabelleIgnore of | ||
Just (PragmaIsabelleIgnore True) -> [] | ||
_ -> concatMap goMutualBlock (_moduleBody ^. Internal.moduleStatements) | ||
} | ||
where | ||
toIsabelleName :: Text -> Text | ||
toIsabelleName name = case reverse $ filter (/= "") $ T.splitOn "." name of | ||
toIsabelleTheoryName :: Text -> Text | ||
toIsabelleTheoryName name = case reverse $ filter (/= "") $ T.splitOn "." name of | ||
h : _ -> h | ||
[] -> impossible | ||
|
||
moduleNameMap :: HashMap Name Name | ||
moduleNameMap = | ||
HashMap.fromList $ concatMap mapGroup groups | ||
where | ||
groups = groupSortOn (toIsabelleTheoryName . (^. nameText)) moduleNames | ||
|
||
mapGroup :: NonEmpty Name -> [(Name, Name)] | ||
mapGroup (name :| names) = | ||
(name, overNameText toIsabelleTheoryName name) : names' | ||
where | ||
names' = | ||
zipWith | ||
(\n (idx :: Int) -> (n, overNameText (<> "_" <> show idx) n)) | ||
names | ||
[0 ..] | ||
|
||
lookupTheoryName :: Name -> Name | ||
lookupTheoryName name = | ||
fromMaybe (error "lookupTheoryName") $ HashMap.lookup name moduleNameMap | ||
|
||
isTypeDef :: Statement -> Bool | ||
isTypeDef = \case | ||
StmtDefinition {} -> False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters