ATTR Module [ | | coreImportDecls : { [(Core.CoreDecl,[Id])] } ] 

INCLUDE "../syntax/UHA_Syntax.ag"
INCLUDE "../codegeneration/ToCoreName.ag"

imports{
import UHA_Syntax
import UHA_Utils
import Id
import qualified Core
import Utils (internalError)
}
  
ATTR Body ImportDeclarations ImportDeclaration
   [ | | coreImportDecls USE { ++ } { [] } : { [(Core.CoreDecl,[Id])] } ]  
    
SEM ImportDeclaration
    | Import 
        lhs.coreImportDecls = [(@loc.importDecls,@loc.hidings)]
        loc.importDecls =
            
          if @qualified || not @asname.isNothing then
              internalError "ExtractImportDecls.ag" "ImportDeclaration.Import" "qualified and as-imports not supported yet"
          else
              Core.DeclImport
                  { Core.declName = idFromName @name.self
                  , Core.declAccess =
                      Core.Imported
                          { Core.accessPublic   = False -- private
                          , Core.importModule   = idFromName @name.self
                          , Core.importName     = dummyId
                          , Core.importKind     = Core.DeclKindModule
                          , Core.importMajorVer = 0
                          , Core.importMinorVer = 0
                          }
                  , Core.declCustoms = []
                  }
                  
        loc.hidings = @importspecification.imps

SEM MaybeImportSpecification [ | | imps : {[Id]}]
    | Nothing              lhs.imps     = []
    | Just                 lhs.imps     = @importspecification.imps

SEM ImportSpecification
    | Import               lhs.imps     =
        if not @hiding then
            internalError "ExtractImportDecls.ag" "ImportSpecification.Import" "import lists are not supported"
        else
            @imports.imps

ATTR ImportSpecification Imports Import [ | | imps USE { ++ } { [] } : {[Id]} ]

SEM Import
    | Variable                lhs.imps = [idFromName @name.self]
    | TypeOrClass             lhs.imps = internalError "ExtractImportDecls.ag" "ImportSpecification.Import" "only variables can be hidden"
    | TypeOrClassComplete     lhs.imps = internalError "ExtractImportDecls.ag" "ImportSpecification.Import" "only variables can be hidden"
