1------------------------------------------------------------------------------ 2-- -- 3-- Matreshka Project -- 4-- -- 5-- Web Framework -- 6-- -- 7-- Tools Component -- 8-- -- 9------------------------------------------------------------------------------ 10-- -- 11-- Copyright © 2015, Vadim Godunko <vgodunko@gmail.com> -- 12-- All rights reserved. -- 13-- -- 14-- Redistribution and use in source and binary forms, with or without -- 15-- modification, are permitted provided that the following conditions -- 16-- are met: -- 17-- -- 18-- * Redistributions of source code must retain the above copyright -- 19-- notice, this list of conditions and the following disclaimer. -- 20-- -- 21-- * Redistributions in binary form must reproduce the above copyright -- 22-- notice, this list of conditions and the following disclaimer in the -- 23-- documentation and/or other materials provided with the distribution. -- 24-- -- 25-- * Neither the name of the Vadim Godunko, IE nor the names of its -- 26-- contributors may be used to endorse or promote products derived from -- 27-- this software without specific prior written permission. -- 28-- -- 29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- 30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- 31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- 32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- 33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- 34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- 35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- 36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- 37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- 38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- 39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- 40-- -- 41------------------------------------------------------------------------------ 42-- $Revision: 5280 $ $Date: 2015-05-12 19:18:31 +0300 (Tue, 12 May 2015) $ 43------------------------------------------------------------------------------ 44with Asis.Declarations; 45with Asis.Elements; 46 47package body Properties.Declarations.Constant_Declarations is 48 49 ------------ 50 -- Bounds -- 51 ------------ 52 53 function Bounds 54 (Engine : access Engines.Contexts.Context; 55 Element : Asis.Declaration; 56 Name : Engines.Text_Property) return League.Strings.Universal_String 57 is 58 Tipe : constant Asis.Definition := 59 Asis.Declarations.Object_Declaration_View (Element); 60 begin 61 return Engine.Text.Get_Property (Tipe, Name); 62 end Bounds; 63 64 ---------- 65 -- Code -- 66 ---------- 67 68 function Code 69 (Engine : access Engines.Contexts.Context; 70 Element : Asis.Declaration; 71 Name : Engines.Text_Property) return League.Strings.Universal_String 72 is 73 List : constant Asis.Defining_Name_List := 74 Asis.Declarations.Names (Element); 75 76 Inside_Package : constant Boolean := Engine.Boolean.Get_Property 77 (Element, Engines.Inside_Package); 78 79 Init_Code : League.Strings.Universal_String; 80 81 Constant_Name : League.Strings.Universal_String; 82 Text : League.Strings.Universal_String; 83 begin 84 Init_Code := Engine.Text.Get_Property (Element, Engines.Initialize); 85 86 for J in List'Range loop 87 if Inside_Package then 88 Text.Append ("_ec."); 89 else 90 Text.Append ("var "); 91 end if; 92 93 Constant_Name := Engine.Text.Get_Property (List (J), Name); 94 Text.Append (Constant_Name); 95 96 if not Init_Code.Is_Empty then 97 Text.Append (" = "); 98 Text.Append (Init_Code); 99 end if; 100 101 Text.Append (";"); 102 end loop; 103 104 return Text; 105 end Code; 106 107 ---------------- 108 -- Initialize -- 109 ---------------- 110 111 function Initialize 112 (Engine : access Engines.Contexts.Context; 113 Element : Asis.Declaration; 114 Name : Engines.Text_Property) return League.Strings.Universal_String 115 is 116 Is_Simple_Ref : constant Boolean := 117 Engine.Boolean.Get_Property (Element, Engines.Is_Simple_Ref); 118 Tipe : constant Asis.Definition := 119 Asis.Declarations.Object_Declaration_View (Element); 120 Init : constant Asis.Expression := 121 Asis.Declarations.Initialization_Expression (Element); 122 Result : League.Strings.Universal_String; 123 begin 124 if Is_Simple_Ref then 125 Result.Append ("{all: "); 126 end if; 127 128 if not Asis.Elements.Is_Nil (Init) then 129 Result.Append (Engine.Text.Get_Property (Init, Engines.Code)); 130 else 131 Result.Append (Engine.Text.Get_Property (Tipe, Name)); 132 end if; 133 134 if Is_Simple_Ref then 135 Result.Append ("}"); 136 end if; 137 138 return Result; 139 end Initialize; 140 141 ------------------- 142 -- Is_Simple_Ref -- 143 ------------------- 144 145 function Is_Simple_Ref 146 (Engine : access Engines.Contexts.Context; 147 Element : Asis.Declaration; 148 Name : Engines.Boolean_Property) return Boolean 149 is 150 pragma Unreferenced (Name); 151 Tipe : constant Asis.Definition := 152 Asis.Declarations.Object_Declaration_View (Element); 153 begin 154 return Asis.Elements.Has_Aliased (Element) and then 155 Engine.Boolean.Get_Property (Tipe, Engines.Is_Simple_Type); 156 end Is_Simple_Ref; 157 158end Properties.Declarations.Constant_Declarations; 159