{- 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 env updates as we progress through a statement list, and for producing the resultant env 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. -} -- env updates syn attr is used by each statement to report -- what changes it makes to the catalog, we use this to update -- the env to feed into the next statement ATTR Statement [||envUpdates : {[EnvironmentUpdate]} libUpdates : {[LocalIdentifierBindingsUpdate]}] ATTR StatementList [envUpdates : {[EnvironmentUpdate]} libUpdates : {[LocalIdentifierBindingsUpdate]}||] --producedenv is used to pass the final updated env out ATTR StatementList Root [|| producedEnv : Environment producedLib : LocalIdentifierBindings] ATTR Statement [inProducedEnv: Environment||] SEM StatementList | Cons Nil --newenv is the environment passed into the head statement --updated with any catalog changes that that statement has made loc.newEnv = fromRight @lhs.env $ updateEnvironment @lhs.env @lhs.envUpdates loc.newLib = fromRight @lhs.lib $ updateBindings @lhs.lib @lhs.env @lhs.libUpdates | Cons hd.env = @loc.newEnv tl.env = @loc.newEnv hd.lib = @loc.newLib tl.lib = @loc.newLib --produced env is used to chain the final updated environment 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.producedEnv = @tl.producedEnv lhs.producedLib = @tl.producedLib --this is probably a bit inefficient: it creates a new environment from scratch --on each statement instead of chaining on the last updated env tl.envUpdates = @hd.envUpdates tl.libUpdates = @hd.libUpdates | Nil lhs.producedEnv = @loc.newEnv lhs.producedLib = @loc.newLib SEM Statement | SelectStatement Insert Update Delete CreateView CreateDomain 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 ++ [EnvUpdates @loc.envUpdates]) loc.envUpdates : {[EnvironmentUpdate]} lhs.envUpdates = @loc.envUpdates 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.inProducedEnv = @tl.producedEnv SEM Root | Root statements.envUpdates = [] statements.libUpdates = [] SEM Statement | CaseStatement ContinueStatement Copy CopyData DropSomething Execute ExecuteInto If NullStatement Perform Raise ReturnNext ReturnQuery Truncate WhileStatement Set CreateLanguage Notify CreateSequence AlterSequence AlterTable CreateTrigger lhs.envUpdates = [] lhs.libUpdates = [] SEM ExpressionListStatementListPair | Tuple x2.envUpdates = [] x2.libUpdates = [] SEM ExpressionStatementListPair | Tuple x2.envUpdates = [] x2.libUpdates = [] SEM FnBody | PlpgsqlFnBody SqlFnBody sts.envUpdates = [] sts.libUpdates = [] SEM Statement | CaseStatement If els.envUpdates = [] els.libUpdates = [] SEM Statement | ForIntegerStatement ForSelectStatement WhileStatement sts.envUpdates = [] 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"