----------------------------------------------- --------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . E N T I T I E S . P R O P E R T I E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2004-2007, GET-Telecom Paris. -- -- -- -- Ocarina 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. Ocarina 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 Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, 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. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Namet; with Charset; with Ocarina.Nodes; with Ocarina.Entities; with Ocarina.Entities.Messages; package body Ocarina.Entities.Properties is function Get_Type_Of_Literal (Literal : Types.node_id) return property_type; ------------------------- -- Get_Type_Of_Literal -- ------------------------- function Get_Type_Of_Literal (Literal : Types.node_id) return property_type is use Ocarina.Nodes; use Types; use Ocarina.AADL_Values; pragma assert (Literal /= No_Node and then Kind (Literal) = k_literal); Literal_Value : constant value_type := Get_Value_Type (Value (Literal)); begin case (Literal_Value.T) is when lt_boolean => return pt_boolean; when lt_string => return pt_string; when lt_real => return pt_float; when lt_integer => return pt_integer; when lt_enumeration => return pt_enumeration; end case; end Get_Type_Of_Literal; ------------------------------------------------ -- Value_Of_Property_Association_Is_Undefined -- ------------------------------------------------ function Value_Of_Property_Association_Is_Undefined (Property : Types.node_id) return Boolean is use Ocarina.Nodes; use Types; pragma assert (Property /= No_Node and then Kind (Property) = k_property_association); pragma assert (Single_Value (Property_Association_Value (Property)) /= No_Node or else Multi_Value (Property_Association_Value (Property)) /= No_List); begin -- the value of a property association is undefined if there is -- no expanded value, and the raw values either are empty, or -- if the expanded values are set to an empty list return Expanded_Single_Value (Property_Association_Value (Property)) = No_Node and then (Expanded_Multi_Value (Property_Association_Value (Property)) = No_List); end Value_Of_Property_Association_Is_Undefined; -------------------------------- -- Type_Of_Property_Is_A_List -- -------------------------------- function Type_Of_Property_Is_A_List (Property : Types.node_id) return Boolean is use Ocarina.Nodes; use Ocarina.AADL_Values; use Types; pragma assert (Property /= No_Node and then (Kind (Property) = k_property_association or else Kind (Property) = k_property_name_declaration or else Kind (Property) = k_property_type_declaration)); begin case Kind (Property) is when k_property_association => if Expanded_Single_Value (Property_Association_Value (Property)) = No_Node and then Expanded_Multi_Value (Property_Association_Value (Property)) = No_List then return Multi_Value (Property_Association_Value (Property)) /= No_List; -- If the property value has not been expanded yet, we -- use the raw property value else return Expanded_Multi_Value (Property_Association_Value (Property)) /= No_List; end if; when k_property_name_declaration => return Is_List (Property_Name_Type (Property)); when k_property_type_declaration => return False; when others => return False; end case; end Type_Of_Property_Is_A_List; -------------------------- -- Get_Type_Of_Property -- -------------------------- function Get_Type_Of_Property (Property : Types.node_id; Use_Evaluated_Values : Boolean := True) return property_type is use Ocarina.Nodes; use Ocarina.AADL_Values; use Types; pragma assert (Property /= No_Node and then (Kind (Property) = k_property_association or else Kind (Property) = k_property_name_declaration or else Kind (Property) = k_property_type_declaration)); begin case Kind (Property) is when k_property_association => return Get_Type_Of_Property_Value (Property_Association_Value (Property), Use_Evaluated_Values); when k_property_name_declaration => declare Associated_Type : node_id; begin if Use_Evaluated_Values and then Expanded_Type_Designator (Property_Name_Type (Property)) /= No_Node then Associated_Type := Expanded_Type_Designator (Property_Name_Type (Property)); else Associated_Type := Property_Type_Designator (Property_Name_Type (Property)); end if; case Kind (Associated_Type) is when k_unique_property_type_identifier => return pt_other; when k_string_type => return pt_string; when k_boolean_type => return pt_boolean; when k_real_type => return pt_float; when k_integer_type => return pt_integer; when k_range_type => return pt_range; when k_enumeration_type => return pt_enumeration; when k_reference_type => return pt_reference; when k_classifier_type => return pt_classifier; when others => return pt_other; end case; end; when k_property_type_declaration => case Kind (Property_Type_Designator (Property)) is when k_integer_type => return pt_integer; when k_real_type => return pt_float; when k_boolean_type => return pt_boolean; when k_string_type => return pt_string; when k_unique_property_type_identifier => return pt_other; when k_range_type => return pt_range; when k_enumeration_type => return pt_enumeration; when k_reference_type => return pt_reference; when k_classifier_type => return pt_classifier; when k_units_type => return pt_other; when others => return pt_other; end case; when others => raise Program_Error; end case; end Get_Type_Of_Property; -------------------------------- -- Get_Type_Of_Property_Value -- -------------------------------- function Get_Type_Of_Property_Value (Property_Value : Types.node_id; Use_Evaluated_Values : Boolean := True) return property_type is use Types; use Ocarina.Nodes; use Ocarina.Entities.Messages; pragma assert (Property_Value = No_Node or else Kind (Property_Value) = k_property_value or else Kind (Property_Value) = k_literal or else Kind (Property_Value) = k_minus_numeric_term or else Kind (Property_Value) = k_signed_aadlnumber or else Kind (Property_Value) = k_number_range_term or else Kind (Property_Value) = k_not_boolean_term or else Kind (Property_Value) = k_and_boolean_term or else Kind (Property_Value) = k_or_boolean_term or else Kind (Property_Value) = k_parenthesis_boolean_term or else Kind (Property_Value) = k_reference_term or else Kind (Property_Value) = k_property_term or else Kind (Property_Value) = k_component_classifier_term or else DNKE (Property_Value)); Value_Type : property_type; Value_Node : node_id; begin if Property_Value = No_Node then Value_Node := No_Node; elsif Kind (Property_Value) = k_property_value then if Use_Evaluated_Values then if Expanded_Single_Value (Property_Value) /= No_Node then Value_Node := Expanded_Single_Value (Property_Value); elsif Expanded_Multi_Value (Property_Value) /= No_List then Value_Node := First_Node (Expanded_Multi_Value (Property_Value)); -- If we are dealing with a list of value, only -- consider the first value, assuming the other ones -- are of the same type else Value_Node := No_Node; end if; else if Single_Value (Property_Value) /= No_Node then Value_Node := Single_Value (Property_Value); elsif Multi_Value (Property_Value) /= No_List then Value_Node := First_Node (Multi_Value (Property_Value)); else Value_Node := No_Node; end if; end if; else Value_Node := Property_Value; end if; if Value_Node /= No_Node then case Kind (Value_Node) is when k_literal => Value_Type := Get_Type_Of_Literal (Value_Node); when k_minus_numeric_term => Value_Type := Get_Type_Of_Property_Value (Numeric_Term (Value_Node), Use_Evaluated_Values); when k_signed_aadlnumber => Value_Type := Get_Type_Of_Property_Value (Number_Value (Value_Node), Use_Evaluated_Values); when k_number_range_term => Value_Type := pt_range; when k_not_boolean_term | k_and_boolean_term | k_or_boolean_term | k_parenthesis_boolean_term => Value_Type := pt_boolean_expression; when k_reference_term => Value_Type := pt_reference; when k_component_classifier_term => Value_Type := pt_classifier; when others => Value_Type := pt_other; end case; else Value_Type := pt_other; end if; return Value_Type; end Get_Type_Of_Property_Value; ----------------------------------- -- Get_Integer_Of_Property_Value -- ----------------------------------- function Get_Integer_Of_Property_Value (Property_Value : Types.node_id) return Types.unsigned_long_long is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Number_Value (Property_Value)) = k_literal); begin return Get_Value_Type (Value (Number_Value (Property_Value))).IVal; end Get_Integer_Of_Property_Value; --------------------------------- -- Get_Float_Of_Property_Value -- --------------------------------- function Get_Float_Of_Property_Value (Property_Value : Types.node_id) return Long_Long_Float is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Number_Value (Property_Value)) = k_literal); begin return Get_Value_Type (Value (Number_Value (Property_Value))).RVal; end Get_Float_Of_Property_Value; ---------------------------------- -- Get_String_Of_Property_Value -- ---------------------------------- function Get_String_Of_Property_Value (Property_Value : Types.node_id) return Types.name_id is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Property_Value) = k_literal); begin return Get_Value_Type (Value (Property_Value)).SVal; end Get_String_Of_Property_Value; ---------------------------------- -- Get_String_Of_Property_Value -- ---------------------------------- function Get_String_Of_Property_Value (Property_Value : Types.node_id) return String is use Namet; use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Property_Value) = k_literal); begin return Get_Name_String (Get_String_Of_Property_Value (Property_Value)); end Get_String_Of_Property_Value; --------------------------------------- -- Get_Enumeration_Of_Property_Value -- --------------------------------------- function Get_Enumeration_Of_Property_Value (Property_Value : Types.node_id) return Types.name_id is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Property_Value) = k_literal and then Get_Value_Type (Value (Property_Value)).T = lt_enumeration); begin return Get_Value_Type (Value (Property_Value)).EVal; end Get_Enumeration_Of_Property_Value; --------------------------------------- -- Get_Enumeration_Of_Property_Value -- --------------------------------------- function Get_Enumeration_Of_Property_Value (Property_Value : Types.node_id) return String is use Types; use Ocarina.Nodes; use Namet; use Ocarina.AADL_Values; pragma assert (Kind (Property_Value) = k_literal and then Get_Value_Type (Value (Property_Value)).T = lt_enumeration); begin return Get_Name_String (Get_Enumeration_Of_Property_Value (Property_Value)); end Get_Enumeration_Of_Property_Value; ----------------------------------- -- Get_Boolean_Of_Property_Value -- ----------------------------------- function Get_Boolean_Of_Property_Value (Property_Value : Types.node_id) return Boolean is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Kind (Property_Value) = k_literal); begin return Get_Value_Type (Value (Property_Value)).BVal; end Get_Boolean_Of_Property_Value; ------------------------------------- -- Get_Reference_Of_Property_Value -- ------------------------------------- function Get_Reference_Of_Property_Value (Property_Value : Types.node_id) return Types.node_id is use Types; use Ocarina.Nodes; use Ocarina.Entities; pragma assert (Property_Value /= No_Node and then Kind (Property_Value) = k_reference_term); begin return Get_Referenced_Entity (Property_Value); end Get_Reference_Of_Property_Value; -------------------------------------- -- Get_Classifier_Of_Property_Value -- -------------------------------------- function Get_Classifier_Of_Property_Value (Property_Value : Types.node_id) return Types.node_id is use Types; use Ocarina.Nodes; use Ocarina.Entities; pragma assert (Property_Value /= No_Node and then Kind (Property_Value) = k_component_classifier_term); begin return Get_Referenced_Entity (Property_Value); end Get_Classifier_Of_Property_Value; --------------------------------------- -- Get_Value_Of_Property_Association -- --------------------------------------- function Get_Value_Of_Property_Association (Property : Types.node_id) return Ocarina.AADL_Values.value_type is use Types; use Ocarina.Nodes; use Ocarina.AADL_Values; pragma assert (Property /= No_Node and then Kind (Property) = k_property_association and then Property_Association_Value (Property) /= No_Node and then Single_Value (Property_Association_Value (Property)) /= No_Node and then (Kind (Single_Value (Property_Association_Value (Property))) = k_literal or else Kind (Number_Value (Single_Value (Property_Association_Value (Property)))) = k_literal)); begin if Kind (Single_Value (Property_Association_Value (Property))) = k_literal then return Get_Value_Type (Value (Single_Value (Property_Association_Value (Property)))); else return Get_Value_Type (Value (Number_Value (Single_Value (Property_Association_Value (Property))))); end if; end Get_Value_Of_Property_Association; ----------------------------------------- -- Find_Property_Association_From_Name -- ----------------------------------------- function Find_Property_Association_From_Name (Property_List : Types.list_id; Property_Name : Types.name_id) return Types.node_id is use Types; use Ocarina.Nodes; List_Node : node_id; Property_Node : node_id := No_Node; begin if Property_List /= No_List then List_Node := First_Node (Property_List); while List_Node /= No_Node loop if Name (Identifier (List_Node)) = Property_Name then Property_Node := List_Node; exit; end if; List_Node := Next_Node (List_Node); end loop; end if; return Property_Node; end Find_Property_Association_From_Name; ----------------------------------------- -- Find_Property_Association_From_Name -- ----------------------------------------- function Find_Property_Association_From_Name (Property_List : Types.list_id; Property_Name : String) return Types.node_id is use Charset; use Namet; use Types; Name : name_id; begin Set_Str_To_Name_Buffer (To_Lower (Property_Name)); Name := Name_Find; return Find_Property_Association_From_Name (Property_List, Name); end Find_Property_Association_From_Name; end Ocarina.Entities.Properties;