packages feed

helium-1.8: src/Helium/ModuleSystem/ExtractImportDecls.ag

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

INCLUDE "UHA_Syntax.ag"
INCLUDE "ToCoreName.ag"

imports{
import Helium.Syntax.UHA_Syntax
import Helium.Syntax.UHA_Utils
import Lvm.Common.Id
import qualified Lvm.Core.Expr as Core
import qualified Lvm.Core.Module as Core
import Helium.Utils.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"