packages feed

hssqlppp-0.2.0: Database/HsSqlPpp/AstInternals/TypeChecking/Statements.ag

{-
Copyright 2009 Jake Wheat

This file contains the general code for statements and statement
lists, and includes the ag files for various flavours of statement.

The attributes and sem statements in this file are for chaining the
cat updates as we progress through a statement list, and for producing
the resultant cat after we've checked a whole ast, this can be used
e.g. to type check multiple files in a row which depend on eachother.

-}

-- cat updates syn attr is used by each statement to report
-- what changes it makes to the catalog, we use this to update
-- the cat to feed into the next statement

ATTR Statement [||catUpdates : {[CatalogUpdate]}
                  libUpdates : {[LocalIdentifierBindingsUpdate]}]


ATTR StatementList [catUpdates : {[CatalogUpdate]}
                    libUpdates : {[LocalIdentifierBindingsUpdate]}||]


--producedcat is used to pass the final updated cat out
ATTR StatementList Root [|| producedCat : Catalog
                            producedLib : LocalIdentifierBindings]

ATTR Statement [inProducedCat: Catalog||]

SEM StatementList
    | Cons Nil
        --newcat is the catalog passed into the head statement
        --updated with any catalog changes that that statement has made
        loc.newCat = fromRight @lhs.cat $ updateCatalog @lhs.cat @lhs.catUpdates
        loc.newLib = fromRight @lhs.lib $ updateBindings @lhs.lib @lhs.cat @lhs.libUpdates
    | Cons
        hd.cat = @loc.newCat
        tl.cat = @loc.newCat
        hd.lib = @loc.newLib
        tl.lib = @loc.newLib
        --produced cat is used to chain the final updated catalog from the last
        --element of the list and pass it back up the list so in can be pushed up
        -- to the root element and sent out from there
        lhs.producedCat = @tl.producedCat
        lhs.producedLib = @tl.producedLib
        --this is probably a bit inefficient: it creates a new catalog from scratch
        --on each statement instead of chaining on the last updated cat
        tl.catUpdates = @hd.catUpdates
        tl.libUpdates = @hd.libUpdates
    | Nil
        lhs.producedCat = @loc.newCat
        lhs.producedLib = @loc.newLib

SEM Statement
    | SelectStatement Insert Update Delete CreateView CreateDomain CreateLanguage
      CreateFunction CreateType CreateTable CreateTableAs Return Assignment
      ForSelectStatement ForIntegerStatement DropFunction
        loc.tpe : {Either [TypeError] Type}
        lhs.annotatedTree = annTypesAndErrors @loc.backTree
                              (tpeToT @loc.tpe)
                              (getErrors @loc.tpe)
                              $ Just (map StatementTypeA @loc.statementType ++
                                      [CatUpdates @loc.catUpdates])
        loc.catUpdates : {[CatalogUpdate]}
        lhs.catUpdates = @loc.catUpdates
        lhs.libUpdates = @loc.libUpdates
    | Insert Update Delete CreateView CreateDomain
      CreateFunction CreateType CreateTable CreateTableAs Return
      Assignment ForSelectStatement ForIntegerStatement Set CreateLanguage
      Notify CreateSequence AlterSequence DropFunction
        loc.libUpdates = []

SEM StatementList
    | Cons hd.inProducedCat = @tl.producedCat


SEM Root
    | Root statements.catUpdates = []
           statements.libUpdates = []

SEM Statement
    | CaseStatement ContinueStatement Copy CopyData
      DropSomething Execute ExecuteInto
      If NullStatement Perform Raise ReturnNext ReturnQuery Truncate
      WhileStatement Set Notify CreateSequence
      AlterSequence AlterTable CreateTrigger
        lhs.catUpdates = []
        lhs.libUpdates = []

SEM ExpressionListStatementListPair
    | Tuple
        x2.catUpdates = []
        x2.libUpdates = []
SEM ExpressionStatementListPair
    | Tuple
        x2.catUpdates = []
        x2.libUpdates = []
SEM FnBody
    | PlpgsqlFnBody SqlFnBody
        sts.catUpdates = []
        sts.libUpdates = []
SEM Statement
    | CaseStatement If
        els.catUpdates = []
        els.libUpdates = []
SEM Statement
    | ForIntegerStatement ForSelectStatement WhileStatement
        sts.catUpdates = []
        sts.libUpdates = []



INCLUDE "TypeChecking/SelectStatement.ag"
INCLUDE "TypeChecking/Dml.ag"
INCLUDE "TypeChecking/CreateTable.ag"
INCLUDE "TypeChecking/MiscCreates.ag"
INCLUDE "TypeChecking/CreateFunction.ag"
INCLUDE "TypeChecking/Drops.ag"
INCLUDE "TypeChecking/Plpgsql.ag"