!standard 3.9 07-05-18 SI99-0024-1/03 !class amendment 06-11-12 !status work item 06-11-12 !status received 06-11-12 !priority High !difficulty Hard !subject Provide a semantic model in addition to existing syntactic model !summary ASIS currently provides a model that is closely based on the syntax. This SI proposes to add a set of packages that provide a canonicalized semantic model, which captures more of the work already done by (the front end of) the compiler. !problem The current ASIS model is very tied to the syntactic structure of the program library. However, there are times when it is more efficient to use a more abstract, semantic model. This SI proposes such a model. In one sense, it may be thought of as defining a "symbol table" for the program library. !proposal SEMANTIC VS. STRUCTURAL MODEL This SI proposes that an additional set of packages be provided as part of ASIS that represent a semantic model of the program library. As currently defined, ASIS provides a structural model of the library, with a relatively limited set of semantic queries that allow references to be traversed to their definitions, and allow traversal between declarations and bodies, or partial and full declarations. The existing approach provides all the information inherent in the original source program, and as such, ensures that other tools can do all the same work that the compiler could do. However, the existing approach doesn't capture much of that work in a useful form, and instead essentially requires that it be performed by every tool. In this SI we propose to capture more of the work already performed by the compiler, and along the way attempt to canonicalize the information so that the many special cases inherent in the syntactic structure of the program library are reduced to a smaller number of semantic concepts that nevertheless still cover the entire realm of possibilities. One way to think about what we are doing is providing a "symbol table" for the program library. GUIDES TO CREATING SEMANTIC MODEL To guide our efforts, we need to decide on what level of information we want to capture. In particular, there is the information that is implementation independent, and simply captures the language-defined static semantic properties of the program. This we might call the "language-level" semantic information. At the next level down, there is information that reflects some of the decisions made by the implementation which might be useful to a tool, such as the layout of a record, or the linkname of a global object. This we might call the "representation-level" information. Finally, as we get to the "object-code level," there is the information about the range of code addresses associated with each line of source, and the layout of the stack frame for particular subprograms. For this initial effort, we propose to focus on the "language-level" implementation-independent semantic properties. We envisage that additional packages might be defined as some later point, or by particular ASIS implementations, that provide the lower level "representation" or "object-code" information. The second guide to our efforts is a list of the typical kinds of applications we imagine being built using this high-level semantic model. One kind of application would be an interpreter, both an interpreter of existing code, and an interpreter of simple expressions or statements typed into the program interactively after establishing a particular context. For example, one might invoke a tool that would essentially elaborate some part of the program library, and then allow the user to type in small test scripts in an Ada-like language which would be interpreted in the context of the given part of the library, as a kind of interactive unit testing capability. Another type of application would be one that attempted to determine the range of values that each variable within the program could have at run-time, based on an "abstract interpretation" or a data and control flow analysis of its logic. This is similar to an interpreter, except that it does not construct an entire run-time context, but rather an abstraction of it that allows run-time properties to be approximated, generally through an iterative algorithm that stabilizes on a fixed-point approximation. BASIC SEMANTIC MODEL The existing ASIS packages define "Elements" which correspond roughly to syntactic "constructs." We propose to define "entities" and "views" thereof that represent the semantic entities defined by the syntactic constructs. In some cases, there is almost a one-to-one correspondence between the entity and the construct, for example, with an exception. For others, such as a "typed view" there may be many different kinds of constructs that create typed views which nevertheless have relatively similar properties. Here are the kinds of entities and views we propose to include in our ASIS semantic model: - Program_Unit_View - Package_View - Subprogram_View - Task_Unit - Protected_Unit - Generic_View - Single_Entry - Entry_Family - Subtype_View - Typed_View - Callable_View - Exception In addition, we propose to define certain other abstractions that allow us to characterize or manipulate the above entities or views: - Direct_Visibility_View - Declarative_Region_View - Region_Part - Profile We use the term view only when there are multiple views possible for the same underlying entity. For a given subprogram, it is possible to have different formal parameter names and defaults, depending on the view. For a package, there is a limited view (associated with a "limited with"), a partial view (e.g. from the outside), a private view (e.g. from a child), and a full view (e.g. from inside the body). On the other hand, there is only one view of an exception. For a generic, the only thing that can vary by the view is the name of the generic, so it may not be worth considering these different views. Many entities and views of entities have declarative regions associated with them. We propose to represent a particular view of a declarative region as a set of "region parts," one for each distinct part of a declarative region. Here are the different kinds of region parts: - generic formal part - discriminant part - formal part - visible part - private part - public child part - private child part - body part In addition to being able to iterate through the declarations of a region part, we propose to support the lookup of an identifier within a region part, within a declarative region view, or within a direct visibility view. If the lookup is successful, the result would be a single non-overloadable declaration, or a list of overloadable declarations. A direct visibility view supports lookups in a particular context, looking into enclosing scopes and taking use visibility into account. Looking up in a region part or a declarative region view does not worry about enclosing scopes or use visibility, and corresponds more closely to what would be called "selective visibility." Because we are proposing a relatively large set of interfaces, we are not currently proposing wording, but rather are working to specify the queries to be provided using a more economical syntax than full Ada package specifications. Once we agree on the set of interfaces to be provided, we will then create actual Ada packages with corresponding detailed descriptions for each operation. DETAILED SEMANTIC MODEL In this section, we define the operations that can be performed on the various kinds of entities and views. The operations available are listed underneath each kind of entity/view. The operations are defined in a notation such as: Subtype_View: ... Is_Derived -> Boolean Parent_Subtype -> Subtype_View Is_Descendant(Subtype_View) -> Boolean The above means that the operation Is_Derived is defined on Subtype_Views and (implicitly) takes one parameter being a Subtype_View, and returns a Boolean result. The indented Parent_Subtype operation is defined only if the Is_Derived operations returns True, and it returns a Subtype_View as a result. Finally, the "Is_Descendant" operation is defined on Subtype_Views, and in addition to the (implicit) first parameter being Subtype_View, this takes an additional parameter (also a Subtype_View in this case), and returns a Boolean result. Hopefully this notation will be sufficiently clear to allow the set of operations to be understood and relatively easily updated, without worrying about continually revising a lot of Ada subprogram specifications. As indicated above, once we settle on the desired interfaces, we can write out the package specifications in full detail. Semantic Attributes: Entity_Or_View Kind_Of_Entity -> enum Expr_Denoting_Entity -> ASIS.Expression Has_Declaration -> Boolean Entity_Declaration -> ASIS.Declaration Entity_Identifier -> ASIS.Identifier Is_Overloadable -> Boolean Enclosing_Scope -> Declarative_Region Logical_Position_In_Region -> Natural Enclosing_Compilation_Unit -> ASIS.Compilation_Unit Is_Renaming -> Boolean Renamed_Entity -> Entity Is_Program_Unit -> Boolean Has_Body -> Boolean Entity_Body -> ASIS.Declaration Has_Stub -> Boolean Entity_Stub -> ASIS.Declaration Is_Compilation_Unit -> Boolean Is_Library_Unit -> Boolean Parent_Library_Unit -> Entity Representation_Items -> List of Representation_Items Contains_Declarative_Region -> Boolean Contained_Region -> Declarative_Region Region_Part Kind_Of_Region_Part -> enum (Generic_Formal_Part, Formal_Part, Discriminant_Part, Entry_Family_Index_Part, Record_Part, Extension_Part, Package_Visible_Part, Package_Private_Part, Task_Visible_Part, Task_Private_Part, Protected_Visible_Part, Protected_Private_Part, Body_Part, Block_Declarative_Part, Loop_Declarative_Part, Child_Part) Enclosing_Region -> Declarative_Region Declarations -> List of Entitities Lookup(Identifier) -> List of Entity_Or_View Declarative_Region -> Enclosing_Entity -> Entity Has_Generic_Formal_Part -> Boolean Generic_Formal_Part -> Region_Part Visible_Parts -> List of Region_Parts Private_Part -> Region_Part (may be empty) Body_Part -> Region_Part (may be empty) Declarative_Region_View -> Region -> Declarative_Region Visible_Position_In_Region -> Natural Introduced_Position_In_Region -> Natural Visible_Children -> Set of Declarative_Region_Views Lookup(Identifier) -> Entity_Or_View Direct_Visibility_View -> Visibility_Stack -> List of Declarative_Region_Views Use_Visibility -> Set of Package_Views + Set of Subtype_Views Subprogram_View Subprogram_Profile -> Profile Is_Instance -> Boolean Instantiated_Generic -> Generic_Subp Actual_Part -> List of Associations Is_Abstract -> Boolean Is_Overriding -> Boolean Overrides -> Set of Subprograms Is_Null -> Boolean Is_Primitive -> Boolean Primitive_On_Types -> Set of Subtypes Is_Dispatching_Operation -> Boolean Associated_Tagged_Type -> Subtype_View Package_View Is_Limited_View -> Boolean Full_View -> Package View Is_Instance -> Boolean Instantiated_Generic -> Generic_Package Actual_Part -> List of Associations Is_Formal_Package -> Boolean Is_Pure -> Boolean Is_Preelaborated -> Boolean Is_Remote_Call_Interface -> Boolean Is_Remote_Types_Package -> Boolean Generic Entity Formal_Part -> Region_Part Current_Instance -> Entity Subtype_View Category -> {boolean, character, ordinary_enum, signed int, modular int, ordinary fixed, decimal fixed, float, access-to-obj, access-to-subp, record, record extension, array, task, protected, interface, private, private extension} Are_Of_Same_Type(Subtype_View) -> Boolean Is_First_Subtype -> Boolean Is_Secondary_Subtype -> Boolean Preconstraint_Subtype -> Subtype_View Constraint -> ASIS.Constraint First_Subtype -> Subtype_View Primitive_Subprograms -> List of Subprograms Is_Formal_Type -> Boolean Is_Aspect_Specified(Aspect) -> Boolean Is_Aspect_Directly_Specified(Aspect) -> Boolean Is_Constrained -> Boolean Constraint -> ASIS.Constraint Is_Definite -> Boolean Is_Derived -> Boolean Parent_Subtype -> Subtype_View Ultimate_Ancestor -> Subtype_View Is_Descendant(Subtype_View) -> Boolean Is_Ancestor(Subtype_View) -> Boolean Is_Incomplete_View -> Boolean Complete_View -> Subtype_View Is_Partial_View -> Boolean Full_View -> Subtype_View Is_Elementary -> Boolean Is_Universal -> Boolean Is_Scalar -> Boolean Base_Subtype -> Subtype_View Low_Bound,High_Bound -> Expression/Value/? Is_Discrete -> Boolean Is_Access -> Boolean Is_Anonymous_Access -> Boolean Is_Access_Parameter_Subtype -> Boolean Is_Access_Result_Subtype -> Boolean Static_Accessibility -> Natural Excludes_Null -> Boolean Is_Access_To_Object -> Boolean Designated_Subtype -> Subtype_View Is_Access_To_Constant -> Boolean Is_Pool_Specific -> Boolean Is_Access_To_Subprogram -> Boolean Designated_Profile -> Profile Is_Composite -> Boolean Is_Record -> Boolean Is_Array -> Boolean Is_Protected -> Boolean Is_Task -> Boolean Is_Tagged -> Boolean Is_Classwide -> Boolean Root_Subtype -> Subtype_View Is_Specific_Tagged -> Boolean Classwide_Subtype -> Subtype_View Is_Synchronized_Tagged -> Boolean Is_Interface -> Boolean Is_Abstract -> Boolean Progenitors -> List of Subtype_Views Has_Known_Discriminants -> Boolean Discriminants -> Region_Part Has_Unknown_Discriminants -> Boolean Has_Nondiscriminant_Components -> Boolean Nondiscriminant_Components -> Region_Part Is_Limited -> Boolean Has_Preelaborable_Initialization -> Boolean Needs_Finalization -> Boolean Contains_Task -> Boolean Typed_View Nominal_Subtype -> Subtype_View Is_Component -> Boolean Enclosing_Object -> Typed_View Is_Constant_View -> Boolean Is_Aliased_View -> Boolean Static_Accessibility -> Natural Callable_View Callable_Profile -> Profile Denoted_Callable_Unit -> Callable_Unit Is_Prefixed_View -> Boolean Prefix_Object -> Typed_View Unprefixed_Callable_View -> Callable_View Profile Parameters -> Region_Part Has_Result_Subtype -> Boolean Result_Subtype -> Subtype_View Has_Family_Index -> Boolean Family_Index_Definition -> Subtype_View Convention -> enum (Intrinsic_Convention, Ada_Convention, Protected_Convention, Entry_Convention, Other_Convention, Unspecified_Convention) Convention_Identifier -> ASIS.Identifier ----------------------- Additional thoughts 11/15/06: Additional operations: Are_Views_Of_Same_Entity(Other_View) -> Boolean Syntax -> Semantic linkages Need some way to get direct-visibility-view from a point in the AST Every declaration/name/expression needs linkage to entity/view Unlike the AST, the objects representing views might not exist until requested. They are more like handles into the symbol table. Prefixed views are a problem, since they are always implicit. Build this incrementally based on needs, e.g. for dispatching calls, for prefixed views, for inherited operations. Is_Implicit_Dereference, Is_Implicit_Tick_Access Corresponding_Representation_Clauses (Aspects, Representation_Items) should be associated with individaul entities, since two entities with the same syntactic declaration can have different representation. Drop the region view lookup stuff Keep the region part stuff Keep the ordering No child part Slice? (enclosing) Is_Value(typed-view) Is_Object(typed-view) Links from existing ASIS expression -> typed view name -> entity_or_view require ASIS expressions under certain circumstances such as for defaults, parameter specifications, formal parameters make it clear what is not provided for implicit expressions, etc. ------------------------------------------- PACKAGE SPECIFICATION In deciding how to represent the above semantic attribute queries as an Ada package, there were a number of significant issues to be decided. Most basically was how to refer to entities or views. ASIS uses the single type Element for essentially every syntactic construct, and then defines "trivial" subtypes which can be used to aid in readability. This existing ASIS approach sacrifices all compile-time checking in the use of the ASIS structural queries, which seems a shame. We would prefer to have some kind of type checking to help find misuses of the newly defined semantic queries at compile time. Given the desire to use multiple types to distinguish different kinds of entities, we then face the issue of limited vs. non-limited, tagged vs. non-tagged, interfaces vs. non-interfaces, explicitly derived vs. conversion functions, explicit pointers vs. opaque references, etc. We had various criteria which led to our current proposal of using a non-tagged hierarchy of discriminated types. One goal was to permit declaring variables whose underlying entity kind might not be known at the point of declaration. Similarly, we wanted to be able to manipulate heterogeneous lists of semantic entities. Both of these precluded using tagged types, since only class-wide types allow heterogeneity, and those require explicit initialization. An alternative would be to use explicit pointers everywhere, but this could introduce a significant storage management and/or dangling reference burden on the user of the semantic queries. Having settled on non-tagged, non-pointer types, we clearly wanted to use non-limited types to allow assignment after initialization. Choosing between explicitly derived types and types that have explicit conversion functions was based on reducing the number of explicit conversions required and/or reducing the number of redundant declarations for queries that are shared across the type hierarchy. The final decision was whether to incorporate any kind of run-time check at the point of conversion to a descendant type (a so-called "narrowing" conversion), or leave the run-time checking to each query. Clearly it seemed preferable to incorporate a check at the point of conversion where feasible. This can be accomplished by defining a "kind" enumeration, using it as a discriminant of the root type, and then using subtypes of the enumeration as the discriminant for descendant types. This works well for a strict hierarchy, but does not work as well when there are non-hierarchical classification, such as distinguishing between declared vs. constructed views. In the latter case, we fall back to relying on checks on each query. Another set of issues revolved around nomenclature. We have chosen to uniformly use the term "subtype" rather than "type or subtype," and use the term "view" rather than "entity or view" as in both cases, the former simpler term includes both of the latter terms. We also had to decide how to classify the views, and we have chosen six basic groups: typed views, callable views, subtype views, package views, exception views, and generic views. An alternative for "typed views" might be "object views" where we ignore the distinction between "value" and "object" (which is almost entirely irrelevant at this point, now that function results and aggregates are considered objects). Similarly, an alternative for "callable view" might be "subprogram view," treating entries and corresponding accept statements as special cases of subprograms. A final issue had to do with packaging. We have chosen to name the packages by the major view groupings. An alternative would be to combine them all into a single package. Because of interdependences, we ended up combining typed views, subtype views, and profiles. !wording package ASIS.Views is type View_Kinds is ( An_Exception, An_Exception_Renaming, A_Generic_Package, A_Generic_Package_Renaming, A_Generic_Subp, A_Generic_Subp_Renaming, A_Noninstance_Package, A_Package_Instance, A_Package_Renaming, A_Limited_Package_View, A_Noninstance_Subp, A_Subp_Instance, A_Subp_Renaming, A_Protected_Subp, An_Imported_Subp, An_Attribute_Subp, An_Intrinsic_Subp, A_Designated_Subp, A_Generic_Formal_Subp, A_Protected_Entry, A_Task_Entry, A_Standalone_Object, A_Generic_Formal_Object, A_Formal_Parameter_Object, An_Object_Renaming, A_Designated_Object, A_Component_Object, An_Attribute_Object, An_Aggregate_Object, A_Function_Result_Object, A_Named_Number, An_Attribute_Value, An_Expr_Value, A_Boolean_Subtype, A_Character_Subtype, An_Ordinary_Enum_Subtype, A_Signed_Integer_Subtype, A_Modular_Integer_Subtype, An_Ordinary_Fixed_Subtype, A_Decimal_Fixed_Subtype, A_Float_Subtype, An_Access_To_Object_Subtype, An_Access_To_Subp_Subtype, An_Array_Subtype, A_Record_Subtype, A_Record_Extension, A_Task_Subtype, A_Protected_Subtype, An_Interface, A_Private_Subtype, A_Private_Extension, An_Incomplete_Subtype ); subtype Exception_View_Kinds is View_Kinds range An_Exception .. An_Exception_Renaming; subtype Generic_View_Kinds is View_Kinds range A_Generic_Package .. A_Generic_Subp_Renaming; subtype Callable_View_Kinds is View_Kinds range A_Noninstance_Subp .. A_Task_Entry; subtype Typed_View_Kinds is View_Kinds range A_Standalone_Object .. An_Expr_Value; subtype Subtype_View_Kinds is View_Kinds range An_Enum_Subtype .. An_Incomplete_Subtype; type View(Kind : View_Kinds) is private; function Expr_Denoting_View(V : View) return ASIS.Expression; function Has_Declaration(V : View) return Boolean; function Is_Exception(V : View) return Boolean; function Is_Generic(V : View) return Boolean; function Is_Callable(V : View) return Boolean; function Is_Typed(V : View) return Boolean; function Is_Subtype(V : View) return Boolean; type Conventions is ( Intrinsic_Convention, Ada_Convention, Protected_Convention, Entry_Convention, Other_Convention, Unspecified_Convention); function Convention(V : View) return Conventions; function Convention_Identifier(V : View) return ASIS.Identifier; end ASIS.Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; package ASIS.Declared_Views is type Declared_View is new View; type Declarative_Region is private; type Region_Part is private; type Region_Part_Array is array(Positive range <>) of Region_Part; type Region_Part_Kinds is (Generic_Formal_Part, Callable_Formal_Part, Discriminant_Part, Entry_Family_Index_Part, Record_Part, Extension_Part, Package_Visible_Part, Package_Private_Part, Task_Visible_Part, Task_Private_Part, Protected_Visible_Part, Protected_Private_Part, Body_Part, Block_Declarative_Part, Loop_Declarative_Part, Child_Part); function Kind(P : Region_Part) return Region_Part_Kinds; function View_Declaration(V : Declared_View) return ASIS.Declaration; function View_Identifier(V : Declared_View) return ASIS.Identifier; function Is_Overloadable(V : Declared_View) return Boolean; function Is_Overriding(V : Declared_View) return Boolean; function Overridden_Entity(V : Declared_View) return Declared_View; function Representation_Items(V : Declared_View) return ASIS.Representation_Clause_List; function Enclosing_Region(V : Declared_View) return Declarative_Region; function Enclosing_Region_Part(V : Declared_View) return Region_Part; function Enclosing_Region(P : Region_Part) return Declarative_Region; function Expanded_Name(V : Declared_View) return String; function Wide_Expanded_Name(V : Declared_View) return Wide_String; function Wide_Wide_Expanded_Name(V : Declared_View) return Wide_Wide_String; type Logical_Position is new Natural; function Logical_Position_In_Region(V : Declared_View) return Logical_Position; function Enclosing_Compilation_Unit(V : Declared_View) return ASIS.Compilation_Unit; function Is_Renaming(V : Declared_View) return Boolean; function Renamed_View(V : Declared_View) return View; function Is_Program_Unit(V : Declared_View) return Boolean; type Program_Unit is new Declared_View; type Program_Unit_Array is array(Positive range <>) of Program_Unit; function Needs_Body(P : Program_Unit) return Boolean; function Has_Body(P : Program_Unit) return Boolean; function Body_Of_Program_Unit(P : Program_Unit) return ASIS.Declaration; function Has_Stub(P : Program_Unit) return Boolean; function Stub_Of_Program_Unit(P : Program_Unit) return ASIS.Declaration; function Is_Instance(P : Program_Unit) return Boolean; function Instantiated_Generic(P : Program_Unit) return Program_Unit; function Actual_Part(P : Program_Unit) return ASIS.Association_List; function Is_Compilation_Unit(P : Program_Unit) return Boolean; function Depends_Semantically_On(P : Program_Unit) return Program_Unit_Array; function Is_Library_Item(P : Program_Unit) return Boolean; type Library_Item is new Program_Unit; function Has_Parent_Library_Unit(L : Library_Item) return Boolean; function Parent_Library_Unit(L : Library_Item) return Library_Item; function Is_Pure(L : Library_Item) return Boolean; function Is_Preelaborated(L : Library_Item) return Boolean; function Is_Remote_Call_Interface(L : Library_Item) return Boolean; function Is_Remote_Types_Package(L : Library_Item) return Boolean; function Declarations(P : Region_Part) return ASIS.Declarative_Item_List; function All_Region_Parts(R : Declarative_Region) return Region_Part_Array; function Visible_Region_Parts(R : Declarative_Region) return Region_Part_Array; function Private_Part(R : Declarative_Region) retrun Region_Part; function Body_Part(R : Declarative_Region) return Region_Part; function Is_Empty(P : Region_Part) return Boolean; function Defines_Declarative_Region(V : View) return Boolean; function Defined_Region(V : View) return Declarative_Region; function Defining_Entity(R : Declarative_Region) return View; end ASIS.Declared_Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; with ASIS.Declared_Views; use ASIS.Declared_Views; package ASIS.Typed_Views is -- This one package defines Typed_View, Subtype_View, and Profile -- because the three types are interdependent type Typed_View(Kind : Typed_View_Kinds := Typed_View_Kinds'First) is new View(Kind); type Profile is private; type Subtype_View(Kind : Subtype_View_Kinds := Subtype_View_Kinds'First) is new View(Kind); subtype Elementary_Subtype_Kinds is Subtype_View_Kinds range An_Enum_Subtype .. An_Access_To_Subp_Subtype; subtype Composite_Subtype_Kinds is Subtype_View_Kinds range An_Array_Subtype .. An_Incomplete_Subtype; subtype Scalar_Subtype_Kinds is Elementary_Subtype_Kinds range An_Enum_Subtype .. A_Float_Subtype; subtype Numeric_Subtype_Kinds is Scalar_Subtype_Kinds range A_Signed_Integer_Subtype .. A_Float_Subtype; subtype Discrete_Subtype_Kinds is Scalar_Subtype_Kinds range An_Enum_Subtype .. A_Modular_Integer_Subtype; subtype Integer_Subtype_Kinds is Numeric_Subtype_Kinds range A_Signed_Integer_Subtype .. A_Modular_Integer_Subtype; subtype Real_Subtype_Kinds is Numeric_Subtype_Kinds range An_Ordinary_Fixed_Subtype .. A_Float_Subtype; subtype Access_Subtype_Kinds is Elementary_Subtype_Kinds range An_Access_To_Object_Subtype .. An_Access_To_Subp_Subtype; function Is_Elementary(S : Subtype_View) return Boolean; function Is_Composite(S : Subtype_View) return Boolean; function Is_Scalar(S : Subtype_View) return Boolean; function Is_Numeric(S : Subtype_View) return Boolean; function Is_Discrete(S : Subtype_View) return Boolean; function Is_Integer(S : Subtype_View) return Boolean; function Is_Real(S : Subtype_View) return Boolean; function Is_Access(S : Subtype_View) return Boolean; function Are_Of_Same_Type(S : Subtype_View) return Boolean; function Is_First_Subtype(S : Subtype_View) return Boolean; function Is_Secondary_Subtype(S : Subtype_View) return Boolean; functino Preconstraint_Subtype(S : Subtype_View) return Subtype_View; function Constraint(S : Subtype_View) return ASIS.Constraint; function First_Subtype(S : Subtype_View) return Subtype_View; function Primitive_Subprograms(S : Subtype_View) return ASIS.Declarative_Item_List; function Is_Formal_Subtype(S : Subtype_View) return Boolean; function Is_Descended_From_Formal_Subtype(S : Subtype_View) return Boolean; type Aspect_Kinds is ( A_Size_Aspect, An_Alignment_Aspect, An_Address_Aspect, A_Position_Aspect, ...); function Is_Aspect_Specified(Aspect : Aspect_Kinds) return Boolean; function Is_Aspect_Directly_Specified(Aspect : Aspect_Kinds) return Boolean; function Is_Static_Subtype(S : Subtype_View) return Boolean; function Is_Constrained(S : Subtype_View) return Boolean; function Is_Statically_Constrained(S : Subtype_View) return Boolean; function Constraint(S : Subtype_View) return ASIS.Constraint; function Are_Statically_Matching(S1, S2 : Subtype_View) return Boolean; function Is_Statically_Compatible(S : Subtype_View; With_Subtype : Subtype_View) return Boolean; function Is_Definite(S : Subtype_View) return Boolean; function Is_Derived_Subtype(S : Subtype_View) return Boolean; function Parent_Subtype(S : Subtype_View) return Subtype_View; function Ultimate_Ancestor(S : Subtype_View) return Subtype_View; function Is_Descendant(S : Subtype_View; Of_Subtype : Subtype_View) return Boolean; function Is_Incomplete_View(S : Subtype_View) return Boolean; function Complete_View(S : Subtype_View) return Subtype_View; function Is_Partial_View(S : Subtype_View) return Boolean; function Full_View(S : Subtype_View) return Subtype_View; function Subtype_Size(S : Subtype_View) return Typed_View; function Subtype_Alignment(S : Subtype_View) return Natural; type Elementary_Subtype( Kind : Elementary_Subtype_Kinds := Elementary_Subtype_Kinds'First) is new Subtype_View(Kind); function Is_Universal(E : Elementary_Subtype) return Boolean; type Scalar_Subtype(Kind : Scalar_Kinds := Scalar_Kinds'First) is new Elementary_Subtype(Kind); function Base_Subtype(S : Scalar_Subtype) return Scalar_Subtype; function Low_Bound(S : Scalar_Subtype) return Typed_View; function High_Bound(S : Scalar_Subtype) return Typed_View; type Access_Subtype( Kind : Access_Subtype_Kinds := Access_Subtype_Kinds'First) is new Elementary_Subtype(Kind); function Is_Anonymous_Access(A : Access_Subtype) return Boolean; function Is_Access_Parameter(A : Access_Subtype) return Boolean; function Is_Access_Result(A : Access_Subtype) return Boolean; function Is_Access_Discriminant(A : Access_Subtype) return Boolean; type Static_Accessibility_Level is new Natural; function Static_Accessibility(A : Access_Subtype) return Static_Accessibility_Level; function Excludes_Null(A : Access_Subtype) return Boolean; function Is_Access_To_Object(A : Access_Subtype) return Boolean; type Access_To_Object_Subtype is new Access_Subtype(An_Access_To_Object_Subtype); function Designated_Subtype(A : Access_To_Object_Subtype) return Subtype_View; function Is_Access_To_Constant(A : Access_To_Object_Subtype) return Boolean; function Is_Pool_Specific(A : Access_To_Object_Subtype) return Boolean; function Storage_Pool(A : Access_To_Object_Subtype) return Typed_View; function Storage_Size(A : Access_To_Object_Subtype) return Typed_View; function Is_Access_To_Subp(A : Access_Subtype) return Boolean; type Access_To_Subp_Subtype is new Access_Subtype(An_Access_To_Subp_Subtype); function Designated_Profile(A : Access_To_Subp_Subtype) return Profile; type Composite_Subtype( Kind : Composite_Subtype_Kinds := Composite_Subtype_Kinds'First) is new Subtype_View(Kind); function Is_Record(C : Composite_Subtype) return Boolean; function Is_Record_Extension(C : Composite_Subtype) return Boolean; function Is_Array(C : Composite_Subtype) return Boolean; type Array_Subtype is new Composite_Subtype(An_Array_Subtype); function Component_Subtype(A : Array_Subtype) return Subtype_View; function Num_Dimensions(A : Array_Subtype) return Positive; function Index_Subtype(A : Array_Subtype; Dimension : Positive := 1) return Discrete_Subtype; function Is_Protected(C : Composite_Subtype) return Boolean; function Is_Task(C : Composite_Subtype) return Boolean; function Is_Limited(C : Composite_Subtype) return Boolean; function Contains_Task(C : Composite_Subtype) return Boolean; function Needs_Finalization(C : Composite_Subtype) return Boolean; function Has_Preelaborable_Initialization(C : Composite_Subtype) return Boolean; function Has_Unknown_Discriminants(C : Composite_Subtype) return Boolean; function Has_Known_Discriminants(C : Composite_Subtype) return Boolean; function Discriminants(C : Composite_Subtype) return Region_Part; function Has_Nondiscriminant_Components(C : Composite_Subtype) return Boolean; function Nondiscriminant_Components(C : Composite_Subtype) return Region_Part; function Is_Tagged(C : Composite_Subtype) return Boolean; type Tagged_Subtype is new Composite_Subtype; type Tagged_Subtype_Array is array(Positive range <>) of Tagged_Subtype; function Is_Classwide(T : Tagged_Subtype) return Boolean; function Root_Subtype(T : Tagged_Subtype) return Tagged_Subtype; function Is_Specific(T : Tagged_Subtype) return Boolean; function Classwide_Subtype(T : Tagged_Subtype) return Tagged_Subtype; function Is_Interface(T : Tagged_Subtype) return Boolean; function Is_Abstract(T : Tagged_Subtype) return Boolean; function Is_Synchronized_Tagged(T : Tagged_Subtype) return Boolean; function Progenitors(T : Tagged_Subtype) return Tagged_Subtype_Array; function External_Tag(T : Tagged_Subtype) return String; ----------------------------------- -- Typed Views (Objects and Values) ----------------------------------- type Typed_View(Kind : Typed_View_Kinds := Typed_View_Kinds'First) is new View(Kind); function Nominal_Subtype(T : Typed_View) return Subtype_View; function Is_Component(T : Typed_View) return Boolean; function Enclosing_Object(T : Typed_View) return Typed_View; function Position(T : Typed_View) return Typed_View; function Is_Constant(T : Typed_View) return Boolean; function Is_Aliased(T : Typed_View) return Boolean; function Static_Accessibility(T : Typed_View) return Static_Accessibility_Level; function Is_Designated_Object(T : Typed_View) return Boolean; function Is_Implicit_Dereference(T : Typed_View) return Boolean; function Is_Implicit_Tick_Access(T : Typed_View) return Boolean; function Is_Static_Integer(T : Typed_View) return Boolean; function Static_Integer_Value(T : Typed_View) return Longest_Integer; function Is_Static_Real(T : Typed_View) return Boolean; function Static_Real_Value(T : Typed_View) return Longest_Float; function Is_Static_String(T : Typed_View) return Boolean; function Static_String_Value(T : Typed_View) return String; function Static_Wide_String_Value(T : Typed_View) return Wide_String; function Static_Wide_Wide_String_Value(T : Typed_View) return Wide_Wide_String; function Object_Size(T : Typed_View) return Typed_View; function Object_Alignment(T : Typed_View) return Natural; -------------------------------- -- Parameter and Result Profiles -------------------------------- function Parameters(P : Profile) return Region_Part; function Is_Function(P : Profile) return Boolean; function Result_Subtype(P : Profile) return Subtype_View; function Has_Family_Index(P : Profile) return Boolean; function Family_Index_Subtype(P : Profile) return Subtype_View; function Convention(P : Profile) return Conventions; function Convention_Identifier(P : Profile) return ASIS.Identifier; end ASIS.Typed_Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; with ASIS.Typed_Views; use ASIS.Typed_Views; package ASIS.Callable_Views is type Callable_View(Kind : Callable_View_Kinds := Callable_View_Kinds'First) is new View(Kind); function Callable_Profile(C : Callable_View) return Profile; function Is_Subprogram(C : Callable_View) return Boolean; function Is_Enum_Literal(C : Callable_View) return Boolean; function Is_Entry(C : Callable_View) return Boolean; function Is_Function(C : Callable_View) return Boolean; function Is_Abstract(C : Callable_View) return Boolean; function Is_Null(C : Callable_View) return Boolean; function Is_Primitive(C : Callable_View) return Boolean; function Primitive_On_Subtypes(C : Callable_View) return Subtype_View_List; function Is_Dispatching_Operation(C : Callable_View) return Boolean; function Associated_Tagged_Type(C : Callable_View) return Composite_Subtype; function Is_Prefixed_View(C : Callable_View) return Boolean; function Prefix_Object(C : Callable_View) return Typed_View; function Unprefixed_Callable_View(C : Callable_View) return Callable_View; function Is_Designated_Subp(C : Callable_View) return Boolean; end ASIS.Callable_Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; with ASIS.Declared_Views; use ASIS.Declared_Views; package ASIS.Package_Views is type Package_View(Kind : Package_View_Kinds := Package_View_Kinds'First) is new Program_Unit(Kind); function Is_Limited_View(P : Package_View) return Boolean; function Full_View(P : Package_View) return Package_View; function Is_Formal_Package(P : Package_View) return Boolean; function Visible_Part(P : Package_View) return Region_Part; end ASIS.Package_Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; with ASIS.Declared_Views; use ASIS.Declared_Views; with ASIS.Callable_Views; with ASIS.Package_Views; package ASIS.Generic_Views is type Generic_View(Kind : Generic_View_kinds := Generic_View_Kinds'First) is new Program_Unit(Kind); function Generic_Formal_Part(G : Generic_View) return Region_Part; function Is_Generic_Package(G : Generic_View) return Boolean; function Current_Package_Instance(G : Generic_View) return Package_Views.Package_View; function Is_Generic_Subp(G : Generic_View) return Boolean; function Current_Subp_Instance(G : Generic_View) return Callable_Views.Callable_View; end ASIS.Generic_Views; --------------------------------------------------------------- with ASIS.Views; use ASIS.Views; with ASIS.Declared_Views; use ASIS.Declared_Views; package ASIS.Exception_Views is type Exception_View( Kind : Exception_View_Kinds := Exception_View_Kinds'First) is new Declared_View(Kind); function Names_Are_Discarded(E : Exception_View) return Boolean; end ASIS.Exception_Views; Add at end of ASIS.Declarations: function Corresponding_Declared_View( Declaration: in ASIS.Declaration) return ASIS.Declared_Views.Declared_View; Add at end of ASIS.Definitions: function Corresponding_Subtype_View( Type_Definition : in ASIS.Type_Definition) return ASIS.Subtype_Views.Subtype_View; Add at end of ASIS.Expressions: function Corresponding_View( Expression : in ASIS.Expression) return ASIS.Views.View; !discussion --!corrigendum A.18.2(239/2) !ACATS test !appendix From: Robert A. Duff Date: Monday, November 13, 2006 9:00 AM > Here is a first draft of my SI on an ASIS semantic model. Thanks. Sergey Rybin (rybin@adacore.com) should be in on the discussion. **************************************************************** From: Jean-Pierre Rosen Date: Friday, June 9, 2006 1:47 AM Specifications of my thick_queries package: ---------------------------------------------------------------------- -- Thick_Queries - Package specification -- -- Copyright (C) 2002 Adalog -- -- Author: J-P. Rosen -- -- -- -- ADALOG is providing training, consultancy, expertise, -- -- assistance and custom developments in Ada and related software -- -- engineering techniques. For more info about our services: -- -- ADALOG Tel: +33 1 41 24 31 40 -- -- 19-21 rue du 8 mai 1945 Fax: +33 1 41 24 07 36 -- -- 94110 ARCUEIL E-m: info@adalog.fr -- -- FRANCE URL: http://www.adalog.fr -- -- -- -- This unit is free software; you can redistribute it and/or -- -- modify it under terms of the GNU General Public License as -- -- published by the Free Software Foundation; either version 2, or -- -- (at your option) any later version. This unit is distributed -- -- in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- -- without even the implied warranty of MERCHANTABILITY or FITNESS -- -- FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU -- -- General Public License distributed with this program; see file -- -- COPYING. If not, write to the Free Software Foundation, 59 -- -- Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics -- -- from this unit, or you link this unit with other files to -- -- produce an executable, this unit does not by itself cause the -- -- resulting executable to be covered by the GNU General Public -- -- License. This exception does not however invalidate any other -- -- reasons why the executable file might be covered by the GNU -- -- Public License. -- ---------------------------------------------------------------------- with Asis; with System; package Thick_Queries is ------------------------------------------------------------------------------------------------- -- -- -- Error report -- -- -- ------------------------------------------------------------------------------------------------- type Error_Procedure is access procedure (Message : Wide_String; Elem : Asis.Element); procedure Set_Error_Procedure (To : Error_Procedure); -- Defines a user defined procedure called in case of an internal error -- ("impossible" cases, or calls with inappropriate elements) -- The user procedure may raise an exception. If it doesn't (or no user procedure is defined), -- Program_Error will be raised. ------------------------------------------------------------------------------------------------- -- -- -- Queries about program structure -- -- -- ------------------------------------------------------------------------------------------------- function Enclosing_Program_Unit (Element : Asis.Element; Including_Accept : Boolean := False) return Asis.Defining_Name; -- Return the Defining_Name of the innermost enclosing program unit of any Element -- If Including_Accept is true and the element is within an accept statement, return -- the corresponding entry name from the entry declaration (not really a program unit, -- but useful f.e. if the Element is a Return_Statement, and you want to know what you -- are returning from). -- -- Appropriate Element_Kinds: -- Any element -- -- Returns -- A_Defining_Name -- Nil_Element if Element is a Compilation_Unit -- function Ultimate_Enclosing_Instantiation (The_Element : Asis.Element) return Asis.Declaration; -- For an entity which Is_Part_Of_Instance: -- Return the "true" instantiation, i.e. the one written by the user, going up instantiations -- that appear in generics. function Is_Part_Of_Generic (Declaration : in Asis.Declaration) return Boolean; -- Checks whether the Declaration is included (directly or indirectly) in a generic -- Expected Element: -- A_Declaration ------------------------------------------------------------------------------------------------- -- -- -- Images -- -- -- ------------------------------------------------------------------------------------------------- function Attribute_Name_Image (Attribute : Asis.Expression) return Wide_String; -- Like Pragma_Name_Image, but for an Attribute_Reference -- -- Appropriate Element_Kinds: -- An_Expression -- Appropriate Expression_Kinds: -- An_Attribute_Reference function Extended_Name_Image (Name_Elem : Asis.Element) return Wide_String; -- Image of a name, given either as a simple name or as a Selected_Name function Full_Name_Image (The_Name : in Asis.Element; With_Profile : in Boolean := False) return Wide_String; -- Full name of a name -- Works like Asis.Declarations.Defining_Name_Image (or Name_Image), -- but returns the full (unique) name of The_Name, starting from the -- enclosing compilation unit (Standard for predefined elements). -- If With_Profile is true, "mangles" the name with a profile to provide a name -- that is unique even if overloaded. -- -- Appropriate Element_Kinds: -- A_Defining_Name -- An_Expression -- Appropriate Expression_Kinds: -- An_Identifier -- A_Selected_Component (returns the image of the selector) function Profile_Image (The_Name : Asis.Element; With_Profile : Boolean := True) return Wide_String; -- Image of the profile of a callable construct -- If name is not a callable construct, returns "" -- Otherwise: -- for a procedure, entry...: -- returns '{' { Field). -- - In the case of a renaming whose target is An_Explicit_Dereference, returns Nil_Element -- (the target is statically unknown) -- - In the case of a renaming whose target is A_Function_Call, returns Nil_Element -- (the target is statically unknown, it designates the result of the function call) -- - In the case of the renaming of an attribute, returns the attribute -- Otherwise: returns its argument -- -- In any case, if The_Name is A_Defining_Name, then A_Defining_Name is returned -- if The_Name is An_Identifier, then An_Identifier (or An_Attribute_Reference) is returned -- -- Appropriate Element_Kinds: -- A_Defining_Name -- An_Expression -- Appropriate Expression_Kinds: -- An_Identifier -- A_Selected_Component (operates on selector) -- An_Attribute_Reference function Ultimate_Expression_Type (The_Element : Asis.Expression) return Asis.Definition; -- return the type definition of the ultimate ancestor type of The_Element -- (going up all subtype and derived type declaration). function Expression_Type_Kind (The_Element : Asis.Expression) return Asis.Type_Kinds; -- Real kind of an expression -- return the Type_Kind of the ultimate ancestor of The_Element -- (going up all subtype and derived type declaration). type Expression_Usage_Kinds is (Untouched, Read, Write, Read_Write); function Expression_Usage_Kind (Expr : Asis.Expression) return Expression_Usage_Kinds; -- Returns Untouched if Expr is part of a renaming declaration -- Returns Write if Expr designates a variable which is the -- target of an assignment statement, or an actual corresponding -- to an out parameter in a procedure or entry call. -- Returns Read_Write if Expr designates a variable which is -- an actual corresponding to an in out parameter in a procedure -- or entry call. -- Returns Read in all other cases (including when Expr is not a variable) -- -- Note that this function handles access types properly, i.e. in: -- Integer_Pointer.all := 1; -- if passed Integer_Pointer.all, it will return Write; -- if passed Integer_Pointer, it will return Read. function Includes_Renaming (Path : Asis.Expression) return Boolean; -- Checks whether any element in the Path is a renaming -- -- Appropriate expression kinds: -- An_Identifier -- A_Selected_Component -- A_Function_Call -- An_Indexed_Component -- A_Slice type Pragma_Set is array (Asis.Pragma_Kinds) of Boolean; function Corresponding_Pragma_Set (Element : in Asis.Element) return Pragma_Set; -- Returns the set of pragmas that apply to the corresponding name or defining name -- Note that unlike Corresponding_Pragmas, this query makes sure that the pragma applies -- really to the given element in the case of a multiple declaration. -- -- Appropriate element kinds: -- An_Expression -- A_Defining_Name -- Appropriate expression kinds -- An_Identifier -- A_Selected_Component (function applied to the selector) ------------------------------------------------------------------------------------------------- -- -- -- Queries about callable constructs -- -- -- ------------------------------------------------------------------------------------------------- function Is_Callable_Construct (Element : Asis.Element) return Boolean; -- Checks whether the Element is a callable construct -- Expected elements: -- A_Declaration -- A_Definition -- A_Defining_Name -- An_Expression -- Appropriate Expression_Kinds: -- An_Identifier -- A_Selected_Component (applies to the selector) function Called_Simple_Name (Call : Asis.Element) return Asis.Expression; -- Given a procedure, entry or function call, returns the simple name of the called -- entity (from the call). -- It handles all cases in the same function (i.e. whether it is a procedure or a function, -- whether the call is from an access to subprogram, etc.) -- Returns the simple name of the called entity (i.e. not a Selected_Name). -- For calls to an entry family, returns the name of the family -- Returns a Nil_Element if the call is through an access to subprogram -- Works with dispatching calls! -- -- Appropriate Element_Kinds: -- A_Statement -- An_Expression -- Appropriate Statement_Kinds: -- A_Procedure_Call_Statement -- An_Entry_Call_Statement -- Appropriate Expression_Kinds: -- A_Function_Call function Called_Profile (Call : Asis.Element) return Asis.Parameter_Specification_List; -- Given a procedure, entry or function call, returns the parameter profile of the called -- entity. -- For simple cases, it is like Parameter_Profile (Corresponding_Called_Entity (Call)), -- but it handles all cases in the same function (i.e. whether it is a procedure or a function, -- whether the call is from an access to subprogram, etc.) -- -- Appropriate Element_Kinds: -- A_Statement -- An_Expression -- Appropriate Statement_Kinds: -- A_Procedure_Call_Statement -- An_Entry_Call_Statement -- Appropriate Expression_Kinds: -- A_Function_Call function Formal_Name (Call : Asis.Element; Actual : Asis.List_Index) return Asis.Defining_Name; -- Given a procedure, entry or function call, or a generic instantiation, returns the defining name -- of the formal corresponding to the actual at the given position in the call. -- Note: if the full Parameter_Specification is desired, it is the Enclosing_Element of the Formal_Name -- -- Returns a nil element if: -- Actual is greater than the number of actuals in the call -- The call is to a dispatching operation function Formal_Name (Assoc : Asis.Association) return Asis.Defining_Name; -- Same as above, but retrieves the call (or instantiation) and the position given an association function Actual_Expression (Call : Asis.Element; Formal : Asis.Defining_Name) return Asis.Expression; -- Given a procedure, entry or function call, or a generic instantiation, returns the value -- of the actual corresponding to the formal whose defining_identifier is passed. -- If there is no such actual (the call used the default value), the default expression is returned. -- -- Returns a nil element if: -- The call is to a dispatching operation -- The formal is not from the called entity function Actual_Parameters (Element : Asis.Element; Normalized : Boolean := False) return Asis.Association_List; -- Returns the actual parameters of a procedure, entry, or function call, or of -- a generic instantiation type Type_Attribute is (None, Base, Class); type Profile_Entry is record Is_Access : Boolean; Attribute : Type_Attribute; Name : Asis.Defining_Name; end record; type Profile_Table is array (Asis.List_Index range <>) of Profile_Entry; type Profile_Descriptor (Formals_Length : Asis.ASIS_Natural) is record Result_Type : Profile_Entry; Formals : Profile_Table (1..Formals_Length); end record; function Types_Profile (Declaration : in Asis.Declaration) return Profile_Descriptor; -- Given a callable entity declaration, returns a list of Defining_Name -- First element is the result type for a function, Nil_Element for other callable entities -- Other elements are (in order of declaration) the *types* of the parameters. -- Multiple declarations are separated, i.e. "A,B : Integer" yields two entries in the table. function External_Call_Target (Call : Asis.Element) return Asis.Expression; -- Returns the prefix of the call that designates the target object -- of an external call (LRM 9.5 (2..7)). -- Returns Nil_Element if Element does not designate an external call. -- -- Appropriate Element_Kinds: -- An_Expression -- A_Statement -- -- Appropriate Expression_Kinds: -- A_Function_Call -- -- Appropriate Statement_Kinds: -- A_Procedure_Call_Statement -- An_Entry_Call_Statement -- A_Reqeue_Statement -- A_Requeue_Statement_With_Abort ------------------------------------------------------------------------------------------------- -- -- -- Static evaluator and static properties of ranges and constraints -- -- -- ------------------------------------------------------------------------------------------------- type Biggest_Int is range System.Min_Int .. System.Max_Int; -- The best we can do Non_Static : constant Biggest_Int := -1; subtype Biggest_Natural is Biggest_Int range 0 .. Biggest_Int'Last; subtype Extended_Biggest_Natural is Biggest_Int range Non_Static .. Biggest_Int'Last; type Extended_Biggest_Natural_List is array (Positive range <>) of Extended_Biggest_Natural; function Static_Expression_Value_Image (Expression : Asis.Expression) return Wide_String; -- Computes the value of Expression if it is a static expression -- and represents it as a (wide) string. For enumeration expressions, the -- image of the Pos value of the defining enumeration or character literal -- corresponding to the value of the expression is returned. -- -- For non-static expressions, or expressions that we cannot (yet) evaluate, -- an empty string is returned. -- -- Currently implemented: -- All types: -- Constant -- Parenthesized expression -- 'Pred, 'Succ, 'Pos, 'Val, 'First, 'Last -- Conversions and qualified expressions -- Integer: (provided values are within System.Min_Int .. System.Max_Int) -- Literal -- Named number -- + - * / ** -- Real: -- Literal -- Named number -- Enumerated: -- Literal -- String: (no way to distinguish true "" from non-static expression) -- Literal -- & -- -- Appropriate Element_Kinds: -- An_Expression -- -- The specification of this function is derived (and compatible with) the one -- declared in the GNAT extension ASIS.Extensions -- (except that we do not have the same set of implemented/non-implemented features) function Discrete_Constraining_Bounds (Elem : Asis.Element) return Asis.Element_List; -- Elem must designate a type, a variable, a constant, a formal parameter, -- or a generic formal object. -- -- Returns the expressions that constrain the values of a discrete type. -- Returned list has two elements -- Signed integer type : returns (First_Expression, Last_Expression) -- Subtype of modular : returns (First_Expression, Last_Expression) -- Modular type : returns (Nil_Element, Mod_Expression) -- Enumerated type : returns (First_Defining_Name, Last_Defining_Name) -- -- Returns the bounds that constrain the indexes of an array type. -- Returned list has an even number of elements (First(1), Last (1), First (2), Last (2), ...) -- Each pair of elements is the same as above -- -- Returns Nil_Element_List if the type that applies to Elem is not discrete or array, or is formal -- -- Appropriate Element_Kinds: -- An_Expression -- A_Declaration -- A_Definition -- -- Appropriate Expression_Kind: -- An_Identifier -- A_Selected_Component (operates on the selector) -- A_Function_Call (operates on the returned object) -- -- Appropriate Declaration_Kinds -- An_Ordinary_Type_Declaration -- A_Subtype_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- A_Private_Extension_Declaration -- An_Incomplete_Type_Declaration -- A_Private_Type_Declaration -- A_Variable_Declaration -- A_Constant_Declaration -- A_Component_Declaration -- A_Parameter_Specification -- A_Formal_Object_Declaration -- -- Appropriate Definition_Kinds -- A_Discrete_Range -- A_Constraint -- -- Returns Element_Kind: -- Not_An_Element -- An_Expression -- A_Defining_Name function Discrete_Constraining_Lengths (Elem : Asis.Element) return Extended_Biggest_Natural_List; -- Like Discrete_Constraining_Bounds, but returns the number of values in the range instead of -- the bounds if statically determinable -- Returns Non_Static (-1) if not statically determinable type Result_Confidence is (Unlikely, Possible, Certain); type Variable_Overlap is (Complete, Partial, None); type Proximity is record Confidence : Result_Confidence; Overlap : Variable_Overlap; end record; Same_Variable : constant Proximity := (Certain, Complete); function Variables_Proximity (Left, Right : Asis.Element) return Proximity; -- Determines if Left and Right can possibly refer to (par of) the same variables. -- If Left or Right is not a variable, always returns (Certain, None) -- Overlap => None is only returned with Confidence => Certain -- -- Some especially useful results: -- (Certain, Complete): Statically known to be the same variable -- (Certain, None) : Statically known to be different variables -- -- Appropriate Element_Kinds: -- An_Expression -- A_Defining_Name function Same_Value (Left, Right : Asis.Expression) return Boolean; -- Determines if Left and Right statically have the same value. -- Returns True if: -- Left and Right statically denote the same constant or in parameter -- or Left and Right are discrete and evaluate statically to the same value. end Thick_Queries; **************************************************************** From: Tucker Taft Sent: Sunday, May 13, 2007 3:16 PM Here is an updated SI on a semantic model for ASIS. [This is version /02 of the SI - ED] I have included a package specification and some rationale. I think it is largely complete, but there are many issues to be discussed and interfaces to be reviewed. Enjoy! **************************************************************** From: Tucker Taft Sent: Friday, May 18, 2007 2:53 PM I realize I never specified the interfaces needed to go from an ASIS Element to the "View" type declared in ASIS.Views. Hence, please add the following to the "wording" section for SI99-0024: [This was done in version /03 of the SI - ED] Add at end of ASIS.Declarations: function Corresponding_Declared_View( Declaration: in ASIS.Declaration) return ASIS.Declared_Views.Declared_View; Add at end of ASIS.Definitions: function Corresponding_Subtype_View( Type_Definition : in ASIS.Type_Definition) return ASIS.Subtype_Views.Subtype_View; Add at end of ASIS.Expressions: function Corresponding_View( Expression : in ASIS.Expression) return ASIS.Views.View; ****************************************************************