-- $Source: /commtar/monoBANK/SQL_MC/parsdecl.dat,v $ -- $Revision: 1.50 $ $Date: 88/07/20 19:02:06 $ $Author: rac $ with Unchecked_Deallocation; with ParseTables; package Parse_Declarations is -- OVERVIEW -- -- -- package PT renames ParseTables; subtype Stack_Index is PT.ParserInteger range 0..200; -------------------------------------------------------------------- type Source_Position is record -- gives the line and column number in the source file Source_Line : positive := 1; Source_Col : positive := 1; end record; type Symbol_Record(Len : integer); type Symbol_Record_Ptr is access Symbol_Record; type Node_Kind_Enum is ( -- enumeration type for the kinds of nodes Empty_kind, Token_Kind, Cursor_Decl_Kind, Param_Decl_Kind, Proc_Decl_Kind, Set_Clause_Kind, Sort_Spec_Kind, Table_Ref_Kind, Table_Exp_Kind, -- enumeration values for the kinds of query expressions Union_Query_Kind, Parenthesized_Query_Kind, Query_Spec_Kind, -- enumeration type for the kinds of search conditions Binary_Search_Kind, Factor_Search_Kind, Comp_Search_Kind, Between_Search_Kind, Exists_Search_Kind, In_Search_Kind, Like_Search_Kind, Null_Search_Kind, Null_Search_Val_Kind, Parenthesized_Search_Kind, Quantified_Search_Kind, -- enumeration values for kinds of type_specs Char_Type_Kind, Integer_Type_Kind, Approx_Numeric_Type_Kind, Exact_Numeric_Type_Kind, -- enumeration values for the kinds of value expressions Null_Val_Kind, Subquery_Val_Kind, Binary_Val_Kind, Unary_Val_Kind, Column_Val_Kind, Parenthesized_Val_Kind, Set_Func_Val_Kind, Param_Spec_Kind, Char_Lit_Kind, Numeric_Lit_Kind, User_Spec_Kind ); subtype Query_Exp_Enum is Node_Kind_Enum range Union_Query_Kind..Query_Spec_Kind; subtype Search_Cond_Enum is Node_Kind_Enum range Binary_Search_Kind..Quantified_Search_Kind; subtype Type_Spec_Enum is Node_Kind_Enum range Char_Type_Kind..Exact_Numeric_Type_Kind; subtype Val_Exp_Enum is Node_Kind_Enum range Null_Val_Kind..User_Spec_Kind; type Node_Type(Node_Kind : Node_Kind_Enum := Empty_Kind); type Parse_Stack_Element is access Node_Type; type Node_Type( Node_Kind : Node_Kind_Enum := Empty_Kind ) is record -- the parse stack element may be a token from the lexer or -- a node built by Actions_Package case Node_Kind is when Empty_Kind => null; when others => -- all other node kinds have a source_pos and next_ptr next : Parse_Stack_Element := null; source_pos : Source_Position; case Node_Kind is when Token_Kind => symbol : Symbol_Record_Ptr; when Cursor_Decl_Kind => -- information needed to declare and open the cursor cursor_name : Parse_Stack_Element := null; cursor_opened_ptr : Parse_Stack_Element := null; -- flag indicating where this cursor was opened query_exp : Parse_Stack_Element := null; order_by_info : Parse_Stack_Element := null; -- pointer to the sort expression tree when Param_Decl_Kind => -- Info about a parameter declaration parameter_name : Parse_Stack_Element := null; parameter_type : Parse_Stack_Element := null; sqlcode_flag : boolean := FALSE; -- flag indicating whether this is the SQLCODE param indicator_flag : boolean := FALSE; -- flag indicating whether this is an indicator parm out_flag : boolean := False; -- whether this should be an Ada out parameter in_flag : boolean := False; -- whether this should be an Ada in parameter when Proc_Decl_Kind => -- Info for a declared procedure specification proc_name : Parse_Stack_Element := null; param_list : Parse_Stack_Element := null; -- linked list of declared parameters when Set_Clause_Kind => set_column_name : Parse_Stack_Element := null; -- Column value to be set set_val_exp : Parse_Stack_Element := null; -- Assigned value expr when Sort_Spec_Kind => -- The sort expression tree node contains the -- info to specify a sorting order for -- the given column specification. sort_column_name : Parse_Stack_Element := null; sort_column_num : Parse_Stack_Element := null; asc_flag : boolean := FALSE; desc_flag : boolean := FALSE; when Table_Ref_Kind => tab_authorization : Parse_Stack_Element := null; tab_name : Parse_Stack_Element := null; correlation_name : Parse_Stack_Element := null; -- if this table is part of a nested query or subquery, -- then this points to table or table list of the query, -- subquery, or statement that contains the nested item next_scope : Parse_Stack_Element := null; when Table_Exp_Kind => -- The table expression tree node contains the clauses -- to specify a table or grouped table that is derived -- FROM one or more named tables in the list of table -- references in the from_clause. This table can be -- further restricted by application of the search -- condition given in the WHERE_clause, the GROUP_by -- clause, and the search condition of the HAVING -- clause from_clause : Parse_Stack_Element := null; where_clause : Parse_Stack_Element := null; -- list of column specs group_clause : Parse_Stack_Element := null; having_clause : Parse_Stack_Element := null; when Union_Query_Kind => -- The union query expression: -- query_left_exp UNION [ALL] query_right_exp -- The children nodes are query expressions. union_all_flag : boolean := FALSE; query_left_exp : Parse_Stack_Element := null; query_right_exp : Parse_Stack_Element := null; when Query_Spec_Kind => -- The query specification (basic query expression) -- SELECT [ALL | DISTINCT] select_list table_exp -- The children nodes are the list of value expressions -- to be selected from the table expression. distinct_flag : boolean := FALSE; table_exp : Parse_Stack_Element := null; select_list : Parse_Stack_Element := null; when Parenthesized_Query_Kind => -- The parenthesized query expression. -- The child node is the query expression to be -- parenthesized. parenthesized_query_exp : Parse_Stack_Element := null; when Binary_Search_Kind => -- Includes "AND", "OR" expressions. -- The children nodes are search condition subtrees. search_left_exp : Parse_Stack_Element := null; search_right_exp : Parse_Stack_Element := null; binary_operator : Parse_Stack_Element := null; when Factor_Search_Kind => -- Includes "NOT" expressions. -- The children nodes are search condition subtrees. search_exp : Parse_Stack_Element := null; factor_operator : Parse_Stack_Element := null; when Comp_Search_Kind => -- Includes expressions with comparison operators: -- "=", "<>", ">", "<", "<=", ">=" -- The left child expression is a value expression. -- The right child expression can be a value expression -- tree or a subquery expression tree. comp_left_val : Parse_Stack_Element := null; comp_right_val : Parse_Stack_Element := null; comp_operator : Parse_Stack_Element := null; when Between_Search_Kind => -- BETWEEN predicate: -- between_val [NOT] BETWEEN -- between_low_val AND between_high_val -- All the children nodes are value expression trees. between_val : Parse_Stack_Element := null; between_low_val : Parse_Stack_Element := null; between_high_val : Parse_Stack_Element := null; not_between_exp : boolean := FALSE; when Exists_Search_Kind => -- EXISTS predicate. -- The child expression is a subquery expression tree. exists_subquery : Parse_Stack_Element := null; when In_Search_Kind => -- IN predicate. -- The children expressions are value expression trees. in_val : Parse_Stack_Element := null; in_val_list : Parse_Stack_Element := null; not_in_exp : boolean := FALSE; when Like_Search_Kind => -- LIKE predicate. -- like_column [NOT] LIKE like_pattern -- ESCAPE like_escape_char -- The like_column child node is a column specification -- value expression. -- The like_pattern and like_escape_char are value -- specification value expressions. like_column : Parse_Stack_Element := null; like_pattern : Parse_Stack_Element := null; like_escape_char : Parse_Stack_Element := null; not_like_exp : boolean := FALSE; when Null_Search_Kind => -- NULL predicate. -- The null_column child node is a column specification -- value expression. null_column : Parse_Stack_Element := null; not_null_exp : boolean := FALSE; when Null_Search_Val_Kind => null; when Parenthesized_Search_Kind => -- parenthesized search condition. -- The child node is the search condition expression -- to be parenthesized. parenthesized_exp : Parse_Stack_Element := null; when Quantified_Search_Kind => -- quantified predicate: -- quantified_val -- quantifier_string quantified_subquery -- The quantified_val child node is the left value -- expression to be compared. -- The quantified_subquery child node is the right -- value expression subquery tree to be compared. -- The quantifier_string is "ALL", "SOME" or "ANY". quantified_val : Parse_Stack_Element := null; quantifier_string : Parse_Stack_Element := null; quantified_subquery : Parse_Stack_Element := null; quantified_operator : Parse_Stack_Element := null; -- the following 4 kinds specify parameter type declarations when Char_Type_Kind => char_length : Symbol_Record_Ptr := null; when Exact_Numeric_Type_Kind => exact_type_name : Symbol_Record_Ptr := null; exact_precision : Symbol_Record_Ptr := null; exact_scale : Symbol_Record_Ptr := null; when Integer_Type_Kind => integer_type_name : Symbol_Record_Ptr := null; when Approx_Numeric_Type_Kind => approx_type_name : Symbol_Record_Ptr := null; approx_precision : Symbol_Record_Ptr := null; -- the rest are value exprs and all have a type spec when others => type_spec : Parse_Stack_Element; case Node_Kind is when Null_Val_Kind => null; when Subquery_Val_Kind => -- The subquery expression tree node contains the -- information to specify a multi-set of values derived -- from the result of a table expression. -- (SELECT [ALL | DISTINCT] subq_result_val subq_tab_exp) -- The child node subq_result_val specifies the resulting -- derived value expression. -- The child node subq_table_exp specifies the table -- expression from which the subquery values are derived. subq_result_val : Parse_Stack_Element := null; subq_table_exp : Parse_Stack_Element := null; all_subq_flag : boolean := FALSE; distinct_subq_flag : boolean := FALSE; when Binary_Val_Kind => -- Includes expressions with the "+", "-", "*", "/" -- binary operators. -- The children nodes are value expression subtrees. val_operator : Parse_Stack_Element := null; val_left_exp : Parse_Stack_Element := null; val_right_exp : Parse_Stack_Element := null; when Unary_Val_Kind => -- Includes expressions with the "+" & "-" -- unary operators. -- The children nodes are value expression subtrees. unary_operator : Parse_Stack_Element := null; unary_exp : Parse_Stack_Element := null; when Column_Val_Kind => -- The column specification includes the column_name -- and an optional column qualifier. col_name : Parse_Stack_Element := null; col_table : Parse_Stack_Element := null; col_authorization : Parse_Stack_Element := null; when Parenthesized_Val_Kind => -- The parenthesized value expression. -- The child node is the value expression to be -- parenthesized. parenthesized_val : Parse_Stack_Element := null; when Set_Func_Val_Kind => -- The set_function value expression specifies a -- value derived by the application of the function -- to an argument. -- The child node func_name is the name of the function: -- COUNT, AVG, MAX, MIN, SUM. -- For all the functions, the function argument is -- specified in func_arg. -- If "DISTINCT" is specified, this is passed to the -- equivalent SQL function, otherwise "ALL" is -- assumed (whether specified explicitly or implicitly -- by not being "distinct"). -- For the COUNT function, the argument is assumed to -- be "(*)" if "distinct" has not been specified. func_name : Parse_Stack_Element := null; func_arg : Parse_Stack_Element := null; distinct_func_flag : boolean := FALSE; when Param_Spec_Kind => -- For parameter value specifications, this includes the -- parameter name and its corresponding indicator -- parameter, if any. param_spec_name : Parse_Stack_Element := null; param_indicator : Parse_Stack_Element := null; when Char_Lit_Kind => char_literal : Symbol_Record_Ptr := null; when Numeric_Lit_Kind => num_literal : Symbol_Record_Ptr := null; when User_Spec_Kind => null; when others => null; end case; end case; end case; end record; Empty_PSE : constant Parse_Stack_Element(Empty_Kind) := null; subtype Token_Type is Parse_Stack_Element(Token_Kind); type Symbol_Record( -- The Symbol_record serves to hold the lexer-determined -- information about a given identifier/keyword. Len : integer -- discriminant value (string length) ) is record Next : Symbol_Record_Ptr := null; -- for chaining collisions in hashtable Name : string (1..Len); -- the actual normalized string text Keyword_flag : boolean := FALSE; Gram_Sym_Val : PT.GrammarSymbolRange := PT.Empty_TokenValue; -- grammar symbol value used by parser . Cursor : Parse_Stack_Element := null; -- points to node for first cursor declared with this id Proc : Parse_Stack_Element := null; -- points to node for first proc declared with this id Precision : Integer := 0; -- number of digits in mantissa of real literal end record; end Parse_Declarations; -- $Cprt start$ -- -- Copyright (C) 1988 by Intermetrics, Inc. -- -- This material may be used duplicated or disclosed by or for the -- U.S. Government pursuant to the copyright license under DAR clause -- 7-104.9(a) (May 1981). -- -- This project was sponsored by the STARS Foundation -- Naval Research Laboratory, Washington DC -- -- $Cprt end$