repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
onox/orka | Ada | 2,282 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2022 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Unchecked_Conversion;
with Orka.SIMD.AVX.Doubles.Swizzle;
with Orka.SIMD.AVX.Integers.Swizzle;
with Orka.SIMD.SSE2.Doubles;
with Orka.SIMD.SSE2.Longs.Shift;
with Orka.SIMD.SSE2.Longs.Convert;
package body Orka.SIMD.AVX.Longs.Random.Emulation is
package SSE2_Random renames Orka.SIMD.SSE2.Integers.Random;
use SIMD.SSE2.Doubles;
use SIMD.SSE2.Integers;
use SIMD.SSE2.Longs;
use SIMD.SSE2.Longs.Shift;
use SIMD.AVX.Integers;
use SIMD.AVX.Integers.Swizzle;
use SIMD.AVX.Doubles.Swizzle;
function Convert is new Ada.Unchecked_Conversion (m256i, m256l);
procedure Next (S : in out State; Value : out m256l) is
High, Low : m128i;
begin
SSE2_Random.Next (SSE2_Random.State (S), Low);
SSE2_Random.Next (SSE2_Random.State (S), High);
Value := Convert (Pack (High => High, Low => Low));
end Next;
function Convert is new Ada.Unchecked_Conversion (m128i, m128l);
function Convert is new Ada.Unchecked_Conversion (m128l, m128i);
procedure Next (S : in out State; Value : out m256d) is
Result : m128i;
High, Low : m128d;
begin
SSE2_Random.Next (SSE2_Random.State (S), Result);
Low := SIMD.SSE2.Longs.Convert.To_Unit_Floats (Result);
Result := Convert (Shift_Elements_Right_Zeros (Convert (Result)));
High := SIMD.SSE2.Longs.Convert.To_Unit_Floats (Result);
Value := Pack (High => High, Low => Low);
end Next;
overriding
procedure Reset (S : out State; Seed : Duration) is
begin
SSE2_Random.Reset (SSE2_Random.State (S), Seed);
end Reset;
end Orka.SIMD.AVX.Longs.Random.Emulation;
|
greifentor/archimedes-legacy | Ada | 87,644 | ads | <Diagramm>
<Colors>
<Anzahl>23</Anzahl>
<Color0>
<B>255</B>
<G>0</G>
<Name>blau</Name>
<R>0</R>
</Color0>
<Color1>
<B>221</B>
<G>212</G>
<Name>blaugrau</Name>
<R>175</R>
</Color1>
<Color10>
<B>192</B>
<G>192</G>
<Name>hellgrau</Name>
<R>192</R>
</Color10>
<Color11>
<B>255</B>
<G>0</G>
<Name>kamesinrot</Name>
<R>255</R>
</Color11>
<Color12>
<B>0</B>
<G>200</G>
<Name>orange</Name>
<R>255</R>
</Color12>
<Color13>
<B>255</B>
<G>247</G>
<Name>pastell-blau</Name>
<R>211</R>
</Color13>
<Color14>
<B>186</B>
<G>245</G>
<Name>pastell-gelb</Name>
<R>255</R>
</Color14>
<Color15>
<B>234</B>
<G>255</G>
<Name>pastell-gr&uuml;n</Name>
<R>211</R>
</Color15>
<Color16>
<B>255</B>
<G>211</G>
<Name>pastell-lila</Name>
<R>244</R>
</Color16>
<Color17>
<B>191</B>
<G>165</G>
<Name>pastell-rot</Name>
<R>244</R>
</Color17>
<Color18>
<B>175</B>
<G>175</G>
<Name>pink</Name>
<R>255</R>
</Color18>
<Color19>
<B>0</B>
<G>0</G>
<Name>rot</Name>
<R>255</R>
</Color19>
<Color2>
<B>61</B>
<G>125</G>
<Name>braun</Name>
<R>170</R>
</Color2>
<Color20>
<B>0</B>
<G>0</G>
<Name>schwarz</Name>
<R>0</R>
</Color20>
<Color21>
<B>255</B>
<G>255</G>
<Name>t&uuml;rkis</Name>
<R>0</R>
</Color21>
<Color22>
<B>255</B>
<G>255</G>
<Name>wei&szlig;</Name>
<R>255</R>
</Color22>
<Color3>
<B>64</B>
<G>64</G>
<Name>dunkelgrau</Name>
<R>64</R>
</Color3>
<Color4>
<B>84</B>
<G>132</G>
<Name>dunkelgr&uuml;n</Name>
<R>94</R>
</Color4>
<Color5>
<B>0</B>
<G>255</G>
<Name>gelb</Name>
<R>255</R>
</Color5>
<Color6>
<B>0</B>
<G>225</G>
<Name>goldgelb</Name>
<R>255</R>
</Color6>
<Color7>
<B>128</B>
<G>128</G>
<Name>grau</Name>
<R>128</R>
</Color7>
<Color8>
<B>0</B>
<G>255</G>
<Name>gr&uuml;n</Name>
<R>0</R>
</Color8>
<Color9>
<B>255</B>
<G>212</G>
<Name>hellblau</Name>
<R>191</R>
</Color9>
</Colors>
<ComplexIndices>
<IndexCount>0</IndexCount>
</ComplexIndices>
<DataSource>
<Import>
<DBName></DBName>
<Description></Description>
<Domains>false</Domains>
<Driver></Driver>
<Name></Name>
<Referenzen>false</Referenzen>
<User></User>
</Import>
<Update>
<DBMode>MYSQL</DBMode>
<DBName></DBName>
<Description></Description>
<DomainFaehig>false</DomainFaehig>
<Driver></Driver>
<FkNotNullBeachten>false</FkNotNullBeachten>
<Name></Name>
<ReferenzenSetzen>false</ReferenzenSetzen>
<User></User>
</Update>
</DataSource>
<DefaultComment>
<Anzahl>0</Anzahl>
</DefaultComment>
<Domains>
<Anzahl>8</Anzahl>
<Domain0>
<Datatype>12</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A type to represent account numbers.</Kommentar>
<Length>20</Length>
<NKS>0</NKS>
<Name>AccountNumber</Name>
</Domain0>
<Domain1>
<Datatype>4</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>An amount of cents.</Kommentar>
<Length>0</Length>
<NKS>0</NKS>
<Name>Amount</Name>
</Domain1>
<Domain2>
<Datatype>12</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A type for bank identification numbers.</Kommentar>
<Length>20</Length>
<NKS>0</NKS>
<Name>BankIdentificationNumber</Name>
</Domain2>
<Domain3>
<Datatype>4</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A type to represent boolean values.</Kommentar>
<Length>0</Length>
<NKS>0</NKS>
<Name>Boolean</Name>
</Domain3>
<Domain4>
<Datatype>4</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A domain for primary keys.</Kommentar>
<Length>0</Length>
<NKS>0</NKS>
<Name>Ident</Name>
</Domain4>
<Domain5>
<Datatype>12</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A domain for names.</Kommentar>
<Length>100</Length>
<NKS>0</NKS>
<Name>Name</Name>
</Domain5>
<Domain6>
<Datatype>12</Datatype>
<History>SEMSTRAL, </History>
<Initialwert>NULL</Initialwert>
<Kommentar>A type for periode enum representations (YEAR, SEMESTRAL, QUARTER, MONTH).</Kommentar>
<Length>10</Length>
<NKS>0</NKS>
<Name>Periode</Name>
</Domain6>
<Domain7>
<Datatype>12</Datatype>
<History>@changed OLI 01.03.2013 - Added.</History>
<Initialwert>NULL</Initialwert>
<Kommentar>A domain for reasons of payment.</Kommentar>
<Length>255</Length>
<NKS>0</NKS>
<Name>ReasonOfPayment</Name>
</Domain7>
</Domains>
<Factories>
<Object>archimedes.legacy.scheme.DefaultObjectFactory</Object>
</Factories>
<Pages>
<PerColumn>5</PerColumn>
<PerRow>10</PerRow>
</Pages>
<Parameter>
<AdditionalSQLScriptListener></AdditionalSQLScriptListener>
<Applicationname>Kroisos</Applicationname>
<AufgehobeneAusblenden>false</AufgehobeneAusblenden>
<Autor>ollie</Autor>
<Basepackagename>kroisos</Basepackagename>
<CodeFactoryClassName></CodeFactoryClassName>
<Codebasispfad>.\</Codebasispfad>
<DBVersionDBVersionColumn></DBVersionDBVersionColumn>
<DBVersionDescriptionColumn></DBVersionDescriptionColumn>
<DBVersionTablename></DBVersionTablename>
<History>@changed OLI 01.03.2013 - Added.</History>
<Kommentar>The model of the Kroisos application.</Kommentar>
<Name>Kroisos</Name>
<PflichtfelderMarkieren>false</PflichtfelderMarkieren>
<ReferenzierteSpaltenAnzeigen>true</ReferenzierteSpaltenAnzeigen>
<SchemaName></SchemaName>
<Schriftgroessen>
<Tabelleninhalte>12</Tabelleninhalte>
<Ueberschriften>24</Ueberschriften>
<Untertitel>12</Untertitel>
</Schriftgroessen>
<Scripte>
<AfterWrite>&lt;null&gt;</AfterWrite>
</Scripte>
<TechnischeFelderAusgrauen>false</TechnischeFelderAusgrauen>
<UdschebtiBaseClassName></UdschebtiBaseClassName>
<Version>1</Version>
<Versionsdatum>01.03.2013</Versionsdatum>
<Versionskommentar>&lt;null&gt;</Versionskommentar>
</Parameter>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Tabellen>
<Anzahl>7</Anzahl>
<Tabelle0>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>pastell-blau</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>A representation of accounts.</Kommentar>
<NMRelation>false</NMRelation>
<Name>Account</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>5</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen></Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The key of the account.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History></History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar></Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Bank</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>RIGHT</Direction0>
<Direction1>LEFT</Direction1>
<Offset0>150</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>Bank</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>RIGHT</Direction0>
<Direction1>LEFT</Direction1>
<Name>Main</Name>
<Offset0>150</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History></History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar></Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Owner</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>RIGHT</Direction0>
<Direction1>LEFT</Direction1>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>Owner</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>RIGHT</Direction0>
<Direction1>LEFT</Direction1>
<Name>Main</Name>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
<Spalte3>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Name</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>A name for the account.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>AccountName</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte3>
<Spalte4>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>AccountNumber</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The account number.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>AccountNumber</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte4>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>100</X>
<Y>100</Y>
</View0>
</Views>
</Tabelle0>
<Tabelle1>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>pastell-rot</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History></History>
<InDevelopment>false</InDevelopment>
<Kommentar></Kommentar>
<NMRelation>false</NMRelation>
<Name>Bank</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>3</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen>LIST: Account</Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The key of the bank.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>BankIdentificationNumber</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History></History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar></Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>BankIdentificationNumber</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter>NOT-EMPTY</Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Name</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The name of the bank.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>BankName</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter>NOT-EMPTY</Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>525</X>
<Y>225</Y>
</View0>
</Views>
</Tabelle1>
<Tabelle2>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>goldgelb</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>The representation of account owners.</Kommentar>
<NMRelation>false</NMRelation>
<Name>Owner</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>3</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen>LIST: Account</Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The id of the owner.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Name</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The first name of the owner.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>FirstName</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Name</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The last name of the owner.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>LastName</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>525</X>
<Y>100</Y>
</View0>
</Views>
</Tabelle2>
<Tabelle3>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>hellblau</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>The representation of the acount entries.</Kommentar>
<NMRelation>false</NMRelation>
<Name>AccountEntry</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>5</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen>LIST: BudgetEntry</Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The id of the account entry.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The account whose balance is decreased by the account of the entry.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Creadit</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>Account</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Name>Main</Name>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The account whose balance is increased by the entry.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Debit</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Offset0>50</Offset0>
<Offset1>50</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>Account</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Name>Main</Name>
<Offset0>50</Offset0>
<Offset1>50</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
<Spalte3>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Boolean</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>A flag which can be used to mark account entries as open.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Invalid</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte3>
<Spalte4>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>ReasonOfPayment</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The reason of payment for the account entry,.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>ReasonOfPayment</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte4>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>100</X>
<Y>375</Y>
</View0>
</Views>
</Tabelle3>
<Tabelle4>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>dunkelgr&uuml;n</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>Representation of a budget.</Kommentar>
<NMRelation>false</NMRelation>
<Name>Budget</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>3</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen></Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The primary key of the budget.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Name</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The name of the budget.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>BudgetName</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Amount</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History></History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar></Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>MaximumAmount</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>100</X>
<Y>800</Y>
</View0>
</Views>
</Tabelle4>
<Tabelle5>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>pastell-gr&uuml;n</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>A single budget entry which represents an amount of an account entry which is to book on the related budget.</Kommentar>
<NMRelation>false</NMRelation>
<Name>BudgetEntry</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>3</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen></Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The account entry which the budget entry is assigned to.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>AccountEntry</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>AccountEntry</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>UP</Direction0>
<Direction1>DOWN</Direction1>
<Name>Main</Name>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The budget which the entry is related to.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Budget</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<Referenz>
<Direction0>DOWN</Direction0>
<Direction1>UP</Direction1>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>Budget</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>DOWN</Direction0>
<Direction1>UP</Direction1>
<Name>Main</Name>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
<Spalte2>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Amount</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The amount which is to book for the budget.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Amount</Name>
<NotNull>false</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte2>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>100</X>
<Y>600</Y>
</View0>
</Views>
</Tabelle5>
<Tabelle6>
<Aufgehoben>false</Aufgehoben>
<Codegenerator>
<AuswahlMembers>
<Anzahl>0</Anzahl>
</AuswahlMembers>
<CompareMembers>
<Anzahl>0</Anzahl>
</CompareMembers>
<Equalsmembers>
<Anzahl>0</Anzahl>
</Equalsmembers>
<HashCodeMembers>
<Anzahl>0</Anzahl>
</HashCodeMembers>
<NReferenzen>
<Anzahl>0</Anzahl>
</NReferenzen>
<OrderMembers>
<Anzahl>0</Anzahl>
</OrderMembers>
<ToComboStringMembers>
<Anzahl>0</Anzahl>
</ToComboStringMembers>
<ToStringMembers>
<Anzahl>0</Anzahl>
</ToStringMembers>
</Codegenerator>
<Farben>
<Hintergrund>blaugrau</Hintergrund>
<Schrift>schwarz</Schrift>
</Farben>
<FirstGenerationDone>false</FirstGenerationDone>
<History>@changed OLI 01.03.2013 - Added.</History>
<InDevelopment>false</InDevelopment>
<Kommentar>A preriodic account entry.</Kommentar>
<NMRelation>false</NMRelation>
<Name>PeriodicAccountEntry</Name>
<Panels>
<Anzahl>1</Anzahl>
<Panel0>
<PanelClass></PanelClass>
<PanelNumber>0</PanelNumber>
<TabMnemonic>1</TabMnemonic>
<TabTitle>1.Daten</TabTitle>
<TabToolTipText>Hier können Sie die Daten des Objekt warten</TabToolTipText>
</Panel0>
</Panels>
<Spalten>
<Anzahl>2</Anzahl>
<Codegenerator>
<ActiveInApplication>false</ActiveInApplication>
<Codegeneratoroptionen></Codegeneratoroptionen>
<Codeverzeichnis>.</Codeverzeichnis>
<Codieren>true</Codieren>
<DynamicCode>true</DynamicCode>
<Inherited>false</Inherited>
<Kontextname></Kontextname>
<UniqueFormula></UniqueFormula>
</Codegenerator>
<Spalte0>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>true</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Ident</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>true</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>@changed OLI 01.03.2013 - Added.</History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The primary key of the periodic account entry.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Id</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>true</PrimaryKey>
<Referenz>
<Direction0>LEFT</Direction0>
<Direction1>RIGHT</Direction1>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
<Spalte>Id</Spalte>
<Tabelle>AccountEntry</Tabelle>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Direction0>LEFT</Direction0>
<Direction1>RIGHT</Direction1>
<Name>Main</Name>
<Offset0>25</Offset0>
<Offset1>25</Offset1>
<Punkte>
<Anzahl>0</Anzahl>
</Punkte>
</View0>
</Views>
</Referenz>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte0>
<Spalte1>
<AlterInBatch>false</AlterInBatch>
<Aufgehoben>false</Aufgehoben>
<CanBeReferenced>false</CanBeReferenced>
<Disabled>false</Disabled>
<Domain>Periode</Domain>
<Editordescriptor>
<Editormember>false</Editormember>
<LabelText></LabelText>
<MaxCharacters>0</MaxCharacters>
<Mnemonic></Mnemonic>
<Position>0</Position>
<ReferenceWeight>keine</ReferenceWeight>
<RessourceIdentifier></RessourceIdentifier>
<ToolTipText></ToolTipText>
</Editordescriptor>
<ForeignKey>false</ForeignKey>
<Global>false</Global>
<GlobalId>false</GlobalId>
<HideReference>false</HideReference>
<History>SEMSTRAL, </History>
<IndexSearchMember>false</IndexSearchMember>
<Indexed>false</Indexed>
<IndividualDefaultValue></IndividualDefaultValue>
<Kodiert>false</Kodiert>
<Kommentar>The periode which is valid for the periodic entry.</Kommentar>
<Konsistenz>
<Writeablemember>false</Writeablemember>
</Konsistenz>
<LastModificationField>false</LastModificationField>
<ListItemField>false</ListItemField>
<Name>Periode</Name>
<NotNull>true</NotNull>
<PanelNumber>0</PanelNumber>
<Parameter></Parameter>
<PrimaryKey>false</PrimaryKey>
<RemovedStateField>false</RemovedStateField>
<TechnicalField>false</TechnicalField>
<Unique>false</Unique>
</Spalte1>
</Spalten>
<Stereotype>
<Anzahl>0</Anzahl>
</Stereotype>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Name>Main</Name>
<X>525</X>
<Y>375</Y>
</View0>
</Views>
</Tabelle6>
</Tabellen>
<Views>
<Anzahl>1</Anzahl>
<View0>
<Beschreibung>Diese Sicht beinhaltet alle Tabellen des Schemas</Beschreibung>
<Name>Main</Name>
<ReferenzierteSpaltenAnzeigen>true</ReferenzierteSpaltenAnzeigen>
<Tabelle0>Account</Tabelle0>
<Tabelle1>Bank</Tabelle1>
<Tabelle2>Owner</Tabelle2>
<Tabelle3>AccountEntry</Tabelle3>
<Tabelle4>Budget</Tabelle4>
<Tabelle5>BudgetEntry</Tabelle5>
<Tabelle6>PeriodicAccountEntry</Tabelle6>
<Tabellenanzahl>7</Tabellenanzahl>
<TechnischeSpaltenVerstecken>false</TechnischeSpaltenVerstecken>
</View0>
</Views>
</Diagramm>
|
zhmu/ananas | Ada | 3,043 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V A L _ F L T --
-- --
-- S p e c --
-- --
-- Copyright (C) 2020-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains routines for scanning real values for floating point
-- type Float, for use in Text_IO.Float_IO and the Value attribute.
with System.Powten_Flt;
with System.Unsigned_Types;
with System.Val_Real;
package System.Val_Flt is
pragma Preelaborate;
package Impl is new Val_Real
(Float,
System.Powten_Flt.Maxpow,
System.Powten_Flt.Powten'Address,
Unsigned_Types.Unsigned);
function Scan_Float
(Str : String;
Ptr : not null access Integer;
Max : Integer) return Float
renames Impl.Scan_Real;
function Value_Float (Str : String) return Float
renames Impl.Value_Real;
end System.Val_Flt;
|
PThierry/ewok-kernel | Ada | 1,147 | ads | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with soc.interrupts;
package ewok.posthook
with spark_mode => off
is
type t_args is new unsigned_32_array (1 .. 2);
type t_args_access is access all t_args;
-- Execute posthook for a given interrupt
procedure exec
(intr : in soc.interrupts.t_interrupt;
status : out unsigned_32;
data : out unsigned_32);
end ewok.posthook;
|
sebsgit/textproc | Ada | 590 | ads | with ImageRegions;
with PixelArray;
package ImageMoments is
type HuMoments is tagged record
h1, h2, h3, h4, h5, h6, h7: Float;
end record;
function match_I1(a, b: HuMoments) return Float;
function match_I2(a, b: HuMoments) return Float;
function match_I3(a, b: HuMoments) return Float;
function match_rms(a, b: HuMoments) return Float;
function calculateMoments(image: PixelArray.ImagePlane; region: ImageRegions.Region) return HuMoments;
function orientationAngle(image: PixelArray.ImagePlane; region: ImageRegions.Region) return Float;
end ImageMoments;
|
sungyeon/drake | Ada | 319 | ads | pragma License (Unrestricted);
with Ada.Containers;
generic
with package Bounded is new Generic_Bounded_Length (<>);
function Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash (
Key : Bounded.Bounded_Wide_Wide_String)
return Containers.Hash_Type;
pragma Preelaborate (Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash);
|
charlie5/aIDE | Ada | 1,659 | adb | with
AdaM.Factory;
package body AdaM.generic_Unit
is
-- Storage Pool
--
record_Version : constant := 1;
pool_Size : constant := 5_000;
package Pool is new AdaM.Factory.Pools (".adam-store",
"generic_units",
pool_Size,
record_Version,
generic_Unit.item,
generic_Unit.view);
-- Forge
--
procedure define (Self : in out Item)
is
begin
null;
end define;
procedure destruct (Self : in out Item)
is
begin
null;
end destruct;
function new_Subprogram return View
is
new_View : constant generic_Unit.view := Pool.new_Item;
begin
define (generic_Unit.item (new_View.all));
return new_View;
end new_Subprogram;
procedure free (Self : in out generic_Unit.view)
is
begin
destruct (generic_Unit.item (Self.all));
Pool.free (Self);
end free;
-- Attributes
--
overriding
function Id (Self : access Item) return AdaM.Id
is
begin
return Pool.to_Id (Self);
end Id;
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
renames Pool.View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
renames Pool.View_read;
end AdaM.generic_Unit;
|
burratoo/Acton | Ada | 1,346 | adb | ------------------------------------------------------------------------------------------
-- --
-- ACTON ANALYSER --
-- --
-- ACTON_ANALYSER --
-- --
-- Copyright (C) 2016-2021, Patrick Bernardi --
-- --
------------------------------------------------------------------------------------------
with ASIS_Application_Driver_1;
with Protected_Objects;
with Tasks;
with Acton_Properties;
with Program_Statistics;
with Schedulers;
procedure Acton_Analyser is
begin
ASIS_Application_Driver_1;
Acton_Properties.Print_Acton_Properties;
Tasks.Print_Task_Units;
Tasks.Print_Task_Objects;
Protected_Objects.Print_Protected_Units;
Protected_Objects.Print_Protected_Objects;
Schedulers.Print_Schedulers;
Program_Statistics.Calculate_Statistics;
Program_Statistics.Print_Statistics;
end Acton_Analyser;
|
zhmu/ananas | Ada | 147 | adb | -- { dg-do compile }
package body Array32 is
procedure Init (A : out Arr) is
begin
A := ((I => 1), (I => 2));
end;
end Array32;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 6,617 | ads | -- This spec has been automatically generated from STM32F0xx.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.DBGMCU is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype IDCODE_DEV_ID_Field is STM32_SVD.UInt12;
subtype IDCODE_DIV_ID_Field is STM32_SVD.UInt4;
subtype IDCODE_REV_ID_Field is STM32_SVD.UInt16;
-- MCU Device ID Code Register
type IDCODE_Register is record
-- Read-only. Device Identifier
DEV_ID : IDCODE_DEV_ID_Field;
-- Read-only. Division Identifier
DIV_ID : IDCODE_DIV_ID_Field;
-- Read-only. Revision Identifier
REV_ID : IDCODE_REV_ID_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for IDCODE_Register use record
DEV_ID at 0 range 0 .. 11;
DIV_ID at 0 range 12 .. 15;
REV_ID at 0 range 16 .. 31;
end record;
subtype CR_DBG_STOP_Field is STM32_SVD.Bit;
subtype CR_DBG_STANDBY_Field is STM32_SVD.Bit;
-- Debug MCU Configuration Register
type CR_Register is record
-- unspecified
Reserved_0_0 : STM32_SVD.Bit := 16#0#;
-- Debug Stop Mode
DBG_STOP : CR_DBG_STOP_Field := 16#0#;
-- Debug Standby Mode
DBG_STANDBY : CR_DBG_STANDBY_Field := 16#0#;
-- unspecified
Reserved_3_31 : STM32_SVD.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
Reserved_0_0 at 0 range 0 .. 0;
DBG_STOP at 0 range 1 .. 1;
DBG_STANDBY at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype APBLFZ_DBG_TIMER2_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_TIMER3_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_TIMER6_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_TIMER14_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_RTC_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_WWDG_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_DBG_IWDG_STOP_Field is STM32_SVD.Bit;
subtype APBLFZ_I2C1_SMBUS_TIMEOUT_Field is STM32_SVD.Bit;
-- APB Low Freeze Register
type APBLFZ_Register is record
-- Debug Timer 2 stopped when Core is halted
DBG_TIMER2_STOP : APBLFZ_DBG_TIMER2_STOP_Field := 16#0#;
-- Debug Timer 3 stopped when Core is halted
DBG_TIMER3_STOP : APBLFZ_DBG_TIMER3_STOP_Field := 16#0#;
-- unspecified
Reserved_2_3 : STM32_SVD.UInt2 := 16#0#;
-- Debug Timer 6 stopped when Core is halted
DBG_TIMER6_STOP : APBLFZ_DBG_TIMER6_STOP_Field := 16#0#;
-- unspecified
Reserved_5_7 : STM32_SVD.UInt3 := 16#0#;
-- Debug Timer 14 stopped when Core is halted
DBG_TIMER14_STOP : APBLFZ_DBG_TIMER14_STOP_Field := 16#0#;
-- unspecified
Reserved_9_9 : STM32_SVD.Bit := 16#0#;
-- Debug RTC stopped when Core is halted
DBG_RTC_STOP : APBLFZ_DBG_RTC_STOP_Field := 16#0#;
-- Debug Window Wachdog stopped when Core is halted
DBG_WWDG_STOP : APBLFZ_DBG_WWDG_STOP_Field := 16#0#;
-- Debug Independent Wachdog stopped when Core is halted
DBG_IWDG_STOP : APBLFZ_DBG_IWDG_STOP_Field := 16#0#;
-- unspecified
Reserved_13_20 : STM32_SVD.Byte := 16#0#;
-- SMBUS timeout mode stopped when Core is halted
I2C1_SMBUS_TIMEOUT : APBLFZ_I2C1_SMBUS_TIMEOUT_Field := 16#0#;
-- unspecified
Reserved_22_31 : STM32_SVD.UInt10 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for APBLFZ_Register use record
DBG_TIMER2_STOP at 0 range 0 .. 0;
DBG_TIMER3_STOP at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
DBG_TIMER6_STOP at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
DBG_TIMER14_STOP at 0 range 8 .. 8;
Reserved_9_9 at 0 range 9 .. 9;
DBG_RTC_STOP at 0 range 10 .. 10;
DBG_WWDG_STOP at 0 range 11 .. 11;
DBG_IWDG_STOP at 0 range 12 .. 12;
Reserved_13_20 at 0 range 13 .. 20;
I2C1_SMBUS_TIMEOUT at 0 range 21 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
subtype APBHFZ_DBG_TIMER1_STOP_Field is STM32_SVD.Bit;
subtype APBHFZ_DBG_TIMER15_STO_Field is STM32_SVD.Bit;
subtype APBHFZ_DBG_TIMER16_STO_Field is STM32_SVD.Bit;
subtype APBHFZ_DBG_TIMER17_STO_Field is STM32_SVD.Bit;
-- APB High Freeze Register
type APBHFZ_Register is record
-- unspecified
Reserved_0_10 : STM32_SVD.UInt11 := 16#0#;
-- Debug Timer 1 stopped when Core is halted
DBG_TIMER1_STOP : APBHFZ_DBG_TIMER1_STOP_Field := 16#0#;
-- unspecified
Reserved_12_15 : STM32_SVD.UInt4 := 16#0#;
-- Debug Timer 15 stopped when Core is halted
DBG_TIMER15_STO : APBHFZ_DBG_TIMER15_STO_Field := 16#0#;
-- Debug Timer 16 stopped when Core is halted
DBG_TIMER16_STO : APBHFZ_DBG_TIMER16_STO_Field := 16#0#;
-- Debug Timer 17 stopped when Core is halted
DBG_TIMER17_STO : APBHFZ_DBG_TIMER17_STO_Field := 16#0#;
-- unspecified
Reserved_19_31 : STM32_SVD.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for APBHFZ_Register use record
Reserved_0_10 at 0 range 0 .. 10;
DBG_TIMER1_STOP at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
DBG_TIMER15_STO at 0 range 16 .. 16;
DBG_TIMER16_STO at 0 range 17 .. 17;
DBG_TIMER17_STO at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Debug support
type DBGMCU_Peripheral is record
-- MCU Device ID Code Register
IDCODE : aliased IDCODE_Register;
-- Debug MCU Configuration Register
CR : aliased CR_Register;
-- APB Low Freeze Register
APBLFZ : aliased APBLFZ_Register;
-- APB High Freeze Register
APBHFZ : aliased APBHFZ_Register;
end record
with Volatile;
for DBGMCU_Peripheral use record
IDCODE at 16#0# range 0 .. 31;
CR at 16#4# range 0 .. 31;
APBLFZ at 16#8# range 0 .. 31;
APBHFZ at 16#C# range 0 .. 31;
end record;
-- Debug support
DBGMCU_Periph : aliased DBGMCU_Peripheral
with Import, Address => System'To_Address (16#40015800#);
end STM32_SVD.DBGMCU;
|
onox/orka | Ada | 953 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
package body Orka.SIMD.SSE.Singles.Compare is
function Is_True (Elements : m128; Position : Index_4D) return Boolean is
begin
return Elements (Position) /= 0.0;
exception
when Constraint_Error =>
return True;
end Is_True;
end Orka.SIMD.SSE.Singles.Compare;
|
fengjixuchui/ewok-kernel | Ada | 5,155 | ads | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with m4.mpu;
with types;
package soc.layout
with spark_mode => on
is
FLASH_BASE : constant system_address := 16#0800_0000#;
-- this specific SoC has two flash bank mapped consecutively, giving access
-- to 2MB of flash
FLASH_SIZE : constant := 2 * MBYTE;
SRAM_BASE : constant system_address := 16#1000_0000#;
SRAM_SIZE : constant := 64 * KBYTE;
BOOTROM_BASE : constant system_address := 16#1FFF_0000#;
RAM_BASE : constant system_address := 16#2000_0000#; -- SRAM
RAM_SIZE : constant := 128 * KBYTE;
USER_RAM_BASE : constant system_address := 16#2000_0000#; -- SRAM
USER_RAM_SIZE : constant := 128 * KBYTE;
KERNEL_RAM_BASE : constant system_address := 16#1000_0000#;
KERNEL_RAM_SIZE : constant := 64 * KBYTE;
PERIPH_BASE : constant system_address := 16#4000_0000#;
MEMORY_BANK1_BASE : constant system_address := 16#6000_0000#;
MEMORY_BANK2_BASE : constant system_address := MEMORY_BANK1_BASE;
APB1PERIPH_BASE : constant system_address := PERIPH_BASE;
APB2PERIPH_BASE : constant system_address := PERIPH_BASE + 16#0001_0000#;
AHB1PERIPH_BASE : constant system_address := PERIPH_BASE + 16#0002_0000#;
AHB2PERIPH_BASE : constant system_address := PERIPH_BASE + 16#1000_0000#;
--
-- AHB1 peripherals
--
GPIOA_BASE : constant system_address := AHB1PERIPH_BASE + 16#0000#;
GPIOB_BASE : constant system_address := AHB1PERIPH_BASE + 16#0400#;
GPIOC_BASE : constant system_address := AHB1PERIPH_BASE + 16#0800#;
GPIOD_BASE : constant system_address := AHB1PERIPH_BASE + 16#0C00#;
GPIOE_BASE : constant system_address := AHB1PERIPH_BASE + 16#1000#;
GPIOF_BASE : constant system_address := AHB1PERIPH_BASE + 16#1400#;
GPIOG_BASE : constant system_address := AHB1PERIPH_BASE + 16#1800#;
GPIOH_BASE : constant system_address := AHB1PERIPH_BASE + 16#1C00#;
GPIOI_BASE : constant system_address := AHB1PERIPH_BASE + 16#2000#;
DMA1_BASE : constant system_address := AHB1PERIPH_BASE + 16#6000#;
DMA2_BASE : constant system_address := AHB1PERIPH_BASE + 16#6400#;
--
-- APB2 peripherals
--
SYSCFG_BASE : constant system_address := APB2PERIPH_BASE + 16#3800#;
--
-- Flash and firmware structure
--
--
-- Flip bank
FW1_SIZE : constant unsigned_32 := 576*1024;
FW1_KERN_BASE : constant unsigned_32 := 16#08020000#;
FW1_KERN_SIZE : constant unsigned_32 := 64*1024;
FW1_KERN_REGION_SIZE : constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_64KB;
FW1_USER_BASE : constant unsigned_32 := 16#08080000#;
FW1_USER_SIZE : constant unsigned_32 := 512*1024;
FW1_USER_REGION_SIZE : constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_512KB;
-- DFU 1
DFU1_SIZE : constant unsigned_32 := 320*1024;
DFU1_KERN_BASE : constant unsigned_32 := 16#08030000#;
DFU1_USER_BASE : constant unsigned_32 := 16#08040000#;
DFU1_KERN_SIZE : constant unsigned_32 := 64*1024;
DFU1_KERN_REGION_SIZE: constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_64KB;
DFU1_USER_SIZE : constant unsigned_32 := 256*1024;
DFU1_USER_REGION_SIZE: constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_256KB;
-- Flop bank
FW2_SIZE : constant unsigned_32 := 576*1024;
FW2_KERN_SIZE : constant unsigned_32 := 64*1024;
FW2_KERN_BASE : constant unsigned_32 := 16#08120000#;
FW2_KERN_REGION_SIZE : constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_64KB;
FW2_USER_BASE : constant unsigned_32 := 16#08180000#;
FW2_USER_SIZE : constant unsigned_32 := 512*1024;
FW2_USER_REGION_SIZE : constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_512KB;
-- FW2_USER_REGION_SIZE : constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_512KB;
-- DFU 2
DFU2_SIZE : constant unsigned_32 := 320*1024;
DFU2_KERN_BASE : constant unsigned_32 := 16#08130000#;
DFU2_KERN_SIZE : constant unsigned_32 := 64*1024;
DFU2_KERN_REGION_SIZE: constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_256KB;
DFU2_USER_BASE : constant unsigned_32 := 16#08140000#;
DFU2_USER_SIZE : constant unsigned_32 := 256*1024;
DFU2_USER_REGION_SIZE: constant m4.mpu.t_region_size := m4.mpu.REGION_SIZE_256KB;
end soc.layout;
|
reznikmm/matreshka | Ada | 3,814 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Style_Register_Truth_Ref_Style_Name_Attributes is
pragma Preelaborate;
type ODF_Style_Register_Truth_Ref_Style_Name_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Style_Register_Truth_Ref_Style_Name_Attribute_Access is
access all ODF_Style_Register_Truth_Ref_Style_Name_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Style_Register_Truth_Ref_Style_Name_Attributes;
|
reznikmm/matreshka | Ada | 4,613 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Fo.Border_Bottom_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Fo_Border_Bottom_Attribute_Node is
begin
return Self : Fo_Border_Bottom_Attribute_Node do
Matreshka.ODF_Fo.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Fo_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Fo_Border_Bottom_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Border_Bottom_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Fo_URI,
Matreshka.ODF_String_Constants.Border_Bottom_Attribute,
Fo_Border_Bottom_Attribute_Node'Tag);
end Matreshka.ODF_Fo.Border_Bottom_Attributes;
|
Letractively/ada-ado | Ada | 2,720 | ads | -----------------------------------------------------------------------
-- ADO Dialects -- Driver support for basic SQL Generation
-- Copyright (C) 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
-- The <b>ADO.Drivers.Dialects</b> package controls the database specific SQL dialects.
package ADO.Drivers.Dialects is
type Keyword_Array is array (Natural range <>) of Util.Strings.Name_Access;
-- --------------------
-- SQL Dialect
-- --------------------
-- The <b>Dialect</b> defines the specific characteristics that must be
-- taken into account when building the SQL statement. This includes:
-- <ul>
-- <li>The definition of reserved keywords that must be escaped</li>
-- <li>How to escape those keywords</li>
-- <li>How to escape special characters</li>
-- </ul>
type Dialect is tagged private;
type Dialect_Access is access all Dialect'Class;
-- Check if the string is a reserved keyword.
function Is_Reserved (D : Dialect;
Name : String) return Boolean;
-- Add a set of keywords to be escaped.
procedure Add_Keywords (D : in out Dialect;
Keywords : in Keyword_Array);
-- Get the quote character to escape an identifier.
function Get_Identifier_Quote (D : in Dialect) return Character;
-- Append the item in the buffer escaping some characters if necessary.
-- The default implementation only escapes the single quote ' by doubling them.
procedure Escape_Sql (D : in Dialect;
Buffer : in out Unbounded_String;
Item : in String);
-- Append the item in the buffer escaping some characters if necessary
procedure Escape_Sql (D : in Dialect;
Buffer : in out Unbounded_String;
Item : in ADO.Blob_Ref);
private
type Dialect is tagged record
Keywords : Util.Strings.String_Set.Set;
end record;
end ADO.Drivers.Dialects;
|
reznikmm/matreshka | Ada | 3,987 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Style_Protect_Attributes;
package Matreshka.ODF_Style.Protect_Attributes is
type Style_Protect_Attribute_Node is
new Matreshka.ODF_Style.Abstract_Style_Attribute_Node
and ODF.DOM.Style_Protect_Attributes.ODF_Style_Protect_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Style_Protect_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Style_Protect_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Style.Protect_Attributes;
|
rveenker/sdlada | Ada | 2,760 | ads | --------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
-- SDL.Video.Displays
--
-- Access to display information including video displays and resolutions.
--------------------------------------------------------------------------------------------------------------------
with Interfaces.C;
with SDL.Video.Pixel_Formats;
with SDL.Video.Rectangles;
with System;
package SDL.Video.Displays is
package C renames Interfaces.C;
type Refresh_Rates is range 0 .. 400 with
Convention => C;
type Mode is
record
Format : SDL.Video.Pixel_Formats.Pixel_Format_Names;
Width : C.int;
Height : C.int;
Refresh_Rate : Refresh_Rates;
Driver_Data : System.Address; -- TODO: Somehow make this a real type.
end record with
Convention => C;
type Access_Mode is access all Mode with
Convention => C;
-- Video displays.
type Display_Indices is new Positive;
function Total return Display_Indices;
function Closest_Mode (Display : in Display_Indices; Wanted : in Mode; Target : out Mode) return Boolean;
function Current_Mode (Display : in Display_Indices; Target : out Mode) return Boolean;
function Desktop_Mode (Display : in Display_Indices; Target : out Mode) return Boolean;
function Display_Mode (Display : in Display_Indices; Index : in Natural; Target : out Mode) return Boolean;
function Total_Display_Modes (Display : in Display_Indices; Total : out Positive) return Boolean;
function Display_Bounds (Display : in Display_Indices; Bounds : out Rectangles.Rectangle) return Boolean;
end SDL.Video.Displays;
|
DrenfongWong/tkm-rpc | Ada | 433 | ads | with Ada.Unchecked_Conversion;
package Tkmrpc.Response.Ike.Esa_Create_No_Pfs.Convert is
function To_Response is new Ada.Unchecked_Conversion (
Source => Esa_Create_No_Pfs.Response_Type,
Target => Response.Data_Type);
function From_Response is new Ada.Unchecked_Conversion (
Source => Response.Data_Type,
Target => Esa_Create_No_Pfs.Response_Type);
end Tkmrpc.Response.Ike.Esa_Create_No_Pfs.Convert;
|
wookey-project/ewok-legacy | Ada | 44 | ads | ../../stm32f439/Ada/soc-layout-stm32f42x.ads |
reznikmm/matreshka | Ada | 4,201 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
limited with AMF.UML.Operations;
package AMF.Utp.Data_Selectors is
pragma Preelaborate;
type Utp_Data_Selector is limited interface;
type Utp_Data_Selector_Access is
access all Utp_Data_Selector'Class;
for Utp_Data_Selector_Access'Storage_Size use 0;
not overriding function Get_Base_Operation
(Self : not null access constant Utp_Data_Selector)
return AMF.UML.Operations.UML_Operation_Access is abstract;
-- Getter of DataSelector::base_Operation.
--
not overriding procedure Set_Base_Operation
(Self : not null access Utp_Data_Selector;
To : AMF.UML.Operations.UML_Operation_Access) is abstract;
-- Setter of DataSelector::base_Operation.
--
end AMF.Utp.Data_Selectors;
|
stcarrez/ada-awa | Ada | 48,191 | adb | -----------------------------------------------------------------------
-- awa-users-services -- User registration, authentication processes
-- Copyright (C) 2009 - 2020, 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings;
with Ada.Calendar;
with Util.Log.Loggers;
with Util.Strings.Transforms;
with Util.Mail;
with Util.Encoders.HMAC.SHA1;
with ADO.SQL;
with ADO.Statements;
with ADO.Objects;
with Security.Contexts;
with Security.Policies;
with AWA.Services;
with AWA.Services.Contexts;
package body AWA.Users.Services is
use Util.Log;
use ADO.Statements;
use ADO.Sessions;
use Ada.Strings.Unbounded;
use ADO.SQL;
use AWA.Services;
use type ADO.Identifier;
package ASC renames AWA.Services.Contexts;
Log : constant Loggers.Logger := Loggers.Create ("AWA.Users.Services");
procedure Send_Alert (Model : in User_Service;
Kind : in AWA.Events.Event_Index;
User : in User_Ref'Class;
Props : in out AWA.Events.Module_Event) is
begin
Props.Set_Event_Kind (Kind);
Props.Set_Parameter ("first_name", User.Get_First_Name);
Props.Set_Parameter ("last_name", User.Get_Last_Name);
Props.Set_Parameter ("name", User.Get_Name);
Model.Send_Event (Props);
end Send_Alert;
function Create_Key (Model : in out User_Service;
Number : in ADO.Identifier) return String is
Rand : constant String := Model.Random.Generate (256);
begin
Log.Info ("Random {0}", Rand);
return Util.Encoders.HMAC.SHA1.Sign_Base64 (Key => Rand,
Data => ADO.Identifier'Image (Number),
URL => True);
end Create_Key;
-- ------------------------------
-- Build the authenticate cookie. The cookie is signed using HMAC-SHA1 with a private key.
-- ------------------------------
function Get_Authenticate_Cookie (Model : in User_Service;
Id : in ADO.Identifier)
return String is
Ident : constant String := Util.Strings.Image (Integer (Id));
Key : constant String := To_String (Model.Auth_Key);
begin
return Ident & '.' & Util.Encoders.HMAC.SHA1.Sign_Base64 (Key => Key, Data => Ident);
end Get_Authenticate_Cookie;
-- ------------------------------
-- Get the password hash. The password is signed using HMAC-SHA1 with the salt.
-- ------------------------------
function Get_Password_Hash (Model : in User_Service;
Password : in String;
Salt : in String)
return String is
pragma Unreferenced (Model);
begin
return Util.Encoders.HMAC.SHA1.Sign_Base64 (Key => Salt, Data => Password);
end Get_Password_Hash;
-- ------------------------------
-- Get the user name from the email address.
-- Returns the possible user name from his email address.
-- ------------------------------
function Get_Name_From_Email (Email : in String) return String is
E : constant Util.Mail.Email_Address := Util.Mail.Parse_Address (Email);
Name : String := To_String (E.Name);
begin
for I in Name'Range loop
if Name (I) = '.' then
Name (I) := ' ';
end if;
end loop;
return Util.Strings.Transforms.Capitalize (Name);
end Get_Name_From_Email;
-- ------------------------------
-- Get the authenticate identifier from the cookie.
-- Verify that the cookie is valid, the signature is correct.
-- Returns the identified or NO_IDENTIFIER
-- ------------------------------
function Get_Authenticate_Id (Model : in User_Service;
Cookie : in String) return ADO.Identifier is
Pos : constant Natural := Util.Strings.Index (Cookie, '.');
Id : ADO.Identifier;
begin
if Pos <= 1 then
return ADO.NO_IDENTIFIER;
end if;
Id := ADO.Identifier'Value (Cookie (Cookie'First .. Pos - 1));
if Cookie /= Model.Get_Authenticate_Cookie (Id) then
return ADO.NO_IDENTIFIER;
end if;
return Id;
exception
when others =>
return ADO.NO_IDENTIFIER;
end Get_Authenticate_Id;
procedure Create_Session (Model : in User_Service;
DB : in out Master_Session;
Session : out Session_Ref'Class;
User : in User_Ref'Class;
Auth : in Authenticate_Ref'Class;
Ip_Addr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
Auth_Session : Session_Ref;
Dummy_Email : constant String := User.Get_Email.Get_Email;
begin
-- Create the authenticate session.
Auth_Session.Set_Start_Date (Ada.Calendar.Clock);
Auth_Session.Set_User (User);
Auth_Session.Set_Ip_Address (Ip_Addr);
Auth_Session.Set_Stype (Users.Models.AUTH_SESSION);
Auth_Session.Set_Server_Id (Model.Server_Id);
Auth_Session.Set_User_Auth (Auth);
Auth_Session.Save (DB);
-- Create the connection session.
Session := Session_Ref'Class (Null_Session);
Session.Set_Start_Date (Auth_Session.Get_Start_Date);
Session.Set_User (User);
Session.Set_Ip_Address (Ip_Addr);
Session.Set_Stype (Users.Models.CONNECT_SESSION);
Session.Set_Auth (Auth_Session);
Session.Set_User_Auth (Auth);
Session.Set_Server_Id (Model.Server_Id);
Session.Save (DB);
Principal := AWA.Users.Principals.Create (User_Ref (User), Session_Ref (Session));
Ctx.Set_Context (Ctx.Get_Application, Principal);
end Create_Session;
-- ------------------------------
-- Authenticate the user with his OpenID identifier. The authentication process
-- was made by an external OpenID provider. If the user does not yet exists in
-- the database, a record is created for him. Create a new session for the user.
-- The IP address of the connection is saved in the session.
-- Raises Not_Found exception if the user is not recognized
-- ------------------------------
procedure Authenticate (Model : in User_Service;
Auth : in Security.Auth.Authentication;
IpAddr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
-- Update the user first name/last name
procedure Update_User;
OpenId : constant String := Security.Auth.Get_Claimed_Id (Auth);
Email_Address : constant String := Security.Auth.Get_Email (Auth);
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Query : ADO.SQL.Query;
Found_Email : Boolean;
Found_Auth : Boolean;
Found_User : Boolean;
User : User_Ref;
Email : Email_Ref;
User_Auth : Authenticate_Ref;
Session : Session_Ref;
-- ------------------------------
-- Update the user first name/last name
-- ------------------------------
procedure Update_User is
Name : constant String := Security.Auth.Get_Full_Name (Auth);
First_Name : constant String := Security.Auth.Get_First_Name (Auth);
Last_Name : constant String := Security.Auth.Get_Last_Name (Auth);
Sep : constant Natural := Util.Strings.Index (Name, ' ');
begin
if Name'Length > 0 and then Name /= String '(User.Get_Name) then
User.Set_Name (Name);
end if;
if First_Name'Length > 0 and then First_Name /= String '(User.Get_First_Name) then
User.Set_First_Name (First_Name);
end if;
if Last_Name'Length > 0 and then Last_Name /= String '(User.Get_Last_Name) then
User.Set_Last_Name (Last_Name);
end if;
if Sep > 0 and then String '(User.Get_First_Name) = "" then
User.Set_First_Name (Name (Name'First .. Sep - 1));
end if;
if Sep > 0 and then String '(User.Get_Last_Name) = "" then
User.Set_Last_Name (Name (Sep + 1 .. Name'Last));
end if;
if Name'Length > 0 and then String '(User.Get_First_Name) = "" then
User.Set_First_Name (Name);
end if;
if Name'Length = 0 then
User.Set_Name (Get_Name_From_Email (Email => Email_Address));
end if;
User.Save (DB);
end Update_User;
begin
Log.Info ("Authenticated user {0}", Email_Address);
Ctx.Start;
-- Find the email address.
Query.Set_Filter ("LOWER(o.email) = LOWER(:email)");
Query.Bind_Param ("email", Email_Address);
Email.Find (DB, Query, Found_Email);
-- Find the authenticate information for the given OpenID identifier.
Query.Clear;
Query.Set_Filter ("o.ident = :ident AND o.method = :method");
Query.Bind_Param ("ident", OpenId);
Query.Bind_Param ("method", Natural (1));
User_Auth.Find (DB, Query, Found_Auth);
if Found_Auth then
User := User_Ref (User_Auth.Get_User);
Found_User := True;
elsif Found_Email then
if Email.Get_User_Id > 0 then
User.Load (DB, Email.Get_User_Id, Found_User);
else
Found_User := False;
end if;
User_Auth.Set_Email (Email);
else
Found_User := False;
end if;
-- User is not found, registration must be enabled to create it.
if not Found_User and then not Model.Allow_Register then
Log.Warn ("Registration disabled: no user associated with email {0}",
Email_Address);
raise Registration_Disabled;
end if;
-- Email is not known and we have a new user: create it.
if not Found_Email and not Found_User then
Log.Info ("Creating email record for {0}", Email_Address);
Email.Set_Email (Email_Address);
Email.Save (DB);
end if;
if not Found_User then
Log.Info ("User {0} is not known", Email_Address);
User.Set_Email (Email);
User.Set_Status (Models.USER_ENABLED);
Update_User;
Email.Set_User_Id (User.Get_Id);
Email.Save (DB);
User_Lifecycle.Notify_Create (Model, User);
elsif User.Get_Status = Models.USER_DISABLED then
raise User_Disabled;
else
if User.Get_Status = Models.USER_REGISTERED then
User.Set_Status (Models.USER_ENABLED);
end if;
Update_User;
-- The user email address could have changed
declare
E : Email_Ref'Class := User.Get_Email;
begin
if Email_Address /= String '(E.Get_Email) then
Log.Info ("Changing email address from {0} to {1} for user {2}",
String '(E.Get_Email), Email_Address, OpenId);
E.Set_Email (Email_Address);
E.Save (DB);
end if;
end;
User_Lifecycle.Notify_Update (Model, User);
end if;
if not Found_Auth then
User_Auth.Set_Email (Email);
User_Auth.Set_User (User);
User_Auth.Set_Ident (OpenId);
User_Auth.Set_Method (AUTH_OAUTH);
User_Auth.Save (DB);
end if;
Create_Session (Model, DB, Session, User, User_Auth, IpAddr, Principal);
if not Found_User then
declare
Event : AWA.Events.Module_Event;
Sec_Ctx : Security.Contexts.Security_Context;
begin
-- Make a security context with the user's credential.
Sec_Ctx.Set_Context (Manager => Model.Permissions.all'Access,
Principal => Principal.all'Access);
-- Send the event to indicate a new user was created.
Event.Set_Parameter ("email", Email_Address);
Model.Send_Alert (User_Create_Event.Kind, User, Event);
end;
end if;
Ctx.Commit;
end Authenticate;
-- ------------------------------
-- Authenticate the user with his email address and his password.
-- If the user is authenticated, return the user information and
-- create a new session. The IP address of the connection is saved
-- in the session.
-- Raises Not_Found exception if the user is not recognized
-- ------------------------------
procedure Authenticate (Model : in User_Service;
Email : in String;
Password : in String;
IpAddr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Query : ADO.SQL.Query;
Found : Boolean;
User : User_Ref;
Session : Session_Ref;
Auth : Authenticate_Ref;
begin
Log.Info ("Authenticate user {0}", Email);
-- Find the user registered under the given email address & password.
Query.Bind_Param (1, Email);
Query.Set_Join ("INNER JOIN awa_email e ON e.user_id = o.id");
Query.Set_Filter ("LOWER(e.email) = LOWER(?)");
User.Find (DB, Query, Found);
if not Found then
Log.Warn ("No user registered under email address {0} or invalid password",
Email);
raise Not_Found with "No user registered under email: " & Email;
end if;
-- Reject authentication on disabled the user account.
if User.Get_Status /= Models.USER_ENABLED then
Log.Warn ("User account {0} is disabled", Email);
raise User_Disabled with "User account is disabled";
end if;
Query.Clear;
Query.Set_Filter ("o.email_id = ? AND o.method = 0");
Query.Bind_Param (1, User.Get_Email.Get_Id);
Auth.Find (DB, Query, Found);
if not Found then
Log.Warn ("No password defined for user {0}", Email);
raise Not_Found with "No password defined with email: " & Email;
end if;
declare
Salt : constant String := Auth.Get_Salt;
Hash : constant String
:= User_Service'Class (Model).Get_Password_Hash (Salt, Password);
begin
-- Reject authentication if the salt is empty: this account is not
-- validated yet for password authentication.
if Salt'Length = 0 then
Log.Warn ("Empty password salt for user {0}", Email);
raise User_Disabled with "User account is not validated: " & Email;
end if;
if Hash /= String '(Auth.Get_Hash) then
Log.Warn ("Invalid password for user {0}", Email);
raise Not_Found with "No user registered under email: " & Email;
end if;
end;
Ctx.Start;
Create_Session (Model, DB, Session, User, Auth, IpAddr, Principal);
Ctx.Commit;
Log.Info ("Session {0} created for user {1}",
ADO.Identifier'Image (Session.Get_Id), Email);
end Authenticate;
-- ------------------------------
-- Authenticate the user with the authenticate cookie generated from a previous authenticate
-- session. If the cookie has the correct signature, matches a valid session,
-- return the user information and create a new session. The IP address of the connection
-- is saved in the session.
-- Raises Not_Found exception if the user is not recognized
-- ------------------------------
procedure Authenticate (Model : in User_Service;
Cookie : in String;
Ip_Addr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
use type Contexts.Service_Context_Access;
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session;
Found : Boolean;
Cookie_Session : Session_Ref;
Auth_Session : Session_Ref;
Session : Session_Ref;
User : User_Ref;
Query : ADO.SQL.Query;
Id : constant ADO.Identifier := Model.Get_Authenticate_Id (Cookie);
begin
Log.Info ("Authenticate cookie {0}", Cookie);
if Id = ADO.NO_IDENTIFIER then
Log.Warn ("Invalid authenticate cookie: {0}", Cookie);
raise Not_Found with "Invalid cookie";
end if;
DB := Model.Get_Master_Session;
-- Find the user registered under the given email address & password.
Query.Bind_Param (1, Id);
Query.Set_Join ("INNER JOIN awa_user AS u ON u.id = o.user_id");
Query.Set_Filter ("o.id = ? AND o.end_date IS NULL");
Cookie_Session.Find (DB, Query, Found);
if not Found then
Log.Warn ("Authenticate session {0} not found in database", ADO.Identifier'Image (Id));
raise Not_Found with "Invalid cookie";
end if;
-- Reject authentication on disabled the user account.
if User.Get_Status /= Models.USER_ENABLED then
Log.Warn ("Authenticate session {0} is disabled", Ado.Identifier'Image (Id));
raise User_Disabled with "User account is disabled";
end if;
if Cookie_Session.Get_Stype /= Users.Models.CONNECT_SESSION then
Log.Warn ("Authenticate session {0} not found in database", ADO.Identifier'Image (Id));
raise Not_Found with "Invalid cookie";
end if;
Auth_Session := Session_Ref (Cookie_Session.Get_Auth);
if not Auth_Session.Get_End_Date.Is_Null then
Log.Warn ("Authenticate session was closed");
raise Not_Found with "Authenticate session was closed.";
end if;
User := User_Ref (Auth_Session.Get_User);
Session.Set_Start_Date (Ada.Calendar.Clock);
Session.Set_User (User);
Session.Set_Ip_Address (Ip_Addr);
Session.Set_Stype (Users.Models.CONNECT_SESSION);
Session.Set_Auth (Auth_Session);
Session.Set_Server_Id (Model.Server_Id);
Session.Save (DB);
Principal := AWA.Users.Principals.Create (User, Session);
if Ctx /= null then
Ctx.Set_Context (Ctx.Get_Application, Principal);
end if;
-- Mark the cookie session as used.
Cookie_Session.Set_Stype (Users.Models.USED_SESSION);
if Cookie_Session.Get_End_Date.Is_Null then
Cookie_Session.Set_End_Date (ADO.Nullable_Time '(Value => Session.Get_Start_Date,
Is_Null => False));
end if;
Cookie_Session.Save (DB);
Log.Info ("Session {0} created for user {1}",
ADO.Identifier'Image (Session.Get_Id), ADO.Identifier'Image (User.Get_Id));
exception
when ADO.Objects.NOT_FOUND =>
Log.Warn ("No user associated with session {0}", ADO.Identifier'Image (Id));
raise Not_Found with "Invalid cookie";
end Authenticate;
-- ------------------------------
-- Create and generate a new access key for the user. The access key is saved in the
-- database and it will expire after the expiration delay.
-- ------------------------------
procedure Create_Access_Key (Model : in out User_Service;
User : in AWA.Users.Models.User_Ref'Class;
Key : in out AWA.Users.Models.Access_Key_Ref;
Kind : in AWA.Users.Models.Key_Type;
Expire : in Duration;
Session : in out ADO.Sessions.Master_Session) is
use type Ada.Calendar.Time;
begin
Key.Set_Access_Key (Model.Create_Key (User.Get_Id));
Key.Set_Expire_Date (Ada.Calendar.Clock + Expire);
Key.Set_Kind (Kind);
Key.Set_User (User);
Key.Save (Session);
end Create_Access_Key;
-- ------------------------------
-- Start the lost password process for a user. Find the user having
-- the given email address and send that user a password reset key
-- in an email.
-- Raises Not_Found exception if no user with such email exist
-- ------------------------------
procedure Lost_Password (Model : in out User_Service;
Email : in String) is
Ctx : constant ASC.Service_Context_Access := ASC.Current;
DB : Master_Session := ASC.Get_Master_Session (Ctx);
User : User_Ref;
Key : Access_Key_Ref;
Query : ADO.SQL.Query;
Found : Boolean;
Stmt : ADO.Statements.Delete_Statement;
begin
Log.Info ("Lost password for {0}", Email);
Ctx.Start;
-- Find the user with the given email address.
Query.Set_Join ("INNER JOIN awa_email e ON e.user_id = o.id");
Query.Set_Filter ("LOWER(e.email) = LOWER(?)");
Query.Bind_Param (1, Email);
User.Find (DB, Query, Found);
if not Found then
Log.Warn ("No user with email address {0}", Email);
raise Not_Found with "No user registered under email: " & Email;
end if;
-- Reject lost password disabled the user account.
if User.Get_Status = Models.USER_DISABLED then
Log.Warn ("User account {0} is disabled", Email);
raise User_Disabled with "User account is disabled";
end if;
-- Delete any previous reset password access key for the user.
Stmt := DB.Create_Statement (AWA.Users.Models.ACCESS_KEY_TABLE);
Stmt.Set_Filter ("user_id = ? and kind = ?");
Stmt.Bind_Param (1, User.Get_Id);
Stmt.Bind_Param (2, Integer (Models.Key_Type'Pos (Models.RESET_PASSWORD_KEY)));
Stmt.Execute;
-- Create the secure key to change the password
Model.Create_Access_Key (User => User,
Key => Key,
Kind => AWA.Users.Models.RESET_PASSWORD_KEY,
Expire => 86400.0,
Session => DB);
-- Send the email with the reset password key
declare
Event : AWA.Events.Module_Event;
begin
Event.Set_Parameter ("key", Key.Get_Access_Key);
Event.Set_Parameter ("email", Email);
Model.Send_Alert (User_Lost_Password_Event.Kind, User, Event);
end;
Ctx.Commit;
end Lost_Password;
-- ------------------------------
-- Reset the password of the user associated with the secure key.
-- Raises Not_Found if there is no key or if the user does not have any email
-- ------------------------------
procedure Reset_Password (Model : in out User_Service;
Key : in String;
Password : in String;
IpAddr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Query : ADO.SQL.Query;
Found : Boolean;
Email : Email_Ref;
Access_Key : Access_Key_Ref;
User : User_Ref;
Auth : Authenticate_Ref;
Session : Session_Ref;
begin
Log.Info ("Reset password with key {0}", Key);
Ctx.Start;
-- Find the user associated with the key.
Query.Bind_Param (1, Key);
Query.Set_Filter ("access_key = ?");
Access_Key.Find (DB, Query, Found);
if not Found then
Log.Warn ("Invalid reset password key {0}", Key);
raise Not_Found with "No such access key: " & Key;
end if;
User := User_Ref (Access_Key.Get_User);
-- Delete the access key.
Access_Key.Delete (DB);
-- Reject reset password disabled the user account.
if User.Get_Status = Models.USER_DISABLED then
Ctx.Commit;
Log.Warn ("User account {0} is disabled", Email.Get_Email);
raise User_Disabled with "User account is disabled";
end if;
-- Get the user primary email address.
Email.Load (DB, User.Get_Email.Get_Id, Found);
if not Found then
Ctx.Commit;
Log.Warn ("User email address not found {0}", Email.Get_Email);
raise Not_Found with "User email address not found: " & Email.Get_Email;
end if;
-- Get the authenticate information for the email address
-- (keep only AUTH_HASH_SHA1).
Query.Clear;
Query.Set_Filter ("o.method = 0 AND o.email_id = :email_id");
Query.Bind_Param ("email_id", Email.Get_Id);
Auth.Find (DB, Query, Found);
if not Found then
Auth.Set_User (User);
Auth.Set_Email (Email);
Auth.Set_Method (AUTH_HASH_SHA1);
Auth.Set_Ident (String '(Email.Get_Email));
end if;
-- Reset the user password
Auth.Set_Salt (Model.Create_Key (User.Get_Id));
Auth.Set_Hash (User_Service'Class (Model).Get_Password_Hash (Auth.Get_Salt, Password));
Auth.Save (DB);
User.Set_Status (Models.USER_ENABLED);
User.Save (DB);
-- Create the authentication session.
Create_Session (Model, DB, Session, User, Auth, IpAddr, Principal);
-- Send the email to warn about the password change
declare
Event : AWA.Events.Module_Event;
begin
Event.Set_Parameter ("ip_address", IpAddr);
Event.Set_Parameter ("email", Email.Get_Email);
Model.Send_Alert (User_Reset_Password_Event.Kind, User, Event);
end;
Ctx.Commit;
exception
when ADO.Objects.NOT_FOUND =>
Log.Warn ("No user associated with access key {0}", Key);
raise Not_Found with "No user associated with access key: " & Key;
end Reset_Password;
-- ------------------------------
-- Create a user in the database with the given user information and
-- the associated email address. Verify that no such user already exist.
-- Build an access key that allows to verify the user email and finish
-- the account creation.
-- Raises User_Exist exception if a user with such email is already registered.
-- ------------------------------
procedure Create_User (Model : in out User_Service;
User : in out User_Ref'Class;
Email : in out Email_Ref'Class;
Password : in String;
Key : in out Access_Key_Ref'Class;
Send : in Boolean) is
COUNT_SQL : constant String
:= "SELECT COUNT(*) FROM awa_email WHERE LOWER(email) = LOWER(?)";
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Stmt : Query_Statement := DB.Create_Statement (COUNT_SQL);
Email_Address : constant String := Email.Get_Email;
begin
Log.Info ("Create user {0}", Email_Address);
-- Reject user creation if the registration is disabled.
if not Model.Allow_Register then
Log.Warn ("Registration disabled: cannot register user with email {0}",
Email_Address);
raise Registration_Disabled;
end if;
Ctx.Start;
-- Check first if this user is already known
Stmt.Bind_Param (1, Email_Address);
Stmt.Execute;
if Stmt.Has_Elements and then Stmt.Get_Integer (0) > 0 then
Log.Warn ("User {0} already registered", Email_Address);
raise User_Exist with "Email address " & Email_Address & "' already used";
end if;
-- Save the email and the user
Email.Set_User_Id (0);
Email.Save (DB);
User.Set_Email (Email);
User.Set_Status (Models.USER_REGISTERED);
if String '(User.Get_Name) = "" then
User.Set_Name (String '(User.Get_First_Name) & " " & String '(User.Get_Last_Name));
end if;
User.Save (DB);
Email.Set_User_Id (User.Get_Id);
Email.Save (DB);
-- Make a random salt and generate the password hash.
-- If there is no password, keep an empty salt/password,
-- this will be refused at authentication.
if Password'Length > 0 then
declare
Auth : Authenticate_Ref;
begin
Auth.Set_User (User);
Auth.Set_Salt (Model.Create_Key (User.Get_Id));
Auth.Set_Hash
(User_Service'Class (Model).Get_Password_Hash (Auth.Get_Salt, Password));
Auth.Set_Email (Email);
Auth.Set_Ident (Email_Address);
Auth.Set_Method (AUTH_HASH_SHA1);
Auth.Save (DB);
end;
end if;
-- Create the access key
Model.Create_Access_Key (User => User,
Key => Access_Key_Ref (Key),
Kind => AWA.Users.Models.SIGNUP_KEY,
Expire => 86400.0,
Session => DB);
-- Send the email with the access key to finish the user registration.
if Send then
declare
Event : AWA.Events.Module_Event;
begin
Event.Set_Parameter ("key", Key.Get_Access_Key);
Event.Set_Parameter ("email", Email_Address);
Model.Send_Alert (User_Register_Event.Kind, User, Event);
end;
end if;
Ctx.Commit;
end Create_User;
-- ------------------------------
-- Create a user in the database with the given user information and
-- the associated email address and for the given access key. The access key is first
-- verified and the user instance associated with it is retrieved. Verify that the email
-- address is unique and can be used by the user. Since the access key is verified,
-- grant immediately the access by opening a session and setting up the principal instance.
-- Raises User_Exist exception if a user with such email is already registered.
-- ------------------------------
procedure Create_User (Model : in out User_Service;
User : in out User_Ref'Class;
Email : in out Email_Ref'Class;
Password : in String;
Key : in String;
IpAddr : in String;
Principal : out AWA.Users.Principals.Principal_Access) is
Ctx : constant ASC.Service_Context_Access := ASC.Current;
DB : Master_Session := ASC.Get_Master_Session (Ctx);
Access_Key : Access_Key_Ref;
Query : ADO.SQL.Query;
Session : Session_Ref;
Exist_Email : Email_Ref;
Email_Address : constant String := Email.Get_Email;
Found : Boolean;
Cur_User : User_Ref;
Cur_Email : Email_Ref;
Auth : Authenticate_Ref;
begin
Log.Info ("Create user {0} with key {1}", Email_Address, Key);
-- We want to allow the user creation if the access key is enabled
-- because that access key was sent by the site administrator and
-- we trust it. If the access key is invalid, the user creation is rejected.
if not Model.Allow_Register then
Log.Info ("Registration is disabled but an access key is used with email {0}",
Email_Address);
end if;
Ctx.Start;
-- Verify the access key validity.
Query.Bind_Param (1, Key);
Query.Set_Filter ("access_key = ?");
Access_Key.Find (DB, Query, Found);
if not Found then
Log.Warn ("No access key {0}", Key);
raise Not_Found with "No access key: " & Key;
end if;
Cur_User := User_Ref (Access_Key.Get_User);
Cur_Email := Email_Ref (Cur_User.Get_Email);
-- Check first if the email address is not used by another user.
Query.Bind_Param (1, Email_Address);
Query.Set_Filter ("LOWER(email) = LOWER(?)");
Exist_Email.Find (DB, Query, Found);
if Found and then Exist_Email.Get_Id /= Cur_Email.Get_Id then
Ctx.Commit;
Log.Warn ("Email address {0} already registered", Email_Address);
raise User_Exist with "Email address " & Email_Address & "' already used";
end if;
-- Make sure the user is not disabled.
if Cur_User.Get_Status = Models.USER_DISABLED then
Access_Key.Delete (DB);
Ctx.Commit;
Log.Warn ("User account {0} is disabled", Email_Address);
raise User_Disabled with "User account '" & Email_Address & "' is disabled";
end if;
-- Save the email and the user
Cur_Email.Set_User_Id (Cur_User.Get_Id);
Cur_Email.Set_Email (Email_Address);
Cur_Email.Save (DB);
Cur_User.Set_Name (String '(User.Get_Name));
Cur_User.Set_First_Name (String '(User.Get_First_Name));
Cur_User.Set_Last_Name (String '(User.Get_Last_Name));
if String '(User.Get_Name) = "" then
User.Set_Name (String '(User.Get_First_Name) & " " & String '(User.Get_Last_Name));
end if;
-- Get the authenticate information for the email address
-- (keep only AUTH_HASH_SHA1).
Query.Clear;
Query.Set_Filter ("o.method = 0 AND o.email_id = :email_id");
Query.Bind_Param ("email_id", Cur_Email.Get_Id);
Auth.Find (DB, Query, Found);
if not Found then
Auth.Set_User (Cur_User);
Auth.Set_Email (Cur_Email);
Auth.Set_Method (AUTH_HASH_SHA1);
Auth.Set_Ident (Email_Address);
end if;
-- Make a random salt and generate the password hash.
Auth.Set_Salt (Model.Create_Key (Cur_User.Get_Id));
Auth.Set_Hash
(User_Service'Class (Model).Get_Password_Hash (Auth.Get_Salt, Password));
Auth.Save (DB);
Cur_User.Set_Status (Models.USER_ENABLED);
Cur_User.Save (DB);
User_Ref (User) := Cur_User;
Email_Ref (Email) := Cur_Email;
User_Lifecycle.Notify_Create (Model, User);
-- Create the authentication session.
Create_Session (Model, DB, Session, User, Auth, IpAddr, Principal);
-- Post the user creation event once the user is registered.
declare
Sec_Ctx : Security.Contexts.Security_Context;
Event : AWA.Events.Module_Event;
begin
Sec_Ctx.Set_Context (Manager => Model.Permissions.all'Access,
Principal => Principal.all'Access);
Event.Set_Parameter ("email", Email.Get_Email);
Model.Send_Alert (User_Create_Event.Kind, User, Event);
-- Post a second event to notify the access key was validated.
-- Can be used by an invitation process.
Event.Set_Parameter ("key", Key);
Model.Send_Alert (User_Key_Validation_Event.Kind, User, Event);
end;
-- Invalidate the key at then end when the event are handled..
Access_Key.Delete (DB);
Ctx.Commit;
end Create_User;
-- ------------------------------
-- Load the user and email address from the invitation key.
-- ------------------------------
procedure Load_User (Model : in out User_Service;
User : in out User_Ref'Class;
Email : in out Email_Ref'Class;
Key : in String) is
pragma Unreferenced (Model);
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Access_Key : Access_Key_Ref;
Query : ADO.SQL.Query;
Found : Boolean;
begin
Log.Info ("Get user from key {1}", Key);
-- Verify the access key validity.
Query.Bind_Param (1, Key);
Query.Set_Filter ("access_key = ?");
Access_Key.Find (DB, Query, Found);
if not Found then
Log.Warn ("No access key {0}", Key);
raise Not_Found with "No access key: " & Key;
end if;
User := Access_Key.Get_User;
Email := User.Get_Email;
end Load_User;
-- ------------------------------
-- Update the user status to enable/disable the user account.
-- ------------------------------
procedure Update_User (Model : in out User_Service;
Email : in String;
Status : in Models.Status_type) is
pragma Unreferenced (Model);
Ctx : constant ASC.Service_Context_Access := ASC.Current;
DB : Master_Session := ASC.Get_Master_Session (Ctx);
User : User_Ref;
Query : ADO.SQL.Query;
Found : Boolean;
begin
Log.Info ("Update user status {0} to {1}", Email, Status'Image);
Ctx.Start;
-- Find the user associated with the email address.
Query.Set_Join ("INNER JOIN awa_email e ON e.user_id = o.id");
Query.Set_Filter ("LOWER(e.email) = LOWER(?)");
Query.Bind_Param (1, Email);
User.Find (DB, Query, Found);
if not Found then
Log.Warn ("No user with email address {0}", Email);
raise Not_Found with "No user registered under email: " & Email;
end if;
User.Set_Status (Status);
User.Save (Db);
Ctx.Commit;
end Update_User;
-- ------------------------------
-- Verify the access key and retrieve the user associated with that key.
-- Starts a new session associated with the given IP address.
-- Raises Not_Found if the access key does not exist.
-- ------------------------------
procedure Verify_User (Model : in User_Service;
Key : in String;
IpAddr : in String;
Principal : out Users.Principals.Principal_Access) is
Ctx : constant ASC.Service_Context_Access := ASC.Current;
DB : Master_Session := ASC.Get_Master_Session (Ctx);
Query : ADO.SQL.Query;
Found : Boolean;
Access_Key : Access_Key_Ref;
User : User_Ref;
Session : Session_Ref;
Email : Email_Ref;
begin
Log.Info ("Verify user with key {0}", Key);
if Key'Length = 0 then
Log.Warn ("Empty access key is refused");
raise Not_Found with "No access key: ''";
end if;
Ctx.Start;
-- Find the user associated with the given key
Query.Bind_Param (1, Key);
Query.Set_Filter ("access_key = ?");
Access_Key.Find (DB, Query, Found);
if not Found then
Log.Warn ("No access key {0}", Key);
raise Not_Found with "No access key: " & Key;
end if;
User := User_Ref (Access_Key.Get_User);
Email := Email_Ref (User.Get_Email);
-- Reject reset password disabled the user account.
if User.Get_Status = Models.USER_DISABLED then
Log.Warn ("User account {0} is disabled", Email.Get_Email);
raise User_Disabled with "User account is disabled";
end if;
-- If the user is registered and has a password, it is now verified
-- and we can enable it.
declare
Auth : Authenticate_Ref;
begin
Query.Clear;
Query.Set_Filter ("o.method = 0 AND o.email_id = ?");
Query.Bind_Param (1, Email.Get_Id);
Auth.Find (DB, Query, Found);
if User.Get_Status = Models.USER_REGISTERED and then Found then
User.Set_Status (Models.USER_ENABLED);
User.Save (DB);
end if;
User_Lifecycle.Notify_Create (Model, User);
Principal := null;
-- This account has no password, keep the key so that we can
-- redirect to the change password page. Otherwise, we must
-- remove the access key and create the authenticate session.
if Found then
Access_Key.Delete (DB);
-- Create the authentication session.
Create_Session (Model, DB, Session, User, Auth, IpAddr, Principal);
-- Post the user creation event once the user is registered.
declare
Sec_Ctx : Security.Contexts.Security_Context;
Event : AWA.Events.Module_Event;
begin
Sec_Ctx.Set_Context (Manager => Model.Permissions.all'Access,
Principal => Principal.all'Access);
Event.Set_Parameter ("email", Email.Get_Email);
Model.Send_Alert (User_Create_Event.Kind, User, Event);
end;
end if;
end;
Ctx.Commit;
exception
when ADO.Objects.NOT_FOUND =>
Log.Warn ("No user linked to access key {0}", Key);
raise Not_Found with "No user for access key: " & Key;
end Verify_User;
-- ------------------------------
-- Verify that the user session identified by <b>Id</b> is valid and still active.
-- Returns the user and the session objects.
-- Raises Not_Found if the session does not exist or was closed.
-- ------------------------------
procedure Verify_Session (Model : in User_Service;
Id : in ADO.Identifier;
User : out User_Ref'Class;
Session : out Session_Ref'Class) is
pragma Unreferenced (Model);
Sid : constant String := ADO.Identifier'Image (Id);
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : ADO.Sessions.Session := AWA.Services.Contexts.Get_Session (Ctx);
Query : ADO.SQL.Query;
Found : Boolean;
begin
Log.Info ("Verify user session {0}", Sid);
Query.Set_Filter ("id = ? AND end_date IS NULL");
Query.Bind_Param (1, Id);
Session.Find (Session => DB,
Query => Query,
Found => Found);
if not Found then
Log.Warn ("Session {0} is not found or closed", Sid);
raise Not_Found with "Session not found: " & Sid;
end if;
User := Session.Get_User;
end Verify_Session;
-- ------------------------------
-- Closes the session identified by <b>Id</b>. The session identified should refer to
-- a valid and not closed connection session.
-- When <b>Logout</b> is set, the authenticate session is also closed. The connection
-- sessions associated with the authenticate session are also closed.
-- Raises <b>Not_Found</b> if the session is invalid or already closed.
-- ------------------------------
procedure Close_Session (Model : in User_Service;
Id : in ADO.Identifier;
Logout : in Boolean := False) is
pragma Unreferenced (Model);
Sid : constant String := ADO.Identifier'Image (Id);
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Session : Session_Ref;
Found : Boolean;
begin
Log.Info ("Closing user session {0}", Sid);
Ctx.Start;
Session.Load (DB, Id, Found);
if not Found then
Log.Warn ("Session {0} is not found", Sid);
raise Not_Found with "Session not found: " & Sid;
end if;
-- The end date must be null. Otherwise, it means the session was closed already.
if not Session.Get_End_Date.Is_Null then
Log.Warn ("Session {0} is already closed", Sid);
raise Not_Found with "Session is closed: " & Sid;
end if;
Session.Set_End_Date (ADO.Nullable_Time '(Value => Ada.Calendar.Clock, Is_Null => False));
Session.Save (DB);
-- When logging out, close the authenticate session.
if Logout then
declare
Auth_Session : Session_Ref'Class := Session.Get_Auth;
begin
Auth_Session.Set_End_Date (Session.Get_End_Date);
Auth_Session.Save (DB);
Session := Session_Ref (Auth_Session);
end;
end if;
-- When closing the authenticate session, close any connection session that is still open.
if Session.Get_Stype = Users.Models.AUTH_SESSION then
declare
Stmt : ADO.Statements.Update_Statement
:= DB.Create_Statement (AWA.Users.Models.SESSION_TABLE);
begin
Stmt.Save_Field (Name => "end_date", Value => Session.Get_End_Date);
Stmt.Set_Filter ("auth_id = :auth AND end_date IS NULL");
Stmt.Bind_Param ("auth", Session.Get_Id);
Stmt.Execute;
end;
end if;
Ctx.Commit;
end Close_Session;
-- ------------------------------
-- Allow to disable the user registration.
-- ------------------------------
procedure Set_Allow_Register (Model : in out User_Service;
Allow : in Boolean) is
begin
Model.Allow_Register := Allow;
end Set_Allow_Register;
-- ------------------------------
-- Initialize the user service.
-- ------------------------------
overriding
procedure Initialize (Model : in out User_Service;
Module : in AWA.Modules.Module'Class) is
DEFAULT_KEY : constant String := "8ef60aad66977c68b12f4f8acab5a4e00a77f6e8";
Sec_Manager : constant Security.Policies.Policy_Manager_Access
:= Module.Get_Application.Get_Security_Manager;
begin
AWA.Modules.Module_Manager (Model).Initialize (Module);
Model.Permissions := Permissions.Services.Permission_Manager'Class (Sec_Manager.all)'Access;
Model.Server_Id := Module.Get_Config ("server_id", 1);
Model.Allow_Register := Module.Get_Config ("allow_register", True);
Set_Unbounded_String (Model.Auth_Key,
Module.Get_Config ("auth_key", DEFAULT_KEY));
if Model.Auth_Key = DEFAULT_KEY then
Log.Error ("The 'auth_key' configuration property not found. Using default key.");
end if;
Log.Info ("User server associated with server id{0}", Integer'Image (Model.Server_Id));
-- Close the connection sessions that have not been closed correctly.
declare
DB : ADO.Sessions.Master_Session := Module.Get_Master_Session;
Stmt : ADO.Statements.Update_Statement
:= DB.Create_Statement (AWA.Users.Models.SESSION_TABLE);
begin
DB.Begin_Transaction;
Stmt.Save_Field (Name => "end_date",
Value => ADO.Nullable_Time '(Value => Ada.Calendar.Clock,
Is_Null => False));
Stmt.Set_Filter ("server_id = :server AND end_date IS NULL AND stype = :type");
Stmt.Bind_Param ("server", Model.Server_Id);
Stmt.Bind_Param ("type", CONNECT_SESSION_TYPE);
Stmt.Execute;
DB.Commit;
end;
end Initialize;
end AWA.Users.Services;
|
reznikmm/matreshka | Ada | 3,784 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Number_Min_Denominator_Digits_Attributes is
pragma Preelaborate;
type ODF_Number_Min_Denominator_Digits_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Number_Min_Denominator_Digits_Attribute_Access is
access all ODF_Number_Min_Denominator_Digits_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Number_Min_Denominator_Digits_Attributes;
|
reznikmm/matreshka | Ada | 3,764 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Draw_Frame_Display_Border_Attributes is
pragma Preelaborate;
type ODF_Draw_Frame_Display_Border_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Draw_Frame_Display_Border_Attribute_Access is
access all ODF_Draw_Frame_Display_Border_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Draw_Frame_Display_Border_Attributes;
|
AaronC98/PlaneSystem | Ada | 3,825 | ads | ------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2000-2014, AdaCore --
-- --
-- This library 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 3, or (at your option) any --
-- later version. This library 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. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
-- This package provides a service to build Callbacks which can support
-- user's data. It is possible to build a new dispatcher by inheriting the
-- handler type and to provides the Dispatch routine.
with Ada.Finalization;
with AWS.Response;
with AWS.Status;
with AWS.Utils;
package AWS.Dispatchers is
type Handler is abstract new Ada.Finalization.Controlled
and AWS.Utils.Clonable with private;
function Dispatch
(Dispatcher : Handler;
Request : Status.Data) return Response.Data is abstract;
-- Call the appropriate inherited dispatcher
function Ref_Counter (Dispatcher : Handler) return Natural;
-- Returns the reference counter for Handler. If 0 is returned then this
-- object is not referenced anymore, it is safe to deallocate resources.
type Handler_Class_Access is access all Handler'Class;
procedure Free (Dispatcher : in out Handler_Class_Access) with Inline;
-- Release memory associated with the dispatcher
private
type Handler is abstract new Ada.Finalization.Controlled
and AWS.Utils.Clonable
with record
Ref_Counter : Utils.Counter_Access;
end record;
overriding procedure Initialize (Dispatcher : in out Handler);
overriding procedure Adjust (Dispatcher : in out Handler);
overriding procedure Finalize (Dispatcher : in out Handler);
-- Initialize/Adjust/Finalize is doing the reference counting, children
-- should just call these routines if possible. It is possible to know if
-- no more object are referenced by calling Ref_Counter below.
end AWS.Dispatchers;
|
zhmu/ananas | Ada | 6,257 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 1 1 3 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Storage_Elements;
with System.Unsigned_Types;
package body System.Pack_113 is
subtype Bit_Order is System.Bit_Order;
Reverse_Bit_Order : constant Bit_Order :=
Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
subtype Ofs is System.Storage_Elements.Storage_Offset;
subtype Uns is System.Unsigned_Types.Unsigned;
subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
use type System.Storage_Elements.Storage_Offset;
use type System.Unsigned_Types.Unsigned;
type Cluster is record
E0, E1, E2, E3, E4, E5, E6, E7 : Bits_113;
end record;
for Cluster use record
E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
end record;
for Cluster'Size use Bits * 8;
for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
1 +
1 * Boolean'Pos (Bits mod 2 = 0) +
2 * Boolean'Pos (Bits mod 4 = 0));
-- Use maximum possible alignment, given the bit field size, since this
-- will result in the most efficient code possible for the field.
type Cluster_Ref is access Cluster;
type Rev_Cluster is new Cluster
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_Cluster_Ref is access Rev_Cluster;
------------
-- Get_113 --
------------
function Get_113
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_113
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end Get_113;
------------
-- Set_113 --
------------
procedure Set_113
(Arr : System.Address;
N : Natural;
E : Bits_113;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end Set_113;
end System.Pack_113;
|
AdaCore/libadalang | Ada | 273 | ads | package Pouet is
package Foo is
A : Integer := 12;
end Foo;
package Bar is
use Foo;
B : Integer := A;
end Bar;
package Baz is
use Bar;
C : Integer := A;
pragma Test (B);
pragma Test (A);
end Baz;
end Pouet;
|
mirror/ncurses | Ada | 4,346 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding --
-- --
-- Terminal_Interface.Curses.Terminfo --
-- --
-- S P E C --
-- --
------------------------------------------------------------------------------
-- Copyright 2020 Thomas E. Dickey --
-- Copyright 2000-2002,2003 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control:
-- $Revision: 1.5 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Interfaces.C;
package Terminal_Interface.Curses.Terminfo is
pragma Preelaborate (Terminal_Interface.Curses.Terminfo);
-- |=====================================================================
-- | Man page curs_terminfo.3x
-- |=====================================================================
-- Not implemented: setupterm, setterm, set_curterm, del_curterm,
-- restartterm, tparm, putp, vidputs, vidattr,
-- mvcur
type Terminfo_String is new String;
-- |
procedure Get_String (Name : String;
Value : out Terminfo_String;
Result : out Boolean);
function Has_String (Name : String) return Boolean;
-- AKA: tigetstr()
-- |
function Get_Flag (Name : String) return Boolean;
-- AKA: tigetflag()
-- |
function Get_Number (Name : String) return Integer;
-- AKA: tigetnum()
type putctype is access function (c : Interfaces.C.int)
return Interfaces.C.int;
pragma Convention (C, putctype);
-- |
procedure Put_String (Str : Terminfo_String;
affcnt : Natural := 1;
putc : putctype := null);
-- AKA: tputs()
end Terminal_Interface.Curses.Terminfo;
|
zhmu/ananas | Ada | 242,349 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ C H 5 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Aspects; use Aspects;
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Exp_Aggr; use Exp_Aggr;
with Exp_Ch6; use Exp_Ch6;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch11; use Exp_Ch11;
with Exp_Dbug; use Exp_Dbug;
with Exp_Pakd; use Exp_Pakd;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Inline; use Inline;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Snames; use Snames;
with Stand; use Stand;
with Stringt; use Stringt;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Ch5 is
procedure Build_Formal_Container_Iteration
(N : Node_Id;
Container : Entity_Id;
Cursor : Entity_Id;
Init : out Node_Id;
Advance : out Node_Id;
New_Loop : out Node_Id);
-- Utility to create declarations and loop statement for both forms
-- of formal container iterators.
function Convert_To_Iterable_Type
(Container : Entity_Id;
Loc : Source_Ptr) return Node_Id;
-- Returns New_Occurrence_Of (Container), possibly converted to an ancestor
-- type, if the type of Container inherited the Iterable aspect from that
-- ancestor.
function Change_Of_Representation (N : Node_Id) return Boolean;
-- Determine if the right-hand side of assignment N is a type conversion
-- which requires a change of representation. Called only for the array
-- and record cases.
procedure Expand_Assign_Array (N : Node_Id; Rhs : Node_Id);
-- N is an assignment which assigns an array value. This routine process
-- the various special cases and checks required for such assignments,
-- including change of representation. Rhs is normally simply the right-
-- hand side of the assignment, except that if the right-hand side is a
-- type conversion or a qualified expression, then the RHS is the actual
-- expression inside any such type conversions or qualifications.
function Expand_Assign_Array_Loop
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean) return Node_Id;
-- N is an assignment statement which assigns an array value. This routine
-- expands the assignment into a loop (or nested loops for the case of a
-- multi-dimensional array) to do the assignment component by component.
-- Larray and Rarray are the entities of the actual arrays on the left-hand
-- and right-hand sides. L_Type and R_Type are the types of these arrays
-- (which may not be the same, due to either sliding, or to a change of
-- representation case). Ndim is the number of dimensions and the parameter
-- Rev indicates if the loops run normally (Rev = False), or reversed
-- (Rev = True). The value returned is the constructed loop statement.
-- Auxiliary declarations are inserted before node N using the standard
-- Insert_Actions mechanism.
function Expand_Assign_Array_Bitfield
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Rev : Boolean) return Node_Id;
-- Alternative to Expand_Assign_Array_Loop for packed bitfields. Generates
-- a call to System.Bitfields.Copy_Bitfield, which is more efficient than
-- copying component-by-component.
function Expand_Assign_Array_Bitfield_Fast
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id) return Node_Id;
-- Alternative to Expand_Assign_Array_Bitfield. Generates a call to
-- System.Bitfields.Fast_Copy_Bitfield, which is more efficient than
-- Copy_Bitfield, but only works in restricted situations.
function Expand_Assign_Array_Loop_Or_Bitfield
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean) return Node_Id;
-- Calls either Expand_Assign_Array_Loop, Expand_Assign_Array_Bitfield, or
-- Expand_Assign_Array_Bitfield_Fast as appropriate.
procedure Expand_Assign_Record (N : Node_Id);
-- N is an assignment of an untagged record value. This routine handles
-- the case where the assignment must be made component by component,
-- either because the target is not byte aligned, or there is a change
-- of representation, or when we have a tagged type with a representation
-- clause (this last case is required because holes in the tagged type
-- might be filled with components from child types).
procedure Expand_Assign_With_Target_Names (N : Node_Id);
-- (AI12-0125): N is an assignment statement whose RHS contains occurrences
-- of @ that designate the value of the LHS of the assignment. If the LHS
-- is side-effect free the target names can be replaced with a copy of the
-- LHS; otherwise the semantics of the assignment is described in terms of
-- a procedure with an in-out parameter, and expanded as such.
procedure Expand_Formal_Container_Loop (N : Node_Id);
-- Use the primitives specified in an Iterable aspect to expand a loop
-- over a so-called formal container, primarily for SPARK usage.
procedure Expand_Formal_Container_Element_Loop (N : Node_Id);
-- Same, for an iterator of the form " For E of C". In this case the
-- iterator provides the name of the element, and the cursor is generated
-- internally.
procedure Expand_Iterator_Loop (N : Node_Id);
-- Expand loop over arrays and containers that uses the form "for X of C"
-- with an optional subtype mark, or "for Y in C".
procedure Expand_Iterator_Loop_Over_Container
(N : Node_Id;
Isc : Node_Id;
I_Spec : Node_Id;
Container : Node_Id;
Container_Typ : Entity_Id);
-- Expand loop over containers that uses the form "for X of C" with an
-- optional subtype mark, or "for Y in C". Isc is the iteration scheme.
-- I_Spec is the iterator specification and Container is either the
-- Container (for OF) or the iterator (for IN).
procedure Expand_Predicated_Loop (N : Node_Id);
-- Expand for loop over predicated subtype
function Make_Tag_Ctrl_Assignment (N : Node_Id) return List_Id;
-- Generate the necessary code for controlled and tagged assignment, that
-- is to say, finalization of the target before, adjustment of the target
-- after and save and restore of the tag and finalization pointers which
-- are not 'part of the value' and must not be changed upon assignment. N
-- is the original Assignment node.
--------------------------------------
-- Build_Formal_Container_Iteration --
--------------------------------------
procedure Build_Formal_Container_Iteration
(N : Node_Id;
Container : Entity_Id;
Cursor : Entity_Id;
Init : out Node_Id;
Advance : out Node_Id;
New_Loop : out Node_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Stats : constant List_Id := Statements (N);
Typ : constant Entity_Id := Base_Type (Etype (Container));
Has_Element_Op : constant Entity_Id :=
Get_Iterable_Type_Primitive (Typ, Name_Has_Element);
First_Op : Entity_Id;
Next_Op : Entity_Id;
begin
-- Use the proper set of primitives depending on the direction of
-- iteration. The legality of a reverse iteration has been checked
-- during analysis.
if Reverse_Present (Iterator_Specification (Iteration_Scheme (N))) then
First_Op := Get_Iterable_Type_Primitive (Typ, Name_Last);
Next_Op := Get_Iterable_Type_Primitive (Typ, Name_Previous);
else
First_Op := Get_Iterable_Type_Primitive (Typ, Name_First);
Next_Op := Get_Iterable_Type_Primitive (Typ, Name_Next);
end if;
-- Declaration for Cursor
Init :=
Make_Object_Declaration (Loc,
Defining_Identifier => Cursor,
Object_Definition => New_Occurrence_Of (Etype (First_Op), Loc),
Expression =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (First_Op, Loc),
Parameter_Associations => New_List (
Convert_To_Iterable_Type (Container, Loc))));
-- Statement that advances (in the right direction) cursor in loop
Advance :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Cursor, Loc),
Expression =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Next_Op, Loc),
Parameter_Associations => New_List (
Convert_To_Iterable_Type (Container, Loc),
New_Occurrence_Of (Cursor, Loc))));
-- Iterator is rewritten as a while_loop
New_Loop :=
Make_Loop_Statement (Loc,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Condition =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Has_Element_Op, Loc),
Parameter_Associations => New_List (
Convert_To_Iterable_Type (Container, Loc),
New_Occurrence_Of (Cursor, Loc)))),
Statements => Stats,
End_Label => Empty);
-- If the contruct has a specified loop name, preserve it in the new
-- loop, for possible use in exit statements.
if Present (Identifier (N))
and then Comes_From_Source (Identifier (N))
then
Set_Identifier (New_Loop, Identifier (N));
end if;
end Build_Formal_Container_Iteration;
------------------------------
-- Change_Of_Representation --
------------------------------
function Change_Of_Representation (N : Node_Id) return Boolean is
Rhs : constant Node_Id := Expression (N);
begin
return
Nkind (Rhs) = N_Type_Conversion
and then not Has_Compatible_Representation
(Target_Type => Etype (Rhs),
Operand_Type => Etype (Expression (Rhs)));
end Change_Of_Representation;
------------------------------
-- Convert_To_Iterable_Type --
------------------------------
function Convert_To_Iterable_Type
(Container : Entity_Id;
Loc : Source_Ptr) return Node_Id
is
Typ : constant Entity_Id := Base_Type (Etype (Container));
Aspect : constant Node_Id := Find_Aspect (Typ, Aspect_Iterable);
Result : Node_Id;
begin
Result := New_Occurrence_Of (Container, Loc);
if Entity (Aspect) /= Typ then
Result :=
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Entity (Aspect), Loc),
Expression => Result);
end if;
return Result;
end Convert_To_Iterable_Type;
-------------------------
-- Expand_Assign_Array --
-------------------------
-- There are two issues here. First, do we let Gigi do a block move, or
-- do we expand out into a loop? Second, we need to set the two flags
-- Forwards_OK and Backwards_OK which show whether the block move (or
-- corresponding loops) can be legitimately done in a forwards (low to
-- high) or backwards (high to low) manner.
procedure Expand_Assign_Array (N : Node_Id; Rhs : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Lhs : constant Node_Id := Name (N);
Act_Lhs : constant Node_Id := Get_Referenced_Object (Lhs);
Act_Rhs : Node_Id := Get_Referenced_Object (Rhs);
L_Type : constant Entity_Id :=
Underlying_Type (Get_Actual_Subtype (Act_Lhs));
R_Type : Entity_Id :=
Underlying_Type (Get_Actual_Subtype (Act_Rhs));
L_Slice : constant Boolean := Nkind (Act_Lhs) = N_Slice;
R_Slice : constant Boolean := Nkind (Act_Rhs) = N_Slice;
Crep : constant Boolean := Change_Of_Representation (N);
pragma Assert
(Crep
or else Is_Bit_Packed_Array (L_Type) = Is_Bit_Packed_Array (R_Type));
Larray : Node_Id;
Rarray : Node_Id;
Ndim : constant Pos := Number_Dimensions (L_Type);
Loop_Required : Boolean := False;
-- This switch is set to True if the array move must be done using
-- an explicit front end generated loop.
procedure Apply_Dereference (Arg : Node_Id);
-- If the argument is an access to an array, and the assignment is
-- converted into a procedure call, apply explicit dereference.
function Has_Address_Clause (Exp : Node_Id) return Boolean;
-- Test if Exp is a reference to an array whose declaration has
-- an address clause, or it is a slice of such an array.
function Is_Formal_Array (Exp : Node_Id) return Boolean;
-- Test if Exp is a reference to an array which is either a formal
-- parameter or a slice of a formal parameter. These are the cases
-- where hidden aliasing can occur.
function Is_Non_Local_Array (Exp : Node_Id) return Boolean;
-- Determine if Exp is a reference to an array variable which is other
-- than an object defined in the current scope, or a component or a
-- slice of such an object. Such objects can be aliased to parameters
-- (unlike local array references).
-----------------------
-- Apply_Dereference --
-----------------------
procedure Apply_Dereference (Arg : Node_Id) is
Typ : constant Entity_Id := Etype (Arg);
begin
if Is_Access_Type (Typ) then
Rewrite (Arg, Make_Explicit_Dereference (Loc,
Prefix => Relocate_Node (Arg)));
Analyze_And_Resolve (Arg, Designated_Type (Typ));
end if;
end Apply_Dereference;
------------------------
-- Has_Address_Clause --
------------------------
function Has_Address_Clause (Exp : Node_Id) return Boolean is
begin
return
(Is_Entity_Name (Exp) and then
Present (Address_Clause (Entity (Exp))))
or else
(Nkind (Exp) = N_Slice and then Has_Address_Clause (Prefix (Exp)));
end Has_Address_Clause;
---------------------
-- Is_Formal_Array --
---------------------
function Is_Formal_Array (Exp : Node_Id) return Boolean is
begin
return
(Is_Entity_Name (Exp) and then Is_Formal (Entity (Exp)))
or else
(Nkind (Exp) = N_Slice and then Is_Formal_Array (Prefix (Exp)));
end Is_Formal_Array;
------------------------
-- Is_Non_Local_Array --
------------------------
function Is_Non_Local_Array (Exp : Node_Id) return Boolean is
begin
case Nkind (Exp) is
when N_Indexed_Component
| N_Selected_Component
| N_Slice
=>
return Is_Non_Local_Array (Prefix (Exp));
when others =>
return
not (Is_Entity_Name (Exp)
and then Scope (Entity (Exp)) = Current_Scope);
end case;
end Is_Non_Local_Array;
-- Determine if Lhs, Rhs are formal arrays or nonlocal arrays
Lhs_Formal : constant Boolean := Is_Formal_Array (Act_Lhs);
Rhs_Formal : constant Boolean := Is_Formal_Array (Act_Rhs);
Lhs_Non_Local_Var : constant Boolean := Is_Non_Local_Array (Act_Lhs);
Rhs_Non_Local_Var : constant Boolean := Is_Non_Local_Array (Act_Rhs);
-- Start of processing for Expand_Assign_Array
begin
-- Deal with length check. Note that the length check is done with
-- respect to the right-hand side as given, not a possible underlying
-- renamed object, since this would generate incorrect extra checks.
Apply_Length_Check_On_Assignment (Rhs, L_Type, Lhs);
-- We start by assuming that the move can be done in either direction,
-- i.e. that the two sides are completely disjoint.
Set_Forwards_OK (N, True);
Set_Backwards_OK (N, True);
-- Normally it is only the slice case that can lead to overlap, and
-- explicit checks for slices are made below. But there is one case
-- where the slice can be implicit and invisible to us: when we have a
-- one dimensional array, and either both operands are parameters, or
-- one is a parameter (which can be a slice passed by reference) and the
-- other is a non-local variable. In this case the parameter could be a
-- slice that overlaps with the other operand.
-- However, if the array subtype is a constrained first subtype in the
-- parameter case, then we don't have to worry about overlap, since
-- slice assignments aren't possible (other than for a slice denoting
-- the whole array).
-- Note: No overlap is possible if there is a change of representation,
-- so we can exclude this case.
if Ndim = 1
and then not Crep
and then
((Lhs_Formal and Rhs_Formal)
or else
(Lhs_Formal and Rhs_Non_Local_Var)
or else
(Rhs_Formal and Lhs_Non_Local_Var))
and then
(not Is_Constrained (Etype (Lhs))
or else not Is_First_Subtype (Etype (Lhs)))
then
Set_Forwards_OK (N, False);
Set_Backwards_OK (N, False);
-- Note: the bit-packed case is not worrisome here, since if we have
-- a slice passed as a parameter, it is always aligned on a byte
-- boundary, and if there are no explicit slices, the assignment
-- can be performed directly.
end if;
-- If either operand has an address clause clear Backwards_OK and
-- Forwards_OK, since we cannot tell if the operands overlap. We
-- exclude this treatment when Rhs is an aggregate, since we know
-- that overlap can't occur.
if (Has_Address_Clause (Lhs) and then Nkind (Rhs) /= N_Aggregate)
or else Has_Address_Clause (Rhs)
then
Set_Forwards_OK (N, False);
Set_Backwards_OK (N, False);
end if;
-- We certainly must use a loop for change of representation and also
-- we use the operand of the conversion on the right-hand side as the
-- effective right-hand side (the component types must match in this
-- situation).
if Crep then
Act_Rhs := Get_Referenced_Object (Rhs);
R_Type := Get_Actual_Subtype (Act_Rhs);
Loop_Required := True;
-- We require a loop if the left side is possibly bit unaligned
elsif Possible_Bit_Aligned_Component (Lhs)
or else
Possible_Bit_Aligned_Component (Rhs)
then
Loop_Required := True;
-- Arrays with controlled components are expanded into a loop to force
-- calls to Adjust at the component level.
elsif Has_Controlled_Component (L_Type) then
Loop_Required := True;
-- If object is full access, we cannot tolerate a loop
elsif Is_Full_Access_Object (Act_Lhs)
or else
Is_Full_Access_Object (Act_Rhs)
then
return;
-- Loop is required if we have atomic components since we have to
-- be sure to do any accesses on an element by element basis.
elsif Has_Atomic_Components (L_Type)
or else Has_Atomic_Components (R_Type)
or else Is_Full_Access (Component_Type (L_Type))
or else Is_Full_Access (Component_Type (R_Type))
then
Loop_Required := True;
-- Case where no slice is involved
elsif not L_Slice and not R_Slice then
-- The following code deals with the case of unconstrained bit packed
-- arrays. The problem is that the template for such arrays contains
-- the bounds of the actual source level array, but the copy of an
-- entire array requires the bounds of the underlying array. It would
-- be nice if the back end could take care of this, but right now it
-- does not know how, so if we have such a type, then we expand out
-- into a loop, which is inefficient but works correctly. If we don't
-- do this, we get the wrong length computed for the array to be
-- moved. The two cases we need to worry about are:
-- Explicit dereference of an unconstrained packed array type as in
-- the following example:
-- procedure C52 is
-- type BITS is array(INTEGER range <>) of BOOLEAN;
-- pragma PACK(BITS);
-- type A is access BITS;
-- P1,P2 : A;
-- begin
-- P1 := new BITS (1 .. 65_535);
-- P2 := new BITS (1 .. 65_535);
-- P2.ALL := P1.ALL;
-- end C52;
-- A formal parameter reference with an unconstrained bit array type
-- is the other case we need to worry about (here we assume the same
-- BITS type declared above):
-- procedure Write_All (File : out BITS; Contents : BITS);
-- begin
-- File.Storage := Contents;
-- end Write_All;
-- We expand to a loop in either of these two cases
-- Question for future thought. Another potentially more efficient
-- approach would be to create the actual subtype, and then do an
-- unchecked conversion to this actual subtype ???
Check_Unconstrained_Bit_Packed_Array : declare
function Is_UBPA_Reference (Opnd : Node_Id) return Boolean;
-- Function to perform required test for the first case, above
-- (dereference of an unconstrained bit packed array).
-----------------------
-- Is_UBPA_Reference --
-----------------------
function Is_UBPA_Reference (Opnd : Node_Id) return Boolean is
Typ : constant Entity_Id := Underlying_Type (Etype (Opnd));
P_Type : Entity_Id;
Des_Type : Entity_Id;
begin
if Present (Packed_Array_Impl_Type (Typ))
and then Is_Array_Type (Packed_Array_Impl_Type (Typ))
and then not Is_Constrained (Packed_Array_Impl_Type (Typ))
then
return True;
elsif Nkind (Opnd) = N_Explicit_Dereference then
P_Type := Underlying_Type (Etype (Prefix (Opnd)));
if not Is_Access_Type (P_Type) then
return False;
else
Des_Type := Designated_Type (P_Type);
return
Is_Bit_Packed_Array (Des_Type)
and then not Is_Constrained (Des_Type);
end if;
else
return False;
end if;
end Is_UBPA_Reference;
-- Start of processing for Check_Unconstrained_Bit_Packed_Array
begin
if Is_UBPA_Reference (Lhs)
or else
Is_UBPA_Reference (Rhs)
then
Loop_Required := True;
-- Here if we do not have the case of a reference to a bit packed
-- unconstrained array case. In this case gigi can most certainly
-- handle the assignment if a forwards move is allowed.
-- (could it handle the backwards case also???)
elsif Forwards_OK (N) then
return;
end if;
end Check_Unconstrained_Bit_Packed_Array;
-- The back end can always handle the assignment if the right side is a
-- string literal (note that overlap is definitely impossible in this
-- case). If the type is packed, a string literal is always converted
-- into an aggregate, except in the case of a null slice, for which no
-- aggregate can be written. In that case, rewrite the assignment as a
-- null statement, a length check has already been emitted to verify
-- that the range of the left-hand side is empty.
-- Note that this code is not executed if we have an assignment of a
-- string literal to a non-bit aligned component of a record, a case
-- which cannot be handled by the backend.
elsif Nkind (Rhs) = N_String_Literal then
if String_Length (Strval (Rhs)) = 0
and then Is_Bit_Packed_Array (L_Type)
then
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
end if;
return;
-- If either operand is bit packed, then we need a loop, since we can't
-- be sure that the slice is byte aligned. Similarly, if either operand
-- is a possibly unaligned slice, then we need a loop (since the back
-- end cannot handle unaligned slices).
elsif Is_Bit_Packed_Array (L_Type)
or else Is_Bit_Packed_Array (R_Type)
or else Is_Possibly_Unaligned_Slice (Lhs)
or else Is_Possibly_Unaligned_Slice (Rhs)
then
Loop_Required := True;
-- If we are not bit-packed, and we have only one slice, then no overlap
-- is possible except in the parameter case, so we can let the back end
-- handle things.
elsif not (L_Slice and R_Slice) then
if Forwards_OK (N) then
return;
end if;
end if;
-- If the right-hand side is a string literal, introduce a temporary for
-- it, for use in the generated loop that will follow.
if Nkind (Rhs) = N_String_Literal then
declare
Temp : constant Entity_Id := Make_Temporary (Loc, 'T', Rhs);
Decl : Node_Id;
begin
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Occurrence_Of (L_Type, Loc),
Expression => Relocate_Node (Rhs));
Insert_Action (N, Decl);
Rewrite (Rhs, New_Occurrence_Of (Temp, Loc));
R_Type := Etype (Temp);
end;
end if;
-- Come here to complete the analysis
-- Loop_Required: Set to True if we know that a loop is required
-- regardless of overlap considerations.
-- Forwards_OK: Set to False if we already know that a forwards
-- move is not safe, else set to True.
-- Backwards_OK: Set to False if we already know that a backwards
-- move is not safe, else set to True
-- Our task at this stage is to complete the overlap analysis, which can
-- result in possibly setting Forwards_OK or Backwards_OK to False, and
-- then generating the final code, either by deciding that it is OK
-- after all to let Gigi handle it, or by generating appropriate code
-- in the front end.
declare
L_Index_Typ : constant Entity_Id := Etype (First_Index (L_Type));
R_Index_Typ : constant Entity_Id := Etype (First_Index (R_Type));
Left_Lo : constant Node_Id := Type_Low_Bound (L_Index_Typ);
Left_Hi : constant Node_Id := Type_High_Bound (L_Index_Typ);
Right_Lo : constant Node_Id := Type_Low_Bound (R_Index_Typ);
Right_Hi : constant Node_Id := Type_High_Bound (R_Index_Typ);
Act_L_Array : Node_Id;
Act_R_Array : Node_Id;
Cleft_Lo : Node_Id;
Cright_Lo : Node_Id;
Condition : Node_Id;
Cresult : Compare_Result;
begin
-- Get the expressions for the arrays. If we are dealing with a
-- private type, then convert to the underlying type. We can do
-- direct assignments to an array that is a private type, but we
-- cannot assign to elements of the array without this extra
-- unchecked conversion.
-- Note: We propagate Parent to the conversion nodes to generate
-- a well-formed subtree.
if Nkind (Act_Lhs) = N_Slice then
Larray := Prefix (Act_Lhs);
else
Larray := Act_Lhs;
if Is_Private_Type (Etype (Larray)) then
declare
Par : constant Node_Id := Parent (Larray);
begin
Larray :=
Unchecked_Convert_To
(Underlying_Type (Etype (Larray)), Larray);
Set_Parent (Larray, Par);
end;
end if;
end if;
if Nkind (Act_Rhs) = N_Slice then
Rarray := Prefix (Act_Rhs);
else
Rarray := Act_Rhs;
if Is_Private_Type (Etype (Rarray)) then
declare
Par : constant Node_Id := Parent (Rarray);
begin
Rarray :=
Unchecked_Convert_To
(Underlying_Type (Etype (Rarray)), Rarray);
Set_Parent (Rarray, Par);
end;
end if;
end if;
-- If both sides are slices, we must figure out whether it is safe
-- to do the move in one direction or the other. It is always safe
-- if there is a change of representation since obviously two arrays
-- with different representations cannot possibly overlap.
if (not Crep) and L_Slice and R_Slice then
Act_L_Array := Get_Referenced_Object (Prefix (Act_Lhs));
Act_R_Array := Get_Referenced_Object (Prefix (Act_Rhs));
-- If both left- and right-hand arrays are entity names, and refer
-- to different entities, then we know that the move is safe (the
-- two storage areas are completely disjoint).
if Is_Entity_Name (Act_L_Array)
and then Is_Entity_Name (Act_R_Array)
and then Entity (Act_L_Array) /= Entity (Act_R_Array)
then
null;
-- Otherwise, we assume the worst, which is that the two arrays
-- are the same array. There is no need to check if we know that
-- is the case, because if we don't know it, we still have to
-- assume it.
-- Generally if the same array is involved, then we have an
-- overlapping case. We will have to really assume the worst (i.e.
-- set neither of the OK flags) unless we can determine the lower
-- or upper bounds at compile time and compare them.
else
Cresult :=
Compile_Time_Compare
(Left_Lo, Right_Lo, Assume_Valid => True);
if Cresult = Unknown then
Cresult :=
Compile_Time_Compare
(Left_Hi, Right_Hi, Assume_Valid => True);
end if;
case Cresult is
when EQ | LE | LT =>
Set_Backwards_OK (N, False);
when GE | GT =>
Set_Forwards_OK (N, False);
when NE | Unknown =>
Set_Backwards_OK (N, False);
Set_Forwards_OK (N, False);
end case;
end if;
end if;
-- If after that analysis Loop_Required is False, meaning that we
-- have not discovered some non-overlap reason for requiring a loop,
-- then the outcome depends on the capabilities of the back end.
if not Loop_Required then
-- Assume the back end can deal with all cases of overlap by
-- falling back to memmove if it cannot use a more efficient
-- approach.
return;
end if;
-- At this stage we have to generate an explicit loop, and we have
-- the following cases:
-- Forwards_OK = True
-- Rnn : right_index := right_index'First;
-- for Lnn in left-index loop
-- left (Lnn) := right (Rnn);
-- Rnn := right_index'Succ (Rnn);
-- end loop;
-- Note: the above code MUST be analyzed with checks off, because
-- otherwise the Succ could overflow. But in any case this is more
-- efficient.
-- Forwards_OK = False, Backwards_OK = True
-- Rnn : right_index := right_index'Last;
-- for Lnn in reverse left-index loop
-- left (Lnn) := right (Rnn);
-- Rnn := right_index'Pred (Rnn);
-- end loop;
-- Note: the above code MUST be analyzed with checks off, because
-- otherwise the Pred could overflow. But in any case this is more
-- efficient.
-- Forwards_OK = Backwards_OK = False
-- This only happens if we have the same array on each side. It is
-- possible to create situations using overlays that violate this,
-- but we simply do not promise to get this "right" in this case.
-- There are two possible subcases. If the No_Implicit_Conditionals
-- restriction is set, then we generate the following code:
-- declare
-- T : constant <operand-type> := rhs;
-- begin
-- lhs := T;
-- end;
-- If implicit conditionals are permitted, then we generate:
-- if Left_Lo <= Right_Lo then
-- <code for Forwards_OK = True above>
-- else
-- <code for Backwards_OK = True above>
-- end if;
-- In order to detect possible aliasing, we examine the renamed
-- expression when the source or target is a renaming. However,
-- the renaming may be intended to capture an address that may be
-- affected by subsequent code, and therefore we must recover
-- the actual entity for the expansion that follows, not the
-- object it renames. In particular, if source or target designate
-- a portion of a dynamically allocated object, the pointer to it
-- may be reassigned but the renaming preserves the proper location.
if Is_Entity_Name (Rhs)
and then
Nkind (Parent (Entity (Rhs))) = N_Object_Renaming_Declaration
and then Nkind (Act_Rhs) = N_Slice
then
Rarray := Rhs;
end if;
if Is_Entity_Name (Lhs)
and then
Nkind (Parent (Entity (Lhs))) = N_Object_Renaming_Declaration
and then Nkind (Act_Lhs) = N_Slice
then
Larray := Lhs;
end if;
-- Cases where either Forwards_OK or Backwards_OK is true
if Forwards_OK (N) or else Backwards_OK (N) then
if Needs_Finalization (Component_Type (L_Type))
and then Base_Type (L_Type) = Base_Type (R_Type)
and then Ndim = 1
and then not No_Ctrl_Actions (N)
then
declare
Proc : constant Entity_Id :=
TSS (Base_Type (L_Type), TSS_Slice_Assign);
Actuals : List_Id;
begin
Apply_Dereference (Larray);
Apply_Dereference (Rarray);
Actuals := New_List (
Duplicate_Subexpr (Larray, Name_Req => True),
Duplicate_Subexpr (Rarray, Name_Req => True),
Duplicate_Subexpr (Left_Lo, Name_Req => True),
Duplicate_Subexpr (Left_Hi, Name_Req => True),
Duplicate_Subexpr (Right_Lo, Name_Req => True),
Duplicate_Subexpr (Right_Hi, Name_Req => True));
Append_To (Actuals,
New_Occurrence_Of (
Boolean_Literals (not Forwards_OK (N)), Loc));
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc, Loc),
Parameter_Associations => Actuals));
end;
else
Rewrite (N,
Expand_Assign_Array_Loop_Or_Bitfield
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => not Forwards_OK (N)));
end if;
-- Case of both are false with No_Implicit_Conditionals
elsif Restriction_Active (No_Implicit_Conditionals) then
declare
T : constant Entity_Id :=
Make_Defining_Identifier (Loc, Chars => Name_T);
begin
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => T,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Etype (Rhs), Loc),
Expression => Relocate_Node (Rhs))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Assignment_Statement (Loc,
Name => Relocate_Node (Lhs),
Expression => New_Occurrence_Of (T, Loc))))));
end;
-- Case of both are false with implicit conditionals allowed
else
-- Before we generate this code, we must ensure that the left and
-- right side array types are defined. They may be itypes, and we
-- cannot let them be defined inside the if, since the first use
-- in the then may not be executed.
Ensure_Defined (L_Type, N);
Ensure_Defined (R_Type, N);
-- We normally compare addresses to find out which way round to
-- do the loop, since this is reliable, and handles the cases of
-- parameters, conversions etc. But we can't do that in the bit
-- packed case, because addresses don't work there.
if not Is_Bit_Packed_Array (L_Type) then
Condition :=
Make_Op_Le (Loc,
Left_Opnd =>
Unchecked_Convert_To (RTE (RE_Integer_Address),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr_Move_Checks (Larray, True),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(L_Index_Typ, Loc),
Attribute_Name => Name_First))),
Attribute_Name => Name_Address)),
Right_Opnd =>
Unchecked_Convert_To (RTE (RE_Integer_Address),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr_Move_Checks (Rarray, True),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(R_Index_Typ, Loc),
Attribute_Name => Name_First))),
Attribute_Name => Name_Address)));
-- For the bit packed and VM cases we use the bounds. That's OK,
-- because we don't have to worry about parameters, since they
-- cannot cause overlap. Perhaps we should worry about weird slice
-- conversions ???
else
-- Copy the bounds
Cleft_Lo := New_Copy_Tree (Left_Lo);
Cright_Lo := New_Copy_Tree (Right_Lo);
-- If the types do not match we add an implicit conversion
-- here to ensure proper match
if Etype (Left_Lo) /= Etype (Right_Lo) then
Cright_Lo :=
Unchecked_Convert_To (Etype (Left_Lo), Cright_Lo);
end if;
-- Reset the Analyzed flag, because the bounds of the index
-- type itself may be universal, and must be reanalyzed to
-- acquire the proper type for the back end.
Set_Analyzed (Cleft_Lo, False);
Set_Analyzed (Cright_Lo, False);
Condition :=
Make_Op_Le (Loc,
Left_Opnd => Cleft_Lo,
Right_Opnd => Cright_Lo);
end if;
if Needs_Finalization (Component_Type (L_Type))
and then Base_Type (L_Type) = Base_Type (R_Type)
and then Ndim = 1
and then not No_Ctrl_Actions (N)
then
-- Call TSS procedure for array assignment, passing the
-- explicit bounds of right- and left-hand sides.
declare
Proc : constant Entity_Id :=
TSS (Base_Type (L_Type), TSS_Slice_Assign);
Actuals : List_Id;
begin
Apply_Dereference (Larray);
Apply_Dereference (Rarray);
Actuals := New_List (
Duplicate_Subexpr (Larray, Name_Req => True),
Duplicate_Subexpr (Rarray, Name_Req => True),
Duplicate_Subexpr (Left_Lo, Name_Req => True),
Duplicate_Subexpr (Left_Hi, Name_Req => True),
Duplicate_Subexpr (Right_Lo, Name_Req => True),
Duplicate_Subexpr (Right_Hi, Name_Req => True));
Append_To (Actuals,
Make_Op_Not (Loc,
Right_Opnd => Condition));
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc, Loc),
Parameter_Associations => Actuals));
end;
else
Rewrite (N,
Make_Implicit_If_Statement (N,
Condition => Condition,
Then_Statements => New_List (
Expand_Assign_Array_Loop_Or_Bitfield
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => False)),
Else_Statements => New_List (
Expand_Assign_Array_Loop_Or_Bitfield
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => True))));
end if;
end if;
Analyze (N, Suppress => All_Checks);
end;
exception
when RE_Not_Available =>
return;
end Expand_Assign_Array;
------------------------------
-- Expand_Assign_Array_Loop --
------------------------------
-- The following is an example of the loop generated for the case of a
-- two-dimensional array:
-- declare
-- R2b : Tm1X1 := 1;
-- begin
-- for L1b in 1 .. 100 loop
-- declare
-- R4b : Tm1X2 := 1;
-- begin
-- for L3b in 1 .. 100 loop
-- vm1 (L1b, L3b) := vm2 (R2b, R4b);
-- R4b := Tm1X2'succ(R4b);
-- end loop;
-- end;
-- R2b := Tm1X1'succ(R2b);
-- end loop;
-- end;
-- Here Rev is False, and Tm1Xn are the subscript types for the right-hand
-- side. The declarations of R2b and R4b are inserted before the original
-- assignment statement.
function Expand_Assign_Array_Loop
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Lnn : array (1 .. Ndim) of Entity_Id;
Rnn : array (1 .. Ndim) of Entity_Id;
-- Entities used as subscripts on left and right sides
L_Index_Type : array (1 .. Ndim) of Entity_Id;
R_Index_Type : array (1 .. Ndim) of Entity_Id;
-- Left and right index types
Assign : Node_Id;
F_Or_L : Name_Id;
S_Or_P : Name_Id;
function Build_Step (J : Nat) return Node_Id;
-- The increment step for the index of the right-hand side is written
-- as an attribute reference (Succ or Pred). This function returns
-- the corresponding node, which is placed at the end of the loop body.
----------------
-- Build_Step --
----------------
function Build_Step (J : Nat) return Node_Id is
Step : Node_Id;
Lim : Name_Id;
begin
if Rev then
Lim := Name_First;
else
Lim := Name_Last;
end if;
Step :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Rnn (J), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (R_Index_Type (J), Loc),
Attribute_Name => S_Or_P,
Expressions => New_List (
New_Occurrence_Of (Rnn (J), Loc))));
-- Note that on the last iteration of the loop, the index is increased
-- (or decreased) past the corresponding bound. This is consistent with
-- the C semantics of the back-end, where such an off-by-one value on a
-- dead index variable is OK. However, in CodePeer mode this leads to
-- spurious warnings, and thus we place a guard around the attribute
-- reference. For obvious reasons we only do this for CodePeer.
if CodePeer_Mode then
Step :=
Make_If_Statement (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Lnn (J), Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (L_Index_Type (J), Loc),
Attribute_Name => Lim)),
Then_Statements => New_List (Step));
end if;
return Step;
end Build_Step;
-- Start of processing for Expand_Assign_Array_Loop
begin
if Rev then
F_Or_L := Name_Last;
S_Or_P := Name_Pred;
else
F_Or_L := Name_First;
S_Or_P := Name_Succ;
end if;
-- Setup index types and subscript entities
declare
L_Index : Node_Id;
R_Index : Node_Id;
begin
L_Index := First_Index (L_Type);
R_Index := First_Index (R_Type);
for J in 1 .. Ndim loop
Lnn (J) := Make_Temporary (Loc, 'L');
Rnn (J) := Make_Temporary (Loc, 'R');
L_Index_Type (J) := Etype (L_Index);
R_Index_Type (J) := Etype (R_Index);
Next_Index (L_Index);
Next_Index (R_Index);
end loop;
end;
-- Now construct the assignment statement
declare
ExprL : constant List_Id := New_List;
ExprR : constant List_Id := New_List;
begin
for J in 1 .. Ndim loop
Append_To (ExprL, New_Occurrence_Of (Lnn (J), Loc));
Append_To (ExprR, New_Occurrence_Of (Rnn (J), Loc));
end loop;
Assign :=
Make_Assignment_Statement (Loc,
Name =>
Make_Indexed_Component (Loc,
Prefix => Duplicate_Subexpr (Larray, Name_Req => True),
Expressions => ExprL),
Expression =>
Make_Indexed_Component (Loc,
Prefix => Duplicate_Subexpr (Rarray, Name_Req => True),
Expressions => ExprR));
-- We set assignment OK, since there are some cases, e.g. in object
-- declarations, where we are actually assigning into a constant.
-- If there really is an illegality, it was caught long before now,
-- and was flagged when the original assignment was analyzed.
Set_Assignment_OK (Name (Assign));
-- Propagate the No_Ctrl_Actions flag to individual assignments
Set_No_Ctrl_Actions (Assign, No_Ctrl_Actions (N));
end;
-- Now construct the loop from the inside out, with the last subscript
-- varying most rapidly. Note that Assign is first the raw assignment
-- statement, and then subsequently the loop that wraps it up.
for J in reverse 1 .. Ndim loop
Assign :=
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Rnn (J),
Object_Definition =>
New_Occurrence_Of (R_Index_Type (J), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (R_Index_Type (J), Loc),
Attribute_Name => F_Or_L))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_Loop_Statement (N,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => Lnn (J),
Reverse_Present => Rev,
Discrete_Subtype_Definition =>
New_Occurrence_Of (L_Index_Type (J), Loc))),
Statements => New_List (Assign, Build_Step (J))))));
end loop;
return Assign;
end Expand_Assign_Array_Loop;
----------------------------------
-- Expand_Assign_Array_Bitfield --
----------------------------------
function Expand_Assign_Array_Bitfield
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Rev : Boolean) return Node_Id
is
pragma Assert (not Rev);
-- Reverse copying is not yet supported by Copy_Bitfield.
pragma Assert (not Change_Of_Representation (N));
-- This won't work, for example, to copy a packed array to an unpacked
-- array.
Loc : constant Source_Ptr := Sloc (N);
L_Index_Typ : constant Entity_Id := Etype (First_Index (L_Type));
R_Index_Typ : constant Entity_Id := Etype (First_Index (R_Type));
Left_Lo : constant Node_Id := Type_Low_Bound (L_Index_Typ);
Right_Lo : constant Node_Id := Type_Low_Bound (R_Index_Typ);
L_Addr : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Larray, True),
Expressions => New_List (New_Copy_Tree (Left_Lo))),
Attribute_Name => Name_Address);
L_Bit : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Larray, True),
Expressions => New_List (New_Copy_Tree (Left_Lo))),
Attribute_Name => Name_Bit);
R_Addr : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Rarray, True),
Expressions => New_List (New_Copy_Tree (Right_Lo))),
Attribute_Name => Name_Address);
R_Bit : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Rarray, True),
Expressions => New_List (New_Copy_Tree (Right_Lo))),
Attribute_Name => Name_Bit);
-- Compute the Size of the bitfield
-- Note that the length check has already been done, so we can use the
-- size of either L or R; they are equal. We can't use 'Size here,
-- because sometimes bit fields get copied into a temp, and the 'Size
-- ends up being the size of the temp (e.g. an 8-bit temp containing
-- a 4-bit bit field).
Size : constant Node_Id :=
Make_Op_Multiply (Loc,
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr (Name (N), True),
Attribute_Name => Name_Length),
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr (Name (N), True),
Attribute_Name => Name_Component_Size));
begin
return Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Copy_Bitfield), Loc),
Parameter_Associations => New_List (
R_Addr, R_Bit, L_Addr, L_Bit, Size));
end Expand_Assign_Array_Bitfield;
---------------------------------------
-- Expand_Assign_Array_Bitfield_Fast --
---------------------------------------
function Expand_Assign_Array_Bitfield_Fast
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id) return Node_Id
is
pragma Assert (not Change_Of_Representation (N));
-- This won't work, for example, to copy a packed array to an unpacked
-- array.
-- For L (A .. B) := R (C .. D), we generate:
--
-- L := Fast_Copy_Bitfield (R, <offset of R(C)>, L, <offset of L(A)>,
-- L (A .. B)'Length * L'Component_Size);
--
-- with L and R suitably uncheckedly converted to/from Val_2.
-- The offsets are from the start of L and R.
Loc : constant Source_Ptr := Sloc (N);
L_Typ : constant Entity_Id := Etype (Larray);
R_Typ : constant Entity_Id := Etype (Rarray);
-- The original type of the arrays
L_Val : constant Node_Id :=
Unchecked_Convert_To (RTE (RE_Val_2), Larray);
R_Val : constant Node_Id :=
Unchecked_Convert_To (RTE (RE_Val_2), Rarray);
-- Converted values of left- and right-hand sides
L_Small : constant Boolean :=
Known_Static_RM_Size (L_Typ)
and then RM_Size (L_Typ) < Standard_Long_Long_Integer_Size;
R_Small : constant Boolean :=
Known_Static_RM_Size (R_Typ)
and then RM_Size (R_Typ) < Standard_Long_Long_Integer_Size;
-- Whether the above unchecked conversions need to be padded with zeros
C_Size : constant Uint := Component_Size (L_Typ);
pragma Assert (C_Size >= 1);
pragma Assert (C_Size = Component_Size (R_Typ));
Larray_Bounds : constant Range_Values :=
Get_Index_Bounds (First_Index (L_Typ));
L_Bounds : constant Range_Values :=
(if Nkind (Name (N)) = N_Slice
then Get_Index_Bounds (Discrete_Range (Name (N)))
else Larray_Bounds);
-- If the left-hand side is A (First..Last), Larray_Bounds is A'Range,
-- and L_Bounds is First..Last. If it's not a slice, we treat it like
-- a slice starting at A'First.
L_Bit : constant Node_Id :=
Make_Integer_Literal
(Loc, (L_Bounds.First - Larray_Bounds.First) * C_Size);
Rarray_Bounds : constant Range_Values :=
Get_Index_Bounds (First_Index (R_Typ));
R_Bounds : constant Range_Values :=
(if Nkind (Expression (N)) = N_Slice
then Get_Index_Bounds (Discrete_Range (Expression (N)))
else Rarray_Bounds);
R_Bit : constant Node_Id :=
Make_Integer_Literal
(Loc, (R_Bounds.First - Rarray_Bounds.First) * C_Size);
Size : constant Node_Id :=
Make_Op_Multiply (Loc,
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr (Name (N), True),
Attribute_Name => Name_Length),
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr (Larray, True),
Attribute_Name => Name_Component_Size));
L_Arg, R_Arg, Call : Node_Id;
begin
-- The semantics of unchecked conversion between bit-packed arrays that
-- are implemented as modular types and modular types is precisely that
-- of unchecked conversion between modular types. Therefore, if it needs
-- to be padded with zeros, the padding must be moved to the correct end
-- for memory order because System.Bitfield_Utils works in memory order.
if L_Small
and then (Bytes_Big_Endian xor Reverse_Storage_Order (L_Typ))
then
L_Arg := Make_Op_Shift_Left (Loc,
Left_Opnd => L_Val,
Right_Opnd => Make_Integer_Literal (Loc,
Standard_Long_Long_Integer_Size - RM_Size (L_Typ)));
else
L_Arg := L_Val;
end if;
if R_Small
and then (Bytes_Big_Endian xor Reverse_Storage_Order (R_Typ))
then
R_Arg := Make_Op_Shift_Left (Loc,
Left_Opnd => R_Val,
Right_Opnd => Make_Integer_Literal (Loc,
Standard_Long_Long_Integer_Size - RM_Size (R_Typ)));
else
R_Arg := R_Val;
end if;
Call := Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Fast_Copy_Bitfield), Loc),
Parameter_Associations => New_List (
R_Arg, R_Bit, L_Arg, L_Bit, Size));
-- Conversely, the final unchecked conversion must take significant bits
if L_Small
and then (Bytes_Big_Endian xor Reverse_Storage_Order (L_Typ))
then
Call := Make_Op_Shift_Right (Loc,
Left_Opnd => Call,
Right_Opnd => Make_Integer_Literal (Loc,
Standard_Long_Long_Integer_Size - RM_Size (L_Typ)));
end if;
return Make_Assignment_Statement (Loc,
Name => Duplicate_Subexpr (Larray, True),
Expression => Unchecked_Convert_To (L_Typ, Call));
end Expand_Assign_Array_Bitfield_Fast;
------------------------------------------
-- Expand_Assign_Array_Loop_Or_Bitfield --
------------------------------------------
function Expand_Assign_Array_Loop_Or_Bitfield
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean) return Node_Id
is
L : constant Node_Id := Name (N);
R : constant Node_Id := Expression (N);
-- Left- and right-hand sides of the assignment statement
Slices : constant Boolean :=
Nkind (L) = N_Slice or else Nkind (R) = N_Slice;
L_Prefix_Comp : constant Boolean :=
-- True if the left-hand side is a slice of a component or slice
Nkind (L) = N_Slice
and then Nkind (Prefix (L)) in
N_Selected_Component | N_Indexed_Component | N_Slice;
R_Prefix_Comp : constant Boolean :=
-- Likewise for the right-hand side
Nkind (R) = N_Slice
and then Nkind (Prefix (R)) in
N_Selected_Component | N_Indexed_Component | N_Slice;
begin
-- Determine whether Copy_Bitfield or Fast_Copy_Bitfield is appropriate
-- (will work, and will be more efficient than component-by-component
-- copy). Copy_Bitfield doesn't work for reversed storage orders. It is
-- efficient for slices of bit-packed arrays. Copy_Bitfield can read and
-- write bits that are not part of the objects being copied, so we don't
-- want to use it if there are volatile or independent components. If
-- the Prefix of the slice is a component or slice, then it might be a
-- part of an object with some other volatile or independent components,
-- so we disable the optimization in that case as well. We could
-- complicate this code by actually looking for such volatile and
-- independent components.
if Is_Bit_Packed_Array (L_Type)
and then Is_Bit_Packed_Array (R_Type)
and then not Reverse_Storage_Order (L_Type)
and then not Reverse_Storage_Order (R_Type)
and then Ndim = 1
and then Slices
and then not Has_Volatile_Component (L_Type)
and then not Has_Volatile_Component (R_Type)
and then not Has_Independent_Components (L_Type)
and then not Has_Independent_Components (R_Type)
and then not L_Prefix_Comp
and then not R_Prefix_Comp
then
-- Here if Copy_Bitfield can work (except for the Rev test below).
-- Determine whether to call Fast_Copy_Bitfield instead. If we
-- are assigning slices, and all the relevant bounds are known at
-- compile time, and the maximum object size is no greater than
-- System.Bitfields.Val_Bits (i.e. Long_Long_Integer'Size / 2), and
-- we don't have enumeration representation clauses, we can use
-- Fast_Copy_Bitfield. The max size test is to ensure that the slices
-- cannot overlap boundaries not supported by Fast_Copy_Bitfield.
pragma Assert (Known_Component_Size (Base_Type (L_Type)));
pragma Assert (Known_Component_Size (Base_Type (R_Type)));
-- Note that L_Type and R_Type do not necessarily have the same base
-- type, because of array type conversions. Hence the need to check
-- various properties of both.
if Compile_Time_Known_Bounds (Base_Type (L_Type))
and then Compile_Time_Known_Bounds (Base_Type (R_Type))
then
declare
Left_Base_Index : constant Entity_Id :=
First_Index (Base_Type (L_Type));
Left_Base_Range : constant Range_Values :=
Get_Index_Bounds (Left_Base_Index);
Right_Base_Index : constant Entity_Id :=
First_Index (Base_Type (R_Type));
Right_Base_Range : constant Range_Values :=
Get_Index_Bounds (Right_Base_Index);
Known_Left_Slice_Low : constant Boolean :=
(if Nkind (L) = N_Slice
then Compile_Time_Known_Value
(Get_Index_Bounds (Discrete_Range (L)).First));
Known_Right_Slice_Low : constant Boolean :=
(if Nkind (R) = N_Slice
then Compile_Time_Known_Value
(Get_Index_Bounds (Discrete_Range (R)).Last));
Val_Bits : constant Pos := Standard_Long_Long_Integer_Size / 2;
begin
if Left_Base_Range.Last - Left_Base_Range.First < Val_Bits
and then Right_Base_Range.Last - Right_Base_Range.First <
Val_Bits
and then Known_Esize (L_Type)
and then Known_Esize (R_Type)
and then Known_Left_Slice_Low
and then Known_Right_Slice_Low
and then Compile_Time_Known_Value
(Get_Index_Bounds (First_Index (Etype (Larray))).First)
and then Compile_Time_Known_Value
(Get_Index_Bounds (First_Index (Etype (Rarray))).First)
and then
not (Is_Enumeration_Type (Etype (Left_Base_Index))
and then Has_Enumeration_Rep_Clause
(Etype (Left_Base_Index)))
and then RTE_Available (RE_Fast_Copy_Bitfield)
then
pragma Assert (Known_Esize (L_Type));
pragma Assert (Known_Esize (R_Type));
return Expand_Assign_Array_Bitfield_Fast (N, Larray, Rarray);
end if;
end;
end if;
-- Fast_Copy_Bitfield can work if Rev is True, because the data is
-- passed and returned by copy. Copy_Bitfield cannot.
if not Rev and then RTE_Available (RE_Copy_Bitfield) then
return Expand_Assign_Array_Bitfield
(N, Larray, Rarray, L_Type, R_Type, Rev);
end if;
end if;
-- Here if we did not return above, with Fast_Copy_Bitfield or
-- Copy_Bitfield.
return Expand_Assign_Array_Loop
(N, Larray, Rarray, L_Type, R_Type, Ndim, Rev);
end Expand_Assign_Array_Loop_Or_Bitfield;
--------------------------
-- Expand_Assign_Record --
--------------------------
procedure Expand_Assign_Record (N : Node_Id) is
Lhs : constant Node_Id := Name (N);
Rhs : Node_Id := Expression (N);
L_Typ : constant Entity_Id := Base_Type (Etype (Lhs));
begin
-- If change of representation, then extract the real right-hand side
-- from the type conversion, and proceed with component-wise assignment,
-- since the two types are not the same as far as the back end is
-- concerned.
if Change_Of_Representation (N) then
Rhs := Expression (Rhs);
-- If this may be a case of a large bit aligned component, then proceed
-- with component-wise assignment, to avoid possible clobbering of other
-- components sharing bits in the first or last byte of the component to
-- be assigned.
elsif Possible_Bit_Aligned_Component (Lhs)
or else
Possible_Bit_Aligned_Component (Rhs)
then
null;
-- If we have a tagged type that has a complete record representation
-- clause, we must do we must do component-wise assignments, since child
-- types may have used gaps for their components, and we might be
-- dealing with a view conversion.
elsif Is_Fully_Repped_Tagged_Type (L_Typ) then
null;
-- If neither condition met, then nothing special to do, the back end
-- can handle assignment of the entire component as a single entity.
else
return;
end if;
-- At this stage we know that we must do a component wise assignment
declare
Loc : constant Source_Ptr := Sloc (N);
R_Typ : constant Entity_Id := Base_Type (Etype (Rhs));
Decl : constant Node_Id := Declaration_Node (R_Typ);
RDef : Node_Id;
F : Entity_Id;
function Find_Component
(Typ : Entity_Id;
Comp : Entity_Id) return Entity_Id;
-- Find the component with the given name in the underlying record
-- declaration for Typ. We need to use the actual entity because the
-- type may be private and resolution by identifier alone would fail.
function Make_Component_List_Assign
(CL : Node_Id;
U_U : Boolean := False) return List_Id;
-- Returns a sequence of statements to assign the components that
-- are referenced in the given component list. The flag U_U is
-- used to force the usage of the inferred value of the variant
-- part expression as the switch for the generated case statement.
function Make_Field_Assign
(C : Entity_Id;
U_U : Boolean := False) return Node_Id;
-- Given C, the entity for a discriminant or component, build an
-- assignment for the corresponding field values. The flag U_U
-- signals the presence of an Unchecked_Union and forces the usage
-- of the inferred discriminant value of C as the right-hand side
-- of the assignment.
function Make_Field_Assigns (CI : List_Id) return List_Id;
-- Given CI, a component items list, construct series of statements
-- for fieldwise assignment of the corresponding components.
--------------------
-- Find_Component --
--------------------
function Find_Component
(Typ : Entity_Id;
Comp : Entity_Id) return Entity_Id
is
Utyp : constant Entity_Id := Underlying_Type (Typ);
C : Entity_Id;
begin
C := First_Entity (Utyp);
while Present (C) loop
if Chars (C) = Chars (Comp) then
return C;
-- The component may be a renamed discriminant, in
-- which case check against the name of the original
-- discriminant of the parent type.
elsif Is_Derived_Type (Scope (Comp))
and then Ekind (Comp) = E_Discriminant
and then Present (Corresponding_Discriminant (Comp))
and then
Chars (C) = Chars (Corresponding_Discriminant (Comp))
then
return C;
end if;
Next_Entity (C);
end loop;
raise Program_Error;
end Find_Component;
--------------------------------
-- Make_Component_List_Assign --
--------------------------------
function Make_Component_List_Assign
(CL : Node_Id;
U_U : Boolean := False) return List_Id
is
CI : constant List_Id := Component_Items (CL);
VP : constant Node_Id := Variant_Part (CL);
Constrained_Typ : Entity_Id;
Alts : List_Id;
DC : Node_Id;
DCH : List_Id;
Expr : Node_Id;
Result : List_Id;
V : Node_Id;
begin
-- Try to find a constrained type to extract discriminant values
-- from, so that the case statement built below gets an
-- opportunity to be folded by Expand_N_Case_Statement.
if U_U or else Is_Constrained (Etype (Rhs)) then
Constrained_Typ := Etype (Rhs);
elsif Is_Constrained (Etype (Expression (N))) then
Constrained_Typ := Etype (Expression (N));
else
Constrained_Typ := Empty;
end if;
Result := Make_Field_Assigns (CI);
if Present (VP) then
V := First_Non_Pragma (Variants (VP));
Alts := New_List;
while Present (V) loop
DCH := New_List;
DC := First (Discrete_Choices (V));
while Present (DC) loop
Append_To (DCH, New_Copy_Tree (DC));
Next (DC);
end loop;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => DCH,
Statements =>
Make_Component_List_Assign (Component_List (V))));
Next_Non_Pragma (V);
end loop;
if Present (Constrained_Typ) then
Expr :=
New_Copy (Get_Discriminant_Value (
Entity (Name (VP)),
Constrained_Typ,
Discriminant_Constraint (Constrained_Typ)));
else
Expr :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Selector_Name =>
Make_Identifier (Loc, Chars (Name (VP))));
end if;
Append_To (Result,
Make_Case_Statement (Loc,
Expression => Expr,
Alternatives => Alts));
end if;
return Result;
end Make_Component_List_Assign;
-----------------------
-- Make_Field_Assign --
-----------------------
function Make_Field_Assign
(C : Entity_Id;
U_U : Boolean := False) return Node_Id
is
A : Node_Id;
Disc : Entity_Id;
Expr : Node_Id;
begin
-- The discriminant entity to be used in the retrieval below must
-- be one in the corresponding type, given that the assignment may
-- be between derived and parent types.
if Is_Derived_Type (Etype (Rhs)) then
Disc := Find_Component (R_Typ, C);
else
Disc := C;
end if;
-- In the case of an Unchecked_Union, use the discriminant
-- constraint value as on the right-hand side of the assignment.
if U_U then
Expr :=
New_Copy (Get_Discriminant_Value (C,
Etype (Rhs),
Discriminant_Constraint (Etype (Rhs))));
else
Expr :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Selector_Name => New_Occurrence_Of (Disc, Loc));
end if;
-- Generate the assignment statement. When the left-hand side
-- is an object with an address clause present, force generated
-- temporaries to be renamings so as to correctly assign to any
-- overlaid objects.
A :=
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix =>
Duplicate_Subexpr
(Exp => Lhs,
Name_Req => False,
Renaming_Req =>
Is_Entity_Name (Lhs)
and then Present (Address_Clause (Entity (Lhs)))),
Selector_Name =>
New_Occurrence_Of (Find_Component (L_Typ, C), Loc)),
Expression => Expr);
-- Set Assignment_OK, so discriminants can be assigned
Set_Assignment_OK (Name (A), True);
if Componentwise_Assignment (N)
and then Nkind (Name (A)) = N_Selected_Component
and then Chars (Selector_Name (Name (A))) = Name_uParent
then
Set_Componentwise_Assignment (A);
end if;
return A;
end Make_Field_Assign;
------------------------
-- Make_Field_Assigns --
------------------------
function Make_Field_Assigns (CI : List_Id) return List_Id is
Item : Node_Id;
Result : List_Id;
begin
Item := First (CI);
Result := New_List;
while Present (Item) loop
-- Look for components, but exclude _tag field assignment if
-- the special Componentwise_Assignment flag is set.
if Nkind (Item) = N_Component_Declaration
and then not (Is_Tag (Defining_Identifier (Item))
and then Componentwise_Assignment (N))
then
Append_To
(Result, Make_Field_Assign (Defining_Identifier (Item)));
end if;
Next (Item);
end loop;
return Result;
end Make_Field_Assigns;
-- Start of processing for Expand_Assign_Record
begin
-- Note that we need to use the base types for this processing in
-- order to retrieve the Type_Definition. In the constrained case,
-- we filter out the non relevant fields in
-- Make_Component_List_Assign.
-- First copy the discriminants. This is done unconditionally. It
-- is required in the unconstrained left side case, and also in the
-- case where this assignment was constructed during the expansion
-- of a type conversion (since initialization of discriminants is
-- suppressed in this case). It is unnecessary but harmless in
-- other cases.
-- Special case: no copy if the target has no discriminants
if Has_Discriminants (L_Typ)
and then Is_Unchecked_Union (Base_Type (L_Typ))
then
null;
elsif Has_Discriminants (L_Typ) then
F := First_Discriminant (R_Typ);
while Present (F) loop
-- If we are expanding the initialization of a derived record
-- that constrains or renames discriminants of the parent, we
-- must use the corresponding discriminant in the parent.
declare
CF : Entity_Id;
begin
if Inside_Init_Proc
and then Present (Corresponding_Discriminant (F))
then
CF := Corresponding_Discriminant (F);
else
CF := F;
end if;
if Is_Unchecked_Union (R_Typ) then
-- Within an initialization procedure this is the
-- assignment to an unchecked union component, in which
-- case there is no discriminant to initialize.
if Inside_Init_Proc then
null;
else
-- The assignment is part of a conversion from a
-- derived unchecked union type with an inferable
-- discriminant, to a parent type.
Insert_Action (N, Make_Field_Assign (CF, True));
end if;
else
Insert_Action (N, Make_Field_Assign (CF));
end if;
Next_Discriminant (F);
end;
end loop;
-- If the derived type has a stored constraint, assign the value
-- of the corresponding discriminants explicitly, skipping those
-- that are renamed discriminants. We cannot just retrieve them
-- from the Rhs by selected component because they are invisible
-- in the type of the right-hand side.
if Stored_Constraint (R_Typ) /= No_Elist then
declare
Assign : Node_Id;
Discr_Val : Elmt_Id;
begin
Discr_Val := First_Elmt (Stored_Constraint (R_Typ));
F := First_Entity (R_Typ);
while Present (F) loop
if Ekind (F) = E_Discriminant
and then Is_Completely_Hidden (F)
and then Present (Corresponding_Record_Component (F))
and then
(not Is_Entity_Name (Node (Discr_Val))
or else Ekind (Entity (Node (Discr_Val))) /=
E_Discriminant)
then
Assign :=
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Selector_Name =>
New_Occurrence_Of
(Corresponding_Record_Component (F), Loc)),
Expression => New_Copy (Node (Discr_Val)));
Set_Assignment_OK (Name (Assign));
Insert_Action (N, Assign);
Next_Elmt (Discr_Val);
end if;
Next_Entity (F);
end loop;
end;
end if;
end if;
-- We know the underlying type is a record, but its current view
-- may be private. We must retrieve the usable record declaration.
if Nkind (Decl) in N_Private_Type_Declaration
| N_Private_Extension_Declaration
and then Present (Full_View (R_Typ))
then
RDef := Type_Definition (Declaration_Node (Full_View (R_Typ)));
else
RDef := Type_Definition (Decl);
end if;
if Nkind (RDef) = N_Derived_Type_Definition then
RDef := Record_Extension_Part (RDef);
end if;
if Nkind (RDef) = N_Record_Definition
and then Present (Component_List (RDef))
then
if Is_Unchecked_Union (R_Typ) then
Insert_Actions (N,
Make_Component_List_Assign (Component_List (RDef), True));
else
Insert_Actions (N,
Make_Component_List_Assign (Component_List (RDef)));
end if;
Rewrite (N, Make_Null_Statement (Loc));
end if;
end;
end Expand_Assign_Record;
-------------------------------------
-- Expand_Assign_With_Target_Names --
-------------------------------------
procedure Expand_Assign_With_Target_Names (N : Node_Id) is
LHS : constant Node_Id := Name (N);
LHS_Typ : constant Entity_Id := Etype (LHS);
Loc : constant Source_Ptr := Sloc (N);
RHS : constant Node_Id := Expression (N);
Ent : Entity_Id;
-- The entity of the left-hand side
function Replace_Target (N : Node_Id) return Traverse_Result;
-- Replace occurrences of the target name by the proper entity: either
-- the entity of the LHS in simple cases, or the formal of the
-- constructed procedure otherwise.
--------------------
-- Replace_Target --
--------------------
function Replace_Target (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) = N_Target_Name then
Rewrite (N, New_Occurrence_Of (Ent, Sloc (N)));
-- The expression will be reanalyzed when the enclosing assignment
-- is reanalyzed, so reset the entity, which may be a temporary
-- created during analysis, e.g. a loop variable for an iterated
-- component association. However, if entity is callable then
-- resolution has established its proper identity (including in
-- rewritten prefixed calls) so we must preserve it.
elsif Is_Entity_Name (N) then
if Present (Entity (N))
and then not Is_Overloadable (Entity (N))
then
Set_Entity (N, Empty);
end if;
end if;
Set_Analyzed (N, False);
return OK;
end Replace_Target;
procedure Replace_Target_Name is new Traverse_Proc (Replace_Target);
-- Local variables
New_RHS : Node_Id;
Proc_Id : Entity_Id;
-- Start of processing for Expand_Assign_With_Target_Names
begin
New_RHS := New_Copy_Tree (RHS);
-- The left-hand side is a direct name
if Is_Entity_Name (LHS)
and then not Is_Renaming_Of_Object (Entity (LHS))
then
Ent := Entity (LHS);
Replace_Target_Name (New_RHS);
-- Generate:
-- LHS := ... LHS ...;
Rewrite (N,
Make_Assignment_Statement (Loc,
Name => Relocate_Node (LHS),
Expression => New_RHS));
-- The left-hand side is not a direct name, but is side-effect free.
-- Capture its value in a temporary to avoid multiple evaluations.
elsif Side_Effect_Free (LHS) then
Ent := Make_Temporary (Loc, 'T');
Replace_Target_Name (New_RHS);
-- Generate:
-- T : LHS_Typ := LHS;
Insert_Before_And_Analyze (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Ent,
Object_Definition => New_Occurrence_Of (LHS_Typ, Loc),
Expression => New_Copy_Tree (LHS)));
-- Generate:
-- LHS := ... T ...;
Rewrite (N,
Make_Assignment_Statement (Loc,
Name => Relocate_Node (LHS),
Expression => New_RHS));
-- Otherwise wrap the whole assignment statement in a procedure with an
-- IN OUT parameter. The original assignment then becomes a call to the
-- procedure with the left-hand side as an actual.
else
Ent := Make_Temporary (Loc, 'T');
Replace_Target_Name (New_RHS);
-- Generate:
-- procedure P (T : in out LHS_Typ) is
-- begin
-- T := ... T ...;
-- end P;
Proc_Id := Make_Temporary (Loc, 'P');
Insert_Before_And_Analyze (N,
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Proc_Id,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Ent,
In_Present => True,
Out_Present => True,
Parameter_Type =>
New_Occurrence_Of (LHS_Typ, Loc)))),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Ent, Loc),
Expression => New_RHS)))));
-- Generate:
-- P (LHS);
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Id, Loc),
Parameter_Associations => New_List (Relocate_Node (LHS))));
end if;
-- Analyze rewritten node, either as assignment or procedure call
Analyze (N);
end Expand_Assign_With_Target_Names;
-----------------------------------
-- Expand_N_Assignment_Statement --
-----------------------------------
-- This procedure implements various cases where an assignment statement
-- cannot just be passed on to the back end in untransformed state.
procedure Expand_N_Assignment_Statement (N : Node_Id) is
Crep : constant Boolean := Change_Of_Representation (N);
Lhs : constant Node_Id := Name (N);
Loc : constant Source_Ptr := Sloc (N);
Rhs : constant Node_Id := Expression (N);
Typ : constant Entity_Id := Underlying_Type (Etype (Lhs));
Exp : Node_Id;
begin
-- Special case to check right away, if the Componentwise_Assignment
-- flag is set, this is a reanalysis from the expansion of the primitive
-- assignment procedure for a tagged type, and all we need to do is to
-- expand to assignment of components, because otherwise, we would get
-- infinite recursion (since this looks like a tagged assignment which
-- would normally try to *call* the primitive assignment procedure).
if Componentwise_Assignment (N) then
Expand_Assign_Record (N);
return;
end if;
-- Defend against invalid subscripts on left side if we are in standard
-- validity checking mode. No need to do this if we are checking all
-- subscripts.
-- Note that we do this right away, because there are some early return
-- paths in this procedure, and this is required on all paths.
if Validity_Checks_On
and then Validity_Check_Default
and then not Validity_Check_Subscripts
then
Check_Valid_Lvalue_Subscripts (Lhs);
end if;
-- Separate expansion if RHS contain target names. Note that assignment
-- may already have been expanded if RHS is aggregate.
if Nkind (N) = N_Assignment_Statement and then Has_Target_Names (N) then
Expand_Assign_With_Target_Names (N);
return;
end if;
-- Ada 2005 (AI-327): Handle assignment to priority of protected object
-- Rewrite an assignment to X'Priority into a run-time call
-- For example: X'Priority := New_Prio_Expr;
-- ...is expanded into Set_Ceiling (X._Object, New_Prio_Expr);
-- Note that although X'Priority is notionally an object, it is quite
-- deliberately not defined as an aliased object in the RM. This means
-- that it works fine to rewrite it as a call, without having to worry
-- about complications that would other arise from X'Priority'Access,
-- which is illegal, because of the lack of aliasing.
if Ada_Version >= Ada_2005 then
declare
Call : Node_Id;
Conctyp : Entity_Id;
Ent : Entity_Id;
Subprg : Entity_Id;
RT_Subprg_Name : Node_Id;
begin
-- Handle chains of renamings
Ent := Name (N);
while Nkind (Ent) in N_Has_Entity
and then Present (Entity (Ent))
and then Is_Object (Entity (Ent))
and then Present (Renamed_Object (Entity (Ent)))
loop
Ent := Renamed_Object (Entity (Ent));
end loop;
-- The attribute Priority applied to protected objects has been
-- previously expanded into a call to the Get_Ceiling run-time
-- subprogram. In restricted profiles this is not available.
if Is_Expanded_Priority_Attribute (Ent) then
-- Look for the enclosing concurrent type
Conctyp := Current_Scope;
while not Is_Concurrent_Type (Conctyp) loop
Conctyp := Scope (Conctyp);
end loop;
pragma Assert (Is_Protected_Type (Conctyp));
-- Generate the first actual of the call
Subprg := Current_Scope;
while not Present (Protected_Body_Subprogram (Subprg)) loop
Subprg := Scope (Subprg);
end loop;
-- Select the appropriate run-time call
if Number_Entries (Conctyp) = 0 then
RT_Subprg_Name :=
New_Occurrence_Of (RTE (RE_Set_Ceiling), Loc);
else
RT_Subprg_Name :=
New_Occurrence_Of (RTE (RO_PE_Set_Ceiling), Loc);
end if;
Call :=
Make_Procedure_Call_Statement (Loc,
Name => RT_Subprg_Name,
Parameter_Associations => New_List (
New_Copy_Tree (First (Parameter_Associations (Ent))),
Relocate_Node (Expression (N))));
Rewrite (N, Call);
Analyze (N);
return;
end if;
end;
end if;
-- Deal with assignment checks unless suppressed
if not Suppress_Assignment_Checks (N) then
-- First deal with generation of range check if required,
-- and then predicate checks if the type carries a predicate.
-- If the Rhs is an expression these tests may have been applied
-- already. This is the case if the RHS is a type conversion.
-- Other such redundant checks could be removed ???
if Nkind (Rhs) /= N_Type_Conversion
or else Entity (Subtype_Mark (Rhs)) /= Typ
then
if Do_Range_Check (Rhs) then
Generate_Range_Check (Rhs, Typ, CE_Range_Check_Failed);
end if;
Apply_Predicate_Check (Rhs, Typ);
end if;
end if;
-- Check for a special case where a high level transformation is
-- required. If we have either of:
-- P.field := rhs;
-- P (sub) := rhs;
-- where P is a reference to a bit packed array, then we have to unwind
-- the assignment. The exact meaning of being a reference to a bit
-- packed array is as follows:
-- An indexed component whose prefix is a bit packed array is a
-- reference to a bit packed array.
-- An indexed component or selected component whose prefix is a
-- reference to a bit packed array is itself a reference ot a
-- bit packed array.
-- The required transformation is
-- Tnn : prefix_type := P;
-- Tnn.field := rhs;
-- P := Tnn;
-- or
-- Tnn : prefix_type := P;
-- Tnn (subscr) := rhs;
-- P := Tnn;
-- Since P is going to be evaluated more than once, any subscripts
-- in P must have their evaluation forced.
if Nkind (Lhs) in N_Indexed_Component | N_Selected_Component
and then Is_Ref_To_Bit_Packed_Array (Prefix (Lhs))
then
declare
BPAR_Expr : constant Node_Id := Relocate_Node (Prefix (Lhs));
BPAR_Typ : constant Entity_Id := Etype (BPAR_Expr);
Tnn : constant Entity_Id :=
Make_Temporary (Loc, 'T', BPAR_Expr);
begin
-- Insert the post assignment first, because we want to copy the
-- BPAR_Expr tree before it gets analyzed in the context of the
-- pre assignment. Note that we do not analyze the post assignment
-- yet (we cannot till we have completed the analysis of the pre
-- assignment). As usual, the analysis of this post assignment
-- will happen on its own when we "run into" it after finishing
-- the current assignment.
Insert_After (N,
Make_Assignment_Statement (Loc,
Name => New_Copy_Tree (BPAR_Expr),
Expression => New_Occurrence_Of (Tnn, Loc)));
-- At this stage BPAR_Expr is a reference to a bit packed array
-- where the reference was not expanded in the original tree,
-- since it was on the left side of an assignment. But in the
-- pre-assignment statement (the object definition), BPAR_Expr
-- will end up on the right-hand side, and must be reexpanded. To
-- achieve this, we reset the analyzed flag of all selected and
-- indexed components down to the actual indexed component for
-- the packed array.
Exp := BPAR_Expr;
loop
Set_Analyzed (Exp, False);
if Nkind (Exp) in N_Indexed_Component | N_Selected_Component
then
Exp := Prefix (Exp);
else
exit;
end if;
end loop;
-- Now we can insert and analyze the pre-assignment
-- If the right-hand side requires a transient scope, it has
-- already been placed on the stack. However, the declaration is
-- inserted in the tree outside of this scope, and must reflect
-- the proper scope for its variable. This awkward bit is forced
-- by the stricter scope discipline imposed by GCC 2.97.
declare
Uses_Transient_Scope : constant Boolean :=
Scope_Is_Transient
and then N = Node_To_Be_Wrapped;
begin
if Uses_Transient_Scope then
Push_Scope (Scope (Current_Scope));
end if;
Insert_Before_And_Analyze (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition => New_Occurrence_Of (BPAR_Typ, Loc),
Expression => BPAR_Expr));
if Uses_Transient_Scope then
Pop_Scope;
end if;
end;
-- Now fix up the original assignment and continue processing
Rewrite (Prefix (Lhs),
New_Occurrence_Of (Tnn, Loc));
-- We do not need to reanalyze that assignment, and we do not need
-- to worry about references to the temporary, but we do need to
-- make sure that the temporary is not marked as a true constant
-- since we now have a generated assignment to it.
Set_Is_True_Constant (Tnn, False);
end;
end if;
-- When we have the appropriate type of aggregate in the expression (it
-- has been determined during analysis of the aggregate by setting the
-- delay flag), let's perform in place assignment and thus avoid
-- creating a temporary.
if Is_Delayed_Aggregate (Rhs) then
Convert_Aggr_In_Assignment (N);
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
return;
end if;
-- Apply discriminant check if required. If Lhs is an access type to a
-- designated type with discriminants, we must always check. If the
-- type has unknown discriminants, more elaborate processing below.
if Has_Discriminants (Etype (Lhs))
and then not Has_Unknown_Discriminants (Etype (Lhs))
then
-- Skip discriminant check if change of representation. Will be
-- done when the change of representation is expanded out.
if not Crep then
Apply_Discriminant_Check (Rhs, Etype (Lhs), Lhs);
end if;
-- If the type is private without discriminants, and the full type
-- has discriminants (necessarily with defaults) a check may still be
-- necessary if the Lhs is aliased. The private discriminants must be
-- visible to build the discriminant constraints.
-- Only an explicit dereference that comes from source indicates
-- aliasing. Access to formals of protected operations and entries
-- create dereferences but are not semantic aliasings.
elsif Is_Private_Type (Etype (Lhs))
and then Has_Discriminants (Typ)
and then Nkind (Lhs) = N_Explicit_Dereference
and then Comes_From_Source (Lhs)
then
declare
Lt : constant Entity_Id := Etype (Lhs);
Ubt : Entity_Id := Base_Type (Typ);
begin
-- In the case of an expander-generated record subtype whose base
-- type still appears private, Typ will have been set to that
-- private type rather than the underlying record type (because
-- Underlying type will have returned the record subtype), so it's
-- necessary to apply Underlying_Type again to the base type to
-- get the record type we need for the discriminant check. Such
-- subtypes can be created for assignments in certain cases, such
-- as within an instantiation passed this kind of private type.
-- It would be good to avoid this special test, but making changes
-- to prevent this odd form of record subtype seems difficult. ???
if Is_Private_Type (Ubt) then
Ubt := Underlying_Type (Ubt);
end if;
Set_Etype (Lhs, Ubt);
Rewrite (Rhs, OK_Convert_To (Base_Type (Ubt), Rhs));
Apply_Discriminant_Check (Rhs, Ubt, Lhs);
Set_Etype (Lhs, Lt);
end;
-- If the Lhs has a private type with unknown discriminants, it may
-- have a full view with discriminants, but those are nameable only
-- in the underlying type, so convert the Rhs to it before potential
-- checking. Convert Lhs as well, otherwise the actual subtype might
-- not be constructible. If the discriminants have defaults the type
-- is unconstrained and there is nothing to check.
-- Ditto if a private type with unknown discriminants has a full view
-- that is an unconstrained array, in which case a length check is
-- needed.
elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs))) then
if Has_Discriminants (Typ)
and then not Has_Defaulted_Discriminants (Typ)
then
Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
Apply_Discriminant_Check (Rhs, Typ, Lhs);
elsif Is_Array_Type (Typ) and then Is_Constrained (Typ) then
Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
Apply_Length_Check (Rhs, Typ);
end if;
-- In the access type case, we need the same discriminant check, and
-- also range checks if we have an access to constrained array.
elsif Is_Access_Type (Etype (Lhs))
and then Is_Constrained (Designated_Type (Etype (Lhs)))
then
if Has_Discriminants (Designated_Type (Etype (Lhs))) then
-- Skip discriminant check if change of representation. Will be
-- done when the change of representation is expanded out.
if not Crep then
Apply_Discriminant_Check (Rhs, Etype (Lhs));
end if;
elsif Is_Array_Type (Designated_Type (Etype (Lhs))) then
Apply_Range_Check (Rhs, Etype (Lhs));
if Is_Constrained (Etype (Lhs)) then
Apply_Length_Check (Rhs, Etype (Lhs));
end if;
end if;
end if;
-- Ada 2005 (AI-231): Generate the run-time check
if Is_Access_Type (Typ)
and then Can_Never_Be_Null (Etype (Lhs))
and then not Can_Never_Be_Null (Etype (Rhs))
-- If an actual is an out parameter of a null-excluding access
-- type, there is access check on entry, so we set the flag
-- Suppress_Assignment_Checks on the generated statement to
-- assign the actual to the parameter block, and we do not want
-- to generate an additional check at this point.
and then not Suppress_Assignment_Checks (N)
then
Apply_Constraint_Check (Rhs, Etype (Lhs));
end if;
-- Ada 2012 (AI05-148): Update current accessibility level if Rhs is a
-- stand-alone obj of an anonymous access type. Do not install the check
-- when the Lhs denotes a container cursor and the Next function employs
-- an access type, because this can never result in a dangling pointer.
if Is_Access_Type (Typ)
and then Is_Entity_Name (Lhs)
and then Ekind (Entity (Lhs)) /= E_Loop_Parameter
and then Present (Effective_Extra_Accessibility (Entity (Lhs)))
then
declare
function Lhs_Entity return Entity_Id;
-- Look through renames to find the underlying entity.
-- For assignment to a rename, we don't care about the
-- Enclosing_Dynamic_Scope of the rename declaration.
----------------
-- Lhs_Entity --
----------------
function Lhs_Entity return Entity_Id is
Result : Entity_Id := Entity (Lhs);
begin
while Present (Renamed_Object (Result)) loop
-- Renamed_Object must return an Entity_Name here
-- because of preceding "Present (E_E_A (...))" test.
Result := Entity (Renamed_Object (Result));
end loop;
return Result;
end Lhs_Entity;
-- Local Declarations
Access_Check : constant Node_Id :=
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd =>
Accessibility_Level (Rhs, Dynamic_Level),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval =>
Scope_Depth
(Enclosing_Dynamic_Scope
(Lhs_Entity)))),
Reason => PE_Accessibility_Check_Failed);
Access_Level_Update : constant Node_Id :=
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of
(Effective_Extra_Accessibility
(Entity (Lhs)), Loc),
Expression =>
Accessibility_Level
(Expr => Rhs,
Level => Dynamic_Level,
Allow_Alt_Model => False));
begin
if not Accessibility_Checks_Suppressed (Entity (Lhs)) then
Insert_Action (N, Access_Check);
end if;
Insert_Action (N, Access_Level_Update);
end;
end if;
-- Case of assignment to a bit packed array element. If there is a
-- change of representation this must be expanded into components,
-- otherwise this is a bit-field assignment.
if Nkind (Lhs) = N_Indexed_Component
and then Is_Bit_Packed_Array (Etype (Prefix (Lhs)))
then
-- Normal case, no change of representation
if not Crep then
Expand_Bit_Packed_Element_Set (N);
return;
-- Change of representation case
else
-- Generate the following, to force component-by-component
-- assignments in an efficient way. Otherwise each component
-- will require a temporary and two bit-field manipulations.
-- T1 : Elmt_Type;
-- T1 := RhS;
-- Lhs := T1;
declare
Tnn : constant Entity_Id := Make_Temporary (Loc, 'T');
Stats : List_Id;
begin
Stats :=
New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition =>
New_Occurrence_Of (Etype (Lhs), Loc)),
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Tnn, Loc),
Expression => Relocate_Node (Rhs)),
Make_Assignment_Statement (Loc,
Name => Relocate_Node (Lhs),
Expression => New_Occurrence_Of (Tnn, Loc)));
Insert_Actions (N, Stats);
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
end;
end if;
-- Build-in-place function call case. This is for assignment statements
-- that come from aggregate component associations or from init procs.
-- User-written assignment statements with b-i-p calls are handled
-- elsewhere.
elsif Is_Build_In_Place_Function_Call (Rhs) then
pragma Assert (not Comes_From_Source (N));
Make_Build_In_Place_Call_In_Assignment (N, Rhs);
elsif Is_Tagged_Type (Typ)
or else (Needs_Finalization (Typ) and then not Is_Array_Type (Typ))
then
Tagged_Case : declare
L : List_Id := No_List;
Expand_Ctrl_Actions : constant Boolean := not No_Ctrl_Actions (N);
begin
-- In the controlled case, we ensure that function calls are
-- evaluated before finalizing the target. In all cases, it makes
-- the expansion easier if the side effects are removed first.
Remove_Side_Effects (Lhs);
Remove_Side_Effects (Rhs);
-- Avoid recursion in the mechanism
Set_Analyzed (N);
-- If dispatching assignment, we need to dispatch to _assign
if Is_Class_Wide_Type (Typ)
-- If the type is tagged, we may as well use the predefined
-- primitive assignment. This avoids inlining a lot of code
-- and in the class-wide case, the assignment is replaced
-- by a dispatching call to _assign. It is suppressed in the
-- case of assignments created by the expander that correspond
-- to initializations, where we do want to copy the tag
-- (Expand_Ctrl_Actions flag is set False in this case). It is
-- also suppressed if restriction No_Dispatching_Calls is in
-- force because in that case predefined primitives are not
-- generated.
or else (Is_Tagged_Type (Typ)
and then Chars (Current_Scope) /= Name_uAssign
and then Expand_Ctrl_Actions
and then
not Restriction_Active (No_Dispatching_Calls))
then
-- We should normally not encounter any limited type here,
-- except in the corner case where an assignment was not
-- intended like the pathological case of a raise expression
-- within a return statement.
if Is_Limited_Type (Typ) then
pragma Assert (not Comes_From_Source (N));
return;
end if;
-- Fetch the primitive op _assign and proper type to call it.
-- Because of possible conflicts between private and full view,
-- fetch the proper type directly from the operation profile.
declare
Op : constant Entity_Id :=
Find_Prim_Op (Typ, Name_uAssign);
F_Typ : Entity_Id := Etype (First_Formal (Op));
begin
-- If the assignment is dispatching, make sure to use the
-- proper type.
if Is_Class_Wide_Type (Typ) then
F_Typ := Class_Wide_Type (F_Typ);
end if;
L := New_List;
-- In case of assignment to a class-wide tagged type, before
-- the assignment we generate run-time check to ensure that
-- the tags of source and target match.
if not Tag_Checks_Suppressed (Typ)
and then Is_Class_Wide_Type (Typ)
and then Is_Tagged_Type (Typ)
and then Is_Tagged_Type (Underlying_Type (Etype (Rhs)))
then
declare
Lhs_Tag : Node_Id;
Rhs_Tag : Node_Id;
begin
if not Is_Interface (Typ) then
Lhs_Tag :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Selector_Name =>
Make_Identifier (Loc, Name_uTag));
Rhs_Tag :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Selector_Name =>
Make_Identifier (Loc, Name_uTag));
else
-- Displace the pointer to the base of the objects
-- applying 'Address, which is later expanded into
-- a call to RE_Base_Address.
Lhs_Tag :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Attribute_Name => Name_Address)));
Rhs_Tag :=
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Attribute_Name => Name_Address)));
end if;
Append_To (L,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd => Lhs_Tag,
Right_Opnd => Rhs_Tag),
Reason => CE_Tag_Check_Failed));
end;
end if;
declare
Left_N : Node_Id := Duplicate_Subexpr (Lhs);
Right_N : Node_Id := Duplicate_Subexpr (Rhs);
begin
-- In order to dispatch the call to _assign the type of
-- the actuals must match. Add conversion (if required).
if Etype (Lhs) /= F_Typ then
Left_N := Unchecked_Convert_To (F_Typ, Left_N);
end if;
if Etype (Rhs) /= F_Typ then
Right_N := Unchecked_Convert_To (F_Typ, Right_N);
end if;
Append_To (L,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Op, Loc),
Parameter_Associations => New_List (
Node1 => Left_N,
Node2 => Right_N)));
end;
end;
else
L := Make_Tag_Ctrl_Assignment (N);
-- We can't afford to have destructive Finalization Actions in
-- the Self assignment case, so if the target and the source
-- are not obviously different, code is generated to avoid the
-- self assignment case:
-- if lhs'address /= rhs'address then
-- <code for controlled and/or tagged assignment>
-- end if;
-- Skip this if Restriction (No_Finalization) is active
if not Statically_Different (Lhs, Rhs)
and then Expand_Ctrl_Actions
and then not Restriction_Active (No_Finalization)
then
L := New_List (
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Attribute_Name => Name_Address),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Attribute_Name => Name_Address)),
Then_Statements => L));
end if;
-- We need to set up an exception handler for implementing
-- 7.6.1(18). The remaining adjustments are tackled by the
-- implementation of adjust for record_controllers (see
-- s-finimp.adb).
-- This is skipped if we have no finalization
if Expand_Ctrl_Actions
and then not Restriction_Active (No_Finalization)
then
L := New_List (
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => L,
Exception_Handlers => New_List (
Make_Handler_For_Ctrl_Operation (Loc)))));
end if;
end if;
Rewrite (N,
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => L)));
-- If no restrictions on aborts, protect the whole assignment
-- for controlled objects as per 9.8(11).
if Needs_Finalization (Typ)
and then Expand_Ctrl_Actions
and then Abort_Allowed
then
declare
Blk : constant Entity_Id :=
New_Internal_Entity
(E_Block, Current_Scope, Sloc (N), 'B');
AUD : constant Entity_Id := RTE (RE_Abort_Undefer_Direct);
begin
Set_Is_Abort_Block (N);
Set_Scope (Blk, Current_Scope);
Set_Etype (Blk, Standard_Void_Type);
Set_Identifier (N, New_Occurrence_Of (Blk, Sloc (N)));
Prepend_To (L, Build_Runtime_Call (Loc, RE_Abort_Defer));
Set_At_End_Proc (Handled_Statement_Sequence (N),
New_Occurrence_Of (AUD, Loc));
-- Present the Abort_Undefer_Direct function to the backend
-- so that it can inline the call to the function.
Add_Inlined_Body (AUD, N);
Expand_At_End_Handler
(Handled_Statement_Sequence (N), Blk);
end;
end if;
-- N has been rewritten to a block statement for which it is
-- known by construction that no checks are necessary: analyze
-- it with all checks suppressed.
Analyze (N, Suppress => All_Checks);
return;
end Tagged_Case;
-- Array types
elsif Is_Array_Type (Typ) then
declare
Actual_Rhs : Node_Id := Rhs;
begin
while Nkind (Actual_Rhs) in
N_Type_Conversion | N_Qualified_Expression
loop
Actual_Rhs := Expression (Actual_Rhs);
end loop;
Expand_Assign_Array (N, Actual_Rhs);
return;
end;
-- Record types
elsif Is_Record_Type (Typ) then
Expand_Assign_Record (N);
return;
-- Scalar types. This is where we perform the processing related to the
-- requirements of (RM 13.9.1(9-11)) concerning the handling of invalid
-- scalar values.
elsif Is_Scalar_Type (Typ) then
-- Case where right side is known valid
if Expr_Known_Valid (Rhs) then
-- Here the right side is valid, so it is fine. The case to deal
-- with is when the left side is a local variable reference whose
-- value is not currently known to be valid. If this is the case,
-- and the assignment appears in an unconditional context, then
-- we can mark the left side as now being valid if one of these
-- conditions holds:
-- The expression of the right side has Do_Range_Check set so
-- that we know a range check will be performed. Note that it
-- can be the case that a range check is omitted because we
-- make the assumption that we can assume validity for operands
-- appearing in the right side in determining whether a range
-- check is required
-- The subtype of the right side matches the subtype of the
-- left side. In this case, even though we have not checked
-- the range of the right side, we know it is in range of its
-- subtype if the expression is valid.
if Is_Local_Variable_Reference (Lhs)
and then not Is_Known_Valid (Entity (Lhs))
and then In_Unconditional_Context (N)
then
if Do_Range_Check (Rhs)
or else Etype (Lhs) = Etype (Rhs)
then
Set_Is_Known_Valid (Entity (Lhs), True);
end if;
end if;
-- Case where right side may be invalid in the sense of the RM
-- reference above. The RM does not require that we check for the
-- validity on an assignment, but it does require that the assignment
-- of an invalid value not cause erroneous behavior.
-- The general approach in GNAT is to use the Is_Known_Valid flag
-- to avoid the need for validity checking on assignments. However
-- in some cases, we have to do validity checking in order to make
-- sure that the setting of this flag is correct.
else
-- Validate right side if we are validating copies
if Validity_Checks_On
and then Validity_Check_Copies
then
-- Skip this if left-hand side is an array or record component
-- and elementary component validity checks are suppressed.
if Nkind (Lhs) in N_Selected_Component | N_Indexed_Component
and then not Validity_Check_Components
then
null;
else
Ensure_Valid (Rhs);
end if;
-- We can propagate this to the left side where appropriate
if Is_Local_Variable_Reference (Lhs)
and then not Is_Known_Valid (Entity (Lhs))
and then In_Unconditional_Context (N)
then
Set_Is_Known_Valid (Entity (Lhs), True);
end if;
-- Otherwise check to see what should be done
-- If left side is a local variable, then we just set its flag to
-- indicate that its value may no longer be valid, since we are
-- copying a potentially invalid value.
elsif Is_Local_Variable_Reference (Lhs) then
Set_Is_Known_Valid (Entity (Lhs), False);
-- Check for case of a nonlocal variable on the left side which
-- is currently known to be valid. In this case, we simply ensure
-- that the right side is valid. We only play the game of copying
-- validity status for local variables, since we are doing this
-- statically, not by tracing the full flow graph.
elsif Is_Entity_Name (Lhs)
and then Is_Known_Valid (Entity (Lhs))
then
-- Note: If Validity_Checking mode is set to none, we ignore
-- the Ensure_Valid call so don't worry about that case here.
Ensure_Valid (Rhs);
-- In all other cases, we can safely copy an invalid value without
-- worrying about the status of the left side. Since it is not a
-- variable reference it will not be considered
-- as being known to be valid in any case.
else
null;
end if;
end if;
end if;
exception
when RE_Not_Available =>
return;
end Expand_N_Assignment_Statement;
------------------------------
-- Expand_N_Block_Statement --
------------------------------
-- Encode entity names defined in block statement
procedure Expand_N_Block_Statement (N : Node_Id) is
begin
Qualify_Entity_Names (N);
end Expand_N_Block_Statement;
-----------------------------
-- Expand_N_Case_Statement --
-----------------------------
procedure Expand_N_Case_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Expr : constant Node_Id := Expression (N);
From_Cond_Expr : constant Boolean := From_Conditional_Expression (N);
Alt : Node_Id;
Len : Nat;
Cond : Node_Id;
Choice : Node_Id;
Chlist : List_Id;
function Expand_General_Case_Statement return Node_Id;
-- Expand a case statement whose selecting expression is not discrete
-----------------------------------
-- Expand_General_Case_Statement --
-----------------------------------
function Expand_General_Case_Statement return Node_Id is
-- expand into a block statement
Selector : constant Entity_Id :=
Make_Temporary (Loc, 'J');
function Selector_Subtype_Mark return Node_Id is
(New_Occurrence_Of (Etype (Expr), Loc));
Renamed_Name : constant Node_Id :=
(if Is_Name_Reference (Expr)
then Expr
else Make_Qualified_Expression (Loc,
Subtype_Mark => Selector_Subtype_Mark,
Expression => Expr));
Selector_Decl : constant Node_Id :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Selector,
Subtype_Mark => Selector_Subtype_Mark,
Name => Renamed_Name);
First_Alt : constant Node_Id := First (Alternatives (N));
function Choice_Index_Decl_If_Needed return Node_Id;
-- If we are going to need a choice index object (that is, if
-- Multidefined_Bindings is true for at least one of the case
-- alternatives), then create and return that object's declaration.
-- Otherwise, return Empty; no need for a decl in that case because
-- it would never be referenced.
---------------------------------
-- Choice_Index_Decl_If_Needed --
---------------------------------
function Choice_Index_Decl_If_Needed return Node_Id is
Alt : Node_Id := First_Alt;
begin
while Present (Alt) loop
if Multidefined_Bindings (Alt) then
return Make_Object_Declaration
(Sloc => Loc,
Defining_Identifier =>
Make_Temporary (Loc, 'K'),
Object_Definition =>
New_Occurrence_Of (Standard_Positive, Loc));
end if;
Next (Alt);
end loop;
return Empty; -- decl not needed
end Choice_Index_Decl_If_Needed;
Choice_Index_Decl : constant Node_Id := Choice_Index_Decl_If_Needed;
function Pattern_Match
(Pattern : Node_Id;
Object : Node_Id;
Choice_Index : Natural;
Alt : Node_Id;
Suppress_Choice_Index_Update : Boolean := False) return Node_Id;
-- Returns a Boolean-valued expression indicating a pattern match
-- for a given pattern and object. If Choice_Index is nonzero,
-- then Choice_Index is assigned to Choice_Index_Decl (unless
-- Suppress_Choice_Index_Update is specified, which should only
-- be the case for a recursive call where the caller has already
-- taken care of the update). Pattern occurs as a choice (or as a
-- subexpression of a choice) of the case statement alternative Alt.
function Top_Level_Pattern_Match_Condition
(Alt : Node_Id) return Node_Id;
-- Returns a Boolean-valued expression indicating a pattern match
-- for the given alternative's list of choices.
-------------------
-- Pattern_Match --
-------------------
function Pattern_Match
(Pattern : Node_Id;
Object : Node_Id;
Choice_Index : Natural;
Alt : Node_Id;
Suppress_Choice_Index_Update : Boolean := False) return Node_Id
is
procedure Finish_Binding_Object_Declaration
(Component_Assoc : Node_Id; Subobject : Node_Id);
-- Finish the work that was started during analysis to
-- declare a binding object. If we are generating a copy,
-- then initialize it. If we are generating a renaming, then
-- initialize the access value designating the renamed object.
function Update_Choice_Index return Node_Id is (
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of
(Defining_Identifier (Choice_Index_Decl), Loc),
Expression => Make_Integer_Literal (Loc, Pos (Choice_Index))));
function PM
(Pattern : Node_Id;
Object : Node_Id;
Choice_Index : Natural := Pattern_Match.Choice_Index;
Alt : Node_Id := Pattern_Match.Alt;
Suppress_Choice_Index_Update : Boolean :=
Pattern_Match.Suppress_Choice_Index_Update) return Node_Id
renames Pattern_Match;
-- convenient rename for recursive calls
function Indexed_Element (Idx : Pos) return Node_Id;
-- Returns the Nth (well, ok, the Idxth) element of Object
---------------------------------------
-- Finish_Binding_Object_Declaration --
---------------------------------------
procedure Finish_Binding_Object_Declaration
(Component_Assoc : Node_Id; Subobject : Node_Id)
is
Decl_Chars : constant Name_Id :=
Binding_Chars (Component_Assoc);
Block_Stmt : constant Node_Id := First (Statements (Alt));
pragma Assert (Nkind (Block_Stmt) = N_Block_Statement);
pragma Assert (No (Next (Block_Stmt)));
Decl : Node_Id := First (Declarations (Block_Stmt));
Def_Id : Node_Id := Empty;
function Declare_Copy (Decl : Node_Id) return Boolean is
(Nkind (Decl) = N_Object_Declaration);
-- Declare_Copy indicates which of the two approaches
-- was chosen during analysis: declare (and initialize)
-- a new variable, or use access values to declare a renaming
-- of the appropriate subcomponent of the selector value.
function Make_Conditional (Stmt : Node_Id) return Node_Id;
-- If there is only one choice for this alternative, then
-- simply return the argument. If there is more than one
-- choice, then wrap an if-statement around the argument
-- so that it is only executed if the current choice matches.
----------------------
-- Make_Conditional --
----------------------
function Make_Conditional (Stmt : Node_Id) return Node_Id
is
Condition : Node_Id;
begin
if Present (Choice_Index_Decl) then
Condition :=
Make_Op_Eq (Loc,
New_Occurrence_Of
(Defining_Identifier (Choice_Index_Decl), Loc),
Make_Integer_Literal (Loc, Int (Choice_Index)));
return Make_If_Statement (Loc,
Condition => Condition,
Then_Statements => New_List (Stmt));
else
-- execute Stmt unconditionally
return Stmt;
end if;
end Make_Conditional;
begin
-- find the variable to be modified (and its declaration)
loop
if Nkind (Decl) in N_Object_Declaration
| N_Object_Renaming_Declaration
then
Def_Id := Defining_Identifier (Decl);
exit when Chars (Def_Id) = Decl_Chars;
end if;
Next (Decl);
pragma Assert (Present (Decl));
end loop;
-- For a binding object, we sometimes make a copy and
-- sometimes introduce a renaming. That decision is made
-- elsewhere. The renaming case involves dereferencing an
-- access value because of the possibility of multiple
-- choices (with multiple binding definitions) for a single
-- alternative. In the copy case, we initialize the copy
-- here (conditionally if there are multiple choices); in the
-- renaming case, we initialize (again, maybe conditionally)
-- the access value.
if Declare_Copy (Decl) then
declare
Assign_Value : constant Node_Id :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Def_Id, Loc),
Expression => Subobject);
HSS : constant Node_Id :=
Handled_Statement_Sequence (Block_Stmt);
begin
Prepend (Make_Conditional (Assign_Value),
Statements (HSS));
Set_Analyzed (HSS, False);
end;
else
pragma Assert (Nkind (Name (Decl)) = N_Explicit_Dereference);
declare
Ptr_Obj : constant Entity_Id :=
Entity (Prefix (Name (Decl)));
Ptr_Decl : constant Node_Id := Parent (Ptr_Obj);
Assign_Reference : constant Node_Id :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Ptr_Obj, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => Subobject,
Attribute_Name => Name_Unrestricted_Access));
begin
Insert_After
(After => Ptr_Decl,
Node => Make_Conditional (Assign_Reference));
if Present (Expression (Ptr_Decl)) then
-- Delete bogus initial value built during analysis.
-- Look for "5432" in sem_case.adb.
pragma Assert (Nkind (Expression (Ptr_Decl)) =
N_Unchecked_Type_Conversion);
Set_Expression (Ptr_Decl, Empty);
end if;
end;
end if;
Set_Analyzed (Block_Stmt, False);
end Finish_Binding_Object_Declaration;
---------------------
-- Indexed_Element --
---------------------
function Indexed_Element (Idx : Pos) return Node_Id is
Obj_Index : constant Node_Id :=
Make_Op_Add (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Copy_Tree (Object)),
Right_Opnd =>
Make_Integer_Literal (Loc, Idx - 1));
begin
return Make_Indexed_Component (Loc,
Prefix => New_Copy_Tree (Object),
Expressions => New_List (Obj_Index));
end Indexed_Element;
-- Start of processing for Pattern_Match
begin
if Choice_Index /= 0 and not Suppress_Choice_Index_Update then
pragma Assert (Present (Choice_Index_Decl));
-- Add Choice_Index update as a side effect of evaluating
-- this condition and try again, this time suppressing
-- Choice_Index update.
return Make_Expression_With_Actions (Loc,
Actions => New_List (Update_Choice_Index),
Expression =>
PM (Pattern, Object,
Suppress_Choice_Index_Update => True));
end if;
if Nkind (Pattern) in N_Has_Etype
and then Is_Discrete_Type (Etype (Pattern))
and then Compile_Time_Known_Value (Pattern)
then
declare
Val : Node_Id;
begin
if Is_Enumeration_Type (Etype (Pattern)) then
Val := Get_Enum_Lit_From_Pos
(Etype (Pattern), Expr_Value (Pattern), Loc);
else
Val := Make_Integer_Literal (Loc, Expr_Value (Pattern));
end if;
return Make_Op_Eq (Loc, Object, Val);
end;
end if;
case Nkind (Pattern) is
when N_Aggregate =>
declare
Result : Node_Id;
begin
if Is_Array_Type (Etype (Pattern)) then
-- Nonpositional aggregates currently unimplemented.
-- We flag that case during analysis, so an assertion
-- is ok here.
--
pragma Assert
(not Is_Non_Empty_List
(Component_Associations (Pattern)));
declare
Agg_Length : constant Node_Id :=
Make_Integer_Literal (Loc,
List_Length (Expressions (Pattern)));
Obj_Length : constant Node_Id :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix => New_Copy_Tree (Object));
begin
Result := Make_Op_Eq (Loc,
Left_Opnd => Obj_Length,
Right_Opnd => Agg_Length);
end;
declare
Expr : Node_Id := First (Expressions (Pattern));
Idx : Pos := 1;
begin
while Present (Expr) loop
Result :=
Make_And_Then (Loc,
Left_Opnd => Result,
Right_Opnd =>
PM (Pattern => Expr,
Object => Indexed_Element (Idx)));
Next (Expr);
Idx := Idx + 1;
end loop;
end;
return Result;
end if;
-- positional notation should have been normalized
pragma Assert (No (Expressions (Pattern)));
declare
Component_Assoc : Node_Id
:= First (Component_Associations (Pattern));
Choice : Node_Id;
function Subobject return Node_Id is
(Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (Object),
Selector_Name => New_Occurrence_Of
(Entity (Choice), Loc)));
begin
Result := New_Occurrence_Of (Standard_True, Loc);
while Present (Component_Assoc) loop
Choice := First (Choices (Component_Assoc));
while Present (Choice) loop
pragma Assert
(Is_Entity_Name (Choice)
and then Ekind (Entity (Choice))
in E_Discriminant | E_Component);
if Box_Present (Component_Assoc) then
-- Box matches anything
pragma Assert
(No (Expression (Component_Assoc)));
else
Result := Make_And_Then (Loc,
Left_Opnd => Result,
Right_Opnd =>
PM (Pattern =>
Expression
(Component_Assoc),
Object => Subobject));
end if;
-- If this component association defines
-- (in the case where the pattern matches)
-- the value of a binding object, then
-- prepend to the statement list for this
-- alternative an assignment to the binding
-- object. This assignment will be conditional
-- if there is more than one choice.
if Binding_Chars (Component_Assoc) /= No_Name
then
Finish_Binding_Object_Declaration
(Component_Assoc => Component_Assoc,
Subobject => Subobject);
end if;
Next (Choice);
end loop;
Next (Component_Assoc);
end loop;
end;
return Result;
end;
when N_String_Literal =>
return Result : Node_Id do
declare
Char_Type : constant Entity_Id :=
Root_Type (Component_Type (Etype (Pattern)));
-- If the component type is not a standard character
-- type then this string lit should have already been
-- transformed into an aggregate in
-- Resolve_String_Literal.
--
pragma Assert (Is_Standard_Character_Type (Char_Type));
Str : constant String_Id := Strval (Pattern);
Strlen : constant Nat := String_Length (Str);
Lit_Length : constant Node_Id :=
Make_Integer_Literal (Loc, Strlen);
Obj_Length : constant Node_Id :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Length,
Prefix => New_Copy_Tree (Object));
begin
Result := Make_Op_Eq (Loc,
Left_Opnd => Obj_Length,
Right_Opnd => Lit_Length);
for Idx in 1 .. Strlen loop
declare
C : constant Char_Code :=
Get_String_Char (Str, Idx);
Obj_Element : constant Node_Id :=
Indexed_Element (Idx);
Char_Lit : Node_Id;
begin
Set_Character_Literal_Name (C);
Char_Lit :=
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value => UI_From_CC (C));
Result :=
Make_And_Then (Loc,
Left_Opnd => Result,
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Obj_Element,
Right_Opnd => Char_Lit));
end;
end loop;
end;
end return;
when N_Qualified_Expression =>
return Make_And_Then (Loc,
Left_Opnd => Make_In (Loc,
Left_Opnd => New_Copy_Tree (Object),
Right_Opnd => New_Copy_Tree (Subtype_Mark (Pattern))),
Right_Opnd =>
PM (Pattern => Expression (Pattern),
Object => New_Copy_Tree (Object)));
when N_Identifier | N_Expanded_Name =>
if Is_Type (Entity (Pattern)) then
return Make_In (Loc,
Left_Opnd => New_Copy_Tree (Object),
Right_Opnd => New_Occurrence_Of
(Entity (Pattern), Loc));
elsif Ekind (Entity (Pattern)) = E_Constant then
return PM (Pattern =>
Expression (Parent (Entity (Pattern))),
Object => Object);
end if;
when N_Others_Choice =>
return New_Occurrence_Of (Standard_True, Loc);
when N_Type_Conversion =>
-- aggregate expansion sometimes introduces conversions
if not Comes_From_Source (Pattern)
and then Base_Type (Etype (Pattern))
= Base_Type (Etype (Expression (Pattern)))
then
return PM (Expression (Pattern), Object);
end if;
when others =>
null;
end case;
-- Avoid cascading errors
pragma Assert (Serious_Errors_Detected > 0);
return New_Occurrence_Of (Standard_True, Loc);
end Pattern_Match;
---------------------------------------
-- Top_Level_Pattern_Match_Condition --
---------------------------------------
function Top_Level_Pattern_Match_Condition
(Alt : Node_Id) return Node_Id
is
Top_Level_Object : constant Node_Id :=
New_Occurrence_Of (Selector, Loc);
Choices : constant List_Id := Discrete_Choices (Alt);
First_Choice : constant Node_Id := First (Choices);
Subsequent : Node_Id := Next (First_Choice);
Choice_Index : Natural := 0;
begin
if Multidefined_Bindings (Alt) then
Choice_Index := 1;
end if;
return Result : Node_Id :=
Pattern_Match (Pattern => First_Choice,
Object => Top_Level_Object,
Choice_Index => Choice_Index,
Alt => Alt)
do
while Present (Subsequent) loop
if Choice_Index /= 0 then
Choice_Index := Choice_Index + 1;
end if;
Result := Make_Or_Else (Loc,
Left_Opnd => Result,
Right_Opnd => Pattern_Match
(Pattern => Subsequent,
Object => Top_Level_Object,
Choice_Index => Choice_Index,
Alt => Alt));
Subsequent := Next (Subsequent);
end loop;
end return;
end Top_Level_Pattern_Match_Condition;
function Elsif_Parts return List_Id;
-- Process subsequent alternatives
-----------------
-- Elsif_Parts --
-----------------
function Elsif_Parts return List_Id is
Alt : Node_Id := First_Alt;
Result : constant List_Id := New_List;
begin
loop
Alt := Next (Alt);
exit when No (Alt);
Append (Make_Elsif_Part (Loc,
Condition => Top_Level_Pattern_Match_Condition (Alt),
Then_Statements => Statements (Alt)),
Result);
end loop;
return Result;
end Elsif_Parts;
function Else_Statements return List_Id;
-- Returns a "raise Constraint_Error" statement if
-- exception propagate is permitted and No_List otherwise.
---------------------
-- Else_Statements --
---------------------
function Else_Statements return List_Id is
begin
if Restriction_Active (No_Exception_Propagation) then
return No_List;
else
return New_List (Make_Raise_Constraint_Error (Loc,
Reason => CE_Invalid_Data));
end if;
end Else_Statements;
-- Local constants
If_Stmt : constant Node_Id :=
Make_If_Statement (Loc,
Condition => Top_Level_Pattern_Match_Condition (First_Alt),
Then_Statements => Statements (First_Alt),
Elsif_Parts => Elsif_Parts,
Else_Statements => Else_Statements);
Declarations : constant List_Id := New_List (Selector_Decl);
-- Start of processing for Expand_General_Case_Statment
begin
if Present (Choice_Index_Decl) then
Append_To (Declarations, Choice_Index_Decl);
end if;
return Make_Block_Statement (Loc,
Declarations => Declarations,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (If_Stmt)));
end Expand_General_Case_Statement;
-- Start of processing for Expand_N_Case_Statement
begin
if Extensions_Allowed and then not Is_Discrete_Type (Etype (Expr)) then
Rewrite (N, Expand_General_Case_Statement);
Analyze (N);
return;
end if;
-- Check for the situation where we know at compile time which branch
-- will be taken.
-- If the value is static but its subtype is predicated and the value
-- does not obey the predicate, the value is marked non-static, and
-- there can be no corresponding static alternative. In that case we
-- replace the case statement with an exception, regardless of whether
-- assertions are enabled or not, unless predicates are ignored.
if Compile_Time_Known_Value (Expr)
and then Has_Predicates (Etype (Expr))
and then not Predicates_Ignored (Etype (Expr))
and then not Is_OK_Static_Expression (Expr)
then
Rewrite (N,
Make_Raise_Constraint_Error (Loc, Reason => CE_Invalid_Data));
Analyze (N);
return;
elsif Compile_Time_Known_Value (Expr)
and then (not Has_Predicates (Etype (Expr))
or else Is_Static_Expression (Expr))
then
Alt := Find_Static_Alternative (N);
-- Do not consider controlled objects found in a case statement which
-- actually models a case expression because their early finalization
-- will affect the result of the expression.
if not From_Conditional_Expression (N) then
Process_Statements_For_Controlled_Objects (Alt);
end if;
-- Move statements from this alternative after the case statement.
-- They are already analyzed, so will be skipped by the analyzer.
Insert_List_After (N, Statements (Alt));
-- That leaves the case statement as a shell. So now we can kill all
-- other alternatives in the case statement.
Kill_Dead_Code (Expression (N));
declare
Dead_Alt : Node_Id;
begin
-- Loop through case alternatives, skipping pragmas, and skipping
-- the one alternative that we select (and therefore retain).
Dead_Alt := First (Alternatives (N));
while Present (Dead_Alt) loop
if Dead_Alt /= Alt
and then Nkind (Dead_Alt) = N_Case_Statement_Alternative
then
Kill_Dead_Code (Statements (Dead_Alt), Warn_On_Deleted_Code);
end if;
Next (Dead_Alt);
end loop;
end;
Rewrite (N, Make_Null_Statement (Loc));
return;
end if;
-- Here if the choice is not determined at compile time
declare
Last_Alt : constant Node_Id := Last (Alternatives (N));
Others_Present : Boolean;
Others_Node : Node_Id;
Then_Stms : List_Id;
Else_Stms : List_Id;
begin
if Nkind (First (Discrete_Choices (Last_Alt))) = N_Others_Choice then
Others_Present := True;
Others_Node := Last_Alt;
else
Others_Present := False;
end if;
-- First step is to worry about possible invalid argument. The RM
-- requires (RM 5.4(13)) that if the result is invalid (e.g. it is
-- outside the base range), then Constraint_Error must be raised.
-- Case of validity check required (validity checks are on, the
-- expression is not known to be valid, and the case statement
-- comes from source -- no need to validity check internally
-- generated case statements).
if Validity_Check_Default
and then not Predicates_Ignored (Etype (Expr))
then
-- Recognize the simple case where Expr is an object reference
-- and the case statement is directly preceded by an
-- "if Obj'Valid then": in this case, do not emit another validity
-- check.
declare
Check_Validity : Boolean := True;
Attr : Node_Id;
begin
if Nkind (Expr) = N_Identifier
and then Nkind (Parent (N)) = N_If_Statement
and then Nkind (Original_Node (Condition (Parent (N))))
= N_Attribute_Reference
and then No (Prev (N))
then
Attr := Original_Node (Condition (Parent (N)));
if Attribute_Name (Attr) = Name_Valid
and then Nkind (Prefix (Attr)) = N_Identifier
and then Entity (Prefix (Attr)) = Entity (Expr)
then
Check_Validity := False;
end if;
end if;
if Check_Validity then
Ensure_Valid (Expr);
end if;
end;
end if;
-- If there is only a single alternative, just replace it with the
-- sequence of statements since obviously that is what is going to
-- be executed in all cases.
Len := List_Length (Alternatives (N));
if Len = 1 then
-- We still need to evaluate the expression if it has any side
-- effects.
Remove_Side_Effects (Expression (N));
Alt := First (Alternatives (N));
-- Do not consider controlled objects found in a case statement
-- which actually models a case expression because their early
-- finalization will affect the result of the expression.
if not From_Conditional_Expression (N) then
Process_Statements_For_Controlled_Objects (Alt);
end if;
Insert_List_After (N, Statements (Alt));
-- That leaves the case statement as a shell. The alternative that
-- will be executed is reset to a null list. So now we can kill
-- the entire case statement.
Kill_Dead_Code (Expression (N));
Rewrite (N, Make_Null_Statement (Loc));
return;
-- An optimization. If there are only two alternatives, and only
-- a single choice, then rewrite the whole case statement as an
-- if statement, since this can result in subsequent optimizations.
-- This helps not only with case statements in the source of a
-- simple form, but also with generated code (discriminant check
-- functions in particular).
-- Note: it is OK to do this before expanding out choices for any
-- static predicates, since the if statement processing will handle
-- the static predicate case fine.
elsif Len = 2 then
Chlist := Discrete_Choices (First (Alternatives (N)));
if List_Length (Chlist) = 1 then
Choice := First (Chlist);
Then_Stms := Statements (First (Alternatives (N)));
Else_Stms := Statements (Last (Alternatives (N)));
-- For TRUE, generate "expression", not expression = true
if Nkind (Choice) = N_Identifier
and then Entity (Choice) = Standard_True
then
Cond := Expression (N);
-- For FALSE, generate "expression" and switch then/else
elsif Nkind (Choice) = N_Identifier
and then Entity (Choice) = Standard_False
then
Cond := Expression (N);
Else_Stms := Statements (First (Alternatives (N)));
Then_Stms := Statements (Last (Alternatives (N)));
-- For a range, generate "expression in range"
elsif Nkind (Choice) = N_Range
or else (Nkind (Choice) = N_Attribute_Reference
and then Attribute_Name (Choice) = Name_Range)
or else (Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice)))
then
Cond :=
Make_In (Loc,
Left_Opnd => Expression (N),
Right_Opnd => Relocate_Node (Choice));
-- A subtype indication is not a legal operator in a membership
-- test, so retrieve its range.
elsif Nkind (Choice) = N_Subtype_Indication then
Cond :=
Make_In (Loc,
Left_Opnd => Expression (N),
Right_Opnd =>
Relocate_Node
(Range_Expression (Constraint (Choice))));
-- For any other subexpression "expression = value"
else
Cond :=
Make_Op_Eq (Loc,
Left_Opnd => Expression (N),
Right_Opnd => Relocate_Node (Choice));
end if;
-- Now rewrite the case as an IF
Rewrite (N,
Make_If_Statement (Loc,
Condition => Cond,
Then_Statements => Then_Stms,
Else_Statements => Else_Stms));
-- The rewritten if statement needs to inherit whether the
-- case statement was expanded from a conditional expression,
-- for proper handling of nested controlled objects.
Set_From_Conditional_Expression (N, From_Cond_Expr);
Analyze (N);
return;
end if;
end if;
-- If the last alternative is not an Others choice, replace it with
-- an N_Others_Choice. Note that we do not bother to call Analyze on
-- the modified case statement, since it's only effect would be to
-- compute the contents of the Others_Discrete_Choices which is not
-- needed by the back end anyway.
-- The reason for this is that the back end always needs some default
-- for a switch, so if we have not supplied one in the processing
-- above for validity checking, then we need to supply one here.
if not Others_Present then
Others_Node := Make_Others_Choice (Sloc (Last_Alt));
-- If Predicates_Ignored is true the value does not satisfy the
-- predicate, and there is no Others choice, Constraint_Error
-- must be raised (4.5.7 (21/3)).
if Predicates_Ignored (Etype (Expr)) then
declare
Except : constant Node_Id :=
Make_Raise_Constraint_Error (Loc,
Reason => CE_Invalid_Data);
New_Alt : constant Node_Id :=
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => New_List (
Make_Others_Choice (Loc)),
Statements => New_List (Except));
begin
Append (New_Alt, Alternatives (N));
Analyze_And_Resolve (Except);
end;
else
Set_Others_Discrete_Choices
(Others_Node, Discrete_Choices (Last_Alt));
Set_Discrete_Choices (Last_Alt, New_List (Others_Node));
end if;
end if;
-- Deal with possible declarations of controlled objects, and also
-- with rewriting choice sequences for static predicate references.
Alt := First_Non_Pragma (Alternatives (N));
while Present (Alt) loop
-- Do not consider controlled objects found in a case statement
-- which actually models a case expression because their early
-- finalization will affect the result of the expression.
if not From_Conditional_Expression (N) then
Process_Statements_For_Controlled_Objects (Alt);
end if;
if Has_SP_Choice (Alt) then
Expand_Static_Predicates_In_Choices (Alt);
end if;
Next_Non_Pragma (Alt);
end loop;
end;
end Expand_N_Case_Statement;
-----------------------------
-- Expand_N_Exit_Statement --
-----------------------------
-- The only processing required is to deal with a possible C/Fortran
-- boolean value used as the condition for the exit statement.
procedure Expand_N_Exit_Statement (N : Node_Id) is
begin
Adjust_Condition (Condition (N));
end Expand_N_Exit_Statement;
----------------------------------
-- Expand_Formal_Container_Loop --
----------------------------------
procedure Expand_Formal_Container_Loop (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Isc : constant Node_Id := Iteration_Scheme (N);
I_Spec : constant Node_Id := Iterator_Specification (Isc);
Cursor : constant Entity_Id := Defining_Identifier (I_Spec);
Container : constant Node_Id := Entity (Name (I_Spec));
Stats : constant List_Id := Statements (N);
Advance : Node_Id;
Init_Decl : Node_Id;
Init_Name : Entity_Id;
New_Loop : Node_Id;
begin
-- The expansion of a formal container loop resembles the one for Ada
-- containers. The only difference is that the primitives mention the
-- domain of iteration explicitly, and function First applied to the
-- container yields a cursor directly.
-- Cursor : Cursor_type := First (Container);
-- while Has_Element (Cursor, Container) loop
-- <original loop statements>
-- Cursor := Next (Container, Cursor);
-- end loop;
Build_Formal_Container_Iteration
(N, Container, Cursor, Init_Decl, Advance, New_Loop);
Append_To (Stats, Advance);
-- Build a block to capture declaration of the cursor
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => New_List (Init_Decl),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (New_Loop))));
-- The loop parameter is declared by an object declaration, but within
-- the loop we must prevent user assignments to it, so we analyze the
-- declaration and reset the entity kind, before analyzing the rest of
-- the loop.
Analyze (Init_Decl);
Init_Name := Defining_Identifier (Init_Decl);
Mutate_Ekind (Init_Name, E_Loop_Parameter);
-- The cursor was marked as a loop parameter to prevent user assignments
-- to it, however this renders the advancement step illegal as it is not
-- possible to change the value of a constant. Flag the advancement step
-- as a legal form of assignment to remedy this side effect.
Set_Assignment_OK (Name (Advance));
Analyze (N);
-- Because we have to analyze the initial declaration of the loop
-- parameter multiple times its scope is incorrectly set at this point
-- to the one surrounding the block statement - so set the scope
-- manually to be the actual block statement, and indicate that it is
-- not visible after the block has been analyzed.
Set_Scope (Init_Name, Entity (Identifier (N)));
Set_Is_Immediately_Visible (Init_Name, False);
end Expand_Formal_Container_Loop;
------------------------------------------
-- Expand_Formal_Container_Element_Loop --
------------------------------------------
procedure Expand_Formal_Container_Element_Loop (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Isc : constant Node_Id := Iteration_Scheme (N);
I_Spec : constant Node_Id := Iterator_Specification (Isc);
Element : constant Entity_Id := Defining_Identifier (I_Spec);
Container : constant Node_Id := Entity (Name (I_Spec));
Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
Stats : constant List_Id := Statements (N);
Cursor : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Element), 'C'));
Elmt_Decl : Node_Id;
Element_Op : constant Entity_Id :=
Get_Iterable_Type_Primitive (Container_Typ, Name_Element);
Advance : Node_Id;
Init : Node_Id;
New_Loop : Node_Id;
begin
-- For an element iterator, the Element aspect must be present,
-- (this is checked during analysis).
-- We create a block to hold a variable declaration initialized with
-- a call to Element, and generate:
-- Cursor : Cursor_Type := First (Container);
-- while Has_Element (Cursor, Container) loop
-- declare
-- Elmt : Element_Type := Element (Container, Cursor);
-- begin
-- <original loop statements>
-- Cursor := Next (Container, Cursor);
-- end;
-- end loop;
Build_Formal_Container_Iteration
(N, Container, Cursor, Init, Advance, New_Loop);
Append_To (Stats, Advance);
Mutate_Ekind (Cursor, E_Variable);
Insert_Action (N, Init);
-- The loop parameter is declared by an object declaration, but within
-- the loop we must prevent user assignments to it; the following flag
-- accomplishes that.
Set_Is_Loop_Parameter (Element);
-- Declaration for Element
Elmt_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Element,
Object_Definition => New_Occurrence_Of (Etype (Element_Op), Loc));
Set_Expression (Elmt_Decl,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Element_Op, Loc),
Parameter_Associations => New_List (
Convert_To_Iterable_Type (Container, Loc),
New_Occurrence_Of (Cursor, Loc))));
Set_Statements (New_Loop,
New_List
(Make_Block_Statement (Loc,
Declarations => New_List (Elmt_Decl),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stats))));
-- The element is only modified in expanded code, so it appears as
-- unassigned to the warning machinery. We must suppress this spurious
-- warning explicitly.
Set_Warnings_Off (Element);
Rewrite (N, New_Loop);
Analyze (N);
end Expand_Formal_Container_Element_Loop;
----------------------------------
-- Expand_N_Goto_When_Statement --
----------------------------------
procedure Expand_N_Goto_When_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
begin
Rewrite (N,
Make_If_Statement (Loc,
Condition => Condition (N),
Then_Statements => New_List (
Make_Goto_Statement (Loc,
Name => Name (N)))));
Analyze (N);
end Expand_N_Goto_When_Statement;
---------------------------
-- Expand_N_If_Statement --
---------------------------
-- First we deal with the case of C and Fortran convention boolean values,
-- with zero/nonzero semantics.
-- Second, we deal with the obvious rewriting for the cases where the
-- condition of the IF is known at compile time to be True or False.
-- Third, we remove elsif parts which have non-empty Condition_Actions and
-- rewrite as independent if statements. For example:
-- if x then xs
-- elsif y then ys
-- ...
-- end if;
-- becomes
--
-- if x then xs
-- else
-- <<condition actions of y>>
-- if y then ys
-- ...
-- end if;
-- end if;
-- This rewriting is needed if at least one elsif part has a non-empty
-- Condition_Actions list. We also do the same processing if there is a
-- constant condition in an elsif part (in conjunction with the first
-- processing step mentioned above, for the recursive call made to deal
-- with the created inner if, this deals with properly optimizing the
-- cases of constant elsif conditions).
procedure Expand_N_If_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Hed : Node_Id;
E : Node_Id;
New_If : Node_Id;
Warn_If_Deleted : constant Boolean :=
Warn_On_Deleted_Code and then Comes_From_Source (N);
-- Indicates whether we want warnings when we delete branches of the
-- if statement based on constant condition analysis. We never want
-- these warnings for expander generated code.
begin
-- Do not consider controlled objects found in an if statement which
-- actually models an if expression because their early finalization
-- will affect the result of the expression.
if not From_Conditional_Expression (N) then
Process_Statements_For_Controlled_Objects (N);
end if;
Adjust_Condition (Condition (N));
-- The following loop deals with constant conditions for the IF. We
-- need a loop because as we eliminate False conditions, we grab the
-- first elsif condition and use it as the primary condition.
while Compile_Time_Known_Value (Condition (N)) loop
-- If condition is True, we can simply rewrite the if statement now
-- by replacing it by the series of then statements.
if Is_True (Expr_Value (Condition (N))) then
-- All the else parts can be killed
Kill_Dead_Code (Elsif_Parts (N), Warn_If_Deleted);
Kill_Dead_Code (Else_Statements (N), Warn_If_Deleted);
Hed := Remove_Head (Then_Statements (N));
Insert_List_After (N, Then_Statements (N));
Rewrite (N, Hed);
return;
-- If condition is False, then we can delete the condition and
-- the Then statements
else
-- We do not delete the condition if constant condition warnings
-- are enabled, since otherwise we end up deleting the desired
-- warning. Of course the backend will get rid of this True/False
-- test anyway, so nothing is lost here.
if not Constant_Condition_Warnings then
Kill_Dead_Code (Condition (N));
end if;
Kill_Dead_Code (Then_Statements (N), Warn_If_Deleted);
-- If there are no elsif statements, then we simply replace the
-- entire if statement by the sequence of else statements.
if No (Elsif_Parts (N)) then
if Is_Empty_List (Else_Statements (N)) then
Rewrite (N,
Make_Null_Statement (Sloc (N)));
else
Hed := Remove_Head (Else_Statements (N));
Insert_List_After (N, Else_Statements (N));
Rewrite (N, Hed);
end if;
return;
-- If there are elsif statements, the first of them becomes the
-- if/then section of the rebuilt if statement This is the case
-- where we loop to reprocess this copied condition.
else
Hed := Remove_Head (Elsif_Parts (N));
Insert_Actions (N, Condition_Actions (Hed));
Set_Condition (N, Condition (Hed));
Set_Then_Statements (N, Then_Statements (Hed));
-- Hed might have been captured as the condition determining
-- the current value for an entity. Now it is detached from
-- the tree, so a Current_Value pointer in the condition might
-- need to be updated.
Set_Current_Value_Condition (N);
if Is_Empty_List (Elsif_Parts (N)) then
Set_Elsif_Parts (N, No_List);
end if;
end if;
end if;
end loop;
-- Loop through elsif parts, dealing with constant conditions and
-- possible condition actions that are present.
if Present (Elsif_Parts (N)) then
E := First (Elsif_Parts (N));
while Present (E) loop
-- Do not consider controlled objects found in an if statement
-- which actually models an if expression because their early
-- finalization will affect the result of the expression.
if not From_Conditional_Expression (N) then
Process_Statements_For_Controlled_Objects (E);
end if;
Adjust_Condition (Condition (E));
-- If there are condition actions, then rewrite the if statement
-- as indicated above. We also do the same rewrite for a True or
-- False condition. The further processing of this constant
-- condition is then done by the recursive call to expand the
-- newly created if statement
if Present (Condition_Actions (E))
or else Compile_Time_Known_Value (Condition (E))
then
New_If :=
Make_If_Statement (Sloc (E),
Condition => Condition (E),
Then_Statements => Then_Statements (E),
Elsif_Parts => No_List,
Else_Statements => Else_Statements (N));
-- Elsif parts for new if come from remaining elsif's of parent
while Present (Next (E)) loop
if No (Elsif_Parts (New_If)) then
Set_Elsif_Parts (New_If, New_List);
end if;
Append (Remove_Next (E), Elsif_Parts (New_If));
end loop;
Set_Else_Statements (N, New_List (New_If));
Insert_List_Before (New_If, Condition_Actions (E));
Remove (E);
if Is_Empty_List (Elsif_Parts (N)) then
Set_Elsif_Parts (N, No_List);
end if;
Analyze (New_If);
-- Note this is not an implicit if statement, since it is part
-- of an explicit if statement in the source (or of an implicit
-- if statement that has already been tested). We set the flag
-- after calling Analyze to avoid generating extra warnings
-- specific to pure if statements, however (see
-- Sem_Ch5.Analyze_If_Statement).
Preserve_Comes_From_Source (New_If, N);
return;
-- No special processing for that elsif part, move to next
else
Next (E);
end if;
end loop;
end if;
-- Some more optimizations applicable if we still have an IF statement
if Nkind (N) /= N_If_Statement then
return;
end if;
-- Another optimization, special cases that can be simplified
-- if expression then
-- return [standard.]true;
-- else
-- return [standard.]false;
-- end if;
-- can be changed to:
-- return expression;
-- and
-- if expression then
-- return [standard.]false;
-- else
-- return [standard.]true;
-- end if;
-- can be changed to:
-- return not (expression);
-- Do these optimizations only for internally generated code and only
-- when -fpreserve-control-flow isn't set, to preserve the original
-- source control flow.
if not Comes_From_Source (N)
and then not Opt.Suppress_Control_Flow_Optimizations
and then Nkind (N) = N_If_Statement
and then No (Elsif_Parts (N))
and then Present (Else_Statements (N))
and then List_Length (Then_Statements (N)) = 1
and then List_Length (Else_Statements (N)) = 1
then
declare
Then_Stm : constant Node_Id := First (Then_Statements (N));
Else_Stm : constant Node_Id := First (Else_Statements (N));
Then_Expr : Node_Id;
Else_Expr : Node_Id;
begin
if Nkind (Then_Stm) = N_Simple_Return_Statement
and then
Nkind (Else_Stm) = N_Simple_Return_Statement
then
Then_Expr := Expression (Then_Stm);
Else_Expr := Expression (Else_Stm);
if Nkind (Then_Expr) in N_Expanded_Name | N_Identifier
and then
Nkind (Else_Expr) in N_Expanded_Name | N_Identifier
then
if Entity (Then_Expr) = Standard_True
and then Entity (Else_Expr) = Standard_False
then
Rewrite (N,
Make_Simple_Return_Statement (Loc,
Expression => Relocate_Node (Condition (N))));
Analyze (N);
elsif Entity (Then_Expr) = Standard_False
and then Entity (Else_Expr) = Standard_True
then
Rewrite (N,
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Op_Not (Loc,
Right_Opnd => Relocate_Node (Condition (N)))));
Analyze (N);
end if;
end if;
end if;
end;
end if;
end Expand_N_If_Statement;
--------------------------
-- Expand_Iterator_Loop --
--------------------------
procedure Expand_Iterator_Loop (N : Node_Id) is
Isc : constant Node_Id := Iteration_Scheme (N);
I_Spec : constant Node_Id := Iterator_Specification (Isc);
Container : constant Node_Id := Name (I_Spec);
Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
begin
-- Processing for arrays
if Is_Array_Type (Container_Typ) then
pragma Assert (Of_Present (I_Spec));
Expand_Iterator_Loop_Over_Array (N);
elsif Has_Aspect (Container_Typ, Aspect_Iterable) then
if Of_Present (I_Spec) then
Expand_Formal_Container_Element_Loop (N);
else
Expand_Formal_Container_Loop (N);
end if;
-- Processing for containers
else
Expand_Iterator_Loop_Over_Container
(N, Isc, I_Spec, Container, Container_Typ);
end if;
end Expand_Iterator_Loop;
-------------------------------------
-- Expand_Iterator_Loop_Over_Array --
-------------------------------------
procedure Expand_Iterator_Loop_Over_Array (N : Node_Id) is
Isc : constant Node_Id := Iteration_Scheme (N);
I_Spec : constant Node_Id := Iterator_Specification (Isc);
Array_Node : constant Node_Id := Name (I_Spec);
Array_Typ : constant Entity_Id := Base_Type (Etype (Array_Node));
Array_Dim : constant Pos := Number_Dimensions (Array_Typ);
Id : constant Entity_Id := Defining_Identifier (I_Spec);
Loc : constant Source_Ptr := Sloc (Isc);
Stats : List_Id := Statements (N);
Core_Loop : Node_Id;
Dim1 : Int;
Ind_Comp : Node_Id;
Iterator : Entity_Id;
begin
if Present (Iterator_Filter (I_Spec)) then
pragma Assert (Ada_Version >= Ada_2022);
Stats := New_List (Make_If_Statement (Loc,
Condition => Iterator_Filter (I_Spec),
Then_Statements => Stats));
end if;
-- for Element of Array loop
-- It requires an internally generated cursor to iterate over the array
pragma Assert (Of_Present (I_Spec));
Iterator := Make_Temporary (Loc, 'C');
-- Generate:
-- Element : Component_Type renames Array (Iterator);
-- Iterator is the index value, or a list of index values
-- in the case of a multidimensional array.
Ind_Comp :=
Make_Indexed_Component (Loc,
Prefix => New_Copy_Tree (Array_Node),
Expressions => New_List (New_Occurrence_Of (Iterator, Loc)));
-- Propagate the original node to the copy since the analysis of the
-- following object renaming declaration relies on the original node.
Set_Original_Node (Prefix (Ind_Comp), Original_Node (Array_Node));
Prepend_To (Stats,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Id,
Subtype_Mark =>
New_Occurrence_Of (Component_Type (Array_Typ), Loc),
Name => Ind_Comp));
-- Mark the loop variable as needing debug info, so that expansion
-- of the renaming will result in Materialize_Entity getting set via
-- Debug_Renaming_Declaration. (This setting is needed here because
-- the setting in Freeze_Entity comes after the expansion, which is
-- too late. ???)
Set_Debug_Info_Needed (Id);
-- Generate:
-- for Iterator in [reverse] Array'Range (Array_Dim) loop
-- Element : Component_Type renames Array (Iterator);
-- <original loop statements>
-- end loop;
-- If this is an iteration over a multidimensional array, the
-- innermost loop is over the last dimension in Ada, and over
-- the first dimension in Fortran.
if Convention (Array_Typ) = Convention_Fortran then
Dim1 := 1;
else
Dim1 := Array_Dim;
end if;
Core_Loop :=
Make_Loop_Statement (Sloc (N),
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => Iterator,
Discrete_Subtype_Definition =>
Make_Attribute_Reference (Loc,
Prefix => New_Copy_Tree (Array_Node),
Attribute_Name => Name_Range,
Expressions => New_List (
Make_Integer_Literal (Loc, Dim1))),
Reverse_Present => Reverse_Present (I_Spec))),
Statements => Stats,
End_Label => Empty);
-- Processing for multidimensional array. The body of each loop is
-- a loop over a previous dimension, going in decreasing order in Ada
-- and in increasing order in Fortran.
if Array_Dim > 1 then
for Dim in 1 .. Array_Dim - 1 loop
if Convention (Array_Typ) = Convention_Fortran then
Dim1 := Dim + 1;
else
Dim1 := Array_Dim - Dim;
end if;
Iterator := Make_Temporary (Loc, 'C');
-- Generate the dimension loops starting from the innermost one
-- for Iterator in [reverse] Array'Range (Array_Dim - Dim) loop
-- <core loop>
-- end loop;
Core_Loop :=
Make_Loop_Statement (Sloc (N),
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => Iterator,
Discrete_Subtype_Definition =>
Make_Attribute_Reference (Loc,
Prefix => New_Copy_Tree (Array_Node),
Attribute_Name => Name_Range,
Expressions => New_List (
Make_Integer_Literal (Loc, Dim1))),
Reverse_Present => Reverse_Present (I_Spec))),
Statements => New_List (Core_Loop),
End_Label => Empty);
-- Update the previously created object renaming declaration with
-- the new iterator, by adding the index of the next loop to the
-- indexed component, in the order that corresponds to the
-- convention.
if Convention (Array_Typ) = Convention_Fortran then
Append_To (Expressions (Ind_Comp),
New_Occurrence_Of (Iterator, Loc));
else
Prepend_To (Expressions (Ind_Comp),
New_Occurrence_Of (Iterator, Loc));
end if;
end loop;
end if;
-- Inherit the loop identifier from the original loop. This ensures that
-- the scope stack is consistent after the rewriting.
if Present (Identifier (N)) then
Set_Identifier (Core_Loop, Relocate_Node (Identifier (N)));
end if;
Rewrite (N, Core_Loop);
Analyze (N);
end Expand_Iterator_Loop_Over_Array;
-----------------------------------------
-- Expand_Iterator_Loop_Over_Container --
-----------------------------------------
-- For a 'for ... in' loop, such as:
-- for Cursor in Iterator_Function (...) loop
-- ...
-- end loop;
-- we generate:
-- Iter : Iterator_Type := Iterator_Function (...);
-- Cursor : Cursor_type := First (Iter); -- or Last for "reverse"
-- while Has_Element (Cursor) loop
-- ...
--
-- Cursor := Iter.Next (Cursor); -- or Prev for "reverse"
-- end loop;
-- For a 'for ... of' loop, such as:
-- for X of Container loop
-- ...
-- end loop;
-- the RM implies the generation of:
-- Iter : Iterator_Type := Container.Iterate; -- the Default_Iterator
-- Cursor : Cursor_Type := First (Iter); -- or Last for "reverse"
-- while Has_Element (Cursor) loop
-- declare
-- X : Element_Type renames Element (Cursor).Element.all;
-- -- or Constant_Element
-- begin
-- ...
-- end;
-- Cursor := Iter.Next (Cursor); -- or Prev for "reverse"
-- end loop;
-- In the general case, we do what the RM says. However, the operations
-- Element and Iter.Next are slow, which is bad inside a loop, because they
-- involve dispatching via interfaces, secondary stack manipulation,
-- Busy/Lock incr/decr, and adjust/finalization/at-end handling. So for the
-- predefined containers, we use an equivalent but optimized expansion.
-- In the optimized case, we make use of these:
-- procedure Next (Position : in out Cursor); -- instead of Iter.Next
-- function Pseudo_Reference
-- (Container : aliased Vector'Class) return Reference_Control_Type;
-- type Element_Access is access all Element_Type;
-- function Get_Element_Access
-- (Position : Cursor) return not null Element_Access;
-- Next is declared in the visible part of the container packages.
-- The other three are added in the private part. (We're not supposed to
-- pollute the namespace for clients. The compiler has no trouble breaking
-- privacy to call things in the private part of an instance.)
-- Source:
-- for X of My_Vector loop
-- X.Count := X.Count + 1;
-- ...
-- end loop;
-- The compiler will generate:
-- Iter : Reversible_Iterator'Class := Iterate (My_Vector);
-- -- Reversible_Iterator is an interface. Iterate is the
-- -- Default_Iterator aspect of Vector. This increments Lock,
-- -- disallowing tampering with cursors. Unfortunately, it does not
-- -- increment Busy. The result of Iterate is Limited_Controlled;
-- -- finalization will decrement Lock. This is a build-in-place
-- -- dispatching call to Iterate.
-- Cur : Cursor := First (Iter); -- or Last
-- -- Dispatching call via interface.
-- Control : Reference_Control_Type := Pseudo_Reference (My_Vector);
-- -- Pseudo_Reference increments Busy, to detect tampering with
-- -- elements, as required by RM. Also redundantly increment
-- -- Lock. Finalization of Control will decrement both Busy and
-- -- Lock. Pseudo_Reference returns a record containing a pointer to
-- -- My_Vector, used by Finalize.
-- --
-- -- Control is not used below, except to finalize it -- it's purely
-- -- an RAII thing. This is needed because we are eliminating the
-- -- call to Reference within the loop.
-- while Has_Element (Cur) loop
-- declare
-- X : My_Element renames Get_Element_Access (Cur).all;
-- -- Get_Element_Access returns a pointer to the element
-- -- designated by Cur. No dispatching here, and no horsing
-- -- around with access discriminants. This is instead of the
-- -- existing
-- --
-- -- X : My_Element renames Reference (Cur).Element.all;
-- --
-- -- which creates a controlled object.
-- begin
-- -- Any attempt to tamper with My_Vector here in the loop
-- -- will correctly raise Program_Error, because of the
-- -- Control.
--
-- X.Count := X.Count + 1;
-- ...
--
-- Next (Cur); -- or Prev
-- -- This is instead of "Cur := Next (Iter, Cur);"
-- end;
-- -- No finalization here
-- end loop;
-- Finalize Iter and Control here, decrementing Lock twice and Busy
-- once.
-- This optimization makes "for ... of" loops over 30 times faster in cases
-- measured.
procedure Expand_Iterator_Loop_Over_Container
(N : Node_Id;
Isc : Node_Id;
I_Spec : Node_Id;
Container : Node_Id;
Container_Typ : Entity_Id)
is
Id : constant Entity_Id := Defining_Identifier (I_Spec);
Elem_Typ : constant Entity_Id := Etype (Id);
Id_Kind : constant Entity_Kind := Ekind (Id);
Loc : constant Source_Ptr := Sloc (N);
Stats : List_Id := Statements (N);
-- Maybe wrapped in a conditional if a filter is present
Cursor : Entity_Id;
Decl : Node_Id;
Iter_Type : Entity_Id;
Iterator : Entity_Id;
Name_Init : Name_Id;
Name_Step : Name_Id;
New_Loop : Node_Id;
Fast_Element_Access_Op : Entity_Id := Empty;
Fast_Step_Op : Entity_Id := Empty;
-- Only for optimized version of "for ... of"
Iter_Pack : Entity_Id;
-- The package in which the iterator interface is instantiated. This is
-- typically an instance within the container package.
Pack : Entity_Id;
-- The package in which the container type is declared
begin
if Present (Iterator_Filter (I_Spec)) then
pragma Assert (Ada_Version >= Ada_2022);
Stats := New_List (Make_If_Statement (Loc,
Condition => Iterator_Filter (I_Spec),
Then_Statements => Stats));
end if;
-- Determine the advancement and initialization steps for the cursor.
-- Analysis of the expanded loop will verify that the container has a
-- reverse iterator.
if Reverse_Present (I_Spec) then
Name_Init := Name_Last;
Name_Step := Name_Previous;
else
Name_Init := Name_First;
Name_Step := Name_Next;
end if;
-- The type of the iterator is the return type of the Iterate function
-- used. For the "of" form this is the default iterator for the type,
-- otherwise it is the type of the explicit function used in the
-- iterator specification. The most common case will be an Iterate
-- function in the container package.
-- The Iterator type is declared in an instance within the container
-- package itself, for example:
-- package Vector_Iterator_Interfaces is new
-- Ada.Iterator_Interfaces (Cursor, Has_Element);
-- If the container type is a derived type, the cursor type is found in
-- the package of the ultimate ancestor type.
if Is_Derived_Type (Container_Typ) then
Pack := Scope (Root_Type (Container_Typ));
else
Pack := Scope (Container_Typ);
end if;
if Of_Present (I_Spec) then
Handle_Of : declare
Container_Arg : Node_Id;
function Get_Default_Iterator
(T : Entity_Id) return Entity_Id;
-- Return the default iterator for a specific type. If the type is
-- derived, we return the inherited or overridden one if
-- appropriate.
--------------------------
-- Get_Default_Iterator --
--------------------------
function Get_Default_Iterator
(T : Entity_Id) return Entity_Id
is
Iter : constant Entity_Id :=
Entity (Find_Value_Of_Aspect (T, Aspect_Default_Iterator));
Prim : Elmt_Id;
Op : Entity_Id;
begin
Container_Arg := New_Copy_Tree (Container);
-- A previous version of GNAT allowed indexing aspects to be
-- redefined on derived container types, while the default
-- iterator was inherited from the parent type. This
-- nonstandard extension is preserved for use by the
-- modeling project under debug flag -gnatd.X.
if Debug_Flag_Dot_XX then
if Base_Type (Etype (Container)) /=
Base_Type (Etype (First_Formal (Iter)))
then
Container_Arg :=
Make_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of
(Etype (First_Formal (Iter)), Loc),
Expression => Container_Arg);
end if;
return Iter;
elsif Is_Derived_Type (T) then
-- The default iterator must be a primitive operation of the
-- type, at the same dispatch slot position. The DT position
-- may not be established if type is not frozen yet.
Prim := First_Elmt (Primitive_Operations (T));
while Present (Prim) loop
Op := Node (Prim);
if Alias (Op) = Iter
or else
(Chars (Op) = Chars (Iter)
and then Present (DTC_Entity (Op))
and then DT_Position (Op) = DT_Position (Iter))
then
return Op;
end if;
Next_Elmt (Prim);
end loop;
-- If we didn't find it, then our parent type is not
-- iterable, so we return the Default_Iterator aspect of
-- this type.
return Iter;
-- Otherwise not a derived type
else
return Iter;
end if;
end Get_Default_Iterator;
-- Local variables
Default_Iter : Entity_Id;
Ent : Entity_Id;
Reference_Control_Type : Entity_Id := Empty;
Pseudo_Reference : Entity_Id := Empty;
-- Start of processing for Handle_Of
begin
if Is_Class_Wide_Type (Container_Typ) then
Default_Iter :=
Get_Default_Iterator (Etype (Base_Type (Container_Typ)));
else
Default_Iter := Get_Default_Iterator (Etype (Container));
end if;
Cursor := Make_Temporary (Loc, 'C');
-- For a container element iterator, the iterator type is obtained
-- from the corresponding aspect, whose return type is descended
-- from the corresponding interface type in some instance of
-- Ada.Iterator_Interfaces. The actuals of that instantiation
-- are Cursor and Has_Element.
Iter_Type := Etype (Default_Iter);
-- The iterator type, which is a class-wide type, may itself be
-- derived locally, so the desired instantiation is the scope of
-- the root type of the iterator type.
Iter_Pack := Scope (Root_Type (Etype (Iter_Type)));
-- Find declarations needed for "for ... of" optimization
-- These declarations come from GNAT sources or sources
-- derived from them. User code may include additional
-- overloadings with similar names, and we need to perforn
-- some reasonable resolution to find the needed primitives.
-- It is unclear whether this mechanism is fragile if a user
-- makes arbitrary changes to the private part of a package
-- that supports iterators.
Ent := First_Entity (Pack);
while Present (Ent) loop
if Chars (Ent) = Name_Get_Element_Access
and then Present (First_Formal (Ent))
and then Chars (First_Formal (Ent)) = Name_Position
and then No (Next_Formal (First_Formal (Ent)))
then
Fast_Element_Access_Op := Ent;
elsif Chars (Ent) = Name_Step
and then Ekind (Ent) = E_Procedure
then
Fast_Step_Op := Ent;
elsif Chars (Ent) = Name_Reference_Control_Type then
Reference_Control_Type := Ent;
elsif Chars (Ent) = Name_Pseudo_Reference then
Pseudo_Reference := Ent;
end if;
Next_Entity (Ent);
end loop;
if Present (Reference_Control_Type)
and then Present (Pseudo_Reference)
then
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'D'),
Object_Definition =>
New_Occurrence_Of (Reference_Control_Type, Loc),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Pseudo_Reference, Loc),
Parameter_Associations =>
New_List (New_Copy_Tree (Container_Arg)))));
end if;
-- Rewrite domain of iteration as a call to the default iterator
-- for the container type. The formal may be an access parameter
-- in which case we must build a reference to the container.
declare
Arg : Node_Id;
begin
if Is_Access_Type (Etype (First_Entity (Default_Iter))) then
Arg :=
Make_Attribute_Reference (Loc,
Prefix => Container_Arg,
Attribute_Name => Name_Unrestricted_Access);
else
Arg := Container_Arg;
end if;
Rewrite (Name (I_Spec),
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Default_Iter, Loc),
Parameter_Associations => New_List (Arg)));
end;
Analyze_And_Resolve (Name (I_Spec));
-- Find cursor type in proper iterator package, which is an
-- instantiation of Iterator_Interfaces.
Ent := First_Entity (Iter_Pack);
while Present (Ent) loop
if Chars (Ent) = Name_Cursor then
Set_Etype (Cursor, Etype (Ent));
exit;
end if;
Next_Entity (Ent);
end loop;
if Present (Fast_Element_Access_Op) then
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Id,
Subtype_Mark =>
New_Occurrence_Of (Elem_Typ, Loc),
Name =>
Make_Explicit_Dereference (Loc,
Prefix =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Fast_Element_Access_Op, Loc),
Parameter_Associations =>
New_List (New_Occurrence_Of (Cursor, Loc)))));
else
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Id,
Subtype_Mark =>
New_Occurrence_Of (Elem_Typ, Loc),
Name =>
Make_Indexed_Component (Loc,
Prefix => Relocate_Node (Container_Arg),
Expressions =>
New_List (New_Occurrence_Of (Cursor, Loc))));
end if;
-- The defining identifier in the iterator is user-visible and
-- must be visible in the debugger.
Set_Debug_Info_Needed (Id);
-- If the container does not have a variable indexing aspect,
-- the element is a constant in the loop. The container itself
-- may be constant, in which case the element is a constant as
-- well. The container has been rewritten as a call to Iterate,
-- so examine original node.
if No (Find_Value_Of_Aspect
(Container_Typ, Aspect_Variable_Indexing))
or else not Is_Variable (Original_Node (Container))
then
Mutate_Ekind (Id, E_Constant);
end if;
Prepend_To (Stats, Decl);
end Handle_Of;
-- X in Iterate (S) : type of iterator is type of explicitly given
-- Iterate function, and the loop variable is the cursor. It will be
-- assigned in the loop and must be a variable.
else
Iter_Type := Etype (Name (I_Spec));
-- The iterator type, which is a class-wide type, may itself be
-- derived locally, so the desired instantiation is the scope of
-- the root type of the iterator type, as in the "of" case.
Iter_Pack := Scope (Root_Type (Etype (Iter_Type)));
Cursor := Id;
end if;
Iterator := Make_Temporary (Loc, 'I');
-- For both iterator forms, add a call to the step operation to advance
-- the cursor. Generate:
-- Cursor := Iterator.Next (Cursor);
-- or else
-- Cursor := Next (Cursor);
if Present (Fast_Element_Access_Op) and then Present (Fast_Step_Op) then
declare
Curs_Name : constant Node_Id := New_Occurrence_Of (Cursor, Loc);
Step_Call : Node_Id;
begin
Step_Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Fast_Step_Op, Loc),
Parameter_Associations => New_List (Curs_Name));
Append_To (Stats, Step_Call);
Set_Assignment_OK (Curs_Name);
end;
else
declare
Rhs : Node_Id;
begin
Rhs :=
Make_Function_Call (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Iterator, Loc),
Selector_Name => Make_Identifier (Loc, Name_Step)),
Parameter_Associations => New_List (
New_Occurrence_Of (Cursor, Loc)));
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Cursor, Loc),
Expression => Rhs));
Set_Assignment_OK (Name (Last (Stats)));
end;
end if;
-- Generate:
-- while Has_Element (Cursor) loop
-- <Stats>
-- end loop;
-- Has_Element is the second actual in the iterator package
New_Loop :=
Make_Loop_Statement (Loc,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Condition =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of
(Next_Entity (First_Entity (Iter_Pack)), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Cursor, Loc)))),
Statements => Stats,
End_Label => Empty);
-- If present, preserve identifier of loop, which can be used in an exit
-- statement in the body.
if Present (Identifier (N)) then
Set_Identifier (New_Loop, Relocate_Node (Identifier (N)));
end if;
-- Create the declarations for Iterator and cursor and insert them
-- before the source loop. Given that the domain of iteration is already
-- an entity, the iterator is just a renaming of that entity. Possible
-- optimization ???
Insert_Action (N,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Iterator,
Subtype_Mark => New_Occurrence_Of (Iter_Type, Loc),
Name => Relocate_Node (Name (I_Spec))));
-- Create declaration for cursor
declare
Cursor_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
Defining_Identifier => Cursor,
Object_Definition =>
New_Occurrence_Of (Etype (Cursor), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Iterator, Loc),
Selector_Name =>
Make_Identifier (Loc, Name_Init)));
begin
-- The cursor is only modified in expanded code, so it appears
-- as unassigned to the warning machinery. We must suppress this
-- spurious warning explicitly. The cursor's kind is that of the
-- original loop parameter (it is a constant if the domain of
-- iteration is constant).
Set_Warnings_Off (Cursor);
Set_Assignment_OK (Cursor_Decl);
Insert_Action (N, Cursor_Decl);
Mutate_Ekind (Cursor, Id_Kind);
end;
-- If the range of iteration is given by a function call that returns
-- a container, the finalization actions have been saved in the
-- Condition_Actions of the iterator. Insert them now at the head of
-- the loop.
Insert_List_Before (N, Condition_Actions (Isc));
Rewrite (N, New_Loop);
Analyze (N);
end Expand_Iterator_Loop_Over_Container;
-----------------------------
-- Expand_N_Loop_Statement --
-----------------------------
-- 1. Remove null loop entirely
-- 2. Deal with while condition for C/Fortran boolean
-- 3. Deal with loops with a non-standard enumeration type range
-- 4. Deal with while loops where Condition_Actions is set
-- 5. Deal with loops over predicated subtypes
-- 6. Deal with loops with iterators over arrays and containers
procedure Expand_N_Loop_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Scheme : constant Node_Id := Iteration_Scheme (N);
Stmt : Node_Id;
begin
-- Delete null loop
if Is_Null_Loop (N) then
Rewrite (N, Make_Null_Statement (Loc));
return;
end if;
-- Deal with condition for C/Fortran Boolean
if Present (Scheme) then
Adjust_Condition (Condition (Scheme));
end if;
-- Nothing more to do for plain loop with no iteration scheme
if No (Scheme) then
null;
-- Case of for loop (Loop_Parameter_Specification present)
-- Note: we do not have to worry about validity checking of the for loop
-- range bounds here, since they were frozen with constant declarations
-- and it is during that process that the validity checking is done.
elsif Present (Loop_Parameter_Specification (Scheme)) then
declare
LPS : constant Node_Id :=
Loop_Parameter_Specification (Scheme);
Loop_Id : constant Entity_Id := Defining_Identifier (LPS);
Ltype : constant Entity_Id := Etype (Loop_Id);
Btype : constant Entity_Id := Base_Type (Ltype);
Stats : constant List_Id := Statements (N);
Expr : Node_Id;
Decls : List_Id;
New_Id : Entity_Id;
begin
-- If Discrete_Subtype_Definition has been rewritten as an
-- N_Raise_xxx_Error, rewrite the whole loop as a raise node to
-- avoid confusing the code generator down the line.
if Nkind (Discrete_Subtype_Definition (LPS)) in N_Raise_xxx_Error
then
Rewrite (N, Discrete_Subtype_Definition (LPS));
return;
end if;
if Present (Iterator_Filter (LPS)) then
pragma Assert (Ada_Version >= Ada_2022);
Set_Statements (N,
New_List (Make_If_Statement (Loc,
Condition => Iterator_Filter (LPS),
Then_Statements => Stats)));
end if;
-- Deal with loop over predicates
if Is_Discrete_Type (Ltype)
and then Present (Predicate_Function (Ltype))
then
Expand_Predicated_Loop (N);
-- Handle the case where we have a for loop with the range type
-- being an enumeration type with non-standard representation.
-- In this case we expand:
-- for x in [reverse] a .. b loop
-- ...
-- end loop;
-- to
-- for xP in [reverse] integer
-- range etype'Pos (a) .. etype'Pos (b)
-- loop
-- declare
-- x : constant etype := Pos_To_Rep (xP);
-- begin
-- ...
-- end;
-- end loop;
elsif Is_Enumeration_Type (Btype)
and then Present (Enum_Pos_To_Rep (Btype))
then
New_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Loop_Id), 'P'));
-- If the type has a contiguous representation, successive
-- values can be generated as offsets from the first literal.
if Has_Contiguous_Rep (Btype) then
Expr :=
Unchecked_Convert_To (Btype,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Enumeration_Rep (First_Literal (Btype))),
Right_Opnd => New_Occurrence_Of (New_Id, Loc)));
else
-- Use the constructed array Enum_Pos_To_Rep
Expr :=
Make_Indexed_Component (Loc,
Prefix =>
New_Occurrence_Of (Enum_Pos_To_Rep (Btype), Loc),
Expressions =>
New_List (New_Occurrence_Of (New_Id, Loc)));
end if;
-- Build declaration for loop identifier
Decls :=
New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Ltype, Loc),
Expression => Expr));
Rewrite (N,
Make_Loop_Statement (Loc,
Identifier => Identifier (N),
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => New_Id,
Reverse_Present => Reverse_Present (LPS),
Discrete_Subtype_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Standard_Natural, Loc),
Constraint =>
Make_Range_Constraint (Loc,
Range_Expression =>
Make_Range (Loc,
Low_Bound =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Btype, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Relocate_Node
(Type_Low_Bound (Ltype)))),
High_Bound =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Btype, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Relocate_Node
(Type_High_Bound
(Ltype))))))))),
Statements => New_List (
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stats))),
End_Label => End_Label (N)));
-- The loop parameter's entity must be removed from the loop
-- scope's entity list and rendered invisible, since it will
-- now be located in the new block scope. Any other entities
-- already associated with the loop scope, such as the loop
-- parameter's subtype, will remain there.
-- In an element loop, the loop will contain a declaration for
-- a cursor variable; otherwise the loop id is the first entity
-- in the scope constructed for the loop.
if Comes_From_Source (Loop_Id) then
pragma Assert (First_Entity (Scope (Loop_Id)) = Loop_Id);
null;
end if;
Set_First_Entity (Scope (Loop_Id), Next_Entity (Loop_Id));
Remove_Homonym (Loop_Id);
if Last_Entity (Scope (Loop_Id)) = Loop_Id then
Set_Last_Entity (Scope (Loop_Id), Empty);
end if;
Analyze (N);
-- Nothing to do with other cases of for loops
else
null;
end if;
end;
-- Second case, if we have a while loop with Condition_Actions set, then
-- we change it into a plain loop:
-- while C loop
-- ...
-- end loop;
-- changed to:
-- loop
-- <<condition actions>>
-- exit when not C;
-- ...
-- end loop
elsif Present (Scheme)
and then Present (Condition_Actions (Scheme))
and then Present (Condition (Scheme))
then
declare
ES : Node_Id;
begin
ES :=
Make_Exit_Statement (Sloc (Condition (Scheme)),
Condition =>
Make_Op_Not (Sloc (Condition (Scheme)),
Right_Opnd => Condition (Scheme)));
Prepend (ES, Statements (N));
Insert_List_Before (ES, Condition_Actions (Scheme));
-- This is not an implicit loop, since it is generated in response
-- to the loop statement being processed. If this is itself
-- implicit, the restriction has already been checked. If not,
-- it is an explicit loop.
Rewrite (N,
Make_Loop_Statement (Sloc (N),
Identifier => Identifier (N),
Statements => Statements (N),
End_Label => End_Label (N)));
Analyze (N);
end;
-- Here to deal with iterator case
elsif Present (Scheme)
and then Present (Iterator_Specification (Scheme))
then
Expand_Iterator_Loop (N);
-- An iterator loop may generate renaming declarations for elements
-- that require debug information. This is the case in particular
-- with element iterators, where debug information must be generated
-- for the temporary that holds the element value. These temporaries
-- are created within a transient block whose local declarations are
-- transferred to the loop, which now has nontrivial local objects.
if Nkind (N) = N_Loop_Statement
and then Present (Identifier (N))
then
Qualify_Entity_Names (N);
end if;
end if;
-- When the iteration scheme mentions attribute 'Loop_Entry, the loop
-- is transformed into a conditional block where the original loop is
-- the sole statement. Inspect the statements of the nested loop for
-- controlled objects.
Stmt := N;
if Subject_To_Loop_Entry_Attributes (Stmt) then
Stmt := Find_Loop_In_Conditional_Block (Stmt);
end if;
Process_Statements_For_Controlled_Objects (Stmt);
end Expand_N_Loop_Statement;
----------------------------
-- Expand_Predicated_Loop --
----------------------------
-- Note: the expander can handle generation of loops over predicated
-- subtypes for both the dynamic and static cases. Depending on what
-- we decide is allowed in Ada 2012 mode and/or extensions allowed
-- mode, the semantic analyzer may disallow one or both forms.
procedure Expand_Predicated_Loop (N : Node_Id) is
Orig_Loop_Id : Node_Id := Empty;
Loc : constant Source_Ptr := Sloc (N);
Isc : constant Node_Id := Iteration_Scheme (N);
LPS : constant Node_Id := Loop_Parameter_Specification (Isc);
Loop_Id : constant Entity_Id := Defining_Identifier (LPS);
Ltype : constant Entity_Id := Etype (Loop_Id);
Stat : constant List_Id := Static_Discrete_Predicate (Ltype);
Stmts : constant List_Id := Statements (N);
begin
-- Case of iteration over non-static predicate, should not be possible
-- since this is not allowed by the semantics and should have been
-- caught during analysis of the loop statement.
if No (Stat) then
raise Program_Error;
-- If the predicate list is empty, that corresponds to a predicate of
-- False, in which case the loop won't run at all, and we rewrite the
-- entire loop as a null statement.
elsif Is_Empty_List (Stat) then
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
-- For expansion over a static predicate we generate the following
-- declare
-- J : Ltype := min-val;
-- begin
-- loop
-- body
-- case J is
-- when endpoint => J := startpoint;
-- when endpoint => J := startpoint;
-- ...
-- when max-val => exit;
-- when others => J := Lval'Succ (J);
-- end case;
-- end loop;
-- end;
-- with min-val replaced by max-val and Succ replaced by Pred if the
-- loop parameter specification carries a Reverse indicator.
-- To make this a little clearer, let's take a specific example:
-- type Int is range 1 .. 10;
-- subtype StaticP is Int with
-- predicate => StaticP in 3 | 10 | 5 .. 7;
-- ...
-- for L in StaticP loop
-- Put_Line ("static:" & J'Img);
-- end loop;
-- In this case, the loop is transformed into
-- begin
-- J : L := 3;
-- loop
-- body
-- case J is
-- when 3 => J := 5;
-- when 7 => J := 10;
-- when 10 => exit;
-- when others => J := L'Succ (J);
-- end case;
-- end loop;
-- end;
-- In addition, if the loop specification is given by a subtype
-- indication that constrains a predicated type, the bounds of
-- iteration are given by those of the subtype indication.
else
Static_Predicate : declare
S : Node_Id;
D : Node_Id;
P : Node_Id;
Alts : List_Id;
Cstm : Node_Id;
-- If the domain is an itype, note the bounds of its range.
L_Hi : Node_Id := Empty;
L_Lo : Node_Id := Empty;
function Lo_Val (N : Node_Id) return Node_Id;
-- Given static expression or static range, returns an identifier
-- whose value is the low bound of the expression value or range.
function Hi_Val (N : Node_Id) return Node_Id;
-- Given static expression or static range, returns an identifier
-- whose value is the high bound of the expression value or range.
------------
-- Hi_Val --
------------
function Hi_Val (N : Node_Id) return Node_Id is
begin
if Is_OK_Static_Expression (N) then
return New_Copy (N);
else
pragma Assert (Nkind (N) = N_Range);
return New_Copy (High_Bound (N));
end if;
end Hi_Val;
------------
-- Lo_Val --
------------
function Lo_Val (N : Node_Id) return Node_Id is
begin
if Is_OK_Static_Expression (N) then
return New_Copy (N);
else
pragma Assert (Nkind (N) = N_Range);
return New_Copy (Low_Bound (N));
end if;
end Lo_Val;
-- Start of processing for Static_Predicate
begin
-- Convert loop identifier to normal variable and reanalyze it so
-- that this conversion works. We have to use the same defining
-- identifier, since there may be references in the loop body.
Set_Analyzed (Loop_Id, False);
Mutate_Ekind (Loop_Id, E_Variable);
-- In most loops the loop variable is assigned in various
-- alternatives in the body. However, in the rare case when
-- the range specifies a single element, the loop variable
-- may trigger a spurious warning that is could be constant.
-- This warning might as well be suppressed.
Set_Warnings_Off (Loop_Id);
if Is_Itype (Ltype) then
L_Hi := High_Bound (Scalar_Range (Ltype));
L_Lo := Low_Bound (Scalar_Range (Ltype));
end if;
-- Loop to create branches of case statement
Alts := New_List;
if Reverse_Present (LPS) then
-- Initial value is largest value in predicate.
if Is_Itype (Ltype) then
D :=
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Object_Definition => New_Occurrence_Of (Ltype, Loc),
Expression => L_Hi);
else
D :=
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Object_Definition => New_Occurrence_Of (Ltype, Loc),
Expression => Hi_Val (Last (Stat)));
end if;
P := Last (Stat);
while Present (P) loop
if No (Prev (P)) then
S := Make_Exit_Statement (Loc);
else
S :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Loop_Id, Loc),
Expression => Hi_Val (Prev (P)));
Set_Suppress_Assignment_Checks (S);
end if;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Statements => New_List (S),
Discrete_Choices => New_List (Lo_Val (P))));
Prev (P);
end loop;
if Is_Itype (Ltype)
and then Is_OK_Static_Expression (L_Lo)
and then
Expr_Value (L_Lo) /= Expr_Value (Lo_Val (First (Stat)))
then
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Statements => New_List (Make_Exit_Statement (Loc)),
Discrete_Choices => New_List (L_Lo)));
end if;
else
-- Initial value is smallest value in predicate
if Is_Itype (Ltype) then
D :=
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Object_Definition => New_Occurrence_Of (Ltype, Loc),
Expression => L_Lo);
else
D :=
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Object_Definition => New_Occurrence_Of (Ltype, Loc),
Expression => Lo_Val (First (Stat)));
end if;
P := First (Stat);
while Present (P) loop
if No (Next (P)) then
S := Make_Exit_Statement (Loc);
else
S :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Loop_Id, Loc),
Expression => Lo_Val (Next (P)));
Set_Suppress_Assignment_Checks (S);
end if;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Statements => New_List (S),
Discrete_Choices => New_List (Hi_Val (P))));
Next (P);
end loop;
if Is_Itype (Ltype)
and then Is_OK_Static_Expression (L_Hi)
and then
Expr_Value (L_Hi) /= Expr_Value (Lo_Val (Last (Stat)))
then
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Statements => New_List (Make_Exit_Statement (Loc)),
Discrete_Choices => New_List (L_Hi)));
end if;
end if;
-- Add others choice
declare
Name_Next : Name_Id;
begin
if Reverse_Present (LPS) then
Name_Next := Name_Pred;
else
Name_Next := Name_Succ;
end if;
S :=
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Loop_Id, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ltype, Loc),
Attribute_Name => Name_Next,
Expressions => New_List (
New_Occurrence_Of (Loop_Id, Loc))));
Set_Suppress_Assignment_Checks (S);
end;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => New_List (Make_Others_Choice (Loc)),
Statements => New_List (S)));
-- Construct case statement and append to body statements
Cstm :=
Make_Case_Statement (Loc,
Expression => New_Occurrence_Of (Loop_Id, Loc),
Alternatives => Alts);
Append_To (Stmts, Cstm);
-- Rewrite the loop preserving the loop identifier in case there
-- are exit statements referencing it.
if Present (Identifier (N)) then
Orig_Loop_Id := New_Occurrence_Of
(Entity (Identifier (N)), Loc);
end if;
Set_Suppress_Assignment_Checks (D);
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => New_List (D),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Loop_Statement (Loc,
Statements => Stmts,
Identifier => Orig_Loop_Id,
End_Label => Empty)))));
Analyze (N);
end Static_Predicate;
end if;
end Expand_Predicated_Loop;
------------------------------
-- Make_Tag_Ctrl_Assignment --
------------------------------
function Make_Tag_Ctrl_Assignment (N : Node_Id) return List_Id is
Asn : constant Node_Id := Relocate_Node (N);
L : constant Node_Id := Name (N);
Loc : constant Source_Ptr := Sloc (N);
Res : constant List_Id := New_List;
T : constant Entity_Id := Underlying_Type (Etype (L));
Comp_Asn : constant Boolean := Is_Fully_Repped_Tagged_Type (T);
Ctrl_Act : constant Boolean := Needs_Finalization (T)
and then not No_Ctrl_Actions (N);
Save_Tag : constant Boolean := Is_Tagged_Type (T)
and then not Comp_Asn
and then not No_Ctrl_Actions (N)
and then Tagged_Type_Expansion;
Adj_Call : Node_Id;
Fin_Call : Node_Id;
Tag_Id : Entity_Id;
begin
-- Finalize the target of the assignment when controlled
-- We have two exceptions here:
-- 1. If we are in an init proc since it is an initialization more
-- than an assignment.
-- 2. If the left-hand side is a temporary that was not initialized
-- (or the parent part of a temporary since it is the case in
-- extension aggregates). Such a temporary does not come from
-- source. We must examine the original node for the prefix, because
-- it may be a component of an entry formal, in which case it has
-- been rewritten and does not appear to come from source either.
-- Case of init proc
if not Ctrl_Act then
null;
-- The left-hand side is an uninitialized temporary object
elsif Nkind (L) = N_Type_Conversion
and then Is_Entity_Name (Expression (L))
and then Nkind (Parent (Entity (Expression (L)))) =
N_Object_Declaration
and then No_Initialization (Parent (Entity (Expression (L))))
then
null;
else
Fin_Call :=
Make_Final_Call
(Obj_Ref => Duplicate_Subexpr_No_Checks (L),
Typ => Etype (L));
if Present (Fin_Call) then
Append_To (Res, Fin_Call);
end if;
end if;
-- Save the Tag in a local variable Tag_Id
if Save_Tag then
Tag_Id := Make_Temporary (Loc, 'A');
Append_To (Res,
Make_Object_Declaration (Loc,
Defining_Identifier => Tag_Id,
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr_No_Checks (L),
Selector_Name =>
New_Occurrence_Of (First_Tag_Component (T), Loc))));
-- Otherwise Tag_Id is not used
else
Tag_Id := Empty;
end if;
-- If the tagged type has a full rep clause, expand the assignment into
-- component-wise assignments. Mark the node as unanalyzed in order to
-- generate the proper code and propagate this scenario by setting a
-- flag to avoid infinite recursion.
if Comp_Asn then
Set_Analyzed (Asn, False);
Set_Componentwise_Assignment (Asn, True);
end if;
Append_To (Res, Asn);
-- Restore the tag
if Save_Tag then
Append_To (Res,
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr_No_Checks (L),
Selector_Name =>
New_Occurrence_Of (First_Tag_Component (T), Loc)),
Expression => New_Occurrence_Of (Tag_Id, Loc)));
end if;
-- Adjust the target after the assignment when controlled (not in the
-- init proc since it is an initialization more than an assignment).
if Ctrl_Act then
Adj_Call :=
Make_Adjust_Call
(Obj_Ref => Duplicate_Subexpr_Move_Checks (L),
Typ => Etype (L));
if Present (Adj_Call) then
Append_To (Res, Adj_Call);
end if;
end if;
return Res;
exception
-- Could use comment here ???
when RE_Not_Available =>
return Empty_List;
end Make_Tag_Ctrl_Assignment;
end Exp_Ch5;
|
jwarwick/aoc_2020 | Ada | 11,182 | ads | with Ada.Containers; use Ada.Containers;
with Ada.Containers.Ordered_Sets;
with Ada.Containers.Indefinite_Ordered_Maps;
package Bag is
type Bag_Color is (
bright_gray,
pale_olive,
mirrored_magenta,
shiny_blue,
dotted_beige,
drab_tomato,
drab_blue,
striped_beige,
dull_gold,
wavy_red,
pale_white,
bright_orange,
plaid_yellow,
clear_red,
light_tomato,
pale_yellow,
shiny_red,
bright_maroon,
dark_crimson,
pale_red,
shiny_lavender,
dotted_blue,
bright_lime,
bright_lavender,
faded_purple,
pale_aqua,
wavy_cyan,
dull_maroon,
muted_fuchsia,
clear_salmon,
drab_maroon,
posh_blue,
shiny_gold,
light_lavender,
pale_violet,
bright_gold,
wavy_maroon,
wavy_salmon,
vibrant_orange,
vibrant_green,
striped_tan,
wavy_silver,
pale_beige,
mirrored_brown,
faded_green,
posh_red,
wavy_turquoise,
drab_indigo,
shiny_black,
wavy_fuchsia,
clear_teal,
posh_tan,
plaid_lime,
vibrant_tomato,
dull_crimson,
dotted_salmon,
striped_orange,
vibrant_bronze,
posh_black,
dim_gray,
pale_chartreuse,
wavy_green,
striped_red,
muted_black,
vibrant_gray,
dotted_plum,
mirrored_salmon,
mirrored_orange,
dark_gold,
muted_orange,
posh_aqua,
dotted_lime,
drab_lime,
bright_blue,
light_orange,
dark_chartreuse,
clear_gray,
vibrant_lime,
light_black,
clear_gold,
light_aqua,
mirrored_tan,
faded_tomato,
drab_chartreuse,
striped_tomato,
clear_white,
shiny_plum,
plaid_violet,
dotted_magenta,
mirrored_cyan,
muted_teal,
striped_maroon,
mirrored_turquoise,
shiny_silver,
striped_green,
striped_silver,
wavy_olive,
clear_brown,
bright_turquoise,
muted_tan,
dull_green,
drab_yellow,
plaid_aqua,
vibrant_chartreuse,
light_chartreuse,
vibrant_tan,
posh_turquoise,
dotted_fuchsia,
dark_turquoise,
dotted_chartreuse,
light_lime,
mirrored_teal,
vibrant_turquoise,
clear_blue,
striped_blue,
muted_silver,
dotted_indigo,
vibrant_teal,
striped_chartreuse,
dotted_violet,
light_brown,
posh_indigo,
drab_violet,
plaid_plum,
dotted_orange,
dotted_teal,
vibrant_brown,
clear_orange,
bright_magenta,
clear_tan,
dotted_brown,
vibrant_plum,
light_indigo,
bright_chartreuse,
clear_turquoise,
dim_crimson,
pale_tan,
plaid_gold,
striped_crimson,
clear_lavender,
dark_maroon,
drab_gray,
faded_olive,
muted_gray,
posh_violet,
shiny_white,
mirrored_indigo,
dark_brown,
muted_tomato,
striped_black,
shiny_crimson,
bright_coral,
dark_yellow,
faded_beige,
wavy_magenta,
wavy_bronze,
dim_lavender,
dim_indigo,
posh_green,
pale_gray,
mirrored_gold,
striped_white,
drab_cyan,
vibrant_aqua,
light_gold,
dotted_yellow,
vibrant_cyan,
posh_yellow,
faded_salmon,
bright_purple,
dotted_purple,
plaid_red,
vibrant_maroon,
clear_crimson,
clear_cyan,
vibrant_salmon,
striped_olive,
dim_turquoise,
bright_brown,
mirrored_tomato,
dark_green,
wavy_white,
shiny_green,
dotted_aqua,
shiny_aqua,
dark_lavender,
dull_violet,
drab_tan,
plaid_turquoise,
pale_lavender,
clear_indigo,
wavy_purple,
shiny_salmon,
mirrored_crimson,
plaid_chartreuse,
pale_orange,
dark_cyan,
dim_brown,
pale_blue,
vibrant_red,
dark_salmon,
bright_black,
vibrant_white,
muted_violet,
wavy_coral,
striped_salmon,
faded_blue,
dim_violet,
faded_chartreuse,
posh_silver,
dim_red,
dull_lime,
striped_fuchsia,
vibrant_lavender,
dark_gray,
drab_lavender,
mirrored_white,
bright_aqua,
dark_silver,
drab_fuchsia,
bright_teal,
striped_indigo,
dark_white,
mirrored_maroon,
wavy_tan,
wavy_lime,
dark_plum,
posh_cyan,
pale_crimson,
clear_yellow,
striped_yellow,
clear_silver,
drab_red,
dotted_turquoise,
striped_purple,
striped_gray,
clear_purple,
light_gray,
dull_tan,
muted_blue,
dull_brown,
bright_fuchsia,
plaid_purple,
drab_silver,
light_salmon,
drab_beige,
posh_beige,
muted_cyan,
dull_magenta,
shiny_cyan,
mirrored_gray,
bright_cyan,
dotted_crimson,
dim_chartreuse,
muted_crimson,
dim_aqua,
wavy_aqua,
bright_beige,
posh_purple,
shiny_fuchsia,
wavy_beige,
wavy_crimson,
pale_tomato,
bright_silver,
mirrored_chartreuse,
mirrored_aqua,
wavy_brown,
dull_purple,
pale_turquoise,
dull_lavender,
dull_aqua,
clear_maroon,
wavy_lavender,
dull_blue,
shiny_olive,
shiny_teal,
dull_teal,
dim_bronze,
muted_bronze,
vibrant_violet,
dull_turquoise,
pale_purple,
drab_aqua,
mirrored_beige,
pale_plum,
dotted_maroon,
muted_olive,
wavy_yellow,
plaid_salmon,
faded_indigo,
pale_brown,
clear_olive,
vibrant_gold,
dark_indigo,
drab_gold,
light_bronze,
vibrant_black,
wavy_tomato,
wavy_orange,
dark_blue,
drab_magenta,
posh_crimson,
mirrored_coral,
faded_crimson,
dotted_tan,
faded_magenta,
light_maroon,
dull_chartreuse,
plaid_white,
plaid_fuchsia,
dark_red,
dark_fuchsia,
dull_plum,
vibrant_crimson,
clear_magenta,
dull_indigo,
vibrant_olive,
striped_lavender,
clear_lime,
faded_orange,
posh_lime,
posh_olive,
dim_yellow,
muted_red,
pale_salmon,
light_beige,
clear_tomato,
shiny_gray,
vibrant_fuchsia,
shiny_violet,
plaid_silver,
light_white,
posh_magenta,
muted_maroon,
light_blue,
pale_teal,
posh_gold,
shiny_indigo,
wavy_teal,
striped_cyan,
pale_black,
light_green,
mirrored_green,
dim_orange,
clear_chartreuse,
dull_black,
dotted_tomato,
faded_maroon,
plaid_cyan,
dark_bronze,
vibrant_purple,
dotted_silver,
mirrored_yellow,
dim_lime,
faded_tan,
drab_plum,
plaid_lavender,
dark_beige,
dotted_red,
dull_orange,
striped_bronze,
wavy_indigo,
light_cyan,
plaid_orange,
faded_turquoise,
shiny_orange,
light_tan,
pale_coral,
faded_lavender,
dull_cyan,
shiny_turquoise,
faded_violet,
mirrored_bronze,
dull_tomato,
faded_red,
dark_magenta,
light_turquoise,
clear_green,
clear_coral,
dotted_bronze,
drab_salmon,
faded_aqua,
bright_violet,
mirrored_silver,
posh_maroon,
striped_brown,
bright_olive,
drab_white,
faded_teal,
striped_plum,
dark_coral,
drab_orange,
bright_tan,
drab_brown,
posh_bronze,
mirrored_purple,
wavy_blue,
dim_cyan,
plaid_olive,
dark_orange,
drab_olive,
pale_fuchsia,
shiny_chartreuse,
shiny_brown,
striped_turquoise,
dull_gray,
wavy_chartreuse,
bright_green,
dark_olive,
dark_black,
dim_purple,
pale_gold,
pale_maroon,
light_plum,
mirrored_plum,
dim_coral,
faded_silver,
posh_salmon,
shiny_purple,
shiny_maroon,
clear_beige,
muted_plum,
plaid_green,
faded_white,
plaid_gray,
shiny_yellow,
mirrored_violet,
plaid_beige,
plaid_black,
mirrored_fuchsia,
pale_indigo,
light_magenta,
striped_teal,
dark_aqua,
bright_red,
dim_teal,
drab_crimson,
dim_silver,
drab_bronze,
drab_teal,
dark_teal,
vibrant_indigo,
mirrored_black,
dotted_gray,
posh_plum,
drab_black,
faded_gray,
muted_white,
wavy_gray,
plaid_magenta,
muted_coral,
plaid_tomato,
dark_lime,
vibrant_coral,
drab_turquoise,
mirrored_red,
plaid_brown,
striped_gold,
drab_purple,
posh_chartreuse,
clear_violet,
striped_magenta,
muted_salmon,
pale_silver,
striped_lime,
dull_silver,
dark_violet,
dim_black,
shiny_beige,
plaid_tan,
faded_yellow,
vibrant_blue,
mirrored_lime,
dull_white,
dim_tomato,
pale_cyan,
light_fuchsia,
posh_gray,
faded_cyan,
plaid_bronze,
dim_olive,
faded_coral,
pale_lime,
dim_white,
muted_turquoise,
clear_bronze,
bright_plum,
posh_orange,
muted_chartreuse,
shiny_bronze,
shiny_coral,
posh_lavender,
clear_fuchsia,
bright_tomato,
light_yellow,
pale_magenta,
bright_bronze,
faded_bronze,
plaid_coral,
dull_coral,
muted_purple,
light_silver,
muted_aqua,
posh_white,
dotted_olive,
muted_lime,
vibrant_magenta,
dotted_coral,
drab_green,
vibrant_silver,
dull_bronze,
striped_coral,
dim_blue,
mirrored_olive,
bright_salmon,
bright_crimson,
vibrant_yellow,
plaid_indigo,
bright_indigo,
clear_aqua,
posh_tomato,
dim_tan,
dim_plum,
posh_teal,
muted_indigo,
dull_beige,
dotted_cyan,
faded_fuchsia,
pale_bronze,
dim_beige,
muted_beige,
dotted_lavender,
pale_green,
drab_coral,
wavy_plum,
dotted_green,
light_violet,
faded_gold,
muted_magenta,
light_red,
dim_maroon,
dull_fuchsia,
wavy_gold,
light_coral,
dark_tan,
faded_plum,
wavy_black,
wavy_violet,
light_teal,
posh_fuchsia,
striped_violet,
plaid_crimson,
light_olive,
dim_magenta,
striped_aqua,
dotted_white,
faded_black,
dotted_black,
dotted_gold,
dark_tomato,
shiny_tan,
muted_gold,
dim_gold,
dull_yellow,
bright_white,
light_purple,
shiny_magenta,
faded_brown,
posh_coral,
dim_green,
dull_red,
clear_plum,
mirrored_lavender,
dim_salmon,
plaid_maroon,
dim_fuchsia,
dull_olive,
muted_brown,
muted_lavender,
faded_lime,
muted_yellow,
dark_purple,
light_crimson,
muted_green,
vibrant_beige,
shiny_tomato,
bright_yellow,
clear_black,
posh_brown,
shiny_lime,
mirrored_blue,
dull_salmon,
plaid_teal,
plaid_blue);
my_color : Bag_Color := shiny_gold;
type Bag_Combo is record
Color : Bag_Color;
Count : Natural := 0;
end record;
function "<" (Left, Right : Bag_Combo) return Boolean;
package Bag_Sets is new Ada.Containers.Ordered_Sets
(Element_Type => Bag_Combo);
use Bag_Sets;
package Bag_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type => Bag_Color,
Element_Type => Bag_Sets.Set);
use Bag_Maps;
function test_data return Bag_Maps.Map;
function input_data return Bag_Maps.Map;
function parse_rules(f : in String) return Bag_Maps.Map;
end Bag;
|
MinimSecure/unum-sdk | Ada | 1,174 | adb | -- Copyright 2014-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pck; use Pck;
procedure Foo_n207_004 is
Full : Full_Table := (False, True, False, True, False);
Prim : Primary_Table := (True, False, False);
Cold : Variable_Table := (Green => False, Blue => True, White => True);
Vars : Variable_Table := New_Variable_Table (Low => Red, High => Green);
begin
Do_Nothing (Full'Address); -- STOP
Do_Nothing (Prim'Address);
Do_Nothing (Cold'Address);
Do_Nothing (Vars'Address);
end Foo_n207_004;
|
optikos/oasis | Ada | 1,978 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Element_Vectors;
with Program.Elements.Paths;
with Program.Lexical_Elements;
package Program.Elements.Case_Paths is
pragma Pure (Program.Elements.Case_Paths);
type Case_Path is limited interface and Program.Elements.Paths.Path;
type Case_Path_Access is access all Case_Path'Class with Storage_Size => 0;
not overriding function Choices
(Self : Case_Path)
return not null Program.Element_Vectors.Element_Vector_Access
is abstract;
not overriding function Statements
(Self : Case_Path)
return not null Program.Element_Vectors.Element_Vector_Access
is abstract;
type Case_Path_Text is limited interface;
type Case_Path_Text_Access is access all Case_Path_Text'Class
with Storage_Size => 0;
not overriding function To_Case_Path_Text
(Self : aliased in out Case_Path)
return Case_Path_Text_Access is abstract;
not overriding function When_Token
(Self : Case_Path_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Arrow_Token
(Self : Case_Path_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
type Case_Path_Vector is
limited interface and Program.Element_Vectors.Element_Vector;
type Case_Path_Vector_Access is access all Case_Path_Vector'Class
with Storage_Size => 0;
overriding function Element
(Self : Case_Path_Vector;
Index : Positive)
return not null Program.Elements.Element_Access is abstract
with Post'Class => Element'Result.Is_Case_Path;
function To_Case_Path
(Self : Case_Path_Vector'Class;
Index : Positive)
return not null Case_Path_Access is (Self.Element (Index).To_Case_Path);
end Program.Elements.Case_Paths;
|
reznikmm/matreshka | Ada | 3,640 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.Standard_Profile_L2.Focuses.Hash is
new AMF.Elements.Generic_Hash (Standard_Profile_L2_Focus, Standard_Profile_L2_Focus_Access);
|
zhmu/ananas | Ada | 4,860 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . V X W O R K S . E X T --
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2022, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
-- This package provides vxworks specific support functions needed
-- by System.OS_Interface.
-- This is the VxWorks 5 and VxWorks MILS version of this package
with Interfaces.C;
package System.VxWorks.Ext is
pragma Preelaborate;
subtype SEM_ID is Long_Integer;
-- typedef struct semaphore *SEM_ID;
type sigset_t is mod 2 ** Interfaces.C.long'Size;
type t_id is new Long_Integer;
subtype int is Interfaces.C.int;
subtype unsigned is Interfaces.C.unsigned;
type STATUS is new int;
-- Equivalent of the C type STATUS
OK : constant STATUS := 0;
ERROR : constant STATUS := -1;
type BOOL is new int;
-- Equivalent of the C type BOOL
type vx_freq_t is new unsigned;
-- Equivalent of the C type _Vx_freq_t
type Interrupt_Handler is access procedure (parameter : System.Address);
pragma Convention (C, Interrupt_Handler);
type Interrupt_Vector is new System.Address;
function Int_Lock return int;
pragma Import (C, Int_Lock, "intLock");
procedure Int_Unlock (Old : int);
pragma Import (C, Int_Unlock, "intUnlock");
function Interrupt_Connect
(Vector : Interrupt_Vector;
Handler : Interrupt_Handler;
Parameter : System.Address := System.Null_Address) return int;
pragma Import (C, Interrupt_Connect, "intConnect");
function Interrupt_Context return BOOL;
pragma Import (C, Interrupt_Context, "intContext");
function Interrupt_Number_To_Vector
(intNum : int) return Interrupt_Vector;
pragma Import (C, Interrupt_Number_To_Vector, "__gnat_inum_to_ivec");
function semDelete (Sem : SEM_ID) return int;
pragma Import (C, semDelete, "semDelete");
function Task_Cont (tid : t_id) return int;
pragma Import (C, Task_Cont, "taskResume");
function Task_Stop (tid : t_id) return int;
pragma Import (C, Task_Stop, "taskSuspend");
function kill (pid : t_id; sig : int) return int;
pragma Import (C, kill, "kill");
function getpid return t_id;
pragma Import (C, getpid, "taskIdSelf");
function Set_Time_Slice (ticks : int) return int;
pragma Import (C, Set_Time_Slice, "kernelTimeSlice");
--------------------------------
-- Processor Affinity for SMP --
--------------------------------
function taskCpuAffinitySet (tid : t_id; CPU : int) return int;
pragma Convention (C, taskCpuAffinitySet);
-- For SMP run-times set the CPU affinity.
-- For uniprocessor systems return ERROR status.
function taskMaskAffinitySet (tid : t_id; CPU_Set : unsigned) return int;
pragma Convention (C, taskMaskAffinitySet);
-- For SMP run-times set the CPU mask affinity.
-- For uniprocessor systems return ERROR status.
end System.VxWorks.Ext;
|
reznikmm/markdown | Ada | 2,091 | ads | -- SPDX-FileCopyrightText: 2020 Max Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.Strings;
limited with Markdown.Visitors;
package Markdown.Blocks is
type Block is abstract tagged limited private;
type Block_Access is access all Block'Class with Storage_Size => 0;
function Is_Assigned (Value : access Block'Class) return Boolean is
(Value /= null);
type Text_Line is record
Line : League.Strings.Universal_String;
Column : Positive;
end record;
not overriding function Create
(Line : not null access Text_Line) return Block is abstract;
not overriding function Is_Container (Self : Block) return Boolean is
(False);
not overriding procedure Append_Line
(Self : in out Block;
Line : Text_Line;
CIP : Can_Interrupt_Paragraph;
Ok : in out Boolean) is null;
not overriding procedure Visit
(Self : in out Block;
Visitor : in out Markdown.Visitors.Visitor'Class) is abstract;
type Container_Block is abstract new Block with private;
type Container_Block_Access is access all Container_Block'Class
with Storage_Size => 0;
not overriding procedure Append_Child
(Self : in out Container_Block;
Child : not null Block_Access);
overriding function Is_Container (Self : Container_Block) return Boolean is
(True);
not overriding procedure Consume_Continuation_Markers
(Self : in out Container_Block;
Line : in out Text_Line;
Match : out Boolean) is abstract;
procedure Wrap_List_Items (Self : in out Container_Block'Class);
-- Create List when neede and move List_Items inside.
procedure Visit_Children
(Self : Container_Block'Class;
Visitor : in out Markdown.Visitors.Visitor'Class);
private
type Block is abstract tagged limited record
Next : Block_Access;
end record;
type Container_Block is abstract new Block with record
Last_Child : Block_Access;
end record;
end Markdown.Blocks;
|
reznikmm/markdown | Ada | 4,606 | adb | -- SPDX-FileCopyrightText: 2020 Max Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.Regexps;
with Markdown.Visitors;
package body Markdown.Fenced_Code_Blocks is
Pattern : constant League.Regexps.Regexp_Pattern :=
League.Regexps.Compile
(League.Strings.To_Universal_String
("^\ {0,3}((\`{3,})\ *([^\`]*)|(\~{3,})\ *(.*))$"));
-- 12 3 4 5
-----------------
-- Append_Line --
-----------------
overriding procedure Append_Line
(Self : in out Fenced_Code_Block;
Line : Markdown.Blocks.Text_Line;
CIP : Can_Interrupt_Paragraph;
Ok : in out Boolean)
is
pragma Unreferenced (CIP);
Match : constant League.Regexps.Regexp_Match :=
Pattern.Find_Match (Line.Line);
begin
if Self.Closed then
Ok := False;
return;
elsif Match.Is_Matched
-- Closing fences cannot have info string
and then Match.Last_Index (3) < Match.First_Index (3)
and then Match.Last_Index (5) < Match.First_Index (5)
then
if Self.Is_Tick_Fence then
Self.Closed := Match.Last_Index (2) > 0 and then
Match.Last_Index (2) - Match.First_Index (2) + 1 >=
Self.Fence_Length;
else
Self.Closed := Match.Last_Index (2) = 0 and then
Match.Last_Index (4) - Match.First_Index (4) + 1 >=
Self.Fence_Length;
end if;
end if;
if not Self.Closed then
declare
From : Positive := 1;
begin
for J in 1 .. Self.Fence_Indent loop
if J <= Line.Line.Length and then
Line.Line (J).To_Wide_Wide_Character = ' '
then
From := J + 1;
else
exit;
end if;
end loop;
if From > Line.Line.Length then
Self.Blank.Append (League.Strings.Empty_Universal_String);
else
Self.Lines.Append (Self.Blank);
Self.Blank.Clear;
Self.Lines.Append (Line.Line.Tail_From (From));
end if;
end;
elsif not Self.Blank.Is_Empty then
Self.Lines.Append (Self.Blank);
Self.Blank.Clear;
end if;
Ok := True;
end Append_Line;
------------
-- Create --
------------
overriding function Create
(Line : not null access Markdown.Blocks.Text_Line)
return Fenced_Code_Block
is
Match : constant League.Regexps.Regexp_Match :=
Pattern.Find_Match (Line.Line);
begin
pragma Assert (Match.Is_Matched);
return Result : Fenced_Code_Block do
Result.Fence_Indent := Match.First_Index (1) - 1;
Result.Is_Tick_Fence := Match.Last_Index (2) > 0;
if Result.Is_Tick_Fence then
Result.Fence_Length :=
Match.Last_Index (2) - Match.First_Index (2) + 1;
Result.Info_String := Line.Line.Slice
(Match.First_Index (3), Match.Last_Index (3));
else
Result.Fence_Length :=
Match.Last_Index (4) - Match.First_Index (4) + 1;
Result.Info_String := Line.Line.Slice
(Match.First_Index (5), Match.Last_Index (5));
end if;
Line.Line.Clear;
end return;
end Create;
------------
-- Filter --
------------
procedure Filter
(Line : Markdown.Blocks.Text_Line;
Tag : in out Ada.Tags.Tag;
CIP : out Can_Interrupt_Paragraph)
is
Match : constant League.Regexps.Regexp_Match :=
Pattern.Find_Match (Line.Line);
begin
if Match.Is_Matched then
Tag := Fenced_Code_Block'Tag;
CIP := True;
end if;
end Filter;
-----------------
-- Info_String --
-----------------
function Info_String (Self : Fenced_Code_Block'Class)
return League.Strings.Universal_String is
begin
return Self.Info_String;
end Info_String;
-----------
-- Lines --
-----------
function Lines (Self : Fenced_Code_Block'Class)
return League.String_Vectors.Universal_String_Vector is
begin
return Self.Lines;
end Lines;
-----------
-- Visit --
-----------
overriding procedure Visit
(Self : in out Fenced_Code_Block;
Visitor : in out Markdown.Visitors.Visitor'Class) is
begin
Visitor.Fenced_Code_Block (Self);
end Visit;
end Markdown.Fenced_Code_Blocks;
|
MinimSecure/unum-sdk | Ada | 799 | adb | -- Copyright 2015-2016 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pack;
procedure Foo is
begin
Pack.Do_Nothing (Pack.AA); -- BREAK
end Foo;
|
reznikmm/matreshka | Ada | 3,694 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Elements;
package ODF.DOM.Text_Sender_Country_Elements is
pragma Preelaborate;
type ODF_Text_Sender_Country is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Text_Sender_Country_Access is
access all ODF_Text_Sender_Country'Class
with Storage_Size => 0;
end ODF.DOM.Text_Sender_Country_Elements;
|
reznikmm/matreshka | Ada | 4,719 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Visitors;
with ODF.DOM.Table_Insertion_Elements;
package Matreshka.ODF_Table.Insertion_Elements is
type Table_Insertion_Element_Node is
new Matreshka.ODF_Table.Abstract_Table_Element_Node
and ODF.DOM.Table_Insertion_Elements.ODF_Table_Insertion
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Table_Insertion_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Insertion_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Table_Insertion_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Table_Insertion_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Table_Insertion_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Table.Insertion_Elements;
|
shintakezou/drake | Ada | 31,490 | adb | -- diff (Ada.Exceptions.Finally)
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with Ada.Streams; -- [gcc-4.7] can not search in private with
with System;
package body Ada.Containers.Hashed_Sets is
use type Hash_Tables.Table_Access;
use type Copy_On_Write.Data_Access;
function Upcast is
new Unchecked_Conversion (Cursor, Hash_Tables.Node_Access);
function Downcast is
new Unchecked_Conversion (Hash_Tables.Node_Access, Cursor);
function Upcast is
new Unchecked_Conversion (Data_Access, Copy_On_Write.Data_Access);
function Downcast is
new Unchecked_Conversion (Copy_On_Write.Data_Access, Data_Access);
-- diff
procedure Free is new Unchecked_Deallocation (Node, Cursor);
type Context_Type is limited record
Left : not null access Element_Type;
end record;
pragma Suppress_Initialization (Context_Type);
function Equivalent_Element (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean;
function Equivalent_Element (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean
is
Context : Context_Type;
for Context'Address use Params;
begin
return Equivalent_Elements (
Context.Left.all,
Downcast (Position).Element);
end Equivalent_Element;
function Equivalent_Node (Left, Right : not null Hash_Tables.Node_Access)
return Boolean;
function Equivalent_Node (Left, Right : not null Hash_Tables.Node_Access)
return Boolean is
begin
return Equivalent_Elements (
Downcast (Left).Element,
Downcast (Right).Element);
end Equivalent_Node;
-- diff (Allocate_Element)
--
--
--
--
--
--
--
--
procedure Allocate_Node (Item : out Cursor; New_Item : Element_Type);
procedure Allocate_Node (Item : out Cursor; New_Item : Element_Type) is
-- diff
-- diff
-- diff
begin
Item := new Node'(Super => <>, Element => New_Item);
-- diff
-- diff
-- diff
end Allocate_Node;
procedure Copy_Node (
Target : out Hash_Tables.Node_Access;
Source : not null Hash_Tables.Node_Access);
procedure Copy_Node (
Target : out Hash_Tables.Node_Access;
Source : not null Hash_Tables.Node_Access)
is
New_Node : Cursor;
begin
Allocate_Node (New_Node, Downcast (Source).Element);
Target := Upcast (New_Node);
end Copy_Node;
procedure Free_Node (Object : in out Hash_Tables.Node_Access);
procedure Free_Node (Object : in out Hash_Tables.Node_Access) is
X : Cursor := Downcast (Object);
begin
-- diff
Free (X);
Object := null;
end Free_Node;
procedure Allocate_Data (
Target : out not null Copy_On_Write.Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
procedure Allocate_Data (
Target : out not null Copy_On_Write.Data_Access;
New_Length : Count_Type;
Capacity : Count_Type)
is
pragma Unreferenced (New_Length);
New_Data : constant Data_Access :=
new Data'(Super => <>, Table => null, Length => 0);
begin
Hash_Tables.Rebuild (New_Data.Table, Capacity);
Target := Upcast (New_Data);
end Allocate_Data;
procedure Copy_Data (
Target : out not null Copy_On_Write.Data_Access;
Source : not null Copy_On_Write.Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
procedure Copy_Data (
Target : out not null Copy_On_Write.Data_Access;
Source : not null Copy_On_Write.Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type)
is
pragma Unreferenced (Length);
pragma Unreferenced (New_Length);
New_Data : constant Data_Access :=
new Data'(Super => <>, Table => null, Length => 0);
begin
Hash_Tables.Copy (
New_Data.Table,
New_Data.Length,
Downcast (Source).Table,
Capacity,
Copy => Copy_Node'Access);
Target := Upcast (New_Data);
end Copy_Data;
procedure Free is new Unchecked_Deallocation (Data, Data_Access);
procedure Free_Data (Data : in out Copy_On_Write.Data_Access);
procedure Free_Data (Data : in out Copy_On_Write.Data_Access) is
X : Data_Access := Downcast (Data);
begin
Hash_Tables.Free (X.Table, X.Length, Free => Free_Node'Access);
Free (X);
Data := null;
end Free_Data;
procedure Reallocate (
Container : in out Set;
Capacity : Count_Type;
To_Update : Boolean);
procedure Reallocate (
Container : in out Set;
Capacity : Count_Type;
To_Update : Boolean) is
begin
Copy_On_Write.Unique (
Target => Container.Super'Access,
Target_Length => 0, -- Length is unused
Target_Capacity => Hashed_Sets.Capacity (Container),
New_Length => 0,
New_Capacity => Capacity,
To_Update => To_Update,
Allocate => Allocate_Data'Access,
Move => Copy_Data'Access,
Copy => Copy_Data'Access,
Free => Free_Data'Access,
Max_Length => Copy_On_Write.Zero'Access);
end Reallocate;
procedure Unique (Container : in out Set; To_Update : Boolean);
procedure Unique (Container : in out Set; To_Update : Boolean) is
begin
if Copy_On_Write.Shared (Container.Super.Data) then
Reallocate (
Container,
Capacity (Container), -- not shrinking
To_Update);
end if;
end Unique;
function Equivalent_Sets (
Left, Right : Set;
Equivalent : not null access function (
Left, Right : not null Hash_Tables.Node_Access)
return Boolean)
return Boolean;
function Equivalent_Sets (
Left, Right : Set;
Equivalent : not null access function (
Left, Right : not null Hash_Tables.Node_Access)
return Boolean)
return Boolean
is
Left_Length : constant Count_Type := Length (Left);
Right_Length : constant Count_Type := Length (Right);
begin
if Left_Length /= Right_Length then
return False;
elsif Left_Length = 0 or else Left.Super.Data = Right.Super.Data then
return True;
else
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access := Downcast (Right.Super.Data);
begin
return Hash_Tables.Equivalent (
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
Equivalent => Equivalent);
end;
end if;
end Equivalent_Sets;
function Find (Container : Set; Hash : Hash_Type; Item : Element_Type)
return Cursor;
function Find (Container : Set; Hash : Hash_Type; Item : Element_Type)
return Cursor is
begin
if Is_Empty (Container) then
return null;
else
Unique (Container'Unrestricted_Access.all, False);
declare
Context : Context_Type := (Left => Item'Unrestricted_Access);
begin
return Downcast (Hash_Tables.Find (
Downcast (Container.Super.Data).Table,
Hash,
Context'Address,
Equivalent => Equivalent_Element'Access));
end;
end if;
end Find;
-- implementation
function Empty_Set return Set is
begin
return (Finalization.Controlled with Super => (null, null));
end Empty_Set;
function Has_Element (Position : Cursor) return Boolean is
begin
return Position /= null;
end Has_Element;
overriding function "=" (Left, Right : Set) return Boolean is
function Equivalent (Left, Right : not null Hash_Tables.Node_Access)
return Boolean;
function Equivalent (Left, Right : not null Hash_Tables.Node_Access)
return Boolean is
begin
return Downcast (Left).Element = Downcast (Right).Element;
end Equivalent;
begin
return Equivalent_Sets (Left, Right, Equivalent => Equivalent'Access);
end "=";
function Equivalent_Sets (Left, Right : Set) return Boolean is
begin
return Equivalent_Sets (Left, Right,
Equivalent => Equivalent_Node'Access);
end Equivalent_Sets;
function To_Set (New_Item : Element_Type) return Set is
begin
return Result : Set do
Insert (Result, New_Item);
end return;
end To_Set;
function Generic_Array_To_Set (S : Element_Array) return Set is
begin
return Result : Set do
Reallocate (Result, S'Length, True);
for I in S'Range loop
Insert (Result, S (I));
end loop;
end return;
end Generic_Array_To_Set;
function Capacity (Container : Set) return Count_Type is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
if Data = null then
return 0;
else
return Hash_Tables.Capacity (Data.Table);
end if;
end Capacity;
procedure Reserve_Capacity (
Container : in out Set;
Capacity : Count_Type)
is
New_Capacity : constant Count_Type :=
Count_Type'Max (Capacity, Length (Container));
begin
Reallocate (Container, New_Capacity, True);
end Reserve_Capacity;
function Length (Container : Set) return Count_Type is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
if Data = null then
return 0;
else
return Data.Length;
end if;
end Length;
function Is_Empty (Container : Set) return Boolean is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
return Data = null or else Data.Length = 0;
end Is_Empty;
procedure Clear (Container : in out Set) is
begin
Copy_On_Write.Clear (Container.Super'Access, Free => Free_Data'Access);
end Clear;
function Element (Position : Cursor) return Element_Type is
begin
return Position.Element;
end Element;
procedure Replace_Element (
Container : in out Set;
Position : Cursor;
New_Item : Element_Type) is
begin
Unique (Container, True);
-- diff
Position.Element := New_Item;
end Replace_Element;
procedure Query_Element (
Position : Cursor;
Process : not null access procedure (Element : Element_Type)) is
begin
Process (Position.Element);
end Query_Element;
function Constant_Reference (Container : aliased Set; Position : Cursor)
return Constant_Reference_Type
is
pragma Unreferenced (Container);
begin
return (Element => Position.all.Element'Access); -- [gcc-6] .all
end Constant_Reference;
procedure Assign (Target : in out Set; Source : Set) is
begin
Copy_On_Write.Assign (
Target.Super'Access,
Source.Super'Access,
Free => Free_Data'Access);
end Assign;
function Copy (Source : Set; Capacity : Count_Type := 0) return Set is
begin
return Result : Set do
Copy_On_Write.Copy (
Result.Super'Access,
Source.Super'Access,
0, -- Length is unused
Count_Type'Max (Capacity, Length (Source)),
Allocate => Allocate_Data'Access,
Copy => Copy_Data'Access);
end return;
end Copy;
procedure Move (Target : in out Set; Source : in out Set) is
begin
Copy_On_Write.Move (
Target.Super'Access,
Source.Super'Access,
Free => Free_Data'Access);
-- diff
end Move;
procedure Insert (
Container : in out Set;
New_Item : Element_Type;
Position : out Cursor;
Inserted : out Boolean)
is
-- diff
-- diff
-- diff
New_Hash : constant Hash_Type := Hash (New_Item);
begin
-- diff
-- diff
Position := Find (Container, New_Hash, New_Item);
Inserted := Position = null;
if Inserted then
Unique (Container, True);
Allocate_Node (Position, New_Item);
declare
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
Hash_Tables.Insert (
Data.Table,
Data.Length,
New_Hash,
Upcast (Position));
end;
end if;
end Insert;
procedure Insert (
Container : in out Set;
New_Item : Element_Type)
is
Position : Cursor;
Inserted : Boolean;
begin
Insert (Container, New_Item, Position, Inserted);
if not Inserted then
raise Constraint_Error;
end if;
end Insert;
procedure Include (Container : in out Set; New_Item : Element_Type) is
Position : Cursor;
Inserted : Boolean;
begin
Insert (Container, New_Item, Position, Inserted);
if not Inserted then
Replace_Element (Container, Position, New_Item);
end if;
end Include;
procedure Replace (Container : in out Set; New_Item : Element_Type) is
begin
Replace_Element (Container, Find (Container, New_Item), New_Item);
end Replace;
procedure Exclude (Container : in out Set; Item : Element_Type) is
Position : Cursor := Find (Container, Item);
begin
if Position /= null then
Delete (Container, Position);
end if;
end Exclude;
procedure Delete (Container : in out Set; Item : Element_Type) is
Position : Cursor := Find (Container, Item);
begin
Delete (Container, Position);
end Delete;
procedure Delete (Container : in out Set; Position : in out Cursor) is
Position_2 : Hash_Tables.Node_Access := Upcast (Position);
begin
Unique (Container, True);
declare
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
Hash_Tables.Remove (Data.Table, Data.Length, Position_2);
end;
Free_Node (Position_2);
Position := null;
end Delete;
procedure Union (Target : in out Set; Source : Set) is
begin
if Is_Empty (Source) or else Target.Super.Data = Source.Super.Data then
null;
elsif Is_Empty (Target) then
Assign (Target, Source);
else
Unique (Target, True);
Unique (Source'Unrestricted_Access.all, False); -- private
declare
Target_Data : constant Data_Access := Downcast (Target.Super.Data);
Source_Data : constant Data_Access := Downcast (Source.Super.Data);
begin
Hash_Tables.Merge (
Target_Data.Table,
Target_Data.Length,
Source_Data.Table,
Source_Data.Length,
(others => True),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access,
Free => Free_Node'Access);
end;
end if;
end Union;
function Union (Left, Right : Set) return Set is
begin
return Result : Set do
if Is_Empty (Right) or else Left.Super.Data = Right.Super.Data then
Assign (Result, Left);
elsif Is_Empty (Left) then
Assign (Result, Right);
else
Unique (Result, True);
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Result_Data : constant Data_Access :=
Downcast (Result.Super.Data);
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access :=
Downcast (Right.Super.Data);
begin
Hash_Tables.Copying_Merge (
Result_Data.Table,
Result_Data.Length,
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
(others => True),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access);
end;
end if;
end return;
end Union;
procedure Intersection (Target : in out Set; Source : Set) is
begin
if Is_Empty (Target) or else Is_Empty (Source) then
Clear (Target);
elsif Target.Super.Data = Source.Super.Data then
null;
else
Unique (Target, True);
Unique (Source'Unrestricted_Access.all, False); -- private
declare
Target_Data : constant Data_Access := Downcast (Target.Super.Data);
Source_Data : constant Data_Access := Downcast (Source.Super.Data);
begin
Hash_Tables.Merge (
Target_Data.Table,
Target_Data.Length,
Source_Data.Table,
Source_Data.Length,
(Hash_Tables.In_Both => True, others => False),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access,
Free => Free_Node'Access);
end;
end if;
end Intersection;
function Intersection (Left, Right : Set) return Set is
begin
return Result : Set do
if Is_Empty (Left) or else Is_Empty (Right) then
null; -- Empty_Set
elsif Left.Super.Data = Right.Super.Data then
Assign (Result, Left);
else
Unique (Result, True);
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Result_Data : constant Data_Access :=
Downcast (Result.Super.Data);
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access :=
Downcast (Right.Super.Data);
begin
Hash_Tables.Copying_Merge (
Result_Data.Table,
Result_Data.Length,
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
(Hash_Tables.In_Both => True, others => False),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access);
end;
end if;
end return;
end Intersection;
procedure Difference (Target : in out Set; Source : Set) is
begin
if Is_Empty (Target) or else Target.Super.Data = Source.Super.Data then
Clear (Target);
elsif Is_Empty (Source) then
null;
else
Unique (Target, True);
Unique (Source'Unrestricted_Access.all, False); -- private
declare
Target_Data : constant Data_Access := Downcast (Target.Super.Data);
Source_Data : constant Data_Access := Downcast (Source.Super.Data);
begin
Hash_Tables.Merge (
Target_Data.Table,
Target_Data.Length,
Source_Data.Table,
Source_Data.Length,
(Hash_Tables.In_Only_Left => True, others => False),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access,
Free => Free_Node'Access);
end;
end if;
end Difference;
function Difference (Left, Right : Set) return Set is
begin
return Result : Set do
if Is_Empty (Left) or else Left.Super.Data = Right.Super.Data then
null; -- Empty_Set
elsif Is_Empty (Right) then
Assign (Result, Left);
else
Unique (Result, True);
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Result_Data : constant Data_Access :=
Downcast (Result.Super.Data);
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access :=
Downcast (Right.Super.Data);
begin
Hash_Tables.Copying_Merge (
Result_Data.Table,
Result_Data.Length,
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
(Hash_Tables.In_Only_Left => True, others => False),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access);
end;
end if;
end return;
end Difference;
procedure Symmetric_Difference (Target : in out Set; Source : Set) is
begin
if Target.Super.Data = Source.Super.Data then
Clear (Target);
elsif Is_Empty (Source) then
null;
elsif Is_Empty (Target) then
Assign (Target, Source);
else
Unique (Target, True);
Unique (Source'Unrestricted_Access.all, False); -- private
declare
Target_Data : constant Data_Access := Downcast (Target.Super.Data);
Source_Data : constant Data_Access := Downcast (Source.Super.Data);
begin
Hash_Tables.Merge (
Target_Data.Table,
Target_Data.Length,
Source_Data.Table,
Source_Data.Length,
(Hash_Tables.In_Both => False, others => True),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access,
Free => Free_Node'Access);
end;
end if;
end Symmetric_Difference;
function Symmetric_Difference (Left, Right : Set) return Set is
begin
return Result : Set do
if Left.Super.Data = Right.Super.Data then
null; -- Empty_Set
elsif Is_Empty (Right) then
Assign (Result, Left);
elsif Is_Empty (Left) then
Assign (Result, Right);
else
Unique (Result, True);
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Result_Data : constant Data_Access :=
Downcast (Result.Super.Data);
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access :=
Downcast (Right.Super.Data);
begin
Hash_Tables.Copying_Merge (
Result_Data.Table,
Result_Data.Length,
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
(Hash_Tables.In_Both => False, others => True),
Equivalent => Equivalent_Node'Access,
Copy => Copy_Node'Access);
end;
end if;
end return;
end Symmetric_Difference;
function Overlap (Left, Right : Set) return Boolean is
begin
if Is_Empty (Left) or else Is_Empty (Right) then
return False;
elsif Left.Super.Data = Right.Super.Data then
return True;
else
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
return Hash_Tables.Overlap (
Downcast (Left.Super.Data).Table,
Downcast (Right.Super.Data).Table,
Equivalent => Equivalent_Node'Access);
end if;
end Overlap;
function Is_Subset (Subset : Set; Of_Set : Set) return Boolean is
begin
if Is_Empty (Subset) or else Subset.Super.Data = Of_Set.Super.Data then
return True;
elsif Is_Empty (Of_Set) then
return False;
else
Unique (Subset'Unrestricted_Access.all, False); -- private
Unique (Of_Set'Unrestricted_Access.all, False); -- private
return Hash_Tables.Is_Subset (
Downcast (Subset.Super.Data).Table,
Downcast (Of_Set.Super.Data).Table,
Equivalent => Equivalent_Node'Access);
end if;
end Is_Subset;
function First (Container : Set) return Cursor is
begin
if Is_Empty (Container) then
return null;
else
Unique (Container'Unrestricted_Access.all, False);
return Downcast (Hash_Tables.First (
Downcast (Container.Super.Data).Table));
end if;
end First;
function Next (Position : Cursor) return Cursor is
begin
return Downcast (Position.Super.Next);
end Next;
procedure Next (Position : in out Cursor) is
begin
Position := Downcast (Position.Super.Next);
end Next;
function Find (Container : Set; Item : Element_Type) return Cursor is
begin
return Find (Container, Hash (Item), Item);
end Find;
function Contains (Container : Set; Item : Element_Type) return Boolean is
begin
return Find (Container, Item) /= null;
end Contains;
function Equivalent_Elements (Left, Right : Cursor)
return Boolean is
begin
return Equivalent_Elements (Left.Element, Right.Element);
end Equivalent_Elements;
function Equivalent_Elements (Left : Cursor; Right : Element_Type)
return Boolean is
begin
return Equivalent_Elements (Left.Element, Right);
end Equivalent_Elements;
procedure Iterate (
Container : Set'Class;
Process : not null access procedure (Position : Cursor))
is
type P1 is access procedure (Position : Cursor);
type P2 is access procedure (Position : Hash_Tables.Node_Access);
function Cast is new Unchecked_Conversion (P1, P2);
begin
if not Is_Empty (Set (Container)) then
Unique (Set (Container)'Unrestricted_Access.all, False);
Hash_Tables.Iterate (
Downcast (Container.Super.Data).Table,
Cast (Process));
end if;
end Iterate;
function Iterate (Container : Set'Class)
return Set_Iterator_Interfaces.Forward_Iterator'Class is
begin
return Set_Iterator'(First => First (Set (Container)));
end Iterate;
overriding procedure Adjust (Object : in out Set) is
begin
Copy_On_Write.Adjust (Object.Super'Access);
end Adjust;
overriding function First (Object : Set_Iterator) return Cursor is
begin
return Object.First;
end First;
overriding function Next (Object : Set_Iterator; Position : Cursor)
return Cursor
is
pragma Unreferenced (Object);
begin
return Next (Position);
end Next;
package body Generic_Keys is
type Context_Type is limited record
Left : not null access Key_Type;
end record;
pragma Suppress_Initialization (Context_Type);
function Equivalent_Key (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean;
function Equivalent_Key (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean
is
Context : Context_Type;
for Context'Address use Params;
begin
return Equivalent_Keys (
Context.Left.all,
Key (Downcast (Position).Element));
end Equivalent_Key;
function Key (Position : Cursor) return Key_Type is
begin
return Key (Position.Element);
end Key;
function Element (Container : Set; Key : Key_Type) return Element_Type is
begin
return Element (Find (Container, Key));
end Element;
procedure Replace (
Container : in out Set;
Key : Key_Type;
New_Item : Element_Type) is
begin
Replace_Element (Container, Find (Container, Key), New_Item);
end Replace;
procedure Exclude (Container : in out Set; Key : Key_Type) is
Position : Cursor := Find (Container, Key);
begin
if Position /= null then
Delete (Container, Position);
end if;
end Exclude;
procedure Delete (Container : in out Set; Key : Key_Type) is
Position : Cursor := Find (Container, Key);
begin
Delete (Container, Position);
end Delete;
function Find (Container : Set; Key : Key_Type) return Cursor is
begin
if Is_Empty (Container) then
return null;
else
Unique (Container'Unrestricted_Access.all, False);
declare
Context : Context_Type := (Left => Key'Unrestricted_Access);
begin
return Downcast (Hash_Tables.Find (
Downcast (Container.Super.Data).Table,
Hash (Key),
Context'Address,
Equivalent => Equivalent_Key'Access));
end;
end if;
end Find;
function Contains (Container : Set; Key : Key_Type) return Boolean is
begin
return Find (Container, Key) /= null;
end Contains;
procedure Update_Element_Preserving_Key (
Container : in out Set;
Position : Cursor;
Process : not null access procedure (
Element : in out Element_Type)) is
begin
Process (Reference_Preserving_Key (Container, Position).Element.all);
end Update_Element_Preserving_Key;
function Reference_Preserving_Key (
Container : aliased in out Set;
Position : Cursor)
return Reference_Type is
begin
Unique (Container, True);
-- diff
return (Element => Position.all.Element'Access); -- [gcc-6] .all
end Reference_Preserving_Key;
function Constant_Reference (Container : aliased Set; Key : Key_Type)
return Constant_Reference_Type is
begin
return Constant_Reference (Container, Find (Container, Key));
end Constant_Reference;
function Reference_Preserving_Key (
Container : aliased in out Set;
Key : Key_Type)
return Reference_Type is
begin
return Reference_Preserving_Key (Container, Find (Container, Key));
end Reference_Preserving_Key;
end Generic_Keys;
package body Streaming is
procedure Read (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : out Set)
is
Length : Count_Type'Base;
begin
Count_Type'Base'Read (Stream, Length);
Clear (Item);
for I in 1 .. Length loop
declare
New_Item : Element_Type;
begin
Element_Type'Read (Stream, New_Item);
Include (Item, New_Item);
end;
end loop;
end Read;
procedure Write (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : Set)
is
Length : constant Count_Type := Hashed_Sets.Length (Item);
begin
Count_Type'Write (Stream, Length);
if Length > 0 then
declare
Position : Cursor := First (Item);
begin
while Position /= null loop
Element_Type'Write (Stream, Position.Element);
Next (Position);
end loop;
end;
end if;
end Write;
end Streaming;
end Ada.Containers.Hashed_Sets;
|
gabemgem/LITEC | Ada | 10,200 | adb | M:time
F:G$SYSCLK_Init$0$0({2}DF,SV:S),C,0,0,0,0,0
F:G$UART0_Init$0$0({2}DF,SV:S),C,0,0,0,0,0
F:G$Sys_Init$0$0({2}DF,SV:S),C,0,0,0,0,0
F:G$putchar$0$0({2}DF,SV:S),C,0,0,0,0,0
F:G$getchar$0$0({2}DF,SC:U),C,0,0,0,0,0
F:G$getchar_nw$0$0({2}DF,SC:U),C,0,0,0,0,0
F:G$main$0$0({2}DF,SV:S),C,0,0,0,0,0
T:Ftime$tm[({0}S:S$tm_sec$0$0({1}SC:U),Z,0,0)({1}S:S$tm_min$0$0({1}SC:U),Z,0,0)({2}S:S$tm_hour$0$0({1}SC:U),Z,0,0)({3}S:S$tm_mday$0$0({1}SC:U),Z,0,0)({4}S:S$tm_mon$0$0({1}SC:U),Z,0,0)({5}S:S$tm_year$0$0({2}SI:S),Z,0,0)({7}S:S$tm_wday$0$0({1}SC:U),Z,0,0)({8}S:S$tm_yday$0$0({2}SI:S),Z,0,0)({10}S:S$tm_isdst$0$0({1}SC:U),Z,0,0)({11}S:S$tm_hundredth$0$0({1}SC:U),Z,0,0)]
S:Ltime.getchar$c$1$10({1}SC:U),R,0,0,[]
S:Ltime.getchar_nw$c$1$12({1}SC:U),R,0,0,[]
S:Ltime.aligned_alloc$size$1$39({2}SI:U),E,0,0
S:Ltime.aligned_alloc$alignment$1$39({2}SI:U),E,0,0
S:G$P0$0$0({1}SC:U),I,0,0
S:G$SP$0$0({1}SC:U),I,0,0
S:G$DPL$0$0({1}SC:U),I,0,0
S:G$DPH$0$0({1}SC:U),I,0,0
S:G$P4$0$0({1}SC:U),I,0,0
S:G$P5$0$0({1}SC:U),I,0,0
S:G$P6$0$0({1}SC:U),I,0,0
S:G$PCON$0$0({1}SC:U),I,0,0
S:G$TCON$0$0({1}SC:U),I,0,0
S:G$TMOD$0$0({1}SC:U),I,0,0
S:G$TL0$0$0({1}SC:U),I,0,0
S:G$TL1$0$0({1}SC:U),I,0,0
S:G$TH0$0$0({1}SC:U),I,0,0
S:G$TH1$0$0({1}SC:U),I,0,0
S:G$CKCON$0$0({1}SC:U),I,0,0
S:G$PSCTL$0$0({1}SC:U),I,0,0
S:G$P1$0$0({1}SC:U),I,0,0
S:G$TMR3CN$0$0({1}SC:U),I,0,0
S:G$TMR3RLL$0$0({1}SC:U),I,0,0
S:G$TMR3RLH$0$0({1}SC:U),I,0,0
S:G$TMR3L$0$0({1}SC:U),I,0,0
S:G$TMR3H$0$0({1}SC:U),I,0,0
S:G$P7$0$0({1}SC:U),I,0,0
S:G$SCON$0$0({1}SC:U),I,0,0
S:G$SCON0$0$0({1}SC:U),I,0,0
S:G$SBUF$0$0({1}SC:U),I,0,0
S:G$SBUF0$0$0({1}SC:U),I,0,0
S:G$SPI0CFG$0$0({1}SC:U),I,0,0
S:G$SPI0DAT$0$0({1}SC:U),I,0,0
S:G$ADC1$0$0({1}SC:U),I,0,0
S:G$SPI0CKR$0$0({1}SC:U),I,0,0
S:G$CPT0CN$0$0({1}SC:U),I,0,0
S:G$CPT1CN$0$0({1}SC:U),I,0,0
S:G$P2$0$0({1}SC:U),I,0,0
S:G$EMI0TC$0$0({1}SC:U),I,0,0
S:G$EMI0CF$0$0({1}SC:U),I,0,0
S:G$PRT0CF$0$0({1}SC:U),I,0,0
S:G$P0MDOUT$0$0({1}SC:U),I,0,0
S:G$PRT1CF$0$0({1}SC:U),I,0,0
S:G$P1MDOUT$0$0({1}SC:U),I,0,0
S:G$PRT2CF$0$0({1}SC:U),I,0,0
S:G$P2MDOUT$0$0({1}SC:U),I,0,0
S:G$PRT3CF$0$0({1}SC:U),I,0,0
S:G$P3MDOUT$0$0({1}SC:U),I,0,0
S:G$IE$0$0({1}SC:U),I,0,0
S:G$SADDR0$0$0({1}SC:U),I,0,0
S:G$ADC1CN$0$0({1}SC:U),I,0,0
S:G$ADC1CF$0$0({1}SC:U),I,0,0
S:G$AMX1SL$0$0({1}SC:U),I,0,0
S:G$P3IF$0$0({1}SC:U),I,0,0
S:G$SADEN1$0$0({1}SC:U),I,0,0
S:G$EMI0CN$0$0({1}SC:U),I,0,0
S:G$_XPAGE$0$0({1}SC:U),I,0,0
S:G$P3$0$0({1}SC:U),I,0,0
S:G$OSCXCN$0$0({1}SC:U),I,0,0
S:G$OSCICN$0$0({1}SC:U),I,0,0
S:G$P74OUT$0$0({1}SC:U),I,0,0
S:G$FLSCL$0$0({1}SC:U),I,0,0
S:G$FLACL$0$0({1}SC:U),I,0,0
S:G$IP$0$0({1}SC:U),I,0,0
S:G$SADEN0$0$0({1}SC:U),I,0,0
S:G$AMX0CF$0$0({1}SC:U),I,0,0
S:G$AMX0SL$0$0({1}SC:U),I,0,0
S:G$ADC0CF$0$0({1}SC:U),I,0,0
S:G$P1MDIN$0$0({1}SC:U),I,0,0
S:G$ADC0L$0$0({1}SC:U),I,0,0
S:G$ADC0H$0$0({1}SC:U),I,0,0
S:G$SMB0CN$0$0({1}SC:U),I,0,0
S:G$SMB0STA$0$0({1}SC:U),I,0,0
S:G$SMB0DAT$0$0({1}SC:U),I,0,0
S:G$SMB0ADR$0$0({1}SC:U),I,0,0
S:G$ADC0GTL$0$0({1}SC:U),I,0,0
S:G$ADC0GTH$0$0({1}SC:U),I,0,0
S:G$ADC0LTL$0$0({1}SC:U),I,0,0
S:G$ADC0LTH$0$0({1}SC:U),I,0,0
S:G$T2CON$0$0({1}SC:U),I,0,0
S:G$T4CON$0$0({1}SC:U),I,0,0
S:G$RCAP2L$0$0({1}SC:U),I,0,0
S:G$RCAP2H$0$0({1}SC:U),I,0,0
S:G$TL2$0$0({1}SC:U),I,0,0
S:G$TH2$0$0({1}SC:U),I,0,0
S:G$SMB0CR$0$0({1}SC:U),I,0,0
S:G$PSW$0$0({1}SC:U),I,0,0
S:G$REF0CN$0$0({1}SC:U),I,0,0
S:G$DAC0L$0$0({1}SC:U),I,0,0
S:G$DAC0H$0$0({1}SC:U),I,0,0
S:G$DAC0CN$0$0({1}SC:U),I,0,0
S:G$DAC1L$0$0({1}SC:U),I,0,0
S:G$DAC1H$0$0({1}SC:U),I,0,0
S:G$DAC1CN$0$0({1}SC:U),I,0,0
S:G$PCA0CN$0$0({1}SC:U),I,0,0
S:G$PCA0MD$0$0({1}SC:U),I,0,0
S:G$PCA0CPM0$0$0({1}SC:U),I,0,0
S:G$PCA0CPM1$0$0({1}SC:U),I,0,0
S:G$PCA0CPM2$0$0({1}SC:U),I,0,0
S:G$PCA0CPM3$0$0({1}SC:U),I,0,0
S:G$PCA0CPM4$0$0({1}SC:U),I,0,0
S:G$ACC$0$0({1}SC:U),I,0,0
S:G$XBR0$0$0({1}SC:U),I,0,0
S:G$XBR1$0$0({1}SC:U),I,0,0
S:G$XBR2$0$0({1}SC:U),I,0,0
S:G$RCAP4L$0$0({1}SC:U),I,0,0
S:G$RCAP4H$0$0({1}SC:U),I,0,0
S:G$EIE1$0$0({1}SC:U),I,0,0
S:G$EIE2$0$0({1}SC:U),I,0,0
S:G$ADC0CN$0$0({1}SC:U),I,0,0
S:G$PCA0L$0$0({1}SC:U),I,0,0
S:G$PCA0CPL0$0$0({1}SC:U),I,0,0
S:G$PCA0CPL1$0$0({1}SC:U),I,0,0
S:G$PCA0CPL2$0$0({1}SC:U),I,0,0
S:G$PCA0CPL3$0$0({1}SC:U),I,0,0
S:G$PCA0CPL4$0$0({1}SC:U),I,0,0
S:G$RSTSRC$0$0({1}SC:U),I,0,0
S:G$B$0$0({1}SC:U),I,0,0
S:G$SCON1$0$0({1}SC:U),I,0,0
S:G$SBUF1$0$0({1}SC:U),I,0,0
S:G$SADDR1$0$0({1}SC:U),I,0,0
S:G$TL4$0$0({1}SC:U),I,0,0
S:G$TH4$0$0({1}SC:U),I,0,0
S:G$EIP1$0$0({1}SC:U),I,0,0
S:G$EIP2$0$0({1}SC:U),I,0,0
S:G$SPI0CN$0$0({1}SC:U),I,0,0
S:G$PCA0H$0$0({1}SC:U),I,0,0
S:G$PCA0CPH0$0$0({1}SC:U),I,0,0
S:G$PCA0CPH1$0$0({1}SC:U),I,0,0
S:G$PCA0CPH2$0$0({1}SC:U),I,0,0
S:G$PCA0CPH3$0$0({1}SC:U),I,0,0
S:G$PCA0CPH4$0$0({1}SC:U),I,0,0
S:G$WDTCN$0$0({1}SC:U),I,0,0
S:G$TMR0$0$0({2}SI:U),I,0,0
S:G$TMR1$0$0({2}SI:U),I,0,0
S:G$TMR2$0$0({2}SI:U),I,0,0
S:G$RCAP2$0$0({2}SI:U),I,0,0
S:G$TMR3$0$0({2}SI:U),I,0,0
S:G$TMR3RL$0$0({2}SI:U),I,0,0
S:G$TMR4$0$0({2}SI:U),I,0,0
S:G$RCAP4$0$0({2}SI:U),I,0,0
S:G$ADC0$0$0({2}SI:U),I,0,0
S:G$ADC0GT$0$0({2}SI:U),I,0,0
S:G$ADC0LT$0$0({2}SI:U),I,0,0
S:G$DAC0$0$0({2}SI:U),I,0,0
S:G$DAC1$0$0({2}SI:U),I,0,0
S:G$PCA0$0$0({2}SI:U),I,0,0
S:G$PCA0CP0$0$0({2}SI:U),I,0,0
S:G$PCA0CP1$0$0({2}SI:U),I,0,0
S:G$PCA0CP2$0$0({2}SI:U),I,0,0
S:G$PCA0CP3$0$0({2}SI:U),I,0,0
S:G$PCA0CP4$0$0({2}SI:U),I,0,0
S:G$P0_0$0$0({1}SX:U),J,0,0
S:G$P0_1$0$0({1}SX:U),J,0,0
S:G$P0_2$0$0({1}SX:U),J,0,0
S:G$P0_3$0$0({1}SX:U),J,0,0
S:G$P0_4$0$0({1}SX:U),J,0,0
S:G$P0_5$0$0({1}SX:U),J,0,0
S:G$P0_6$0$0({1}SX:U),J,0,0
S:G$P0_7$0$0({1}SX:U),J,0,0
S:G$IT0$0$0({1}SX:U),J,0,0
S:G$IE0$0$0({1}SX:U),J,0,0
S:G$IT1$0$0({1}SX:U),J,0,0
S:G$IE1$0$0({1}SX:U),J,0,0
S:G$TR0$0$0({1}SX:U),J,0,0
S:G$TF0$0$0({1}SX:U),J,0,0
S:G$TR1$0$0({1}SX:U),J,0,0
S:G$TF1$0$0({1}SX:U),J,0,0
S:G$P1_0$0$0({1}SX:U),J,0,0
S:G$P1_1$0$0({1}SX:U),J,0,0
S:G$P1_2$0$0({1}SX:U),J,0,0
S:G$P1_3$0$0({1}SX:U),J,0,0
S:G$P1_4$0$0({1}SX:U),J,0,0
S:G$P1_5$0$0({1}SX:U),J,0,0
S:G$P1_6$0$0({1}SX:U),J,0,0
S:G$P1_7$0$0({1}SX:U),J,0,0
S:G$RI$0$0({1}SX:U),J,0,0
S:G$RI0$0$0({1}SX:U),J,0,0
S:G$TI$0$0({1}SX:U),J,0,0
S:G$TI0$0$0({1}SX:U),J,0,0
S:G$RB8$0$0({1}SX:U),J,0,0
S:G$RB80$0$0({1}SX:U),J,0,0
S:G$TB8$0$0({1}SX:U),J,0,0
S:G$TB80$0$0({1}SX:U),J,0,0
S:G$REN$0$0({1}SX:U),J,0,0
S:G$REN0$0$0({1}SX:U),J,0,0
S:G$SM2$0$0({1}SX:U),J,0,0
S:G$SM20$0$0({1}SX:U),J,0,0
S:G$MCE0$0$0({1}SX:U),J,0,0
S:G$SM1$0$0({1}SX:U),J,0,0
S:G$SM10$0$0({1}SX:U),J,0,0
S:G$SM0$0$0({1}SX:U),J,0,0
S:G$SM00$0$0({1}SX:U),J,0,0
S:G$S0MODE$0$0({1}SX:U),J,0,0
S:G$P2_0$0$0({1}SX:U),J,0,0
S:G$P2_1$0$0({1}SX:U),J,0,0
S:G$P2_2$0$0({1}SX:U),J,0,0
S:G$P2_3$0$0({1}SX:U),J,0,0
S:G$P2_4$0$0({1}SX:U),J,0,0
S:G$P2_5$0$0({1}SX:U),J,0,0
S:G$P2_6$0$0({1}SX:U),J,0,0
S:G$P2_7$0$0({1}SX:U),J,0,0
S:G$EX0$0$0({1}SX:U),J,0,0
S:G$ET0$0$0({1}SX:U),J,0,0
S:G$EX1$0$0({1}SX:U),J,0,0
S:G$ET1$0$0({1}SX:U),J,0,0
S:G$ES0$0$0({1}SX:U),J,0,0
S:G$ES$0$0({1}SX:U),J,0,0
S:G$ET2$0$0({1}SX:U),J,0,0
S:G$EA$0$0({1}SX:U),J,0,0
S:G$P3_0$0$0({1}SX:U),J,0,0
S:G$P3_1$0$0({1}SX:U),J,0,0
S:G$P3_2$0$0({1}SX:U),J,0,0
S:G$P3_3$0$0({1}SX:U),J,0,0
S:G$P3_4$0$0({1}SX:U),J,0,0
S:G$P3_5$0$0({1}SX:U),J,0,0
S:G$P3_6$0$0({1}SX:U),J,0,0
S:G$P3_7$0$0({1}SX:U),J,0,0
S:G$PX0$0$0({1}SX:U),J,0,0
S:G$PT0$0$0({1}SX:U),J,0,0
S:G$PX1$0$0({1}SX:U),J,0,0
S:G$PT1$0$0({1}SX:U),J,0,0
S:G$PS0$0$0({1}SX:U),J,0,0
S:G$PS$0$0({1}SX:U),J,0,0
S:G$PT2$0$0({1}SX:U),J,0,0
S:G$SMBTOE$0$0({1}SX:U),J,0,0
S:G$SMBFTE$0$0({1}SX:U),J,0,0
S:G$AA$0$0({1}SX:U),J,0,0
S:G$SI$0$0({1}SX:U),J,0,0
S:G$STO$0$0({1}SX:U),J,0,0
S:G$STA$0$0({1}SX:U),J,0,0
S:G$ENSMB$0$0({1}SX:U),J,0,0
S:G$BUSY$0$0({1}SX:U),J,0,0
S:G$CPRL2$0$0({1}SX:U),J,0,0
S:G$CT2$0$0({1}SX:U),J,0,0
S:G$TR2$0$0({1}SX:U),J,0,0
S:G$EXEN2$0$0({1}SX:U),J,0,0
S:G$TCLK$0$0({1}SX:U),J,0,0
S:G$RCLK$0$0({1}SX:U),J,0,0
S:G$EXF2$0$0({1}SX:U),J,0,0
S:G$TF2$0$0({1}SX:U),J,0,0
S:G$P$0$0({1}SX:U),J,0,0
S:G$F1$0$0({1}SX:U),J,0,0
S:G$OV$0$0({1}SX:U),J,0,0
S:G$RS0$0$0({1}SX:U),J,0,0
S:G$RS1$0$0({1}SX:U),J,0,0
S:G$F0$0$0({1}SX:U),J,0,0
S:G$AC$0$0({1}SX:U),J,0,0
S:G$CY$0$0({1}SX:U),J,0,0
S:G$CCF0$0$0({1}SX:U),J,0,0
S:G$CCF1$0$0({1}SX:U),J,0,0
S:G$CCF2$0$0({1}SX:U),J,0,0
S:G$CCF3$0$0({1}SX:U),J,0,0
S:G$CCF4$0$0({1}SX:U),J,0,0
S:G$CR$0$0({1}SX:U),J,0,0
S:G$CF$0$0({1}SX:U),J,0,0
S:G$ADLJST$0$0({1}SX:U),J,0,0
S:G$AD0LJST$0$0({1}SX:U),J,0,0
S:G$ADWINT$0$0({1}SX:U),J,0,0
S:G$AD0WINT$0$0({1}SX:U),J,0,0
S:G$ADSTM0$0$0({1}SX:U),J,0,0
S:G$AD0CM0$0$0({1}SX:U),J,0,0
S:G$ADSTM1$0$0({1}SX:U),J,0,0
S:G$AD0CM1$0$0({1}SX:U),J,0,0
S:G$ADBUSY$0$0({1}SX:U),J,0,0
S:G$AD0BUSY$0$0({1}SX:U),J,0,0
S:G$ADCINT$0$0({1}SX:U),J,0,0
S:G$AD0INT$0$0({1}SX:U),J,0,0
S:G$ADCTM$0$0({1}SX:U),J,0,0
S:G$AD0TM$0$0({1}SX:U),J,0,0
S:G$ADCEN$0$0({1}SX:U),J,0,0
S:G$AD0EN$0$0({1}SX:U),J,0,0
S:G$SPIEN$0$0({1}SX:U),J,0,0
S:G$MSTEN$0$0({1}SX:U),J,0,0
S:G$SLVSEL$0$0({1}SX:U),J,0,0
S:G$TXBSY$0$0({1}SX:U),J,0,0
S:G$RXOVRN$0$0({1}SX:U),J,0,0
S:G$MODF$0$0({1}SX:U),J,0,0
S:G$WCOL$0$0({1}SX:U),J,0,0
S:G$SPIF$0$0({1}SX:U),J,0,0
S:G$SYSCLK_Init$0$0({2}DF,SV:S),C,0,0
S:G$UART0_Init$0$0({2}DF,SV:S),C,0,0
S:G$Sys_Init$0$0({2}DF,SV:S),C,0,0
S:G$getchar_nw$0$0({2}DF,SC:U),C,0,0
S:G$_print_format$0$0({2}DF,SI:S),C,0,0
S:G$printf_small$0$0({2}DF,SV:S),C,0,0
S:G$printf$0$0({2}DF,SI:S),C,0,0
S:G$vprintf$0$0({2}DF,SI:S),C,0,0
S:G$sprintf$0$0({2}DF,SI:S),C,0,0
S:G$vsprintf$0$0({2}DF,SI:S),C,0,0
S:G$puts$0$0({2}DF,SI:S),C,0,0
S:G$getchar$0$0({2}DF,SC:U),C,0,0
S:G$putchar$0$0({2}DF,SV:S),C,0,0
S:G$printf_fast$0$0({2}DF,SV:S),C,0,0
S:G$printf_fast_f$0$0({2}DF,SV:S),C,0,0
S:G$printf_tiny$0$0({2}DF,SV:S),C,0,0
S:G$atof$0$0({2}DF,SF:S),C,0,0
S:G$atoi$0$0({2}DF,SI:S),C,0,0
S:G$atol$0$0({2}DF,SL:S),C,0,0
S:G$_uitoa$0$0({2}DF,SV:S),C,0,0
S:G$_itoa$0$0({2}DF,SV:S),C,0,0
S:G$_ultoa$0$0({2}DF,SV:S),C,0,0
S:G$_ltoa$0$0({2}DF,SV:S),C,0,0
S:G$rand$0$0({2}DF,SI:S),C,0,0
S:G$srand$0$0({2}DF,SV:S),C,0,0
S:G$calloc$0$0({2}DF,DX,SV:S),C,0,0
S:G$malloc$0$0({2}DF,DX,SV:S),C,0,0
S:G$realloc$0$0({2}DF,DX,SV:S),C,0,0
S:G$aligned_alloc$0$0({2}DF,DG,SV:S),C,0,0
S:G$free$0$0({2}DF,SV:S),C,0,0
S:G$abs$0$0({2}DF,SI:S),C,0,0
S:G$labs$0$0({2}DF,SL:S),C,0,0
S:G$mblen$0$0({2}DF,SI:S),C,0,0
S:G$mbtowc$0$0({2}DF,SI:S),C,0,0
S:G$wctomb$0$0({2}DF,SI:S),C,0,0
S:G$time$0$0({2}DF,SL:U),C,0,0
S:G$gmtime$0$0({2}DF,DG,STtm:S),C,0,0
S:G$localtime$0$0({2}DF,DG,STtm:S),C,0,0
S:G$mktime$0$0({2}DF,SL:U),C,0,0
S:G$asctime$0$0({2}DF,DG,SC:U),C,0,0
S:G$ctime$0$0({2}DF,DG,SC:U),C,0,0
S:G$main$0$0({2}DF,SV:S),C,0,0
|
AdaCore/libadalang | Ada | 691 | adb | with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
package body Support is
-----------------------------
-- Unit_Requested_Callback --
-----------------------------
overriding procedure Unit_Requested_Callback
(Self : in out My_EH;
Context : Analysis_Context'Class;
Name : Text_Type;
From : Analysis_Unit'Class;
Found : Boolean;
Is_Not_Found_Error : Boolean) is
begin
if not Found and then Is_Not_Found_Error then
Put_Line ("Missing " & Simple_Name (Image (Name)));
end if;
end Unit_Requested_Callback;
end Support;
|
sungyeon/drake | Ada | 11,038 | ads | pragma License (Unrestricted);
with Ada.IO_Exceptions;
with Ada.Text_IO;
package Ada.Wide_Wide_Text_IO is
-- modified
-- type File_Type is limited private;
subtype File_Type is Text_IO.File_Type;
-- AI12-0054-2, Text_IO (see A.10.1) could have used predicates to describe
-- some common exceptional conditions as follows:
-- subtype Open_File_Type is File_Type
-- with
-- Dynamic_Predicate => Is_Open (Open_File_Type),
-- Predicate_Failure => raise Status_Error with "File not open";
-- subtype Input_File_Type is Open_File_Type
-- with
-- Dynamic_Predicate => Mode (Input_File_Type) = In_File,
-- Predicate_Failure =>
-- raise Mode_Error with
-- "Cannot read file: " & Name (Input_File_Type);
-- subtype Output_File_Type is Open_File_Type
-- with
-- Dynamic_Predicate => Mode (Output_File_Type) /= In_File,
-- Predicate_Failure =>
-- raise Mode_Error with
-- "Cannot write file: " & Name (Output_File_Type);
-- type File_Mode is (In_File, Out_File, Append_File);
subtype File_Mode is Text_IO.File_Mode;
function In_File return File_Mode
renames Text_IO.In_File;
function Out_File return File_Mode
renames Text_IO.Out_File;
function Append_File return File_Mode
renames Text_IO.Append_File;
-- type Count is range 0 .. implementation-defined;
subtype Count is Text_IO.Count;
subtype Positive_Count is Count range 1 .. Count'Last;
Unbounded : constant Count := 0;
subtype Field is
Integer range 0 .. Text_IO.Field'Last; -- implementation-defined
subtype Number_Base is Integer range 2 .. 16;
-- type Type_Set is (Lower_Case, Upper_Case);
subtype Type_Set is Text_IO.Type_Set;
function Lower_Case return Type_Set
renames Text_IO.Lower_Case;
function Upper_Case return Type_Set
renames Text_IO.Upper_Case;
-- File Management
procedure Create (
File : in out File_Type;
Mode : File_Mode := Out_File;
Name : String := "";
Form : String := "")
renames Text_IO.Create;
procedure Open (
File : in out File_Type;
Mode : File_Mode;
Name : String;
Form : String := "")
renames Text_IO.Open;
procedure Close (File : in out File_Type)
renames Text_IO.Close;
procedure Delete (File : in out File_Type)
renames Text_IO.Delete;
procedure Reset (File : in out File_Type; Mode : File_Mode)
renames Text_IO.Reset;
procedure Reset (File : in out File_Type)
renames Text_IO.Reset;
function Mode (
File : File_Type) -- Open_File_Type
return File_Mode
renames Text_IO.Mode;
function Name (
File : File_Type) -- Open_File_Type
return String
renames Text_IO.Name;
function Form (
File : File_Type) -- Open_File_Type
return String
renames Text_IO.Form;
function Is_Open (File : File_Type) return Boolean
renames Text_IO.Is_Open;
-- Control of default input and output files
procedure Set_Input (File : File_Type)
renames Text_IO.Set_Input;
procedure Set_Output (File : File_Type)
renames Text_IO.Set_Output;
procedure Set_Error (File : File_Type)
renames Text_IO.Set_Error;
-- function Standard_Input return File_Type;
-- function Standard_Output return File_Type;
-- function Standard_Error return File_Type;
-- function Current_Input return File_Type;
-- function Current_Output return File_Type;
-- function Current_Error return File_Type;
-- type File_Access is access constant File_Type;
subtype File_Access is Text_IO.File_Access;
function Standard_Input return File_Access
renames Text_IO.Standard_Input;
function Standard_Output return File_Access
renames Text_IO.Standard_Output;
function Standard_Error return File_Access
renames Text_IO.Standard_Error;
function Current_Input return File_Access
renames Text_IO.Current_Input;
function Current_Output return File_Access
renames Text_IO.Current_Output;
function Current_Error return File_Access
renames Text_IO.Current_Error;
-- Buffer control
procedure Flush (
File : File_Type) -- Output_File_Type
renames Text_IO.Flush;
procedure Flush
renames Text_IO.Flush;
-- Specification of line and page lengths
procedure Set_Line_Length (
File : File_Type; -- Output_File_Type
To : Count)
renames Text_IO.Set_Line_Length;
procedure Set_Line_Length (To : Count)
renames Text_IO.Set_Line_Length;
procedure Set_Page_Length (
File : File_Type; -- Output_File_Type
To : Count)
renames Text_IO.Set_Page_Length;
procedure Set_Page_Length (To : Count)
renames Text_IO.Set_Page_Length;
function Line_Length (
File : File_Type) -- Output_File_Type
return Count
renames Text_IO.Line_Length;
function Line_Length return Count
renames Text_IO.Line_Length;
function Page_Length (
File : File_Type) -- Output_File_Type
return Count
renames Text_IO.Page_Length;
function Page_Length return Count
renames Text_IO.Page_Length;
-- Column, Line, and Page Control
procedure New_Line (
File : File_Type; -- Output_File_Type
Spacing : Positive_Count := 1)
renames Text_IO.New_Line;
procedure New_Line (Spacing : Positive_Count := 1)
renames Text_IO.New_Line;
procedure Skip_Line (
File : File_Type; -- Input_File_Type
Spacing : Positive_Count := 1)
renames Text_IO.Skip_Line;
procedure Skip_Line (Spacing : Positive_Count := 1)
renames Text_IO.Skip_Line;
function End_Of_Line (
File : File_Type) -- Input_File_Type
return Boolean
renames Text_IO.End_Of_Line;
function End_Of_Line return Boolean
renames Text_IO.End_Of_Line;
procedure New_Page (
File : File_Type) -- Output_File_Type
renames Text_IO.New_Page;
procedure New_Page
renames Text_IO.New_Page;
procedure Skip_Page (
File : File_Type) -- Input_File_Type
renames Text_IO.Skip_Page;
procedure Skip_Page
renames Text_IO.Skip_Page;
function End_Of_Page (
File : File_Type) -- Input_File_Type
return Boolean
renames Text_IO.End_Of_Page;
function End_Of_Page return Boolean
renames Text_IO.End_Of_Page;
function End_Of_File (
File : File_Type) -- Input_File_Type
return Boolean
renames Text_IO.End_Of_File;
function End_Of_File return Boolean
renames Text_IO.End_Of_File;
procedure Set_Col (
File : File_Type; -- Open_File_Type
To : Positive_Count)
renames Text_IO.Set_Col;
procedure Set_Col (To : Positive_Count)
renames Text_IO.Set_Col;
procedure Set_Line (
File : File_Type; -- Open_File_Type
To : Positive_Count)
renames Text_IO.Set_Line;
procedure Set_Line (To : Positive_Count)
renames Text_IO.Set_Line;
function Col (
File : File_Type) -- Open_File_Type
return Positive_Count
renames Text_IO.Col;
function Col return Positive_Count
renames Text_IO.Col;
function Line (
File : File_Type) -- Open_File_Type
return Positive_Count
renames Text_IO.Line;
function Line return Positive_Count
renames Text_IO.Line;
function Page (
File : File_Type) -- Open_File_Type
return Positive_Count
renames Text_IO.Page;
function Page return Positive_Count
renames Text_IO.Page;
-- Character Input-Output
procedure Get (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_Character)
renames Text_IO.Overloaded_Get;
procedure Get (Item : out Wide_Wide_Character)
renames Text_IO.Overloaded_Get;
procedure Put (
File : File_Type; -- Output_File_Type
Item : Wide_Wide_Character)
renames Text_IO.Overloaded_Put;
procedure Put (Item : Wide_Wide_Character)
renames Text_IO.Overloaded_Put;
procedure Look_Ahead (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_Character;
End_Of_Line : out Boolean)
renames Text_IO.Overloaded_Look_Ahead;
procedure Look_Ahead (
Item : out Wide_Wide_Character;
End_Of_Line : out Boolean)
renames Text_IO.Overloaded_Look_Ahead;
procedure Get_Immediate (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_Character)
renames Text_IO.Overloaded_Get_Immediate;
procedure Get_Immediate (Item : out Wide_Wide_Character)
renames Text_IO.Overloaded_Get_Immediate;
procedure Get_Immediate (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_Character;
Available : out Boolean)
renames Text_IO.Overloaded_Get_Immediate;
procedure Get_Immediate (
Item : out Wide_Wide_Character;
Available : out Boolean)
renames Text_IO.Overloaded_Get_Immediate;
-- String Input-Output
procedure Get (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_String)
renames Text_IO.Overloaded_Get;
procedure Get (Item : out Wide_Wide_String)
renames Text_IO.Overloaded_Get;
procedure Put (
File : File_Type; -- Output_File_Type
Item : Wide_Wide_String)
renames Text_IO.Overloaded_Put;
procedure Put (Item : Wide_Wide_String)
renames Text_IO.Overloaded_Put;
procedure Get_Line (
File : File_Type; -- Input_File_Type
Item : out Wide_Wide_String;
Last : out Natural)
renames Text_IO.Overloaded_Get_Line;
procedure Get_Line (
Item : out Wide_Wide_String;
Last : out Natural)
renames Text_IO.Overloaded_Get_Line;
function Get_Line (
File : File_Type) -- Input_File_Type
return Wide_Wide_String
renames Text_IO.Overloaded_Get_Line;
function Get_Line return Wide_Wide_String
renames Text_IO.Overloaded_Get_Line;
procedure Put_Line (
File : File_Type; -- Output_File_Type
Item : Wide_Wide_String)
renames Text_IO.Overloaded_Put_Line;
procedure Put_Line (Item : Wide_Wide_String)
renames Text_IO.Overloaded_Put_Line;
-- Generic packages for Input-Output of Integer Types
-- Generic packages for Input-Output of Real Types
-- Generic package for Input-Output of Enumeration Types
-- Note: Integer_IO, Modular_IO, Float_IO, Fixed_IO, Decimal_IO, and
-- Enumeration_IO are separated by compiler.
-- Exceptions
Status_Error : exception
renames IO_Exceptions.Status_Error;
Mode_Error : exception
renames IO_Exceptions.Mode_Error;
Name_Error : exception
renames IO_Exceptions.Name_Error;
Use_Error : exception
renames IO_Exceptions.Use_Error;
Device_Error : exception
renames IO_Exceptions.Device_Error;
End_Error : exception
renames IO_Exceptions.End_Error;
Data_Error : exception
renames IO_Exceptions.Data_Error;
Layout_Error : exception
renames IO_Exceptions.Layout_Error;
end Ada.Wide_Wide_Text_IO;
|
A1rPun/nurture | Ada | 110 | adb | with Ada.Text_IO;
use Ada.Text_IO;
procedure Helloworld is
begin
Put_Line("hello, world");
end HelloWorld;
|
rveenker/sdlada | Ada | 23,304 | adb | --------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with Interfaces.C;
with SDL.Error;
package body SDL.Video.Renderers is
package C renames Interfaces.C;
use type C.int;
use type SDL.C_Pointers.Renderer_Pointer;
type Internal_Flip is mod 2 ** 32 with
Convention => C;
-- type Internal_Flip_Array is array (Renderer_Flip) of Internal_Flip;
Internal_Flip_None : constant Internal_Flip := 16#0000_0000#;
Internal_Flip_Horizontal : constant Internal_Flip := 16#0000_0001#;
Internal_Flip_Vertical : constant Internal_Flip := 16#0000_0002#;
Internal_Flips : constant array (Renderer_Flip) of Internal_Flip :=
(Internal_Flip_None,
Internal_Flip_Horizontal,
Internal_Flip_Vertical,
Internal_Flip_Horizontal or Internal_Flip_Vertical);
function Get_Internal_Window (Self : in SDL.Video.Windows.Window) return SDL.C_Pointers.Windows_Pointer with
Convention => Ada,
Import => True;
function Get_Internal_Texture (Self : in SDL.Video.Textures.Texture) return SDL.C_Pointers.Texture_Pointer with
Import => True,
Convention => Ada;
function Total_Drivers return Positive is
function SDL_Get_Num_Render_Drivers return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetNumRenderDrivers";
Result : C.int := SDL_Get_Num_Render_Drivers;
begin
if Result < C.int (Positive'First) then
raise Renderer_Error with SDL.Error.Get;
end if;
return Positive (Result);
end Total_Drivers;
overriding
procedure Finalize (Self : in out Renderer) is
procedure SDL_Destroy_Renderer (R : in SDL.C_Pointers.Renderer_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_DestroyRenderer";
begin
if Self.Internal /= null and then Self.Owns then
SDL_Destroy_Renderer (Self.Internal);
Self.Internal := null;
end if;
end Finalize;
function Get_Blend_Mode (Self : in Renderer) return Blend_Modes is
function SDL_Get_Render_Draw_Blend_Mode (R : in SDL.C_Pointers.Renderer_Pointer;
M : out Blend_Modes) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetRenderDrawBlendMode";
Mode : Blend_Modes;
Result : C.int := SDL_Get_Render_Draw_Blend_Mode (Self.Internal, Mode);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
return Mode;
end Get_Blend_Mode;
procedure Set_Blend_Mode (Self : in out Renderer; Mode : in Blend_Modes) is
function SDL_Set_Render_Draw_Blend_Mode (R : in SDL.C_Pointers.Renderer_Pointer;
M : in Blend_Modes) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetRenderDrawBlendMode";
Result : C.int := SDL_Set_Render_Draw_Blend_Mode (Self.Internal, Mode);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Blend_Mode;
function Get_Draw_Colour (Self : in Renderer) return SDL.Video.Palettes.Colour is
function SDL_Get_Render_Draw_Color
(R : in SDL.C_Pointers.Renderer_Pointer;
Red, Green, Blue, Alpha : out SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetRenderDrawColor";
Colour : SDL.Video.Palettes.Colour;
Result : C.int := SDL_Get_Render_Draw_Color (Self.Internal, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
return Colour;
end Get_Draw_Colour;
procedure Set_Draw_Colour (Self : in out Renderer; Colour : in SDL.Video.Palettes.Colour) is
function SDL_Set_Render_Draw_Color
(R : in SDL.C_Pointers.Renderer_Pointer;
Red, Green, Blue, Alpha : in SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetRenderDrawColor";
Result : C.int := SDL_Set_Render_Draw_Color (Self.Internal, Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Draw_Colour;
procedure Clear (Self : in out Renderer) is
function SDL_Render_Clear (R : in SDL.C_Pointers.Renderer_Pointer) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderClear";
Result : C.int := SDL_Render_Clear (Self.Internal);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Clear;
procedure Copy
(Self : in out Renderer;
Copy_From : in SDL.Video.Textures.Texture) is
function SDL_Render_Copy
(R : in SDL.C_Pointers.Renderer_Pointer;
T : in SDL.C_Pointers.Texture_Pointer;
Src, Dest : in SDL.Video.Rectangles.Rectangle_Access) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderCopy";
Result : C.int := SDL_Render_Copy (Self.Internal,
Get_Internal_Texture (Copy_From),
null,
null);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Copy;
-- TODO: Check to make sure this works, if it does, apply the same logic to CopyEx, see below.
procedure Copy
(Self : in out Renderer;
Copy_From : in SDL.Video.Textures.Texture;
From : in SDL.Video.Rectangles.Rectangle;
To : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Copy
(R : in SDL.C_Pointers.Renderer_Pointer;
T : in SDL.C_Pointers.Texture_Pointer;
Src, Dest : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderCopy";
Result : C.int := SDL_Render_Copy (Self.Internal,
Get_Internal_Texture (Copy_From),
From,
To);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Copy;
procedure Copy
(Self : in out Renderer;
Copy_From : in SDL.Video.Textures.Texture;
To : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Copy
(R : in SDL.C_Pointers.Renderer_Pointer;
T : in SDL.C_Pointers.Texture_Pointer;
Src : in SDL.Video.Rectangles.Rectangle_Access;
Dest : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderCopy";
Result : C.int := SDL_Render_Copy (Self.Internal,
Get_Internal_Texture (Copy_From),
null,
To);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Copy;
-- TODO: See above, rearrange the params so that the rectangles are the last elements and make
-- them default to null_rectangle.
procedure Copy
(Self : in out Renderer;
Copy_From : in SDL.Video.Textures.Texture;
From : in SDL.Video.Rectangles.Rectangle;
To : in SDL.Video.Rectangles.Rectangle;
Angle : in Long_Float;
Centre : in SDL.Video.Rectangles.Point;
Flip : in Renderer_Flip) is
function SDL_Render_Copy_Ex
(R : in SDL.C_Pointers.Renderer_Pointer;
T : in SDL.C_Pointers.Texture_Pointer;
Src, Dest : in SDL.Video.Rectangles.Rectangle;
A : in C.double;
Centre : in SDL.Video.Rectangles.Point;
F : in Internal_Flip) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderCopyEx";
Result : C.int := SDL_Render_Copy_Ex (Self.Internal,
Get_Internal_Texture (Copy_From),
From,
To,
C.double (Angle),
Centre,
Internal_Flips (Flip));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Copy;
procedure Draw (Self : in out Renderer; Line : in SDL.Video.Rectangles.Line_Segment) is
function SDL_Render_Draw_Line (R : in SDL.C_Pointers.Renderer_Pointer;
X1, Y1, X2, Y2 : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawLine";
Result : C.int := SDL_Render_Draw_Line (Self.Internal, Line.Start.X, Line.Start.Y, Line.Finish.X, Line.Finish.Y);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
-- TODO: Check this works!
procedure Draw (Self : in out Renderer; Lines : in SDL.Video.Rectangles.Line_Arrays) is
-- As the records and arrays are defined as C types, an array of lines is also an array of points.
function SDL_Render_Draw_Lines (R : in SDL.C_Pointers.Renderer_Pointer;
P : in SDL.Video.Rectangles.Line_Arrays;
Count : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawLines";
Result : C.int := SDL_Render_Draw_Lines (Self.Internal, Lines, C.int (Lines'Length * 2));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
procedure Draw (Self : in out Renderer; Point : in SDL.Video.Rectangles.Point) is
function SDL_Render_Draw_Point (R : in SDL.C_Pointers.Renderer_Pointer; X, Y : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawPoint";
Result : C.int := SDL_Render_Draw_Point (Self.Internal, Point.X, Point.Y);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
procedure Draw (Self : in out Renderer; Points : in SDL.Video.Rectangles.Point_Arrays) is
function SDL_Render_Draw_Points (R : in SDL.C_Pointers.Renderer_Pointer;
P : in SDL.Video.Rectangles.Point_Arrays;
Count : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawPoints";
Result : C.int := SDL_Render_Draw_Points (Self.Internal, Points, C.int (Points'Length));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
procedure Draw (Self : in out Renderer; Rectangle : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Draw_Rect (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawRect";
Result : C.int := SDL_Render_Draw_Rect (Self.Internal, Rectangle);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
procedure Draw (Self : in out Renderer; Rectangles : in SDL.Video.Rectangles.Rectangle_Arrays) is
function SDL_Render_Draw_Rects (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle_Arrays;
Count : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderDrawRects";
Result : C.int := SDL_Render_Draw_Rects (Self.Internal, Rectangles, C.int (Rectangles'Length));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Draw;
procedure Fill (Self : in out Renderer; Rectangle : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Fill_Rect (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderFillRect";
Result : C.int := SDL_Render_Fill_Rect (Self.Internal, Rectangle);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Fill;
procedure Fill (Self : in out Renderer; Rectangles : in SDL.Video.Rectangles.Rectangle_Arrays) is
function SDL_Render_Fill_Rects (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle_Arrays;
Count : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderFillRects";
Result : C.int := SDL_Render_Fill_Rects (Self.Internal, Rectangles, C.int (Rectangles'Length));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Fill;
procedure Get_Clip (Self : in Renderer; Rectangle : out SDL.Video.Rectangles.Rectangle) is
procedure SDL_Render_Get_Clip_Rect (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : out SDL.Video.Rectangles.Rectangle) with
Import => True,
Convention => C,
External_Name => "SDL_RenderGetClipRect";
begin
SDL_Render_Get_Clip_Rect (Self.Internal, Rectangle);
end Get_Clip;
procedure Set_Clip (Self : in out Renderer; Rectangle : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Set_Clip_Rect (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderSetClipRect";
Result : C.int := SDL_Render_Set_Clip_Rect (Self.Internal, Rectangle);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Clip;
procedure Get_Logical_Size (Self : in Renderer; Size : out SDL.Sizes) is
procedure SDL_Render_Get_Logical_Size (R : in SDL.C_Pointers.Renderer_Pointer;
S : out SDL.Sizes) with
Import => True,
Convention => C,
External_Name => "SDL_RenderGetLogicalSize";
begin
SDL_Render_Get_Logical_Size (Self.Internal, Size);
end Get_Logical_Size;
procedure Set_Logical_Size (Self : in out Renderer; Size : in SDL.Sizes) is
function SDL_Render_Set_Logical_Size (R : in SDL.C_Pointers.Renderer_Pointer;
S : in SDL.Sizes) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderSetLogicalSize";
Result : C.int := SDL_Render_Set_Logical_Size (Self.Internal, Size);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Logical_Size;
procedure Get_Scale (Self : in Renderer; X, Y : out Float) is
procedure SDL_Render_Get_Scale (R : in SDL.C_Pointers.Renderer_Pointer; X, Y : out C.C_float) with
Import => True,
Convention => C,
External_Name => "SDL_RenderGetScale";
begin
SDL_Render_Get_Scale (Self.Internal, C.C_float (X), C.C_float (Y));
end Get_Scale;
procedure Set_Scale (Self : in out Renderer; X, Y : in Float) is
function SDL_Render_Set_Scale (R : in SDL.C_Pointers.Renderer_Pointer; X, Y : in C.C_float) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderSetScale";
Result : C.int := SDL_Render_Set_Scale (Self.Internal, C.C_float (X), C.C_float (Y));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Scale;
procedure Get_Viewport (Self : in Renderer; Rectangle : out SDL.Video.Rectangles.Rectangle) is
procedure SDL_Render_Get_Viewport (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : out SDL.Video.Rectangles.Rectangle) with
Import => True,
Convention => C,
External_Name => "SDL_RenderGetViewport";
begin
SDL_Render_Get_Viewport (Self.Internal, Rectangle);
end Get_Viewport;
procedure Set_Viewport (Self : in out Renderer; Rectangle : in SDL.Video.Rectangles.Rectangle) is
function SDL_Render_Set_Viewport (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : in SDL.Video.Rectangles.Rectangle) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderSetViewport";
Result : C.int := SDL_Render_Set_Viewport (Self.Internal, Rectangle);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Viewport;
procedure Present (Self : in Renderer) is
procedure SDL_Render_Present (R : in SDL.C_Pointers.Renderer_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_RenderPresent";
begin
SDL_Render_Present (Self.Internal);
end Present;
procedure Read_Pixels (Self : in Renderer;
Rectangle : access SDL.Video.Rectangles.Rectangle;
Format : in SDL.Video.Pixel_Formats.Pixel_Format_Names;
Pixels : in C.Strings.chars_ptr;
Pitch : in Interfaces.C.int) is
-- Convert the Pixel_Format_Name to an Unsigned_32 because the compiler is changing the value somewhere along
-- the lines from the start of this procedure to calling SDL_Create_Texture.
function To_Unsigned32 is new Ada.Unchecked_Conversion (Source => SDL.Video.Pixel_Formats.Pixel_Format_Names,
Target => Interfaces.Unsigned_32);
function SDL_Render_Read_Pixels (R : in SDL.C_Pointers.Renderer_Pointer;
Rect : access SDL.Video.Rectangles.Rectangle;
Format : in Interfaces.Unsigned_32;
Pixels : in C.Strings.chars_ptr;
Pitch : in C.int) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_RenderReadPixels";
Result : C.int := SDL_Render_Read_Pixels (Self.Internal,
Rectangle,
To_Unsigned32 (Format),
Pixels,
Pitch);
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Read_Pixels;
function Supports_Targets (Self : in Renderer) return Boolean is
function SDL_Render_Target_Supported (R : in SDL.C_Pointers.Renderer_Pointer) return SDL_Bool with
Import => True,
Convention => C,
External_Name => "SDL_RenderTargetSupported";
begin
return (if SDL_Render_Target_Supported (Self.Internal) = SDL_True then True else False);
end Supports_Targets;
procedure Set_Target (Self : in out Renderer; Target : in SDL.Video.Textures.Texture) is
function SDL_Set_Render_Target (R : in SDL.C_Pointers.Renderer_Pointer;
T : in SDL.C_Pointers.Texture_Pointer) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetRenderTarget";
Result : C.int := SDL_Set_Render_Target (Self.Internal, Get_Internal_Texture (Target));
begin
if Result /= Success then
raise Renderer_Error with SDL.Error.Get;
end if;
end Set_Target;
function Get_Renderer (Window : in SDL.Video.Windows.Window) return Renderer is
function SDL_Get_Renderer (W : in SDL.C_Pointers.Windows_Pointer) return SDL.C_Pointers.Renderer_Pointer with
Import => True,
Convention => C,
External_Name => "SDL_GetRenderer";
begin
return Result : constant Renderer :=
(Ada.Finalization.Limited_Controlled with
Internal => SDL_Get_Renderer (Get_Internal_Window (Window)), Owns => False) do
null;
end return;
end Get_Renderer;
procedure Get_Renderer (Self : in out Renderer;
From_Window : in SDL.Video.Windows.Window) is
begin
Self.Internal := Get_Renderer (From_Window).Internal;
if Self.Internal = null then
raise Constraint_Error;
end if;
end Get_Renderer;
function Get_Internal_Renderer (Self : in Renderer) return SDL.C_Pointers.Renderer_Pointer is
begin
return Self.Internal;
end Get_Internal_Renderer;
end SDL.Video.Renderers;
|
Fabien-Chouteau/AGATE | Ada | 11,376 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017-2020, Fabien Chouteau --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with System; use System;
with AGATE.Traces;
with AGATE.Scheduler.Context_Switch;
with AGATE.Arch; use AGATE.Arch;
with AGATE.Timer;
with AGATE.Stack_Canaries_Enable;
package body AGATE.Scheduler is
Alarm_List : Task_Object_Access := null;
Idle_Stack : aliased Task_Stack := (1 .. 512 => 0);
Idle_Sec_Stack : aliased Task_Sec_Stack := (1 .. 0 => 0);
Idle_Heap : aliased Task_Heap := (1 .. 0 => 0);
Idle_Task : aliased Task_Object
(Proc => AGATE.Arch.Idle_Procedure'Access,
Base_Prio => -1,
Stack => Idle_Stack'Access,
Sec_Stack => Idle_Sec_Stack'Access,
Heap => Idle_Heap'Access);
function In_Ready_Tasks (ID : Task_ID) return Boolean;
procedure Extract (ID : Task_ID);
procedure Insert (ID : Task_ID)
with Pre => not In_Ready_Tasks (ID);
procedure Insert_Alarm
(T : Task_Object_Access);
procedure Update_Alarm_Time;
--------------
-- Register --
--------------
procedure Register
(ID : Task_ID;
Name : String)
is
T : constant Task_Object_Access := Task_Object_Access (ID);
begin
T.Status := Ready;
T.Name (Task_Name'First .. Task_Name'First + Name'Length - 1) := Name;
T.Current_Prio := T.Base_Prio;
Initialize_Task_Context (ID);
if AGATE.Stack_Canaries_Enable.Enabled then
Set_Stack_Canary (ID);
end if;
Insert (Task_ID (T));
ID.All_Task_Next := All_Tasks_List;
All_Tasks_List := Task_Object_Access (ID);
Traces.Register (Task_ID (T), T.Name);
end Register;
-----------
-- Start --
-----------
procedure Start is
begin
if Ready_Tasks = null then
raise Program_Error with "No task to run";
end if;
Register (Idle_Task'Access, "idle");
Running_Task := Ready_Tasks;
Jump_In_Task (Task_ID (Running_Task));
end Start;
------------------
-- Current_Task --
------------------
function Current_Task
return Task_ID
is (Task_ID (Running_Task));
--------------------------
-- Current_Task_Context --
--------------------------
function Current_Task_Context
return System.Address
is
begin
return Running_Task.Context (Running_Task.Context'First)'Address;
end Current_Task_Context;
-----------------
-- Task_To_Run --
-----------------
function Task_To_Run
return Task_ID
is (Task_ID (Ready_Tasks));
--------------------
-- In_Ready_Tasks --
--------------------
function In_Ready_Tasks
(ID : Task_ID)
return Boolean
is
T : Task_Object_Access := Ready_Tasks;
begin
while T /= null and then Task_ID (T) /= ID loop
T := T.Next;
end loop;
return Task_ID (T) = ID;
end In_Ready_Tasks;
----------------------
-- Print_Read_Tasks --
----------------------
procedure Print_Ready_Tasks
is
T : Task_Object_Access := Ready_Tasks;
begin
-- Ada.Text_IO.Put_Line ("Ready tasks:");
while T /= null loop
-- Ada.Text_IO.Put_Line (" - " & Image (Task_ID (T)));
T := T.Next;
end loop;
end Print_Ready_Tasks;
-------------
-- Extract --
-------------
procedure Extract
(ID : Task_ID)
is
Prev, Curr : Task_Object_Access;
begin
if Task_ID (Ready_Tasks) = ID then
-- Extract head
Ready_Tasks := Ready_Tasks.Next;
ID.Next := null;
else
-- Extract from inside the list
Prev := null;
Curr := Ready_Tasks;
while Curr /= null and then Task_ID (Curr) /= ID loop
Prev := Curr;
Curr := Curr.Next;
end loop;
if Task_ID (Curr) = ID then
Prev.Next := Curr.Next;
ID.Next := null;
end if;
end if;
end Extract;
------------
-- Insert --
------------
procedure Insert
(ID : Task_ID)
is
Acc : constant Task_Object_Access := Task_Object_Access (ID);
Cur : Task_Object_Access := Ready_Tasks;
Prev : Task_Object_Access := null;
begin
Acc.Next := null;
while Cur /= null and then Cur.Current_Prio >= Acc.Current_Prio loop
Prev := Cur;
Cur := Cur.Next;
end loop;
Acc.Next := Cur;
if Prev = null then
-- Head insertion
Ready_Tasks := Acc;
else
Prev.Next := Acc;
end if;
end Insert;
-----------
-- Yield --
-----------
procedure Yield
is
begin
Extract (Current_Task);
Insert (Current_Task);
Current_Task.Status := Ready;
if Context_Switch_Needed then
Context_Switch.Switch;
end if;
end Yield;
------------
-- Resume --
------------
procedure Resume
(ID : Task_ID)
is
begin
Task_Object_Access (ID).Status := Ready;
Insert (ID);
Traces.Resume (ID);
if Context_Switch_Needed then
Context_Switch.Switch;
end if;
end Resume;
-------------
-- Suspend --
-------------
procedure Suspend
(Reason : Suspend_Reason)
is
begin
Extract (Current_Task);
Current_Task.Status := (case Reason is
when Alarm => Suspended_Alarm,
when Semaphore => Suspended_Semaphore,
when Mutex => Suspended_Mutex);
Traces.Suspend (Current_Task);
end Suspend;
-----------
-- Fault --
-----------
procedure Fault (ID : Task_ID) is
begin
Extract (ID);
ID.Status := Fault;
Traces.Fault (ID);
end Fault;
-----------
-- Fault --
-----------
procedure Fault is
begin
Fault (Current_Task);
end Fault;
---------------------
-- Change_Priority --
---------------------
procedure Change_Priority
(New_Prio : Task_Priority)
is
T : constant Task_ID := Current_Task;
begin
if New_Prio < T.Base_Prio then
raise Program_Error with
"Cannot set priority below the task base priority";
end if;
Traces.Change_Priority (T, New_Prio);
if New_Prio >= T.Current_Prio then
-- The current task already have the highest priority of the ready
-- task, by the properties of the FIFO within priorities scheduling.
-- So the current task position in the ready tasks list won't change,
-- We don't have to re-insert it.
T.Current_Prio := New_Prio;
else
Extract (T);
T.Current_Prio := New_Prio;
Insert (T);
end if;
end Change_Priority;
-----------------
-- Delay_Until --
-----------------
procedure Delay_Until
(Wake_Up_Time : Time)
is
T : constant Task_Object_Access := Task_Object_Access (Current_Task);
Now : constant Time := AGATE.Timer.Clock;
begin
if Wake_Up_Time <= Now then
Scheduler.Yield;
else
Scheduler.Suspend (Alarm);
T.Alarm_Time := Wake_Up_Time;
Insert_Alarm (T);
if Context_Switch_Needed then
Context_Switch.Switch;
end if;
end if;
end Delay_Until;
------------------
-- Insert_Alarm --
------------------
procedure Insert_Alarm
(T : Task_Object_Access)
is
Cur : Task_Object_Access := Alarm_List;
Prev : Task_Object_Access := null;
begin
while Cur /= null and then Cur.Alarm_Time < T.Alarm_Time loop
Prev := Cur;
Cur := Cur.Next;
end loop;
if Prev = null then
-- Head insertion
T.Next := Alarm_List;
Alarm_List := T;
else
Prev.Next := T;
T.Next := Cur;
end if;
Update_Alarm_Time;
end Insert_Alarm;
---------------------------
-- Wakeup_Expired_Alarms --
---------------------------
procedure Wakeup_Expired_Alarms
is
Now : constant Time := AGATE.Timer.Clock;
T : Task_Object_Access := Alarm_List;
begin
while Alarm_List /= null and then Alarm_List.Alarm_Time <= Now loop
T := Alarm_List;
Alarm_List := T.Next;
Scheduler.Resume (Task_ID (T));
end loop;
Update_Alarm_Time;
end Wakeup_Expired_Alarms;
-----------------------
-- Update_Alarm_Time --
-----------------------
procedure Update_Alarm_Time
is
begin
if Alarm_List = null then
AGATE.Timer.Set_Alarm (Time'Last);
else
AGATE.Timer.Set_Alarm (Alarm_List.Alarm_Time);
end if;
end Update_Alarm_Time;
---------------------------
-- Context_Switch_Needed --
---------------------------
function Context_Switch_Needed
return Boolean
is (Task_To_Run /= Current_Task);
-----------------------
-- Do_Context_Switch --
-----------------------
procedure Do_Context_Switch renames AGATE.Scheduler.Context_Switch.Switch;
end AGATE.Scheduler;
|
reznikmm/matreshka | Ada | 25,626 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2015, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Streams;
with League.Stream_Element_Vectors.Internals;
with League.Strings.Internals;
with Matreshka.Internals.Stream_Element_Vectors;
with Matreshka.Internals.Strings.Configuration;
with Matreshka.Internals.Utf16;
package body League.Base_Codecs is
use type Ada.Streams.Stream_Element;
use type Ada.Streams.Stream_Element_Offset;
use type Matreshka.Internals.Utf16.Utf16_Code_Unit;
use type Matreshka.Internals.Utf16.Utf16_String_Index;
procedure Decode_64
(Item : Matreshka.Internals.Utf16.Utf16_Code_Unit;
Value : out Ada.Streams.Stream_Element;
Success : out Boolean);
procedure Decode_64_URL
(Item : Matreshka.Internals.Utf16.Utf16_Code_Unit;
Value : out Ada.Streams.Stream_Element;
Success : out Boolean);
Encode_64 : constant
array (Ada.Streams.Stream_Element range 0 .. 63)
of Matreshka.Internals.Utf16.Utf16_Code_Unit
:= (Character'Pos ('A'), Character'Pos ('B'), Character'Pos ('C'),
Character'Pos ('D'), Character'Pos ('E'), Character'Pos ('F'),
Character'Pos ('G'), Character'Pos ('H'), Character'Pos ('I'),
Character'Pos ('J'), Character'Pos ('K'), Character'Pos ('L'),
Character'Pos ('M'), Character'Pos ('N'), Character'Pos ('O'),
Character'Pos ('P'), Character'Pos ('Q'), Character'Pos ('R'),
Character'Pos ('S'), Character'Pos ('T'), Character'Pos ('U'),
Character'Pos ('V'), Character'Pos ('W'), Character'Pos ('X'),
Character'Pos ('Y'), Character'Pos ('Z'), Character'Pos ('a'),
Character'Pos ('b'), Character'Pos ('c'), Character'Pos ('d'),
Character'Pos ('e'), Character'Pos ('f'), Character'Pos ('g'),
Character'Pos ('h'), Character'Pos ('i'), Character'Pos ('j'),
Character'Pos ('k'), Character'Pos ('l'), Character'Pos ('m'),
Character'Pos ('n'), Character'Pos ('o'), Character'Pos ('p'),
Character'Pos ('q'), Character'Pos ('r'), Character'Pos ('s'),
Character'Pos ('t'), Character'Pos ('u'), Character'Pos ('v'),
Character'Pos ('w'), Character'Pos ('x'), Character'Pos ('y'),
Character'Pos ('z'), Character'Pos ('0'), Character'Pos ('1'),
Character'Pos ('2'), Character'Pos ('3'), Character'Pos ('4'),
Character'Pos ('5'), Character'Pos ('6'), Character'Pos ('7'),
Character'Pos ('8'), Character'Pos ('9'), Character'Pos ('+'),
Character'Pos ('/'));
Encode_64_URL : constant
array (Ada.Streams.Stream_Element range 0 .. 63)
of Matreshka.Internals.Utf16.Utf16_Code_Unit
:= (Character'Pos ('A'), Character'Pos ('B'), Character'Pos ('C'),
Character'Pos ('D'), Character'Pos ('E'), Character'Pos ('F'),
Character'Pos ('G'), Character'Pos ('H'), Character'Pos ('I'),
Character'Pos ('J'), Character'Pos ('K'), Character'Pos ('L'),
Character'Pos ('M'), Character'Pos ('N'), Character'Pos ('O'),
Character'Pos ('P'), Character'Pos ('Q'), Character'Pos ('R'),
Character'Pos ('S'), Character'Pos ('T'), Character'Pos ('U'),
Character'Pos ('V'), Character'Pos ('W'), Character'Pos ('X'),
Character'Pos ('Y'), Character'Pos ('Z'), Character'Pos ('a'),
Character'Pos ('b'), Character'Pos ('c'), Character'Pos ('d'),
Character'Pos ('e'), Character'Pos ('f'), Character'Pos ('g'),
Character'Pos ('h'), Character'Pos ('i'), Character'Pos ('j'),
Character'Pos ('k'), Character'Pos ('l'), Character'Pos ('m'),
Character'Pos ('n'), Character'Pos ('o'), Character'Pos ('p'),
Character'Pos ('q'), Character'Pos ('r'), Character'Pos ('s'),
Character'Pos ('t'), Character'Pos ('u'), Character'Pos ('v'),
Character'Pos ('w'), Character'Pos ('x'), Character'Pos ('y'),
Character'Pos ('z'), Character'Pos ('0'), Character'Pos ('1'),
Character'Pos ('2'), Character'Pos ('3'), Character'Pos ('4'),
Character'Pos ('5'), Character'Pos ('6'), Character'Pos ('7'),
Character'Pos ('8'), Character'Pos ('9'), Character'Pos ('-'),
Character'Pos ('_'));
---------------
-- Decode_64 --
---------------
procedure Decode_64
(Item : Matreshka.Internals.Utf16.Utf16_Code_Unit;
Value : out Ada.Streams.Stream_Element;
Success : out Boolean) is
begin
Success := True;
case Item is
when Character'Pos ('A') .. Character'Pos ('Z') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('A');
when Character'Pos ('a') .. Character'Pos ('z') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('a') + 26;
when Character'Pos ('0') .. Character'Pos ('9') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('0') + 52;
when Character'Pos ('+') =>
Value := 62;
when Character'Pos ('/') =>
Value := 63;
when Character'Pos ('=') =>
Value := 0;
when others =>
Success := False;
end case;
end Decode_64;
-------------------
-- Decode_64_URL --
-------------------
procedure Decode_64_URL
(Item : Matreshka.Internals.Utf16.Utf16_Code_Unit;
Value : out Ada.Streams.Stream_Element;
Success : out Boolean) is
begin
Success := True;
case Item is
when Character'Pos ('A') .. Character'Pos ('Z') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('A');
when Character'Pos ('a') .. Character'Pos ('z') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('a') + 26;
when Character'Pos ('0') .. Character'Pos ('9') =>
Value :=
Ada.Streams.Stream_Element (Item) - Character'Pos ('0') + 52;
when Character'Pos ('-') =>
Value := 62;
when Character'Pos ('_') =>
Value := 63;
when Character'Pos ('=') =>
Value := 0;
when others =>
Success := False;
end case;
end Decode_64_URL;
------------------
-- From_Base_64 --
------------------
function From_Base_64
(Data : League.Strings.Universal_String)
return League.Stream_Element_Vectors.Stream_Element_Vector
is
Aux : League.Stream_Element_Vectors.Stream_Element_Vector;
Success : Boolean;
begin
From_Base_64 (Data, Aux, Success);
if Success then
return Aux;
else
raise Constraint_Error with "Mailformed base64 data";
end if;
end From_Base_64;
------------------
-- From_Base_64 --
------------------
procedure From_Base_64
(Data : League.Strings.Universal_String;
Value : in out League.Stream_Element_Vectors.Stream_Element_Vector;
Success : out Boolean)
is
Source : constant Matreshka.Internals.Strings.Shared_String_Access
:= League.Strings.Internals.Internal (Data);
Size : constant Ada.Streams.Stream_Element_Offset
:= Ada.Streams.Stream_Element_Offset (Source.Length) / 4 * 3;
Target :
Matreshka.Internals.Stream_Element_Vectors
.Shared_Stream_Element_Vector_Access
:= League.Stream_Element_Vectors.Internals.Internal (Value);
Unused : Ada.Streams.Stream_Element_Offset := 0;
First : Matreshka.Internals.Utf16.Utf16_String_Index := 0;
begin
if Source.Length = 0 then
Value.Clear;
Success := True;
return;
end if;
if Source.Length mod 4 /= 0 then
Value.Clear;
Success := False;
return;
end if;
-- Check whether storage of passed internal object can be reused, and
-- create new shared object if can't.
if not Matreshka.Internals.Stream_Element_Vectors.Can_Be_Reused
(Target, Size)
then
Target :=
Matreshka.Internals.Stream_Element_Vectors.Allocate (Size);
League.Stream_Element_Vectors.Internals.Replace (Value, Target);
end if;
while Source.Unused > First loop
declare
S1 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First);
S2 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 1);
S3 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 2);
S4 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 3);
A1 : Ada.Streams.Stream_Element;
A2 : Ada.Streams.Stream_Element;
A3 : Ada.Streams.Stream_Element;
A4 : Ada.Streams.Stream_Element;
begin
Decode_64 (S1, A1, Success);
exit when not Success;
Decode_64 (S2, A2, Success);
exit when not Success;
Target.Value (Unused) := (A1 * 4) or ((A2 and 2#0011_0000#) / 16);
Unused := Unused + 1;
if S3 /= Character'Pos ('=') then
Decode_64 (S3, A3, Success);
exit when not Success;
Target.Value (Unused) :=
((A2 and 2#0000_1111#) * 16) or ((A3 and 2#0011_1100#) / 4);
Unused := Unused + 1;
if S4 /= Character'Pos ('=') then
Decode_64 (S4, A4, Success);
exit when not Success;
Target.Value (Unused) := ((A3 and 2#0000_0011#) * 64) or A4;
Unused := Unused + 1;
end if;
end if;
First := First + 4;
end;
end loop;
Target.Length := Unused;
end From_Base_64;
----------------------
-- From_Base_64_URL --
----------------------
function From_Base_64_URL
(Data : League.Strings.Universal_String)
return League.Stream_Element_Vectors.Stream_Element_Vector
is
Aux : League.Stream_Element_Vectors.Stream_Element_Vector;
Success : Boolean;
begin
From_Base_64_URL (Data, Aux, Success);
if Success then
return Aux;
else
raise Constraint_Error with "Mailformed base64url data";
end if;
end From_Base_64_URL;
----------------------
-- From_Base_64_URL --
----------------------
procedure From_Base_64_URL
(Data : League.Strings.Universal_String;
Value : in out League.Stream_Element_Vectors.Stream_Element_Vector;
Success : out Boolean)
is
Source : constant Matreshka.Internals.Strings.Shared_String_Access
:= League.Strings.Internals.Internal (Data);
Size : constant Ada.Streams.Stream_Element_Offset
:= Ada.Streams.Stream_Element_Offset (Source.Length) / 4 * 3;
Target :
Matreshka.Internals.Stream_Element_Vectors
.Shared_Stream_Element_Vector_Access
:= League.Stream_Element_Vectors.Internals.Internal (Value);
Unused : Ada.Streams.Stream_Element_Offset := 0;
First : Matreshka.Internals.Utf16.Utf16_String_Index := 0;
begin
if Source.Length = 0 then
Value.Clear;
Success := True;
return;
end if;
if Source.Length mod 4 = 0 then
-- Check whether storage of passed internal object can be reused, and
-- create new shared object if can't.
if not Matreshka.Internals.Stream_Element_Vectors.Can_Be_Reused
(Target, Size)
then
Target :=
Matreshka.Internals.Stream_Element_Vectors.Allocate (Size);
League.Stream_Element_Vectors.Internals.Replace (Value, Target);
end if;
while Source.Unused > First loop
declare
S1 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First);
S2 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 1);
S3 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 2);
S4 : constant Matreshka.Internals.Utf16.Utf16_Code_Unit
:= Source.Value (First + 3);
A1 : Ada.Streams.Stream_Element;
A2 : Ada.Streams.Stream_Element;
A3 : Ada.Streams.Stream_Element;
A4 : Ada.Streams.Stream_Element;
begin
Decode_64_URL (S1, A1, Success);
exit when not Success;
Decode_64_URL (S2, A2, Success);
exit when not Success;
Target.Value (Unused) :=
(A1 * 4) or ((A2 and 2#0011_0000#) / 16);
Unused := Unused + 1;
if S3 /= Character'Pos ('=') then
Decode_64_URL (S3, A3, Success);
exit when not Success;
Target.Value (Unused) :=
((A2 and 2#0000_1111#) * 16) or ((A3 and 2#0011_1100#) / 4);
Unused := Unused + 1;
if S4 /= Character'Pos ('=') then
Decode_64_URL (S4, A4, Success);
exit when not Success;
Target.Value (Unused) :=
((A3 and 2#0000_0011#) * 64) or A4;
Unused := Unused + 1;
end if;
end if;
First := First + 4;
end;
end loop;
Target.Length := Unused;
if Target.Length = 0 then
Value.Clear;
end if;
else
Value.Clear;
Success := False;
end if;
end From_Base_64_URL;
----------------
-- To_Base_64 --
----------------
function To_Base_64
(Data : League.Stream_Element_Vectors.Stream_Element_Vector)
return League.Strings.Universal_String
is
Source : constant
Matreshka.Internals.Stream_Element_Vectors
.Shared_Stream_Element_Vector_Access
:= League.Stream_Element_Vectors.Internals.Internal (Data);
Target : Matreshka.Internals.Strings.Shared_String_Access;
First : Ada.Streams.Stream_Element_Offset := 0;
Unused : Matreshka.Internals.Utf16.Utf16_String_Index := 0;
Aux : Ada.Streams.Stream_Element;
begin
-- Return empty string when data is empty.
if Source.Length = 0 then
return League.Strings.Empty_Universal_String;
end if;
-- Allocate string for result. (Length + 2) / 3 * 4 is exact required
-- length for the result.
Target :=
Matreshka.Internals.Strings.Allocate
(Matreshka.Internals.Utf16.Utf16_String_Index
((Source.Length + 2) / 3 * 4));
-- Encode each triplet of bytes when available.
while Source.Length - First >= 3 loop
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
S2 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 1);
S3 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 2);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux :=
((S1 and 2#0000_0011#) * 16) or ((S2 and 2#1111_0000#) / 16);
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux :=
((S2 and 2#0000_1111#) * 4) or ((S3 and 2#1100_0000#) / 64);
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux := S3 and 2#0011_1111#;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
end;
First := First + 3;
end loop;
if Source.Length - First = 1 then
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux := (S1 and 2#0000_0011#) * 16;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
end;
elsif Source.Length - First = 2 then
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
S2 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 1);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux :=
((S1 and 2#0000_0011#) * 16) or ((S2 and 2#1111_0000#) / 16);
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Aux := (S2 and 2#0000_1111#) * 4;
Target.Value (Unused) := Encode_64 (Aux);
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
end;
end if;
Target.Unused := Unused;
Target.Length := Integer (Target.Unused);
-- All characters of base64 character set occupy one code unit, thus
-- length of the string is always equal to the number of used code
-- units.
Matreshka.Internals.Strings.Configuration.String_Handler
.Fill_Null_Terminator (Target);
return League.Strings.Internals.Wrap (Target);
exception
when others =>
Matreshka.Internals.Strings.Dereference (Target);
raise;
end To_Base_64;
--------------------
-- To_Base_64_URL --
--------------------
function To_Base_64_URL
(Data : League.Stream_Element_Vectors.Stream_Element_Vector)
return League.Strings.Universal_String
is
Source : constant
Matreshka.Internals.Stream_Element_Vectors
.Shared_Stream_Element_Vector_Access
:= League.Stream_Element_Vectors.Internals.Internal (Data);
Target : Matreshka.Internals.Strings.Shared_String_Access;
First : Ada.Streams.Stream_Element_Offset := 0;
Unused : Matreshka.Internals.Utf16.Utf16_String_Index := 0;
Aux : Ada.Streams.Stream_Element;
begin
-- Return empty string when data is empty.
if Source.Length = 0 then
return League.Strings.Empty_Universal_String;
end if;
-- Allocate string for result. (Length + 2) / 3 * 4 is exact required
-- length for the result.
Target :=
Matreshka.Internals.Strings.Allocate
(Matreshka.Internals.Utf16.Utf16_String_Index
((Source.Length + 2) / 3 * 4));
-- Encode each triplet of bytes when available.
while Source.Length - First >= 3 loop
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
S2 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 1);
S3 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 2);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux :=
((S1 and 2#0000_0011#) * 16) or ((S2 and 2#1111_0000#) / 16);
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux :=
((S2 and 2#0000_1111#) * 4) or ((S3 and 2#1100_0000#) / 64);
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux := S3 and 2#0011_1111#;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
end;
First := First + 3;
end loop;
if Source.Length - First = 1 then
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux := (S1 and 2#0000_0011#) * 16;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
end;
elsif Source.Length - First = 2 then
declare
S1 : constant Ada.Streams.Stream_Element := Source.Value (First);
S2 : constant Ada.Streams.Stream_Element
:= Source.Value (First + 1);
begin
Aux := (S1 and 2#1111_1100#) / 4;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux :=
((S1 and 2#0000_0011#) * 16) or ((S2 and 2#1111_0000#) / 16);
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Aux := (S2 and 2#0000_1111#) * 4;
Target.Value (Unused) := Encode_64_URL (Aux);
Unused := Unused + 1;
Target.Value (Unused) := Character'Pos ('=');
Unused := Unused + 1;
end;
end if;
Target.Unused := Unused;
Target.Length := Integer (Target.Unused);
-- All characters of base64 character set occupy one code unit, thus
-- length of the string is always equal to the number of used code
-- units.
Matreshka.Internals.Strings.Configuration.String_Handler
.Fill_Null_Terminator (Target);
return League.Strings.Internals.Wrap (Target);
exception
when others =>
Matreshka.Internals.Strings.Dereference (Target);
raise;
end To_Base_64_URL;
end League.Base_Codecs;
|
coopht/axmpp | Ada | 5,767 | ads | ------------------------------------------------------------------------------
-- --
-- AXMPP Project --
-- --
-- XMPP Library for Ada --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2016, Alexander Basov <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Alexander Basov, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Strings;
with XML.SAX.Pretty_Writers;
with XMPP.Objects;
package XMPP.Challenges is
type XMPP_Challenge is new XMPP.Objects.XMPP_Object with private;
type XMPP_Challenge_Access is access all XMPP_Challenge'Class;
function Create return XMPP_Challenge_Access;
overriding
function Get_Kind (Self : XMPP_Challenge) return XMPP.Object_Kind;
overriding procedure Serialize
(Self : XMPP_Challenge;
Writer : in out XML.SAX.Pretty_Writers.XML_Pretty_Writer'Class);
overriding
procedure Set_Content (Self : in out XMPP_Challenge;
Parameter : League.Strings.Universal_String;
Value : League.Strings.Universal_String);
procedure Set_Realm (Self : in out XMPP_Challenge;
Realm : League.Strings.Universal_String);
procedure Set_Nonce (Self : in out XMPP_Challenge;
Nonce : League.Strings.Universal_String);
procedure Set_Qop (Self : in out XMPP_Challenge;
Qop : League.Strings.Universal_String);
procedure Set_Charset (Self : in out XMPP_Challenge;
Charset : League.Strings.Universal_String);
procedure Set_Algorithm (Self : in out XMPP_Challenge;
Algorithm : League.Strings.Universal_String);
-- data for response
procedure Set_JID (Self : in out XMPP_Challenge;
JID : League.Strings.Universal_String);
procedure Set_Password (Self : in out XMPP_Challenge;
Password : League.Strings.Universal_String);
procedure Set_RSP_Auth (Self : in out XMPP_Challenge;
RSP_Auth : League.Strings.Universal_String);
function Generate_Response (Self : XMPP_Challenge)
return League.Strings.Universal_String;
private
type XMPP_Challenge is new XMPP.Objects.XMPP_Object with
record
Realm : League.Strings.Universal_String;
Nonce : League.Strings.Universal_String;
Qop : League.Strings.Universal_String;
Charset : League.Strings.Universal_String;
Algorithm : League.Strings.Universal_String;
RSP_Auth : League.Strings.Universal_String;
-- data for response
JID : League.Strings.Universal_String;
Host : League.Strings.Universal_String;
Password : League.Strings.Universal_String;
end record;
procedure Parse_Challenge (Self : in out XMPP_Challenge;
Challenge : String);
end XMPP.Challenges;
|
reznikmm/matreshka | Ada | 19,097 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements;
with AMF.Internals.Element_Collections;
with AMF.Internals.Helpers;
with AMF.Internals.Tables.UML_Attributes;
with AMF.Visitors.UML_Iterators;
with AMF.Visitors.UML_Visitors;
with League.Strings.Internals;
with Matreshka.Internals.Strings;
package body AMF.Internals.UML_Interface_Realizations is
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access constant UML_Interface_Realization_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
AMF.Visitors.UML_Visitors.UML_Visitor'Class
(Visitor).Enter_Interface_Realization
(AMF.UML.Interface_Realizations.UML_Interface_Realization_Access (Self),
Control);
end if;
end Enter_Element;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access constant UML_Interface_Realization_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
AMF.Visitors.UML_Visitors.UML_Visitor'Class
(Visitor).Leave_Interface_Realization
(AMF.UML.Interface_Realizations.UML_Interface_Realization_Access (Self),
Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access constant UML_Interface_Realization_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Iterator in AMF.Visitors.UML_Iterators.UML_Iterator'Class then
AMF.Visitors.UML_Iterators.UML_Iterator'Class
(Iterator).Visit_Interface_Realization
(Visitor,
AMF.UML.Interface_Realizations.UML_Interface_Realization_Access (Self),
Control);
end if;
end Visit_Element;
------------------
-- Get_Contract --
------------------
overriding function Get_Contract
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Interfaces.UML_Interface_Access is
begin
return
AMF.UML.Interfaces.UML_Interface_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Contract
(Self.Element)));
end Get_Contract;
------------------
-- Set_Contract --
------------------
overriding procedure Set_Contract
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.Interfaces.UML_Interface_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Contract
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Contract;
---------------------------------
-- Get_Implementing_Classifier --
---------------------------------
overriding function Get_Implementing_Classifier
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Behaviored_Classifiers.UML_Behaviored_Classifier_Access is
begin
return
AMF.UML.Behaviored_Classifiers.UML_Behaviored_Classifier_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Implementing_Classifier
(Self.Element)));
end Get_Implementing_Classifier;
---------------------------------
-- Set_Implementing_Classifier --
---------------------------------
overriding procedure Set_Implementing_Classifier
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.Behaviored_Classifiers.UML_Behaviored_Classifier_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Implementing_Classifier
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Implementing_Classifier;
-----------------
-- Get_Mapping --
-----------------
overriding function Get_Mapping
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access is
begin
return
AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Mapping
(Self.Element)));
end Get_Mapping;
-----------------
-- Set_Mapping --
-----------------
overriding procedure Set_Mapping
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Mapping
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Mapping;
----------------
-- Get_Client --
----------------
overriding function Get_Client
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
return
AMF.UML.Named_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Client
(Self.Element)));
end Get_Client;
------------------
-- Get_Supplier --
------------------
overriding function Get_Supplier
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
return
AMF.UML.Named_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Supplier
(Self.Element)));
end Get_Supplier;
----------------
-- Get_Source --
----------------
overriding function Get_Source
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Elements.Collections.Set_Of_UML_Element is
begin
return
AMF.UML.Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Source
(Self.Element)));
end Get_Source;
----------------
-- Get_Target --
----------------
overriding function Get_Target
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Elements.Collections.Set_Of_UML_Element is
begin
return
AMF.UML.Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Target
(Self.Element)));
end Get_Target;
-------------------------
-- Get_Related_Element --
-------------------------
overriding function Get_Related_Element
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Elements.Collections.Set_Of_UML_Element is
begin
return
AMF.UML.Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Related_Element
(Self.Element)));
end Get_Related_Element;
---------------------------
-- Get_Client_Dependency --
---------------------------
overriding function Get_Client_Dependency
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency is
begin
return
AMF.UML.Dependencies.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Client_Dependency
(Self.Element)));
end Get_Client_Dependency;
-------------------------
-- Get_Name_Expression --
-------------------------
overriding function Get_Name_Expression
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access is
begin
return
AMF.UML.String_Expressions.UML_String_Expression_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Name_Expression
(Self.Element)));
end Get_Name_Expression;
-------------------------
-- Set_Name_Expression --
-------------------------
overriding procedure Set_Name_Expression
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Name_Expression
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Name_Expression;
-------------------
-- Get_Namespace --
-------------------
overriding function Get_Namespace
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access is
begin
return
AMF.UML.Namespaces.UML_Namespace_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Namespace
(Self.Element)));
end Get_Namespace;
------------------------
-- Get_Qualified_Name --
------------------------
overriding function Get_Qualified_Name
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.Optional_String is
begin
declare
use type Matreshka.Internals.Strings.Shared_String_Access;
Aux : constant Matreshka.Internals.Strings.Shared_String_Access
:= AMF.Internals.Tables.UML_Attributes.Internal_Get_Qualified_Name (Self.Element);
begin
if Aux = null then
return (Is_Empty => True);
else
return (False, League.Strings.Internals.Create (Aux));
end if;
end;
end Get_Qualified_Name;
-----------------------------------
-- Get_Owning_Template_Parameter --
-----------------------------------
overriding function Get_Owning_Template_Parameter
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
begin
return
AMF.UML.Template_Parameters.UML_Template_Parameter_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owning_Template_Parameter
(Self.Element)));
end Get_Owning_Template_Parameter;
-----------------------------------
-- Set_Owning_Template_Parameter --
-----------------------------------
overriding procedure Set_Owning_Template_Parameter
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Owning_Template_Parameter
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Owning_Template_Parameter;
----------------------------
-- Get_Template_Parameter --
----------------------------
overriding function Get_Template_Parameter
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
begin
return
AMF.UML.Template_Parameters.UML_Template_Parameter_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Parameter
(Self.Element)));
end Get_Template_Parameter;
----------------------------
-- Set_Template_Parameter --
----------------------------
overriding procedure Set_Template_Parameter
(Self : not null access UML_Interface_Realization_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Template_Parameter
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Template_Parameter;
-------------------------
-- All_Owning_Packages --
-------------------------
overriding function All_Owning_Packages
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "All_Owning_Packages unimplemented");
raise Program_Error with "Unimplemented procedure UML_Interface_Realization_Proxy.All_Owning_Packages";
return All_Owning_Packages (Self);
end All_Owning_Packages;
-----------------------------
-- Is_Distinguishable_From --
-----------------------------
overriding function Is_Distinguishable_From
(Self : not null access constant UML_Interface_Realization_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented");
raise Program_Error with "Unimplemented procedure UML_Interface_Realization_Proxy.Is_Distinguishable_From";
return Is_Distinguishable_From (Self, N, Ns);
end Is_Distinguishable_From;
---------------
-- Namespace --
---------------
overriding function Namespace
(Self : not null access constant UML_Interface_Realization_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Namespace unimplemented");
raise Program_Error with "Unimplemented procedure UML_Interface_Realization_Proxy.Namespace";
return Namespace (Self);
end Namespace;
------------------------
-- Is_Compatible_With --
------------------------
overriding function Is_Compatible_With
(Self : not null access constant UML_Interface_Realization_Proxy;
P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Compatible_With unimplemented");
raise Program_Error with "Unimplemented procedure UML_Interface_Realization_Proxy.Is_Compatible_With";
return Is_Compatible_With (Self, P);
end Is_Compatible_With;
---------------------------
-- Is_Template_Parameter --
---------------------------
overriding function Is_Template_Parameter
(Self : not null access constant UML_Interface_Realization_Proxy)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Template_Parameter unimplemented");
raise Program_Error with "Unimplemented procedure UML_Interface_Realization_Proxy.Is_Template_Parameter";
return Is_Template_Parameter (Self);
end Is_Template_Parameter;
end AMF.Internals.UML_Interface_Realizations;
|
leo-brewin/adm-bssn-numerical | Ada | 543 | ads | package ADMBase.Data_IO is
procedure read_data (file_name : String := "data.txt");
procedure read_grid (file_name : String := "grid.txt");
procedure write_data (file_name : String := "data.txt");
procedure write_grid (file_name : String := "grid.txt");
procedure read_data_fmt (file_name : String := "data.txt");
procedure read_grid_fmt (file_name : String := "grid.txt");
procedure write_data_fmt (file_name : String := "data.txt");
procedure write_grid_fmt (file_name : String := "grid.txt");
end ADMBase.Data_IO;
|
optikos/oasis | Ada | 583 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.Strings;
with Ada.Containers.Vectors;
with Meta.Classes;
package Meta.Read is
package Class_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Meta.Classes.Class,
"=" => Meta.Classes."=");
procedure Read_AST
(File_Name : League.Strings.Universal_String;
Result : out Class_Vectors.Vector);
end Meta.Read;
|
onox/orka | Ada | 3,851 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2021 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Unchecked_Conversion;
with Orka.SIMD.AVX2.Longs.Arithmetic;
with Orka.SIMD.AVX2.Longs.Convert;
with Orka.SIMD.AVX2.Longs.Logical;
with Orka.SIMD.AVX2.Longs.Shift;
package body Orka.SIMD.AVX2.Longs.Random is
-- This is an Ada port of xoshiro256++ random number generator.
--
-- https://arxiv.org/abs/1805.01407
-- doi:10.1145/3460772
-- https://arxiv.org/abs/1910.06437
--
-- David Blackman and Sebastiano Vigna.
-- Scrambled linear pseudorandom number generators. ACM Trans. Math. Softw., 47:1−32, 2021.
--
-- The following comment is from https://prng.di.unimi.it/xoshiro256plusplus.c:
--
-- /* Written in 2019 by David Blackman and Sebastiano Vigna ([email protected])
--
-- To the extent possible under law, the author has dedicated all copyright
-- and related and neighboring rights to this software to the public domain
-- worldwide. This software is distributed without any warranty.
--
-- See <http://creativecommons.org/publicdomain/zero/1.0/>. */
--
-- /* This is xoshiro256++ 1.0, one of our all-purpose, rock-solid generators.
-- It has excellent (sub-ns) speed, a state (256 bits) that is large
-- enough for any parallel application, and it passes all tests we are
-- aware of.
-- For generating just floating-point numbers, xoshiro256+ is even faster.
-- The state must be seeded so that it is not everywhere zero. If you have
-- a 64-bit seed, we suggest to seed a splitmix64 generator and use its
-- output to fill s. */
procedure Next (S : in out State; Value : out m256l) is
use Orka.SIMD.AVX2.Longs.Arithmetic;
use Orka.SIMD.AVX2.Longs.Logical;
use Orka.SIMD.AVX2.Longs.Shift;
function Rotate_Left (X : m256l; K : Bits_Count) return m256l is
(Shift_Bits_Left_Zeros (X, K) or Shift_Bits_Right_Zeros (X, Unsigned_64'Size - K));
-- xoshiro256++ (xoshiro256+ is just S (0) + S (3))
Result : constant m256l := Rotate_Left (S (0) + S (3), 23) + S (0);
T : constant m256l := Shift_Bits_Left_Zeros (S (1), 17);
begin
S (2) := S (2) xor S (0);
S (3) := S (3) xor S (1);
S (1) := S (1) xor S (2);
S (0) := S (0) xor S (3);
S (2) := S (2) xor T;
S (3) := Rotate_Left (S (3), 45);
Value := Result;
end Next;
procedure Next (S : in out State; Value : out m256d) is
Result : m256l;
begin
Next (S, Result);
Value := SIMD.AVX2.Longs.Convert.To_Unit_Floats (Result);
end Next;
procedure Reset (S : out State; Seed : Duration) is
Value : constant Unsigned_64 := Unsigned_64 (Seed);
function Convert is new Ada.Unchecked_Conversion (Unsigned_64, Integer_64);
function Rotate_Left (X : Unsigned_64; K : Natural) return Unsigned_64 is
((X * 2**K) or (X / 2**(Unsigned_64'Size - K)));
begin
for I in S'Range loop
S (I) :=
(Convert (Rotate_Left (Value, 1)),
Convert (Rotate_Left (Value, 2)),
Convert (Rotate_Left (Value, 3)),
Convert (Rotate_Left (Value, 4)));
end loop;
end Reset;
end Orka.SIMD.AVX2.Longs.Random;
|
stcarrez/jason | Ada | 893 | ads | -----------------------------------------------------------------------
-- jason-projects -- Module projects
-- Copyright (C) 2016 Stephane.Carrez
-- Written by Stephane.Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package Jason.Projects is
end Jason.Projects;
|
reznikmm/matreshka | Ada | 3,537 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
package Matreshka.Internals.Unicode.Characters.General_Punctuation is
pragma Pure;
Line_Separator : constant := 16#2028#;
end Matreshka.Internals.Unicode.Characters.General_Punctuation;
|
charlie5/aIDE | Ada | 1,789 | adb | with
AdaM.Factory;
package body AdaM.use_Clause.for_package
is
-- Storage Pool
--
record_Version : constant := 1;
pool_Size : constant := 5_000;
package Pool is new AdaM.Factory.Pools (".adam-store",
"use_Clauses-for_package",
pool_Size,
record_Version,
use_Clause.for_package.item,
use_Clause.for_package.view);
-- Forge
--
procedure define (Self : in out Item)
is
begin
null;
end define;
overriding
procedure destruct (Self : in out Item)
is
begin
null;
end destruct;
function new_Subprogram return View
is
new_View : constant use_Clause.for_package.view := Pool.new_Item;
begin
define (use_Clause.for_package.item (new_View.all));
return new_View;
end new_Subprogram;
procedure free (Self : in out use_Clause.for_package.view)
is
begin
destruct (use_Clause.for_package.item (Self.all));
Pool.free (Self);
end free;
-- Attributes
--
overriding
function Id (Self : access Item) return AdaM.Id
is
begin
return Pool.to_Id (Self);
end Id;
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
renames Pool.View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
renames Pool.View_read;
end AdaM.use_Clause.for_package;
|
zhmu/ananas | Ada | 22,527 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . S O C K E T S . T H I N --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2022, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides a target dependent thin interface to the sockets
-- layer for use by the GNAT.Sockets package (g-socket.ads). This package
-- should not be directly with'ed by an applications program.
-- This version is for NT
with Ada.Unchecked_Conversion;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
package body GNAT.Sockets.Thin is
use type C.unsigned;
WSAData_Dummy : array (1 .. 512) of C.int;
WS_Version : constant := 16#0202#;
-- Winsock 2.2
Initialized : Boolean := False;
function Standard_Connect
(S : C.int;
Name : System.Address;
Namelen : C.int) return C.int;
pragma Import (Stdcall, Standard_Connect, "connect");
function Standard_Select
(Nfds : C.int;
Readfds : access Fd_Set;
Writefds : access Fd_Set;
Exceptfds : access Fd_Set;
Timeout : Timeval_Access) return C.int;
pragma Import (Stdcall, Standard_Select, "select");
type Error_Type is
(N_EINTR,
N_EBADF,
N_EACCES,
N_EFAULT,
N_EINVAL,
N_EMFILE,
N_EWOULDBLOCK,
N_EINPROGRESS,
N_EALREADY,
N_ENOTSOCK,
N_EDESTADDRREQ,
N_EMSGSIZE,
N_EPROTOTYPE,
N_ENOPROTOOPT,
N_EPROTONOSUPPORT,
N_ESOCKTNOSUPPORT,
N_EOPNOTSUPP,
N_EPFNOSUPPORT,
N_EAFNOSUPPORT,
N_EADDRINUSE,
N_EADDRNOTAVAIL,
N_ENETDOWN,
N_ENETUNREACH,
N_ENETRESET,
N_ECONNABORTED,
N_ECONNRESET,
N_ENOBUFS,
N_EISCONN,
N_ENOTCONN,
N_ESHUTDOWN,
N_ETOOMANYREFS,
N_ETIMEDOUT,
N_ECONNREFUSED,
N_ELOOP,
N_ENAMETOOLONG,
N_EHOSTDOWN,
N_EHOSTUNREACH,
N_WSASYSNOTREADY,
N_WSAVERNOTSUPPORTED,
N_WSANOTINITIALISED,
N_WSAEDISCON,
N_HOST_NOT_FOUND,
N_TRY_AGAIN,
N_NO_RECOVERY,
N_NO_DATA,
N_OTHERS);
Error_Messages : constant array (Error_Type) of chars_ptr :=
(N_EINTR =>
New_String ("Interrupted system call"),
N_EBADF =>
New_String ("Bad file number"),
N_EACCES =>
New_String ("Permission denied"),
N_EFAULT =>
New_String ("Bad address"),
N_EINVAL =>
New_String ("Invalid argument"),
N_EMFILE =>
New_String ("Too many open files"),
N_EWOULDBLOCK =>
New_String ("Operation would block"),
N_EINPROGRESS =>
New_String ("Operation now in progress. This error is "
& "returned if any Windows Sockets API "
& "function is called while a blocking "
& "function is in progress"),
N_EALREADY =>
New_String ("Operation already in progress"),
N_ENOTSOCK =>
New_String ("Socket operation on nonsocket"),
N_EDESTADDRREQ =>
New_String ("Destination address required"),
N_EMSGSIZE =>
New_String ("Message too long"),
N_EPROTOTYPE =>
New_String ("Protocol wrong type for socket"),
N_ENOPROTOOPT =>
New_String ("Protocol not available"),
N_EPROTONOSUPPORT =>
New_String ("Protocol not supported"),
N_ESOCKTNOSUPPORT =>
New_String ("Socket type not supported"),
N_EOPNOTSUPP =>
New_String ("Operation not supported on socket"),
N_EPFNOSUPPORT =>
New_String ("Protocol family not supported"),
N_EAFNOSUPPORT =>
New_String ("Address family not supported by protocol family"),
N_EADDRINUSE =>
New_String ("Address already in use"),
N_EADDRNOTAVAIL =>
New_String ("Cannot assign requested address"),
N_ENETDOWN =>
New_String ("Network is down. This error may be "
& "reported at any time if the Windows "
& "Sockets implementation detects an "
& "underlying failure"),
N_ENETUNREACH =>
New_String ("Network is unreachable"),
N_ENETRESET =>
New_String ("Network dropped connection on reset"),
N_ECONNABORTED =>
New_String ("Software caused connection abort"),
N_ECONNRESET =>
New_String ("Connection reset by peer"),
N_ENOBUFS =>
New_String ("No buffer space available"),
N_EISCONN =>
New_String ("Socket is already connected"),
N_ENOTCONN =>
New_String ("Socket is not connected"),
N_ESHUTDOWN =>
New_String ("Cannot send after socket shutdown"),
N_ETOOMANYREFS =>
New_String ("Too many references: cannot splice"),
N_ETIMEDOUT =>
New_String ("Connection timed out"),
N_ECONNREFUSED =>
New_String ("Connection refused"),
N_ELOOP =>
New_String ("Too many levels of symbolic links"),
N_ENAMETOOLONG =>
New_String ("File name too long"),
N_EHOSTDOWN =>
New_String ("Host is down"),
N_EHOSTUNREACH =>
New_String ("No route to host"),
N_WSASYSNOTREADY =>
New_String ("Returned by WSAStartup(), indicating that "
& "the network subsystem is unusable"),
N_WSAVERNOTSUPPORTED =>
New_String ("Returned by WSAStartup(), indicating that "
& "the Windows Sockets DLL cannot support "
& "this application"),
N_WSANOTINITIALISED =>
New_String ("Winsock not initialized. This message is "
& "returned by any function except WSAStartup(), "
& "indicating that a successful WSAStartup() has "
& "not yet been performed"),
N_WSAEDISCON =>
New_String ("Disconnected"),
N_HOST_NOT_FOUND =>
New_String ("Host not found. This message indicates "
& "that the key (name, address, and so on) was not found"),
N_TRY_AGAIN =>
New_String ("Nonauthoritative host not found. This error may "
& "suggest that the name service itself is not "
& "functioning"),
N_NO_RECOVERY =>
New_String ("Nonrecoverable error. This error may suggest that the "
& "name service itself is not functioning"),
N_NO_DATA =>
New_String ("Valid name, no data record of requested type. "
& "This error indicates that the key (name, address, "
& "and so on) was not found."),
N_OTHERS =>
New_String ("Unknown system error"));
---------------
-- C_Connect --
---------------
function C_Connect
(S : C.int;
Name : System.Address;
Namelen : C.int) return C.int
is
Res : C.int;
begin
Res := Standard_Connect (S, Name, Namelen);
if Res = -1 then
if Socket_Errno = SOSC.EWOULDBLOCK then
Set_Socket_Errno (SOSC.EINPROGRESS);
end if;
end if;
return Res;
end C_Connect;
------------------
-- Socket_Ioctl --
------------------
function Socket_Ioctl
(S : C.int;
Req : SOSC.IOCTL_Req_T;
Arg : access C.int) return C.int
is
begin
return C_Ioctl (S, Req, Arg);
end Socket_Ioctl;
---------------
-- C_Recvmsg --
---------------
function C_Recvmsg
(S : C.int;
Msg : System.Address;
Flags : C.int) return System.CRTL.ssize_t
is
use type C.size_t;
Fill : constant Boolean :=
SOSC.MSG_WAITALL /= -1
and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
-- Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
Res : C.int;
Count : C.int := 0;
MH : Msghdr;
for MH'Address use Msg;
Iovec : array (0 .. MH.Msg_Iovlen - 1) of Vector_Element;
for Iovec'Address use MH.Msg_Iov;
pragma Import (Ada, Iovec);
Iov_Index : Integer;
Current_Iovec : Vector_Element;
function To_Access is new Ada.Unchecked_Conversion
(System.Address, Stream_Element_Reference);
pragma Warnings (Off, Stream_Element_Reference);
Req : Request_Type (Name => N_Bytes_To_Read);
begin
-- Windows does not provide an implementation of recvmsg(). The spec for
-- WSARecvMsg() is incompatible with the data types we define, and is
-- available starting with Windows Vista and Server 2008 only. So,
-- we use C_Recv instead.
-- Check how much data are available
Control_Socket (Socket_Type (S), Req);
-- Fill the vectors
Iov_Index := -1;
Current_Iovec := (Base => null, Length => 0);
loop
if Current_Iovec.Length = 0 then
Iov_Index := Iov_Index + 1;
exit when Iov_Index > Integer (Iovec'Last);
Current_Iovec := Iovec (SOSC.Msg_Iovlen_T (Iov_Index));
end if;
Res :=
C_Recv
(S,
Current_Iovec.Base.all'Address,
C.int (Current_Iovec.Length),
Flags);
if Res < 0 then
return System.CRTL.ssize_t (Res);
elsif Res = 0 and then not Fill then
exit;
else
pragma Assert (Interfaces.C.size_t (Res) <= Current_Iovec.Length);
Count := Count + Res;
Current_Iovec.Length :=
Current_Iovec.Length - Interfaces.C.size_t (Res);
Current_Iovec.Base :=
To_Access (Current_Iovec.Base.all'Address
+ Storage_Offset (Res));
-- If all the data that was initially available read, do not
-- attempt to receive more, since this might block, or merge data
-- from successive datagrams for a datagram-oriented socket. We
-- still try to receive more if we need to fill all vectors
-- (MSG_WAITALL flag is set).
exit when Natural (Count) >= Req.Size
and then
-- Either we are not in fill mode
(not Fill
-- Or else last vector filled
or else (Interfaces.C.size_t (Iov_Index) = Iovec'Last
and then Current_Iovec.Length = 0));
end if;
end loop;
return System.CRTL.ssize_t (Count);
end C_Recvmsg;
--------------
-- C_Select --
--------------
function C_Select
(Nfds : C.int;
Readfds : access Fd_Set;
Writefds : access Fd_Set;
Exceptfds : access Fd_Set;
Timeout : Timeval_Access) return C.int
is
Original_WFS : aliased Fd_Set;
Res : C.int;
S : aliased C.int;
Last : aliased C.int;
begin
-- Asynchronous connection failures are notified in the exception fd
-- set instead of the write fd set. To ensure POSIX compatibility, copy
-- write fd set into exception fd set. Once select() returns, check any
-- socket present in the exception fd set and peek at incoming
-- out-of-band data. If the test is not successful, and the socket is
-- present in the initial write fd set, then move the socket from the
-- exception fd set to the write fd set.
if Writefds /= null then
Original_WFS := Writefds.all;
-- Add any socket present in write fd set into exception fd set
declare
WFS : aliased Fd_Set := Writefds.all;
begin
Last := Nfds - 1;
loop
Get_Socket_From_Set
(WFS'Access, S'Unchecked_Access, Last'Unchecked_Access);
exit when S = -1;
Insert_Socket_In_Set (Exceptfds, S);
end loop;
end;
end if;
Res := Standard_Select (Nfds, Readfds, Writefds, Exceptfds, Timeout);
if Exceptfds /= null then
declare
EFSC : aliased Fd_Set := Exceptfds.all;
Flag : constant C.int := SOSC.MSG_PEEK + SOSC.MSG_OOB;
Buffer : Character;
Length : C.int;
Fromlen : aliased C.int;
begin
Last := Nfds - 1;
loop
Get_Socket_From_Set
(EFSC'Access, S'Unchecked_Access, Last'Unchecked_Access);
-- No more sockets in EFSC
exit when S = -1;
-- Check out-of-band data
Length :=
C_Recvfrom
(S, Buffer'Address, 1, Flag,
From => System.Null_Address,
Fromlen => Fromlen'Unchecked_Access);
-- Is Fromlen necessary if From is Null_Address???
-- If the signal is not an out-of-band data, then it
-- is a connection failure notification.
if Length = -1 then
Remove_Socket_From_Set (Exceptfds, S);
-- If S is present in the initial write fd set, move it from
-- exception fd set back to write fd set. Otherwise, ignore
-- this event since the user is not watching for it.
if Writefds /= null
and then Is_Socket_In_Set (Original_WFS'Access, S) /= 0
then
Insert_Socket_In_Set (Writefds, S);
end if;
end if;
end loop;
end;
end if;
return Res;
end C_Select;
---------------
-- C_Sendmsg --
---------------
function C_Sendmsg
(S : C.int;
Msg : System.Address;
Flags : C.int) return System.CRTL.ssize_t
is
use type C.size_t;
Res : C.int;
Count : C.int := 0;
MH : Msghdr;
for MH'Address use Msg;
Iovec : array (0 .. MH.Msg_Iovlen - 1) of Vector_Element;
for Iovec'Address use MH.Msg_Iov;
pragma Import (Ada, Iovec);
begin
-- Windows does not provide an implementation of sendmsg(). The spec for
-- WSASendMsg() is incompatible with the data types we define, and is
-- available starting with Windows Vista and Server 2008 only. So
-- use C_Sendto instead.
for J in Iovec'Range loop
Res :=
C_Sendto
(S,
Iovec (J).Base.all'Address,
C.int (Iovec (J).Length),
Flags => Flags,
To => MH.Msg_Name,
Tolen => C.int (MH.Msg_Namelen));
if Res < 0 then
return System.CRTL.ssize_t (Res);
else
Count := Count + Res;
end if;
-- Exit now if the buffer is not fully transmitted
exit when Interfaces.C.size_t (Res) < Iovec (J).Length;
end loop;
return System.CRTL.ssize_t (Count);
end C_Sendmsg;
------------------
-- C_Socketpair --
------------------
function C_Socketpair
(Domain : C.int;
Typ : C.int;
Protocol : C.int;
Fds : not null access Fd_Pair) return C.int is separate;
--------------
-- Finalize --
--------------
procedure Finalize is
begin
if Initialized then
WSACleanup;
Initialized := False;
end if;
end Finalize;
-------------------------
-- Host_Error_Messages --
-------------------------
package body Host_Error_Messages is
-- On Windows, socket and host errors share the same code space, and
-- error messages are provided by Socket_Error_Message, so the default
-- separate body for Host_Error_Messages is not used in this case.
function Host_Error_Message (H_Errno : Integer) return String
renames Socket_Error_Message;
end Host_Error_Messages;
----------------
-- Initialize --
----------------
procedure Initialize is
Return_Value : Interfaces.C.int;
begin
if not Initialized then
Return_Value := WSAStartup (WS_Version, WSAData_Dummy'Address);
pragma Assert (Return_Value = 0);
Initialized := True;
end if;
end Initialize;
--------------------
-- Signalling_Fds --
--------------------
package body Signalling_Fds is separate;
--------------------------
-- Socket_Error_Message --
--------------------------
function Socket_Error_Message (Errno : Integer) return String is
use GNAT.Sockets.SOSC;
Errm : C.Strings.chars_ptr;
begin
case Errno is
when EINTR => Errm := Error_Messages (N_EINTR);
when EBADF => Errm := Error_Messages (N_EBADF);
when EACCES => Errm := Error_Messages (N_EACCES);
when EFAULT => Errm := Error_Messages (N_EFAULT);
when EINVAL => Errm := Error_Messages (N_EINVAL);
when EMFILE => Errm := Error_Messages (N_EMFILE);
when EWOULDBLOCK => Errm := Error_Messages (N_EWOULDBLOCK);
when EINPROGRESS => Errm := Error_Messages (N_EINPROGRESS);
when EALREADY => Errm := Error_Messages (N_EALREADY);
when ENOTSOCK => Errm := Error_Messages (N_ENOTSOCK);
when EDESTADDRREQ => Errm := Error_Messages (N_EDESTADDRREQ);
when EMSGSIZE => Errm := Error_Messages (N_EMSGSIZE);
when EPROTOTYPE => Errm := Error_Messages (N_EPROTOTYPE);
when ENOPROTOOPT => Errm := Error_Messages (N_ENOPROTOOPT);
when EPROTONOSUPPORT => Errm := Error_Messages (N_EPROTONOSUPPORT);
when ESOCKTNOSUPPORT => Errm := Error_Messages (N_ESOCKTNOSUPPORT);
when EOPNOTSUPP => Errm := Error_Messages (N_EOPNOTSUPP);
when EPFNOSUPPORT => Errm := Error_Messages (N_EPFNOSUPPORT);
when EAFNOSUPPORT => Errm := Error_Messages (N_EAFNOSUPPORT);
when EADDRINUSE => Errm := Error_Messages (N_EADDRINUSE);
when EADDRNOTAVAIL => Errm := Error_Messages (N_EADDRNOTAVAIL);
when ENETDOWN => Errm := Error_Messages (N_ENETDOWN);
when ENETUNREACH => Errm := Error_Messages (N_ENETUNREACH);
when ENETRESET => Errm := Error_Messages (N_ENETRESET);
when ECONNABORTED => Errm := Error_Messages (N_ECONNABORTED);
when ECONNRESET => Errm := Error_Messages (N_ECONNRESET);
when ENOBUFS => Errm := Error_Messages (N_ENOBUFS);
when EISCONN => Errm := Error_Messages (N_EISCONN);
when ENOTCONN => Errm := Error_Messages (N_ENOTCONN);
when ESHUTDOWN => Errm := Error_Messages (N_ESHUTDOWN);
when ETOOMANYREFS => Errm := Error_Messages (N_ETOOMANYREFS);
when ETIMEDOUT => Errm := Error_Messages (N_ETIMEDOUT);
when ECONNREFUSED => Errm := Error_Messages (N_ECONNREFUSED);
when ELOOP => Errm := Error_Messages (N_ELOOP);
when ENAMETOOLONG => Errm := Error_Messages (N_ENAMETOOLONG);
when EHOSTDOWN => Errm := Error_Messages (N_EHOSTDOWN);
when EHOSTUNREACH => Errm := Error_Messages (N_EHOSTUNREACH);
-- Windows-specific error codes
when WSASYSNOTREADY => Errm := Error_Messages (N_WSASYSNOTREADY);
when WSAVERNOTSUPPORTED =>
Errm := Error_Messages (N_WSAVERNOTSUPPORTED);
when WSANOTINITIALISED =>
Errm := Error_Messages (N_WSANOTINITIALISED);
when WSAEDISCON => Errm := Error_Messages (N_WSAEDISCON);
-- h_errno values
when HOST_NOT_FOUND => Errm := Error_Messages (N_HOST_NOT_FOUND);
when TRY_AGAIN => Errm := Error_Messages (N_TRY_AGAIN);
when NO_RECOVERY => Errm := Error_Messages (N_NO_RECOVERY);
when NO_DATA => Errm := Error_Messages (N_NO_DATA);
when others => Errm := Error_Messages (N_OTHERS);
end case;
return Value (Errm);
end Socket_Error_Message;
end GNAT.Sockets.Thin;
|
charlie5/lace | Ada | 1,750 | ads | private
with
openGL.Buffer.indices;
package openGL.Primitive.indexed
--
-- Provides a class for indexed openGL primitives.
--
is
type Item is limited new Primitive.item with private;
subtype Class is Item'Class;
type View is access all Item'class;
type Views is array (Index_t range <>) of View;
---------
-- Forge
--
function new_Primitive (Kind : in facet_Kind;
Indices : in openGL.Indices;
line_Width : in Real := unused_line_Width) return Primitive.indexed.view;
function new_Primitive (Kind : in facet_Kind;
Indices : in openGL.long_Indices;
line_Width : in Real := unused_line_Width) return Primitive.indexed.view;
procedure define (Self : in out Item; Kind : in facet_Kind;
Indices : in openGL.Indices;
line_Width : in Real);
procedure define (Self : in out Item; Kind : in facet_Kind;
Indices : in openGL.long_Indices;
line_Width : in Real);
overriding
procedure destroy (Self : in out Item);
--------------
-- Attributes
--
procedure Indices_are (Self : in out Item; Now : in Indices);
procedure Indices_are (Self : in out Item; Now : in long_Indices);
--------------
-- Operations
--
overriding
procedure render (Self : in out Item);
private
type Item is limited new Primitive.item with
record
Indices : Buffer.indices.view;
end record;
end openGL.Primitive.indexed;
|
Lucretia/Cherry | Ada | 660 | adb | --
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;
package body Macros is
use Ada.Strings.Unbounded;
package Macro_Vectors is
new Ada.Containers.Vectors
(Positive,
Unbounded_String);
Macros : Macro_Vectors.Vector;
procedure Append (Name : in String)
is
begin
Macros.Append (To_Unbounded_String (Name));
end Append;
end Macros;
|
AdaCore/libadalang | Ada | 60 | ads | package PK1 is
type Record_Type is null record;
end PK1;
|
PThierry/ewok-kernel | Ada | 11,750 | adb | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with ada.unchecked_conversion;
with m4.mpu; use m4.mpu;
with ewok.mpu.handler;
with ewok.layout;
with ewok.debug;
with soc.layout;
with applications; -- generated
package body ewok.mpu
with spark_mode => on
is
procedure init
(success : out boolean)
with spark_mode => off -- handler is not SPARK compatible
is
-- Layout mapping validation of generated constants
pragma assert
(applications.txt_kern_size + applications.txt_kern_region_base
<= applications.txt_user_region_base);
function get_region_size (size : t_region_size) return unsigned_32
is (2**(natural (size) + 1));
begin
--
-- Initializing the MPU
--
-- Testing if there's an MPU
m4.mpu.is_mpu_available (success);
if not success then
pragma DEBUG (debug.log (debug.ERROR, "No MPU!"));
return;
end if;
-- Register memory fault handler
-- Note: unproved because SPARK doesn't allow "'address" attribute
ewok.mpu.handler.init; -- not PARK compatible
-- Disable MPU
m4.mpu.disable;
-- Enable privileged software access (PRIVDEFENA) to default memory map
-- and enable the memory fault exception. When ENABLE and PRIVDEFENA are
-- both set to 1, privileged code can freely access the default memory
-- map. Any access by unprivileged software that does not address an
-- enabled memory region causes a memory management fault.
m4.mpu.init;
--
-- Configuring MPU regions
--
-- Region: kernel code
if get_region_size (REGION_SIZE_64KB) /= ewok.layout.FW1_KERN_SIZE then
pragma DEBUG
(debug.log (debug.ERROR, "MPU: invalid 'KERNEL CODE' size"));
return;
end if;
set_region
(region_number => KERN_CODE_REGION,
addr => applications.txt_kern_region_base,
size => applications.txt_kern_region_size,
region_type => REGION_TYPE_KERN_CODE,
subregion_mask => 0);
-- Region: devices that may be accessed by the kernel
set_region
(region_number => KERN_DEVICES_REGION,
addr => soc.layout.PERIPH_BASE,
size => REGION_SIZE_512MB,
region_type => REGION_TYPE_KERN_DEVICES,
subregion_mask => 0);
-- Region: kernel data + stack
if get_region_size (REGION_SIZE_64KB) /= ewok.layout.KERN_DATA_SIZE then
pragma DEBUG
(debug.log (debug.ERROR, "MPU: invalid 'KERNEL DATA' size"));
return;
end if;
set_region
(region_number => KERN_DATA_REGION,
addr => ewok.layout.KERN_DATA_BASE,
size => REGION_SIZE_64KB,
region_type => REGION_TYPE_KERN_DATA,
subregion_mask => 0);
-- Region: user data
-- Note: This is for the whole area. Each task will use only a fixed
-- number of sub-regions
if get_region_size (REGION_SIZE_128KB) /= ewok.layout.USER_RAM_SIZE then
pragma DEBUG (debug.log (debug.ERROR, "MPU: invalid 'USER DATA' size"));
return;
end if;
set_region
(region_number => USER_DATA_REGION,
addr => ewok.layout.USER_DATA_BASE,
size => REGION_SIZE_128KB,
region_type => REGION_TYPE_USER_DATA,
subregion_mask => 0);
-- Region: user code
-- Note: This is for the whole area. Each task will use only a fixed
-- number of sub-regions
if get_region_size (REGION_SIZE_256KB) /= ewok.layout.FW1_USER_SIZE then
pragma DEBUG (debug.log (debug.ERROR, "MPU: invalid 'USER CODE' size"));
return;
end if;
set_region
(region_number => USER_CODE_REGION,
addr => applications.txt_user_region_base,
size => applications.txt_user_region_size,
region_type => REGION_TYPE_USER_CODE,
subregion_mask => 0);
pragma DEBUG (debug.log (debug.INFO, "MPU is configured"));
m4.mpu.enable;
pragma DEBUG (debug.log (debug.INFO, "MPU is enabled"));
end init;
procedure enable_unrestricted_kernel_access
is
begin
m4.mpu.enable_unrestricted_kernel_access;
end enable_unrestricted_kernel_access;
procedure disable_unrestricted_kernel_access
is
begin
m4.mpu.disable_unrestricted_kernel_access;
end disable_unrestricted_kernel_access;
procedure set_region
(region_number : in m4.mpu.t_region_number;
addr : in system_address;
size : in m4.mpu.t_region_size;
region_type : in t_region_type;
subregion_mask : in unsigned_8)
is
access_perm : m4.mpu.t_region_perm;
xn, b, s : boolean;
region_config : m4.mpu.t_region_config;
begin
-- A memory region must never be mapped RWX
case (region_type) is
when REGION_TYPE_KERN_CODE =>
access_perm := REGION_PERM_PRIV_RO_USER_NO;
xn := false;
b := false;
s := false;
when REGION_TYPE_KERN_DATA =>
access_perm := REGION_PERM_PRIV_RW_USER_NO;
xn := true;
b := false;
s := true;
when REGION_TYPE_KERN_DEVICES =>
access_perm := REGION_PERM_PRIV_RW_USER_NO;
xn := true;
b := true;
s := true;
when REGION_TYPE_USER_CODE =>
access_perm := REGION_PERM_PRIV_RO_USER_RO;
xn := false;
b := false;
s := false;
when REGION_TYPE_USER_DATA =>
access_perm := REGION_PERM_PRIV_RW_USER_RW;
xn := true;
b := false;
s := true;
when REGION_TYPE_USER_DEV =>
access_perm := REGION_PERM_PRIV_RW_USER_RW;
xn := true;
b := true;
s := true;
when REGION_TYPE_USER_DEV_RO =>
access_perm := REGION_PERM_PRIV_RW_USER_RO;
xn := true;
b := true;
s := true;
when REGION_TYPE_ISR_STACK =>
access_perm := REGION_PERM_PRIV_RW_USER_RW;
xn := true;
b := false;
s := true;
end case;
region_config :=
(region_number => region_number,
addr => addr,
size => size,
access_perm => access_perm,
xn => xn,
b => b,
s => s,
subregion_mask => subregion_mask);
m4.mpu.configure_region (region_config);
end set_region;
procedure update_subregions
(region_number : in m4.mpu.t_region_number;
subregion_mask : in unsigned_8)
is
begin
m4.mpu.update_subregion_mask (region_number, subregion_mask);
end update_subregions;
procedure bytes_to_region_size
(bytes : in unsigned_32;
region_size : out m4.mpu.t_region_size;
success : out boolean)
is
begin
success := true;
case (bytes) is
when 32 => region_size := REGION_SIZE_32B;
when 64 => region_size := REGION_SIZE_64B;
when 128 => region_size := REGION_SIZE_128B;
when 256 => region_size := REGION_SIZE_256B;
when 512 => region_size := REGION_SIZE_512B;
when 1*KBYTE => region_size := REGION_SIZE_1KB;
when 2*KBYTE => region_size := REGION_SIZE_2KB;
when 4*KBYTE => region_size := REGION_SIZE_4KB;
when 8*KBYTE => region_size := REGION_SIZE_8KB;
when 16*KBYTE => region_size := REGION_SIZE_16KB;
when 32*KBYTE => region_size := REGION_SIZE_32KB;
when 64*KBYTE => region_size := REGION_SIZE_64KB;
when 128*KBYTE => region_size := REGION_SIZE_128KB;
when 256*KBYTE => region_size := REGION_SIZE_256KB;
when 512*KBYTE => region_size := REGION_SIZE_512KB;
when 1*MBYTE => region_size := REGION_SIZE_1MB;
when 2*MBYTE => region_size := REGION_SIZE_2MB;
when 4*MBYTE => region_size := REGION_SIZE_4MB;
when 8*MBYTE => region_size := REGION_SIZE_8MB;
when 16*MBYTE => region_size := REGION_SIZE_16MB;
when 32*MBYTE => region_size := REGION_SIZE_32MB;
when 64*MBYTE => region_size := REGION_SIZE_64MB;
when 128*MBYTE => region_size := REGION_SIZE_128MB;
when 256*MBYTE => region_size := REGION_SIZE_256MB;
when 512*MBYTE => region_size := REGION_SIZE_512MB;
when 1*GBYTE => region_size := REGION_SIZE_1GB;
when 2*GBYTE => region_size := REGION_SIZE_2GB;
when others =>
region_size := REGION_SIZE_32B;
success := false;
end case;
end bytes_to_region_size;
function can_be_mapped return boolean
is
begin
for region in regions_pool'range loop
if not regions_pool(region).used then
return true;
end if;
end loop;
return false;
end can_be_mapped;
procedure map
(addr : in system_address;
size : in unsigned_32;
region_type : in ewok.mpu.t_region_type;
subregion_mask : in unsigned_8;
success : out boolean)
is
region_size : m4.mpu.t_region_size;
ok : boolean;
begin
for region in regions_pool'range loop
if not regions_pool(region).used then
ewok.mpu.bytes_to_region_size (size, region_size, ok);
if not ok then
raise program_error;
end if;
regions_pool(region).used := true;
regions_pool(region).addr := addr;
ewok.mpu.set_region
(region, addr, region_size, region_type, subregion_mask);
success := true;
return;
end if;
end loop;
success := false;
end map;
procedure unmap
(addr : in system_address)
is
begin
for region in regions_pool'range loop
if regions_pool(region).addr = addr and then
regions_pool(region).used
then
m4.mpu.disable_region (region);
regions_pool(region) := (false, 0);
return;
end if;
end loop;
raise program_error;
end unmap;
procedure unmap_all
is
begin
for region in regions_pool'range loop
if regions_pool(region).used then
regions_pool(region) := (false, 0);
m4.mpu.disable_region (region);
end if;
end loop;
end unmap_all;
end ewok.mpu;
|
rtoal/enhanced-dining-philosophers | Ada | 1,977 | ads | ------------------------------------------------------------------------------
-- waiters.ads
--
-- This package supplies a task type for the Waiters in the Enhanced Dining
-- Philosophers simulation, and an array of waiters.
--
-- Entries:
--
-- Here_Is_Your_Name (Name) assigns the name Name to the waiter.
-- Place_Order(O, P, Available) gets order O from Philosopher P and
-- returns whether a cook is immediately
-- available to cook it.
--
-- Behavior:
--
-- A waiter does nothing until assigned a name; then he reports in. At work
-- a waiter runs back and forth between the table and the kitchen. At the
-- table he tries to pick up an order from a customer, but he only waits
-- five seconds for one. If he picks one up he takes it to the kitchen and
-- tries to get a chef to cook it. If none of the cooks are immediately
-- available the waiter gives a coupon to the philosopher that placed the
-- order. At the kitchen the waiter waits up to two seconds to pick up an
-- order from the heat lamp, and then delivers it to the philosopher that
-- ordered it.
--
-- Termination:
--
-- A waiter dies naturally (by completing its task body) whenever he notes
-- that the host has died. Before dying, he checks to see if he is the last
-- waiter to leave (by decrementing and testing a protected counter) and if
-- so, he "locks up" the restaurant (reports that it is closing).
------------------------------------------------------------------------------
with Names, Orders;
use Names, Orders;
package Waiters is
task type Waiter is
entry Here_Is_Your_Name (Name: Waiter_Name);
entry Place_Order(An_Order: Order;
Customer: Philosopher_Name;
Cook_Immediately_Available: out boolean);
end Waiter;
Waiter_Array: array (Waiter_Name) of Waiter;
end Waiters;
|
AdaCore/libadalang | Ada | 109 | adb | procedure Pkg.Foo is
X : Pkg.T;
Y : Integer;
begin
Y := X.X;
pragma Test_Statement;
end Pkg.Foo;
|
onox/orka | Ada | 18,742 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Command_Line;
with Ada.Containers.Indefinite_Holders;
with Ada.Directories;
with Ada.Exceptions;
with Ada.Real_Time;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Containers.Vectors;
with GL.Objects.Samplers;
with GL.Objects.Textures;
with GL.Toggles;
with GL.Types;
with GL.Viewports;
with Orka.Behaviors;
with Orka.Cameras.Rotate_Around_Cameras;
with Orka.Contexts.AWT;
with Orka.Debug;
with Orka.Loggers.Terminal;
with Orka.Logging;
with Orka.Loops;
with Orka.Rendering.Drawing;
with Orka.Rendering.Framebuffers;
with Orka.Rendering.Programs.Modules;
with Orka.Rendering.Programs.Uniforms;
with Orka.Rendering.Textures;
with Orka.Resources.Locations.Directories;
with Orka.Resources.Textures.KTX;
with Orka.Types;
with Orka.Windows;
with AWT.Inputs;
with Orka_Package_KTX;
procedure Orka_KTX is
Width : constant := 1280;
Height : constant := 720;
type Zoom_Mode is (Best_Fit, Actual_Size);
type View_Mode is (External, Internal);
package Job_System renames Orka_Package_KTX.Job_System;
package Loader renames Orka_Package_KTX.Loader;
use type Orka.Integer_32;
package SU renames Ada.Strings.Unbounded;
use type SU.Unbounded_String;
begin
if Ada.Command_Line.Argument_Count /= 1 then
Ada.Text_IO.Put_Line ("Usage: <path to .ktx file>");
Job_System.Shutdown;
Loader.Shutdown;
return;
end if;
Orka.Logging.Set_Logger (Orka.Loggers.Terminal.Create_Logger (Level => Orka.Loggers.Info));
declare
Context : constant Orka.Contexts.Context'Class := Orka.Contexts.AWT.Create_Context
(Version => (4, 2), Flags => (Debug => True, others => False));
Window : constant Orka.Windows.Window'Class
:= Orka.Contexts.AWT.Create_Window (Context, Width, Height, Resizable => False);
begin
Orka.Debug.Set_Log_Messages (Enable => True);
declare
Full_Path : constant String := Ada.Command_Line.Argument (1);
Location_Path : constant String := Ada.Directories.Containing_Directory (Full_Path);
Texture_Path : SU.Unbounded_String :=
SU.To_Unbounded_String (Ada.Directories.Simple_Name (Full_Path));
Load_Texture_Path : SU.Unbounded_String := Texture_Path;
type Load_Action_Kind is (Previous_File, Next_File);
procedure Load_File (Action : Load_Action_Kind) is
package String_Vectors is new Ada.Containers.Vectors
(Positive, SU.Unbounded_String);
Files : String_Vectors.Vector;
procedure Process_File (File : Ada.Directories.Directory_Entry_Type) is
Name : constant String := Ada.Directories.Simple_Name (File);
begin
Files.Append (SU.To_Unbounded_String (Name));
end Process_File;
use all type Ada.Directories.File_Kind;
begin
Ada.Directories.Search
(Directory => Location_Path,
Pattern => "*.ktx",
Filter => (Ordinary_File => True, others => False),
Process => Process_File'Access);
declare
Cursor : String_Vectors.Cursor := Files.Find (Texture_Path);
use type String_Vectors.Cursor;
begin
case Action is
when Previous_File =>
Cursor := String_Vectors.Previous (Cursor);
when Next_File =>
Cursor := String_Vectors.Next (Cursor);
end case;
if Cursor /= String_Vectors.No_Element then
Load_Texture_Path := Files (Cursor);
end if;
end;
end Load_File;
use Orka.Rendering.Programs;
use Orka.Rendering.Framebuffers;
use Orka.Resources;
----------------------------------------------------------------------
FB_D : Framebuffer := Create_Default_Framebuffer (Window.Width, Window.Height);
use Orka.Cameras;
Lens : constant Camera_Lens :=
Create_Lens (Width, Height, Transforms.FOV (36.0, 50.0));
Current_Camera : aliased Rotate_Around_Cameras.Rotate_Around_Camera :=
Rotate_Around_Cameras.Create_Camera (Lens);
----------------------------------------------------------------------
use GL.Objects.Textures;
use GL.Objects.Samplers;
Sampler_1 : Sampler;
Location_Textures : constant Locations.Location_Ptr :=
Locations.Directories.Create_Location (Location_Path);
package Texture_Holders is new Ada.Containers.Indefinite_Holders
(Element_Type => GL.Objects.Textures.Texture);
T_1 : Texture_Holders.Holder;
Maximum_Level : Mipmap_Level;
----------------------------------------------------------------------
Location_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("data/shaders");
function Get_Module (Kind : LE.Texture_Kind) return Modules.Module is
use all type LE.Texture_Kind;
begin
case Kind is
when Texture_1D =>
return Modules.Create_Module (Location_Shaders,
VS => "oversized-triangle.vert",
FS => "tools/ktx-1D.frag");
when Texture_2D =>
return Modules.Create_Module (Location_Shaders,
VS => "oversized-triangle.vert",
FS => "tools/ktx-2D.frag");
when Texture_3D =>
return Modules.Create_Module (Location_Shaders,
VS => "tools/volume.vert",
FS => "tools/ktx-3D.frag");
when Texture_Cube_Map =>
return Modules.Create_Module (Location_Shaders,
VS => "tools/cube.vert",
FS => "tools/ktx-cube.frag");
when Texture_2D_Array =>
return Modules.Create_Module (Location_Shaders,
VS => "oversized-triangle.vert",
FS => "tools/ktx-2D-array.frag");
when others => raise Constraint_Error with "Unsupported texture kind";
end case;
end Get_Module;
procedure Draw (Kind : LE.Texture_Kind) is
use all type LE.Texture_Kind;
begin
case Kind is
when Texture_1D | Texture_2D | Texture_2D_Array =>
Orka.Rendering.Drawing.Draw (GL.Types.Triangles, 0, 3);
when Texture_3D | Texture_Cube_Map =>
Orka.Rendering.Drawing.Draw (GL.Types.Triangles, 0, 6 * 6);
when others => raise Constraint_Error;
end case;
end Draw;
procedure Update_Title
(Kind : LE.Texture_Kind;
Mode : Zoom_Mode;
View : View_Mode;
Colors : Boolean;
Level, Levels : Mipmap_Level)
is
use all type LE.Texture_Kind;
Text : SU.Unbounded_String := "KTX viewer - " & Texture_Path;
begin
if Levels > 1 then
SU.Append (Text, " (level " & Orka.Logging.Trim (Mipmap_Level'Image (Level + 1)) &
"/" & Orka.Logging.Trim (Levels'Image) & ")");
end if;
case Kind is
when Texture_1D | Texture_2D | Texture_2D_Array =>
SU.Append (Text, " (zoom: " & Mode'Image & ")");
when Texture_3D | Texture_Cube_Map =>
SU.Append (Text, " (view: " & View'Image & ")");
SU.Append (Text, " (colors: " & Colors'Image & ")");
when others => null;
end case;
Window.Set_Title (SU.To_String (Text));
end Update_Title;
function Get_Orientation
(Pointer : AWT.Inputs.Pointer_State;
Render_View : View_Mode;
Rotate : Boolean) return Orka.Types.Doubles.Vector4
is
use all type AWT.Inputs.Dimension;
use all type Orka.Index_4D;
use type Orka.Float_64;
Result : Orka.Types.Doubles.Vector4 :=
(0.0, 0.0, Orka.Float_64 (Pointer.Scroll (Y)), 0.0);
begin
if Rotate then
Result (X) := Orka.Float_64 (Pointer.Relative (X));
Result (Y) := Orka.Float_64 (Pointer.Relative (Y));
case Render_View is
when Internal => Result (X) := -Result (X);
when External => Result (Y) := -Result (Y);
end case;
end if;
return Result;
end Get_Orientation;
P_1 : Program;
begin
-- Clear color to black and depth to 0.0 (because of reversed Z)
FB_D.Set_Default_Values
((Color => (0.0, 0.0, 0.0, 1.0), Depth => 0.0, others => <>));
FB_D.Use_Framebuffer;
Sampler_1.Set_X_Wrapping (Clamp_To_Edge);
Sampler_1.Set_Y_Wrapping (Clamp_To_Edge);
Sampler_1.Set_Minifying_Filter (Linear);
Sampler_1.Set_Magnifying_Filter (Linear);
Sampler_1.Bind (0);
GL.Toggles.Disable (GL.Toggles.Depth_Test);
GL.Toggles.Enable (GL.Toggles.Texture_Cube_Map_Seamless);
declare
Level : Mipmap_Level := 0 with Atomic;
Render_Zoom : Zoom_Mode := Best_Fit with Atomic;
Render_View : View_Mode := External with Atomic;
Render_Colors : Boolean := False with Atomic;
package Loops is new Orka.Loops
(Time_Step => Ada.Real_Time.Microseconds (2_083),
Frame_Limit => Ada.Real_Time.Microseconds (16_667),
Camera => Current_Camera'Unchecked_Access,
Job_Manager => Job_System);
procedure Render
(Scene : not null Orka.Behaviors.Behavior_Array_Access;
Camera : Orka.Cameras.Camera_Ptr)
is
use all type LE.Texture_Kind;
begin
FB_D.Clear;
if Load_Texture_Path /= SU.Null_Unbounded_String then
T_1 := Texture_Holders.To_Holder (Orka.Resources.Textures.KTX.Read_Texture
(Location_Textures, SU.To_String (Load_Texture_Path)));
P_1 := Create_Program (Get_Module (T_1.Constant_Reference.Kind));
P_1.Use_Program;
declare
Uni_Texture : constant Uniforms.Uniform_Sampler :=
P_1.Uniform_Sampler ("colorTexture");
begin
Uni_Texture.Verify_Compatibility (T_1.Constant_Reference);
Orka.Rendering.Textures.Bind
(T_1.Constant_Reference, Orka.Rendering.Textures.Texture, 0);
end;
Maximum_Level := T_1.Constant_Reference.Mipmap_Levels - 1;
Level := Mipmap_Level'Min (Level, Maximum_Level);
Texture_Path := Load_Texture_Path;
Load_Texture_Path := SU.Null_Unbounded_String;
end if;
T_1.Constant_Reference.Set_Lowest_Mipmap_Level (Level);
Update_Title
(T_1.Constant_Reference.Kind, Render_Zoom, Render_View, Render_Colors,
Level, Maximum_Level + 1);
case T_1.Constant_Reference.Kind is
when Texture_1D | Texture_2D | Texture_2D_Array =>
declare
Uni_Screen : constant Uniforms.Uniform := P_1.Uniform ("screenSize");
Uni_Best_Fit : constant Uniforms.Uniform := P_1.Uniform ("useBestFit");
begin
Uni_Screen.Set_Vector (Orka.Types.Singles.Vector4'
(Orka.Float_32 (Window.Width), Orka.Float_32 (Window.Height), 0.0, 0.0)
);
Uni_Best_Fit.Set_Boolean (Render_Zoom = Best_Fit);
end;
when Texture_3D | Texture_Cube_Map =>
declare
Uni_View : constant Uniforms.Uniform := P_1.Uniform ("view");
Uni_Proj : constant Uniforms.Uniform := P_1.Uniform ("proj");
Uni_External : constant Uniforms.Uniform := P_1.Uniform ("showExternal");
Uni_Colors : constant Uniforms.Uniform := P_1.Uniform ("showColors");
begin
Uni_View.Set_Matrix (Camera.View_Matrix);
Uni_Proj.Set_Matrix (Camera.Projection_Matrix);
Uni_External.Set_Boolean (Render_View = External);
Uni_Colors.Set_Boolean (Render_Colors);
end;
when others => null;
end case;
-- The viewport of the default framebuffer could be adjusted
-- automatically by implementing Window's procedure On_Configure
GL.Viewports.Set_Viewports
((0 => (X => 0.0,
Y => 0.0,
Width => Orka.Float_32 (Window.Width),
Height => Orka.Float_32 (Window.Height))
));
Draw (T_1.Constant_Reference.Kind);
Window.Swap_Buffers;
if Window.Should_Close then
Loops.Stop_Loop;
end if;
end Render;
begin
Loops.Scene.Add (Orka.Behaviors.Null_Behavior);
declare
task Render_Task is new Orka.Contexts.Task_With_Surface_Context with
entry Move_Context
(Context : not null Orka.Contexts.Surface_Context_Access;
Window : in out Orka.Windows.Window'Class);
end Render_Task;
task body Render_Task is
Context : Orka.Contexts.Surface_Context_Access;
begin
accept Move_Context
(Context : not null Orka.Contexts.Surface_Context_Access;
Window : in out Orka.Windows.Window'Class)
do
Context.Make_Current (Window);
Render_Task.Context := Context;
end Move_Context;
Loops.Run_Loop (Render'Access);
Context.Make_Not_Current;
exception
when Error : others =>
Ada.Text_IO.Put_Line ("Error: " &
Ada.Exceptions.Exception_Information (Error));
Context.Make_Not_Current;
raise;
end Render_Task;
Did_Rotate_Camera : Boolean := False;
begin
Context.Move_To (Render_Task, Window);
while not Window.Should_Close loop
AWT.Process_Events (0.016667);
declare
Pointer : constant AWT.Inputs.Pointer_State := Window.State;
Keyboard : constant AWT.Inputs.Keyboard_State := Window.State;
use all type AWT.Inputs.Button_State;
use all type AWT.Inputs.Keyboard_Button;
use all type AWT.Inputs.Pointer_Button;
use all type AWT.Inputs.Pointer_Mode;
Rotate_Camera : constant Boolean :=
Pointer.Focused and Pointer.Buttons (Right) = Pressed;
begin
if Keyboard.Pressed (Key_Escape) then
Window.Close;
end if;
if Keyboard.Pressed (Key_Arrow_Down) then
Level := Mipmap_Level'Max (0, Level - 1);
end if;
if Keyboard.Pressed (Key_Arrow_Up) then
Level := Mipmap_Level'Min (Maximum_Level, Level + 1);
end if;
if Keyboard.Pressed (Key_Arrow_Left) then
Load_File (Previous_File);
end if;
if Keyboard.Pressed (Key_Arrow_Right) then
Load_File (Next_File);
end if;
if Keyboard.Pressed (Key_Z) then
if Render_Zoom = Zoom_Mode'Last then
Render_Zoom := Zoom_Mode'First;
else
Render_Zoom := Zoom_Mode'Succ (Render_Zoom);
end if;
end if;
if Keyboard.Pressed (Key_V) then
if Render_View = View_Mode'Last then
Render_View := View_Mode'First;
else
Render_View := View_Mode'Succ (Render_View);
end if;
end if;
if Keyboard.Pressed (Key_C) then
Render_Colors := not Render_Colors;
end if;
if Rotate_Camera /= Did_Rotate_Camera then
Window.Set_Pointer_Mode (if Rotate_Camera then Locked else Visible);
end if;
Did_Rotate_Camera := Rotate_Camera;
-- FIXME Update with PO?
Rotate_Around_Cameras.Rotate_Around_Camera'Class
(Current_Camera).Change_Orientation
(Get_Orientation (Pointer, Render_View, Rotate_Camera));
end;
end loop;
end;
end;
end;
end;
Job_System.Shutdown;
Loader.Shutdown;
exception
when Error : others =>
Ada.Text_IO.Put_Line ("Error: " & Ada.Exceptions.Exception_Information (Error));
Job_System.Shutdown;
Loader.Shutdown;
end Orka_KTX;
|
Fabien-Chouteau/Ada_Drivers_Library | Ada | 4,081 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
package HAL.Touch_Panel is
type TP_Touch_State is record
X : Natural;
Y : Natural;
Weight : Natural;
end record;
Null_Touch_State : constant TP_Touch_State := (0, 0, 0);
type Swap_State is new UInt3;
Invert_X : constant Swap_State;
Invert_Y : constant Swap_State;
Swap_XY : constant Swap_State;
subtype Touch_Identifier is Natural range 0 .. 10;
type TP_State is array (Touch_Identifier range <>) of TP_Touch_State;
type Touch_Panel_Device is limited interface;
type Any_Touch_Panel is access all Touch_Panel_Device'Class;
procedure Set_Bounds (This : in out Touch_Panel_Device;
Width : Natural;
Height : Natural;
Swap : Swap_State) is abstract;
-- Set screen bounds. Touch_State must should stay within screen bounds
function Active_Touch_Points (This : in out Touch_Panel_Device)
return Touch_Identifier is abstract;
-- Retrieve the number of active touch points
function Get_Touch_Point (This : in out Touch_Panel_Device;
Touch_Id : Touch_Identifier)
return TP_Touch_State is abstract;
-- Retrieves the position and pressure information of the specified
-- touch
function Get_All_Touch_Points
(This : in out Touch_Panel_Device)
return TP_State is abstract;
-- Retrieves the position and pressure information of every active touch
-- points
private
Invert_X : constant Swap_State := 2#001#;
Invert_Y : constant Swap_State := 2#010#;
Swap_XY : constant Swap_State := 2#100#;
end HAL.Touch_Panel;
|
reznikmm/matreshka | Ada | 17,767 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Utp.Coding_Rules;
with AMF.Utp.Data_Partitions;
with AMF.Utp.Data_Pools;
with AMF.Utp.Data_Selectors;
with AMF.Utp.Default_Applications;
with AMF.Utp.Defaults;
with AMF.Utp.Determ_Alts;
with AMF.Utp.Finish_Actions;
with AMF.Utp.Get_Timezone_Actions;
with AMF.Utp.Literal_Anies;
with AMF.Utp.Literal_Any_Or_Nulls;
with AMF.Utp.Log_Actions;
with AMF.Utp.Managed_Elements;
with AMF.Utp.Read_Timer_Actions;
with AMF.Utp.SUTs;
with AMF.Utp.Set_Timezone_Actions;
with AMF.Utp.Start_Timer_Actions;
with AMF.Utp.Stop_Timer_Actions;
with AMF.Utp.Test_Cases;
with AMF.Utp.Test_Components;
with AMF.Utp.Test_Contexts;
with AMF.Utp.Test_Log_Applications;
with AMF.Utp.Test_Logs;
with AMF.Utp.Test_Objectives;
with AMF.Utp.Test_Suites;
with AMF.Utp.Time_Out_Actions;
with AMF.Utp.Time_Out_Messages;
with AMF.Utp.Time_Outs;
with AMF.Utp.Timer_Running_Actions;
with AMF.Utp.Validation_Actions;
package AMF.Visitors.Utp_Visitors is
pragma Preelaborate;
type Utp_Visitor is limited interface and AMF.Visitors.Abstract_Visitor;
not overriding procedure Enter_Coding_Rule
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Coding_Rules.Utp_Coding_Rule_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Coding_Rule
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Coding_Rules.Utp_Coding_Rule_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Data_Partition
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Partitions.Utp_Data_Partition_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Data_Partition
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Partitions.Utp_Data_Partition_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Data_Pool
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Pools.Utp_Data_Pool_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Data_Pool
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Pools.Utp_Data_Pool_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Data_Selector
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Selectors.Utp_Data_Selector_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Data_Selector
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Data_Selectors.Utp_Data_Selector_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Default
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Defaults.Utp_Default_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Default
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Defaults.Utp_Default_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Default_Application
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Default_Applications.Utp_Default_Application_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Default_Application
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Default_Applications.Utp_Default_Application_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Determ_Alt
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Determ_Alts.Utp_Determ_Alt_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Determ_Alt
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Determ_Alts.Utp_Determ_Alt_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Finish_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Finish_Actions.Utp_Finish_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Finish_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Finish_Actions.Utp_Finish_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Get_Timezone_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Get_Timezone_Actions.Utp_Get_Timezone_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Get_Timezone_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Get_Timezone_Actions.Utp_Get_Timezone_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Literal_Any
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Literal_Anies.Utp_Literal_Any_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Literal_Any
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Literal_Anies.Utp_Literal_Any_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Literal_Any_Or_Null
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Literal_Any_Or_Nulls.Utp_Literal_Any_Or_Null_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Literal_Any_Or_Null
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Literal_Any_Or_Nulls.Utp_Literal_Any_Or_Null_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Log_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Log_Actions.Utp_Log_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Log_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Log_Actions.Utp_Log_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Managed_Element
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Managed_Elements.Utp_Managed_Element_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Managed_Element
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Managed_Elements.Utp_Managed_Element_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Read_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Read_Timer_Actions.Utp_Read_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Read_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Read_Timer_Actions.Utp_Read_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_SUT
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.SUTs.Utp_SUT_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_SUT
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.SUTs.Utp_SUT_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Set_Timezone_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Set_Timezone_Actions.Utp_Set_Timezone_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Set_Timezone_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Set_Timezone_Actions.Utp_Set_Timezone_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Start_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Start_Timer_Actions.Utp_Start_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Start_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Start_Timer_Actions.Utp_Start_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Stop_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Stop_Timer_Actions.Utp_Stop_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Stop_Timer_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Stop_Timer_Actions.Utp_Stop_Timer_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Case
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Cases.Utp_Test_Case_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Case
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Cases.Utp_Test_Case_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Component
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Components.Utp_Test_Component_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Component
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Components.Utp_Test_Component_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Context
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Contexts.Utp_Test_Context_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Context
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Contexts.Utp_Test_Context_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Log
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Logs.Utp_Test_Log_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Log
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Logs.Utp_Test_Log_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Log_Application
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Log_Applications.Utp_Test_Log_Application_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Log_Application
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Log_Applications.Utp_Test_Log_Application_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Objective
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Objectives.Utp_Test_Objective_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Objective
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Objectives.Utp_Test_Objective_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Test_Suite
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Suites.Utp_Test_Suite_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Test_Suite
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Test_Suites.Utp_Test_Suite_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Time_Out
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Outs.Utp_Time_Out_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Time_Out
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Outs.Utp_Time_Out_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Time_Out_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Out_Actions.Utp_Time_Out_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Time_Out_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Out_Actions.Utp_Time_Out_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Time_Out_Message
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Out_Messages.Utp_Time_Out_Message_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Time_Out_Message
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Time_Out_Messages.Utp_Time_Out_Message_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Timer_Running_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Timer_Running_Actions.Utp_Timer_Running_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Timer_Running_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Timer_Running_Actions.Utp_Timer_Running_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Enter_Validation_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Validation_Actions.Utp_Validation_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
not overriding procedure Leave_Validation_Action
(Self : in out Utp_Visitor;
Element : not null AMF.Utp.Validation_Actions.Utp_Validation_Action_Access;
Control : in out AMF.Visitors.Traverse_Control) is null;
end AMF.Visitors.Utp_Visitors;
|
Tim-Tom/project-euler | Ada | 1,090 | adb | with Ada.Text_IO;
package body Problem_04 is
package IO renames Ada.Text_IO;
procedure Solve is
begin
for Larger in reverse 100 .. 999 loop
for Smaller in reverse 100 .. Larger loop
declare
word : constant String := Positive'Image(Larger * Smaller);
lower : Positive := word'First;
upper : Positive := word'Last;
begin
while word(lower) = ' ' loop
lower := lower + 1;
end loop;
while lower < upper loop
if word(lower) /= word(upper) then
goto Next_Number;
end if;
lower := lower + 1;
upper := upper - 1;
end loop;
IO.Put_Line(word);
-- This isn't strictly true, but it happens to work out
-- for this particular problem. (For example 998*998 > 999*100)
return;
end;
end loop;
<<Next_Number>> null;
end loop;
end Solve;
end Problem_04;
|
mfkiwl/ewok-kernel-security-OS | Ada | 2,900 | ads | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with system;
package soc.pwr
with spark_mode => on
is
-----------------------------------------
-- PWR power control register (PWR_CR) --
-- for STM32F42xxx and STM32F43xxx --
-----------------------------------------
type t_vos is (VOS_SCALE3, VOS_SCALE2, VOS_SCALE1) with size => 2;
for t_vos use
(VOS_SCALE3 => 2#01#,
VOS_SCALE2 => 2#10#,
VOS_SCALE1 => 2#11#);
type t_PWR_CR is record
LPDS : bit;
PDDS : bit;
CWUF : bit;
CSBF : bit;
PVDE : bit;
PLS : bits_3;
DBP : bit;
FPDS : bit;
LPUDS : bit;
MRUDS : bit;
reserved_12_12 : bit;
ADCDC1 : bit;
VOS : t_vos;
ODEN : bit;
ODSWEN : bit;
UDEN : bits_2;
reserved_20_31 : bits_12;
end record
with volatile_full_access, size => 32;
for t_PWR_CR use record
LPDS at 0 range 0 .. 0;
PDDS at 0 range 1 .. 1;
CWUF at 0 range 2 .. 2;
CSBF at 0 range 3 .. 3;
PVDE at 0 range 4 .. 4;
PLS at 0 range 5 .. 7;
DBP at 0 range 8 .. 8;
FPDS at 0 range 9 .. 9;
LPUDS at 0 range 10 .. 10;
MRUDS at 0 range 11 .. 11;
reserved_12_12 at 0 range 12 .. 12;
ADCDC1 at 0 range 13 .. 13;
VOS at 0 range 14 .. 15;
ODEN at 0 range 16 .. 16;
ODSWEN at 0 range 17 .. 17;
UDEN at 0 range 18 .. 19;
reserved_20_31 at 0 range 20 .. 31;
end record;
--------------------
-- PWR peripheral --
--------------------
type t_PWR_peripheral is record
CR : t_PWR_CR;
end record
with volatile;
for t_PWR_peripheral use record
CR at 16#00# range 0 .. 31;
end record;
PWR : t_PWR_peripheral
with
import,
volatile,
address => system'to_address(16#4000_7000#);
end soc.pwr;
|
flyx/OpenGLAda | Ada | 1,491 | adb | -- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Buffers; use GL.Buffers;
with GL.Immediate; use GL.Immediate;
with GL.Fixed.Matrix; use GL.Fixed.Matrix;
with GL.Types.Colors; use GL.Types;
use GL.Fixed;
with GL_Test.Display_Backend;
procedure GL_Test.Immediate is
use GL.Types.Doubles;
begin
Display_Backend.Init;
Display_Backend.Open_Window (Width => 500, Height => 500);
Projection.Load_Identity;
Projection.Apply_Orthogonal (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
while not Display_Backend.Escape_Pressed and
Display_Backend.Window_Opened loop
Clear (Buffer_Bits'(others => True));
Projection.Push;
for I in 1 .. 12 loop
declare
Token : Input_Token := Start (Line_Strip);
begin
Set_Color (Colors.Color'(1.0, 0.0, 0.0, 0.0));
Token.Add_Vertex (Vector4'(0.1, 0.4, 0.0, 1.0));
Token.Add_Vertex (Vector4'(0.1, 0.6, 0.0, 1.0));
Token.Add_Vertex (Vector4'(-0.1, 0.6, 0.0, 1.0));
Token.Add_Vertex (Vector4'(-0.1, 0.4, 0.0, 1.0));
end;
Projection.Apply_Rotation (360.0 / 12.0, 0.0, 0.0, 1.0);
end loop;
Projection.Pop;
Projection.Apply_Rotation (0.8, 0.0, 0.0, 1.0);
GL.Flush;
Display_Backend.Swap_Buffers;
Display_Backend.Poll_Events;
end loop;
Display_Backend.Shutdown;
end GL_Test.Immediate;
|
reznikmm/matreshka | Ada | 4,019 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Table_Start_Table_Attributes;
package Matreshka.ODF_Table.Start_Table_Attributes is
type Table_Start_Table_Attribute_Node is
new Matreshka.ODF_Table.Abstract_Table_Attribute_Node
and ODF.DOM.Table_Start_Table_Attributes.ODF_Table_Start_Table_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Start_Table_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Start_Table_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Table.Start_Table_Attributes;
|
MinimSecure/unum-sdk | Ada | 832 | adb | -- Copyright 2014-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package body Pck is
procedure Do_Nothing (A : System.Address) is
begin
null;
end Do_Nothing;
end Pck;
|
rkoeninger/life | Ada | 2,580 | adb | package body World is
---------------
-- New_World --
---------------
function New_World (Size : Positive) return World_Grid is
begin
return World_Grid'(Size => Size,
Grid1 => (others => (others => False)),
Grid2 => (others => (others => False)),
Step => 0);
end;
--------------
-- Get_Spot --
--------------
function Get_Spot (W : World_Grid; X, Y : Positive) return Boolean is
begin
if X not in 1 .. W.Size or Y not in 1 .. W.Size then
return False;
elsif W.Size mod 2 = 1 then
return W.Grid1 (X, Y);
else
return W.Grid2 (X, Y);
end if;
end;
--------------
-- Set_Spot --
--------------
procedure Set_Spot (W : in out World_Grid; X, Y : Positive; B : Boolean) is
begin
if W.Size mod 2 = 1 then
W.Grid2 (X, Y) := B;
else
W.Grid1 (X, Y) := B;
end if;
end;
--------------
-- Run_Step --
--------------
procedure Run_Step (W : in out World_Grid) is
Count : Natural;
begin
W.Step := W.Step + 1;
for X in Positive range 1 .. W.Size loop
for Y in Positive range 1 .. W.Size loop
Count := Live_Neighbors (W, X, Y);
if Count < 2 then
Set_Spot (W, X, Y, False); -- Underpopulation
elsif Count = 2 then
Set_Spot (W, X, Y, Get_Spot (W, X, Y)); -- Survival
elsif Count = 3 then
Set_Spot (W, X, Y, True); -- Reproduction
elsif Count > 3 then
Set_Spot (W, X, Y, False); -- Overpopulation
end if;
end loop;
end loop;
end;
--------------------
-- Live_Neighbors --
--------------------
function Live_Neighbors (W : World_Grid; X, Y : Positive) return Natural is
Count : Natural := 0;
procedure Count_Neighbor (W : World_Grid; Count : in out Natural; X, Y : Positive) is
begin
if Get_Spot (W, X, Y) then
Count := Count + 1;
end if;
end Count_Neighbor;
begin
Count_Neighbor (W, Count, X - 1, Y - 1);
Count_Neighbor (W, Count, X, Y - 1);
Count_Neighbor (W, Count, X + 1, Y - 1);
Count_Neighbor (W, Count, X - 1, Y);
Count_Neighbor (W, Count, X + 1, Y);
Count_Neighbor (W, Count, X - 1, Y + 1);
Count_Neighbor (W, Count, X, Y + 1);
Count_Neighbor (W, Count, X + 1, Y + 1);
return Count;
end;
end;
|
optikos/oasis | Ada | 1,965 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Element_Vectors;
with Program.Elements.Definitions;
with Program.Lexical_Elements;
package Program.Elements.Variants is
pragma Pure (Program.Elements.Variants);
type Variant is
limited interface and Program.Elements.Definitions.Definition;
type Variant_Access is access all Variant'Class with Storage_Size => 0;
not overriding function Choices
(Self : Variant)
return not null Program.Element_Vectors.Element_Vector_Access
is abstract;
not overriding function Components
(Self : Variant)
return not null Program.Element_Vectors.Element_Vector_Access
is abstract;
type Variant_Text is limited interface;
type Variant_Text_Access is access all Variant_Text'Class
with Storage_Size => 0;
not overriding function To_Variant_Text
(Self : aliased in out Variant)
return Variant_Text_Access is abstract;
not overriding function When_Token
(Self : Variant_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Arrow_Token
(Self : Variant_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
type Variant_Vector is
limited interface and Program.Element_Vectors.Element_Vector;
type Variant_Vector_Access is access all Variant_Vector'Class
with Storage_Size => 0;
overriding function Element
(Self : Variant_Vector;
Index : Positive)
return not null Program.Elements.Element_Access is abstract
with Post'Class => Element'Result.Is_Variant;
function To_Variant
(Self : Variant_Vector'Class;
Index : Positive)
return not null Variant_Access is (Self.Element (Index).To_Variant);
end Program.Elements.Variants;
|
adamnemecek/GA_Ada | Ada | 1,677 | ads |
with GL.Types; use GL.Types;
with GA_Maths;
with E2GA;
with E3GA;
with Multivector;
package GL_Util is
type Pick_Window is array (1 .. 4) of Single;
type GL_Pick is record
Pick_Active : Boolean := False; -- set to true during picking
-- set to picking window (x, y, w, h) during picking
OpenGL_Pick : Pick_Window := (others => 0.0);
-- Must be set correctly by caller of pick() to get correct distances returned
Frustum_Near : Single := 1.0;
-- Must be set correctly by caller of pick() to get correct distances returned
Frustum_Far : Single := 100.0;
-- not required for pick(), provided for completenes
FrustumWidth : Single := 0.0;
-- not required for pick(), provided for completenes
Frustum_Height : Single := 0.0;
Pick_Window_Size : Int := 4;
end record;
procedure GL_Color_3fm (R, G, B : GL.Types.Single);
procedure Load_Pick_Matrix;
function Rotor_To_GL_Matrix (R : Multivector.Rotor) return GL.Types.Singles.Matrix4;
procedure Rotor_GL_Multiply (R : Multivector.Rotor; GL_Matrix : in out GL.Types.Singles.Matrix4);
function To_GL (V3 : Multivector.Vector) return GL.Types.Doubles.Vector3;
function To_GL (V3 : Multivector.Vector) return GL.Types.Singles.Vector3;
-- function To_GL (V2 : Multivector.Vector) return GL.Types.Singles.Vector3;
procedure Viewport_Coordinates (Pt_World : GA_Maths.Array_3D;
Model_View_Matrix,
Projection_Matrix : GL.Types.Singles.Matrix4;
Coords : out GL.Types.Singles.Vector2);
end GL_Util;
|
ZinebZaad/ENSEEIHT | Ada | 3,257 | adb | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Lire_Entier is
Base_MAX : constant Integer := 10 + 26; -- 10 chiffres ('0'..'9') + 26 lettres ('A'..'Z')
-- Est-ce que la base est valide ?
function Est_Base_Valide(Base : in Integer) return Boolean is
begin
return 2 <= Base and Base <= Base_MAX;
--return True;
end Est_Base_Valide;
-- Transformer indice en nombre entierdans base10
function Indice_En_Base10(Indice: Character) return Integer is
begin
if Indice >= '0' and Indice <= '9' then
return Character'Pos(Indice) - Character'Pos('0');
else
return 10 + Character'Pos(Indice) - Character'Pos('A');
end if;
end Indice_En_Base10;
function Nombre_En_Indice(Nombre: Integer) return Character is
begin
if Nombre < 10 then
return Character'Val(Nombre + Character'Pos('0'));
else
return Character'Val(Nombre - 10 + Character'Pos('A'));
end if;
end Nombre_En_Indice;
-- Lire un entier au clavier dans la base considérée.
procedure Lire (
Nombre: out Integer ; -- l'entier lu au clavier
Base: in Integer := 10 -- la base à utiliser
) with
Pre => Est_Base_Valide (Base)
is
NbrEnBase: String(1 .. 10);
Iteration: Integer;
begin
Get_Line(NbrEnBase, Iteration);
Nombre := 0;
for char of NbrEnBase loop
Iteration := Iteration - 1;
Nombre := Nombre + Indice_En_Base10(char) * Base**Iteration;
exit when Iteration = 0;
end loop;
end Lire;
-- Écrire un entier dans une base donnée.
procedure Ecrire (
Nombre: in Integer ; -- l'entier à écrire
Base : in Integer -- la base à utliser
) with
Pre => Est_Base_Valide (Base)
and Nombre >= 0
is
begin
if Nombre < Base then
Put(Nombre_En_Indice(Nombre));
return;
end if;
Ecrire(Nombre/Base, Base);
Put(Nombre_En_Indice(Nombre mod Base));
end Ecrire;
Base_Lecture: Integer; -- la base de l'entier lu
Base_Ecriture: Integer; -- la base de l'entier écrit
Un_Entier: Integer; -- un entier lu au clavier
begin
-- Demander la base de lecture
Put ("Base de l'entier lu : ");
Get (Base_Lecture);
Skip_Line;
-- Demander un entier
Put ("Un entier (base ");
Put (Base_Lecture, 1);
Put (") : ");
if Est_Base_Valide(Base_Lecture) then
Lire (Un_Entier, Base_Lecture);
else
Skip_Line;
Un_Entier := 0;
end if;
-- Afficher l'entier lu en base 10
Put ("L'entier lu est (base 10) : ");
Put (Un_Entier, 1);
New_Line;
-- Demander la base d'écriture
Put ("Base pour écrire l'entier : ");
Get (Base_Ecriture);
Skip_Line;
-- Afficher l'entier lu dans la base d'écriture
if Est_Base_Valide(Base_Lecture) then
Put ("L'entier en base ");
Put (Base_Ecriture, 1);
Put (" est ");
Ecrire (Un_Entier, Base_Ecriture);
New_Line;
end if;
-- Remarque : on aurait pu utiliser les sous-programme Lire pour lire
-- les bases et Ecrire pour les écrire en base 10. Nous utilisons les
-- Get et Put d'Ada pour faciliter le test du programme.
end Lire_Entier; |
zhmu/ananas | Ada | 3,690 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . E X P O N T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Signed integer exponentiation (checks on)
with Ada.Numerics.Big_Numbers.Big_Integers_Ghost;
use Ada.Numerics.Big_Numbers.Big_Integers_Ghost;
generic
type Int is range <>;
package System.Expont
with Pure, SPARK_Mode
is
-- Preconditions in this unit are meant for analysis only, not for run-time
-- checking, so that the expected exceptions are raised. This is enforced
-- by setting the corresponding assertion policy to Ignore. Postconditions
-- and contract cases should not be executed at runtime as well, in order
-- not to slow down the execution of these functions.
pragma Assertion_Policy (Pre => Ignore,
Post => Ignore,
Contract_Cases => Ignore,
Ghost => Ignore);
package Signed_Conversion is new Signed_Conversions (Int => Int);
function Big (Arg : Int) return Big_Integer is
(Signed_Conversion.To_Big_Integer (Arg))
with Ghost;
function In_Int_Range (Arg : Big_Integer) return Boolean is
(In_Range (Arg, Big (Int'First), Big (Int'Last)))
with Ghost;
function Expon (Left : Int; Right : Natural) return Int
with
Pre => In_Int_Range (Big (Left) ** Right),
Post => Expon'Result = Left ** Right;
end System.Expont;
|
michalkonecny/polypaver | Ada | 9,452 | adb | with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
with Ada.Characters;
with Ada.Characters.Handling;
use Ada.Characters.Handling;
with Ada.Exceptions;
with Asis;
with Asis.Implementation;
with Asis.Exceptions;
with Asis.Errors;
with Asis.Iterator;
with Asis.Expressions;
with Asis.Declarations;
with Asis.Text;
with FP_Detect; use FP_Detect;
package body FP_Translation is
-- Put the program text defined by the given span within
-- the compilation unit body that contains the given Element.
procedure Put_Current_Span
(Element : Asis.Element; State : Traversal_State)
is
Span : constant Asis.Text.Span := State.Span;
begin
if not Asis.Text.Is_Nil(Span) then
declare
LS : Asis.Text.Line_List := Asis.Text.Lines(Element, Span);
L1 : Wide_String := Asis.Text.Line_Image(LS(LS'First));
begin
Put(State.Output_File, L1(Span.First_Column .. L1'Last));
if Span.First_Line < Span.Last_Line then
New_Line(State.Output_File);
for I in LS'First+1 .. LS'Last-1 loop
Put(State.Output_File, Asis.Text.Line_Image(LS(I)));
New_Line(State.Output_File);
end loop;
Put(State.Output_File, Asis.Text.Line_Image(LS(LS'Last)));
end if;
end;
end if;
end Put_Current_Span;
function Spans_Multiple_Lines (Expr : Asis.Element) return Boolean is
Expr_Span : Asis.Text.Span := Asis.Text.Element_Span(Expr);
begin
return Expr_Span.First_Line < Expr_Span.Last_Line;
end Spans_Multiple_Lines;
procedure Put_Prefix
(FP_Operator : Maybe_FP_Operator;
State : Traversal_State;
Is_Multi_Line : Boolean;
First_Column : Positive)
is
Type_Info : FP_Type := FP_Operator.Type_Info;
begin
-- add type conversion if the type is non-standard:
if not Type_Info.Is_Standard then
Put(State.Output_File, Asis.Declarations.Defining_Name_Image(Type_Info.Name));
end if;
Put(State.Output_File, "(PP_");
Put(State.Output_File, FP_Type_Code'Wide_Image(FP_Operator.Type_Info.Code));
Put(State.Output_File, "_Rounded.");
case FP_Operator.Kind is
when Field_Op =>
case FP_Operator.Op_Kind is
when Asis.A_Plus_Operator => Put(State.Output_File, "Plus");
when Asis.A_Minus_Operator => Put(State.Output_File, "Minus");
when Asis.A_Multiply_Operator => Put(State.Output_File, "Multiply");
when Asis.A_Divide_Operator => Put(State.Output_File, "Divide");
when Asis.An_Exponentiate_Operator => Put(State.Output_File, "Exponentiate");
when others => Put(State.Output_File, "UNKNOWN_FP_OP");
end case;
when Elementary_Fn =>
Put(State.Output_File, Asis.Expressions.Name_Image(FP_Operator.Fn_Name));
when Not_An_FP_Operator =>
Put(State.Output_File, "UNKNOWN_FP_OP");
end case;
Put(State.Output_File, "(");
Put(State.Output_File, To_Wide_String(Integer'Image(FP_Operator.Type_Info.Precision)));
end Put_Prefix;
procedure Recursive_Construct_Processing is new
Asis.Iterator.Traverse_Element
(State_Information => Traversal_State,
Pre_Operation => Pre_Op,
Post_Operation => Post_Op);
procedure Put_Params
(Params_Association : Asis.Association_List;
Is_Standard_Type : Boolean;
State : in out Traversal_State;
Is_Multi_Line : Boolean;
First_Column : Positive)
is
Param : Asis.Element;
begin
for I in Params_Association'Range loop
Param := Asis.Expressions.Actual_Parameter(Params_Association(I));
declare
Process_Control : Asis.Traverse_Control := Asis.Continue;
begin
-- print parameter separator, possibly a multi-line one:
if Is_Multi_Line then
New_Line(State.Output_File);
for I in 2..First_Column loop Put(State.Output_File, " "); end loop;
end if;
Put(State.Output_File, ", ");
-- optionally put type conversion if the type is non-standard:
if not Is_Standard_Type then
Put(State.Output_File, " Long_Float");
end if;
Put(State.Output_File, "(");
-- traverse the actual parameter expression,
-- translating FP operators within it:
State.Span := Asis.Text.Element_Span(Param);
Recursive_Construct_Processing
(Element => Param,
Control => Process_Control,
State => State);
-- print the remainder of the parameter expression:
Put_Current_Span(Param, State);
Put(State.Output_File, ")");
end;
end loop;
end Put_Params;
procedure Split_Span
(orig, sub : in Asis.Text.Span;
left, right : out Asis.Text.Span)
is
begin
left :=
(First_Line => orig.First_Line,
First_Column => orig.First_Column,
Last_Line => sub.First_Line,
Last_Column => sub.First_Column - 1);
right :=
(First_Line => sub.Last_Line,
First_Column => sub.Last_Column + 1,
Last_Line => orig.Last_Line,
Last_Column => orig.Last_Column);
end Split_Span;
procedure Put_Span_Description(Span : Asis.Text.Span) is
begin
Put("(");
Put(To_Wide_String(Integer'Image(Span.First_Line)));
Put(":");
Put(To_Wide_String(Integer'Image(Span.First_Column)));
Put(")..(");
Put(To_Wide_String(Integer'Image(Span.Last_Line)));
Put(":");
Put(To_Wide_String(Integer'Image(Span.Last_Column)));
Put(")");
end Put_Span_Description;
procedure Pre_Op
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out Traversal_State)
is
This_FP_Operator : Maybe_FP_Operator := Is_FP_Operator_Expression(Element);
Is_Multi_Line : Boolean := Spans_Multiple_Lines(Element);
begin
if This_FP_Operator.Kind /= Not_An_FP_Operator then
-- do not traverse the sub-expressions:
Control := Asis.Abandon_Children;
if State.Trace then
Put("Processing FP expression at ");
Put_Span_Description(Asis.Text.Element_Span(Element));
New_Line;
Put("--------");
New_Line;
Put(Asis.Text.Element_Image(Element));
New_Line;
Put("--------");
New_Line;
end if;
declare
e_span : Asis.Text.Span := Asis.Text.Element_Span(Element);
left, right : Asis.Text.Span;
begin
Split_Span(State.Span, e_span, left, right);
-- put everything up to this expression:
State.Span := left;
Put_Current_Span(Element, State);
Put_Prefix(This_FP_Operator,
State,
Is_Multi_Line,
e_span.First_Column);
Put_Params(Asis.Expressions.Function_Call_Parameters(Element),
This_FP_Operator.Type_Info.Is_Standard,
State,
Is_Multi_Line,
e_span.First_Column);
Put(State.Output_File, "))");
-- only the "right" span now remains to be processed and put:
State.Span := right;
end;
end if;
exception
when Ex : Asis.Exceptions.ASIS_Inappropriate_Context |
Asis.Exceptions.ASIS_Inappropriate_Container |
Asis.Exceptions.ASIS_Inappropriate_Compilation_Unit |
Asis.Exceptions.ASIS_Inappropriate_Element |
Asis.Exceptions.ASIS_Inappropriate_Line |
Asis.Exceptions.ASIS_Inappropriate_Line_Number |
Asis.Exceptions.ASIS_Failed =>
Ada.Wide_Text_IO.Put ("Pre_Op : ASIS exception (");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Name (Ex)));
Ada.Wide_Text_IO.Put (") is raised");
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put ("ASIS Error Status is ");
Ada.Wide_Text_IO.Put
(Asis.Errors.Error_Kinds'Wide_Image (Asis.Implementation.Status));
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put ("ASIS Diagnosis is ");
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put (Asis.Implementation.Diagnosis);
Ada.Wide_Text_IO.New_Line;
Asis.Implementation.Set_Status;
when Ex : others =>
Ada.Wide_Text_IO.Put ("Pre_Op : ");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Name (Ex)));
Ada.Wide_Text_IO.Put (" is raised (");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Information (Ex)));
Ada.Wide_Text_IO.Put (")");
Ada.Wide_Text_IO.New_Line;
end Pre_Op;
procedure Post_Op
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out Traversal_State)
is
begin
null;
end Post_Op;
end FP_Translation;
|
stcarrez/atlas | Ada | 3,320 | adb | -----------------------------------------------------------------------
-- atlas-microblog-modules -- Module microblog
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Calendar;
with AWA.Modules.Beans;
with AWA.Modules.Get;
with AWA.Services.Contexts;
with ADO.Sessions;
with Util.Log.Loggers;
with Atlas.Microblog.Beans;
package body Atlas.Microblog.Modules is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Atlas.Microblog.Module");
package Register is new AWA.Modules.Beans (Module => Microblog_Module,
Module_Access => Microblog_Module_Access);
-- ------------------------------
-- Initialize the microblog module.
-- ------------------------------
overriding
procedure Initialize (Plugin : in out Microblog_Module;
App : in AWA.Modules.Application_Access;
Props : in ASF.Applications.Config) is
begin
Log.Info ("Initializing the microblog module");
-- Register here any bean class, servlet, filter.
Register.Register (Plugin => Plugin,
Name => "Atlas.Microblog.Beans.Microblog_Bean",
Handler => Atlas.Microblog.Beans.Create_Microblog_Bean'Access);
Register.Register (Plugin => Plugin,
Name => "Atlas.Microblog.Beans.List_Bean",
Handler => Atlas.Microblog.Beans.Create_List_Bean'Access);
AWA.Modules.Module (Plugin).Initialize (App, Props);
-- Add here the creation of manager instances.
end Initialize;
-- ------------------------------
-- Get the microblog module.
-- ------------------------------
function Get_Microblog_Module return Microblog_Module_Access is
function Get is new AWA.Modules.Get (Microblog_Module, Microblog_Module_Access, NAME);
begin
return Get;
end Get_Microblog_Module;
-- ------------------------------
-- Create a post for the microblog.
-- ------------------------------
procedure Create (Plugin : in Microblog_Module;
Post : in out Atlas.Microblog.Models.Mblog_Ref) is
pragma Unreferenced (Plugin);
use AWA.Services;
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
begin
Ctx.Start;
Post.Set_Creation_Date (Ada.Calendar.Clock);
Post.Set_Author (Ctx.Get_User);
Post.Save (DB);
Ctx.Commit;
end Create;
end Atlas.Microblog.Modules;
|
twdroeger/ada-awa | Ada | 10,404 | adb | -----------------------------------------------------------------------
-- awa-modules-tests - Unit tests for Modules
-- Copyright (C) 2011, 2012, 2019 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Beans.Basic;
with Util.Beans.Objects;
with Ada.Unchecked_Deallocation;
with EL.Contexts.Default;
with ASF.Applications.Main;
with AWA.Modules.Beans;
with AWA.Services.Contexts;
package body AWA.Modules.Tests is
use Util.Tests;
type Test_Module is new AWA.Modules.Module with null record;
type Test_Module_Access is access all Test_Module'Class;
type Test_Bean is new Util.Beans.Basic.Bean with record
Module : Test_Module_Access := null;
Name : Util.Beans.Objects.Object;
Email : Util.Beans.Objects.Object;
end record;
type Test_Bean_Access is access all Test_Bean'Class;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
overriding
function Get_Value (From : in Test_Bean;
Name : in String) return Util.Beans.Objects.Object;
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
overriding
procedure Set_Value (From : in out Test_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object);
function Create_Form_Bean (Plugin : in Test_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access;
package Module_Register is new AWA.Modules.Beans (Test_Module, Test_Module_Access);
package Caller is new Util.Test_Caller (Test, "AWA.Modules");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test ASF.Modules.Register",
Test_Create_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Modules.Find_Module",
Test_Find_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Applications.Main.Register",
Test_Create_Application_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Applications.Main.Create",
Test_Create_Application_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Navigations.Mappers",
Test_Module_Navigation'Access);
end Add_Tests;
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
function Get_Value (From : in Test_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "module" then
return Util.Beans.Objects.To_Object (From.Module.Get_Name);
elsif Name = "name" then
return From.Name;
elsif Name = "email" then
return From.Email;
else
return Util.Beans.Objects.Null_Object;
end if;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
-- ------------------------------
overriding
procedure Set_Value (From : in out Test_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "name" then
From.Name := Value;
elsif Name = "email" then
From.Email := Value;
end if;
end Set_Value;
function Create_Form_Bean (Plugin : in Test_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Test_Bean_Access := new Test_Bean;
begin
Result.Module := Plugin;
return Result.all'Access;
end Create_Form_Bean;
-- ------------------------------
-- Initialize the test application
-- ------------------------------
procedure Set_Up (T : in out Test) is
Fact : ASF.Applications.Main.Application_Factory;
C : ASF.Applications.Config;
begin
Log.Info ("Creating application");
T.App := new AWA.Applications.Application;
C.Copy (Util.Tests.Get_Properties);
C.Set ("app_search_dirs", Util.Tests.Get_Path ("regtests") & ";"
& C.Get ("app_search_dirs", ""));
T.App.Initialize (C, Fact);
T.App.Register ("layoutMsg", "layout");
end Set_Up;
-- ------------------------------
-- Deletes the application object
-- ------------------------------
overriding
procedure Tear_Down (T : in out Test) is
procedure Free is
new Ada.Unchecked_Deallocation (Object => AWA.Applications.Application'Class,
Name => AWA.Applications.Application_Access);
begin
Log.Info ("Releasing application");
Free (T.App);
end Tear_Down;
-- ------------------------------
-- Test creation of module
-- ------------------------------
procedure Test_Create_Module (T : in out Test) is
M : aliased Test_Module;
R : aliased Module_Registry;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
R.Config.Copy (Util.Tests.Get_Properties);
M.App := T.App.all'Access;
Register (R'Unchecked_Access, M.App, M'Unchecked_Access, "empty", "uri");
T.Assert_Equals ("empty", M.Get_Name, "Invalid module name");
T.Assert_Equals ("uri", M.Get_URI, "Invalid module uri");
T.Assert (Find_By_Name (R, "empty") = M'Unchecked_Access, "Find_By_Name failed");
T.Assert (Find_By_URI (R, "uri") = M'Unchecked_Access, "Find_By_URI failed");
end Test_Create_Module;
-- ------------------------------
-- Test looking for module
-- ------------------------------
procedure Test_Find_Module (T : in out Test) is
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
T.App.Register (M'Unchecked_Access, "empty", "uri");
T.Assert (M.Find_Module ("empty") /= null, "Find_Module should not return a null value");
T.Assert (M.Find_Module ("toto") = null, "Find_Module should return null");
end Test_Find_Module;
-- ------------------------------
-- Test creation of a module and registration in an application.
-- ------------------------------
procedure Test_Create_Application_Module (T : in out Test) is
use ASF.Beans;
procedure Check (Name : in String;
Kind : in ASF.Beans.Scope_Type);
procedure Check (Name : in String;
Kind : in ASF.Beans.Scope_Type) is
use type Util.Beans.Basic.Readonly_Bean_Access;
Value : Util.Beans.Objects.Object;
Bean : Util.Beans.Basic.Readonly_Bean_Access;
Scope : ASF.Beans.Scope_Type;
Context : EL.Contexts.Default.Default_Context;
begin
T.App.Create (Name => To_Unbounded_String (Name),
Context => Context,
Result => Bean,
Scope => Scope);
T.Assert (Kind = Scope, "Invalid scope for " & Name);
T.Assert (Bean /= null, "Invalid bean object");
Value := Util.Beans.Objects.To_Object (Bean);
T.Assert (not Util.Beans.Objects.Is_Null (Value), "Invalid bean");
T.Assert_Equals ("test-module",
Util.Beans.Objects.To_String (Bean.Get_Value ("module")),
"Bean module name");
-- Special test for the sessionForm bean which is initialized by configuration properties
if Name = "sessionForm" then
T.Assert_Equals ("[email protected]",
Util.Beans.Objects.To_String (Bean.Get_Value ("email")),
"Session form not initialized");
end if;
end Check;
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
Module_Register.Register (Plugin => M,
Name => "ASF.Applications.Tests.Form_Bean",
Handler => Create_Form_Bean'Access);
T.App.Register (M'Unchecked_Access, "test-module", "uri");
T.Assert (M.Find_Module ("test-module") /= null,
"Find_Module should not return a null value");
T.Assert (M.Find_Module ("toto") = null, "Find_Module should return null");
-- Check the 'regtests/config/test-module.xml' managed bean configuration.
Check ("applicationForm", ASF.Beans.APPLICATION_SCOPE);
Check ("sessionForm", ASF.Beans.SESSION_SCOPE);
Check ("requestForm", ASF.Beans.REQUEST_SCOPE);
end Test_Create_Application_Module;
-- ------------------------------
-- Test module and navigation rules
-- ------------------------------
procedure Test_Module_Navigation (T : in out Test) is
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
Module_Register.Register (Plugin => M,
Name => "ASF.Applications.Tests.Form_Bean",
Handler => Create_Form_Bean'Access);
T.App.Register (M'Unchecked_Access, "test-navigations", "uri");
T.Assert (M.Find_Module ("test-navigations") /= null,
"Find_Module should not return a null value");
end Test_Module_Navigation;
end AWA.Modules.Tests;
|
glencornell/ada-socketcan | Ada | 2,897 | adb | -- MIT License
--
-- Copyright (c) 2021 Glen Cornell <[email protected]>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
with Ada.Text_Io;
with Sockets.Can.Broadcast_Manager;
with Sockets.Can_Frame;
with Interfaces;
with Create_Can_Frame;
procedure Bcm_Cyclic_Writer is
If_Name : constant String := "vcan0";
Unused_C : Character;
Bcm : Sockets.Can.Broadcast_Manager.Broadcast_Manager_Type;
Frame_1 : constant Sockets.Can_Frame.Can_Frame :=
Create_Can_Frame (Can_Id => 16#10#,
Data => (16#11#, 16#22#, 16#33#));
Frame_2 : Sockets.Can_Frame.Can_Frame :=
Create_Can_Frame (Can_Id => 16#20#,
Data => (1 => 16#AA#));
Frame_3 : constant Sockets.Can_Frame.Can_Frame :=
Create_Can_Frame (Can_Id => 16#30#,
Data => (16#DE#, 16#AD#, 16#BE#, 16#EF#));
task type T is
entry Start;
entry Stop;
end T;
task body T is
use type Interfaces.Unsigned_8;
I : Interfaces.Unsigned_8 := 255;
Terminated : Boolean := False;
begin
accept Start;
while not Terminated loop
-- Modular integer types in Ada have wrap-around semantics.
-- So the addition operation below will not raise an
-- exception and will allow one to observe continual changes
-- to the first data byte in CAN frame with ID=0x20.
I := I + 1;
Frame_2.Data(Frame_2.Data'First) := I;
Bcm.Update_Periodic (Frame_2);
select
accept Stop do
Terminated := True;
end Stop;
or
delay 0.1;
end select;
end loop;
end T;
Updater : T;
begin
Bcm.Create (If_Name);
Bcm.Send_Periodic (Frame_1, 0.5);
Bcm.Send_Periodic (Frame_2, 1.0);
Bcm.Send_Periodic (Frame_3, 0.25);
Updater.Start;
Ada.Text_Io.Put_Line ("Press any key to stop");
Ada.Text_Io.Get (Unused_C);
Updater.Stop;
end Bcm_Cyclic_Writer;
|
reznikmm/matreshka | Ada | 7,141 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.CMOF.Associations;
with AMF.CMOF.Classes;
with AMF.CMOF.Comments;
with AMF.CMOF.Constraints;
with AMF.CMOF.Data_Types;
with AMF.CMOF.Element_Imports;
with AMF.CMOF.Enumeration_Literals;
with AMF.CMOF.Enumerations;
with AMF.CMOF.Expressions;
with AMF.CMOF.Opaque_Expressions;
with AMF.CMOF.Operations;
with AMF.CMOF.Package_Imports;
with AMF.CMOF.Package_Merges;
with AMF.CMOF.Packages;
with AMF.CMOF.Parameters;
with AMF.CMOF.Primitive_Types;
with AMF.CMOF.Properties;
with AMF.CMOF.Tags;
package AMF.Factories.CMOF_Factories is
pragma Preelaborate;
type CMOF_Factory is limited interface
and AMF.Factories.Factory;
type CMOF_Factory_Access is access all CMOF_Factory'Class;
for CMOF_Factory_Access'Storage_Size use 0;
not overriding function Create_Association
(Self : not null access CMOF_Factory)
return AMF.CMOF.Associations.CMOF_Association_Access is abstract;
not overriding function Create_Class
(Self : not null access CMOF_Factory)
return AMF.CMOF.Classes.CMOF_Class_Access is abstract;
not overriding function Create_Comment
(Self : not null access CMOF_Factory)
return AMF.CMOF.Comments.CMOF_Comment_Access is abstract;
not overriding function Create_Constraint
(Self : not null access CMOF_Factory)
return AMF.CMOF.Constraints.CMOF_Constraint_Access is abstract;
not overriding function Create_Data_Type
(Self : not null access CMOF_Factory)
return AMF.CMOF.Data_Types.CMOF_Data_Type_Access is abstract;
not overriding function Create_Element_Import
(Self : not null access CMOF_Factory)
return AMF.CMOF.Element_Imports.CMOF_Element_Import_Access is abstract;
not overriding function Create_Enumeration
(Self : not null access CMOF_Factory)
return AMF.CMOF.Enumerations.CMOF_Enumeration_Access is abstract;
not overriding function Create_Enumeration_Literal
(Self : not null access CMOF_Factory)
return AMF.CMOF.Enumeration_Literals.CMOF_Enumeration_Literal_Access is abstract;
not overriding function Create_Expression
(Self : not null access CMOF_Factory)
return AMF.CMOF.Expressions.CMOF_Expression_Access is abstract;
not overriding function Create_Opaque_Expression
(Self : not null access CMOF_Factory)
return AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access is abstract;
not overriding function Create_Operation
(Self : not null access CMOF_Factory)
return AMF.CMOF.Operations.CMOF_Operation_Access is abstract;
not overriding function Create_Package
(Self : not null access CMOF_Factory)
return AMF.CMOF.Packages.CMOF_Package_Access is abstract;
not overriding function Create_Package_Import
(Self : not null access CMOF_Factory)
return AMF.CMOF.Package_Imports.CMOF_Package_Import_Access is abstract;
not overriding function Create_Package_Merge
(Self : not null access CMOF_Factory)
return AMF.CMOF.Package_Merges.CMOF_Package_Merge_Access is abstract;
not overriding function Create_Parameter
(Self : not null access CMOF_Factory)
return AMF.CMOF.Parameters.CMOF_Parameter_Access is abstract;
not overriding function Create_Primitive_Type
(Self : not null access CMOF_Factory)
return AMF.CMOF.Primitive_Types.CMOF_Primitive_Type_Access is abstract;
not overriding function Create_Property
(Self : not null access CMOF_Factory)
return AMF.CMOF.Properties.CMOF_Property_Access is abstract;
not overriding function Create_Tag
(Self : not null access CMOF_Factory)
return AMF.CMOF.Tags.CMOF_Tag_Access is abstract;
end AMF.Factories.CMOF_Factories;
|
zhmu/ananas | Ada | 438 | adb | -- { dg-do run }
-- { dg-options "-O" }
with Loop_Optimization17_Pkg; use Loop_Optimization17_Pkg;
procedure Loop_Optimization17 is
Data : Arr;
begin
Data := (others => (I => 0,
V1 => (others => 0.0),
V2 => (others => 0.0),
S => 0.0));
for I in Index_T'Range loop
Object (I).V1 := F (Data (I).V1);
Object (I).V2 := F (Data (I).V2);
end loop;
end;
|
MinimSecure/unum-sdk | Ada | 819 | adb | -- Copyright 2017-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package body Pck is
procedure P (A : Integer_Access) is
begin
GA := A;
end P;
end Pck;
|
reznikmm/matreshka | Ada | 3,969 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Text_Number_Attributes;
package Matreshka.ODF_Text.Number_Attributes is
type Text_Number_Attribute_Node is
new Matreshka.ODF_Text.Abstract_Text_Attribute_Node
and ODF.DOM.Text_Number_Attributes.ODF_Text_Number_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Text_Number_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Text_Number_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Text.Number_Attributes;
|
reznikmm/matreshka | Ada | 3,689 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Chart_Name_Attributes is
pragma Preelaborate;
type ODF_Chart_Name_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Chart_Name_Attribute_Access is
access all ODF_Chart_Name_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Chart_Name_Attributes;
|
faelys/ada-syslog | Ada | 1,867 | ads | ------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Syslog.RFC_5424 outputs messages formatted according to the --
-- RFC 5424 ("The Syslog Protocol"). --
------------------------------------------------------------------------------
package Syslog.RFC_5424 is
procedure Build_Message
(Output : out String;
Last : out Natural;
Pri : in Priority;
Message : in String;
Hostname : in String := "-";
App_Name : in String := "-";
Proc_ID : in String := "-";
Msg_ID : in String := "-";
With_Time_Frac : in Boolean := True);
end Syslog.RFC_5424;
|
sungyeon/drake | Ada | 36,176 | adb | with Ada.Numerics.dSFMT.Generating;
with System.Formatting;
with System.Long_Long_Integer_Types;
with System.Random_Initiators;
with System.Storage_Elements;
package body Ada.Numerics.dSFMT is
pragma Check_Policy (Validate => Ignore);
use type Interfaces.Unsigned_32;
use type Interfaces.Unsigned_64;
use type System.Storage_Elements.Storage_Offset;
subtype Word_Unsigned is System.Long_Long_Integer_Types.Word_Unsigned;
subtype Long_Long_Unsigned is
System.Long_Long_Integer_Types.Long_Long_Unsigned;
procedure memset (
b : System.Address;
c : Integer;
n : System.Storage_Elements.Storage_Count)
with Import,
Convention => Intrinsic, External_Name => "__builtin_memset";
type Long_Boolean is new Boolean;
for Long_Boolean'Size use Long_Integer'Size;
function expect (exp, c : Long_Boolean) return Long_Boolean
with Import,
Convention => Intrinsic, External_Name => "__builtin_expect";
package Impl is new Generating;
-- STATIC FUNCTIONS
function ini_func1 (x : Unsigned_32) return Unsigned_32
with Convention => Intrinsic;
function ini_func2 (x : Unsigned_32) return Unsigned_32
with Convention => Intrinsic;
pragma Inline_Always (ini_func1);
pragma Inline_Always (ini_func2);
procedure gen_rand_array_c1o2 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
with Convention => Intrinsic;
procedure gen_rand_array_c0o1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
with Convention => Intrinsic;
procedure gen_rand_array_o0c1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
with Convention => Intrinsic;
procedure gen_rand_array_o0o1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
with Convention => Intrinsic;
pragma Inline_Always (gen_rand_array_c1o2);
pragma Inline_Always (gen_rand_array_c0o1);
pragma Inline_Always (gen_rand_array_o0c1);
pragma Inline_Always (gen_rand_array_o0o1);
function idxof (i : Integer) return Integer
with Convention => Intrinsic;
pragma Inline_Always (idxof);
procedure initial_mask (dsfmt : in out State);
procedure period_certification (dsfmt : in out State);
-- This function simulate a 32-bit array index overlapped to 64-bit array
-- of LITTLE ENDIAN in BIG ENDIAN machine.
function idxof (i : Integer) return Integer is
type Unsigned is mod 2 ** Integer'Size;
begin
case System.Default_Bit_Order is
when System.High_Order_First =>
return Integer (Unsigned'Mod (i) xor 1);
when System.Low_Order_First =>
return i;
end case;
end idxof;
-- This function fills the user-specified array with double precision
-- floating point pseudorandom numbers of the IEEE 754 format.
procedure gen_rand_array_c1o2 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
is
pragma Suppress (Index_Check);
the_array : w128_t_Array (0 .. size - 1);
for the_array'Address use Item'Address;
i, j : Integer;
lung : aliased w128_t := dsfmt.lung;
begin
Impl.do_recursion (
the_array (0),
dsfmt.status (0),
dsfmt.status (POS1),
lung);
i := 1;
while i < N - POS1 loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
dsfmt.status (i + POS1),
lung);
i := i + 1;
end loop;
while i < N loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
the_array (i - (N - POS1)),
lung);
i := i + 1;
end loop;
while i < size - N loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
i := i + 1;
end loop;
j := 0;
while j < N - (size - N) loop
dsfmt.status (j) := the_array (j + (size - N));
j := j + 1;
end loop;
while i < size loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
dsfmt.status (j) := the_array (i);
i := i + 1;
j := j + 1;
end loop;
dsfmt.lung := lung;
end gen_rand_array_c1o2;
-- This function fills the user-specified array with double precision
-- floating point pseudorandom numbers of the IEEE 754 format.
procedure gen_rand_array_c0o1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
is
pragma Suppress (Index_Check);
the_array : w128_t_Array (0 .. size - 1);
for the_array'Address use Item'Address;
i, j : Integer;
lung : aliased w128_t := dsfmt.lung;
begin
Impl.do_recursion (
the_array (0),
dsfmt.status (0),
dsfmt.status (POS1),
lung);
i := 1;
while i < N - POS1 loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
dsfmt.status (i + POS1),
lung);
i := i + 1;
end loop;
while i < N loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
the_array (i - (N - POS1)),
lung);
i := i + 1;
end loop;
while i < size - N loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
Impl.convert_c0o1 (the_array (i - N)); -- [0 .. size - 2 * N)
i := i + 1;
end loop;
j := 0;
while j < N - (size - N) loop
dsfmt.status (j) := the_array (j + (size - N));
j := j + 1;
end loop;
while i < size loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
dsfmt.status (j) := the_array (i);
Impl.convert_c0o1 (the_array (i - N)); -- [size - 2 * N .. size - N)
i := i + 1;
j := j + 1;
end loop;
i := size - N;
while i < size loop
Impl.convert_c0o1 (the_array (i)); -- [size - N .. size)
i := i + 1;
end loop;
dsfmt.lung := lung;
end gen_rand_array_c0o1;
-- This function fills the user-specified array with double precision
-- floating point pseudorandom numbers of the IEEE 754 format.
procedure gen_rand_array_o0c1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
is
pragma Suppress (Index_Check);
the_array : w128_t_Array (0 .. size - 1);
for the_array'Address use Item'Address;
i, j : Integer;
lung : aliased w128_t := dsfmt.lung;
begin
Impl.do_recursion (
the_array (0),
dsfmt.status (0),
dsfmt.status (POS1),
lung);
i := 1;
while i < N - POS1 loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
dsfmt.status (i + POS1),
lung);
i := i + 1;
end loop;
while i < N loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
the_array (i - (N - POS1)),
lung);
i := i + 1;
end loop;
while i < size - N loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
Impl.convert_o0c1 (the_array (i - N));
i := i + 1;
end loop;
j := 0;
while j < N - (size - N) loop
dsfmt.status (j) := the_array (j + (size - N));
j := j + 1;
end loop;
while i < size loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
dsfmt.status (j) := the_array (i);
Impl.convert_o0c1 (the_array (i - N));
i := i + 1;
j := j + 1;
end loop;
i := size - N;
while i < size loop
Impl.convert_o0c1 (the_array (i));
i := i + 1;
end loop;
dsfmt.lung := lung;
end gen_rand_array_o0c1;
-- This function fills the user-specified array with double precision
-- floating point pseudorandom numbers of the IEEE 754 format.
procedure gen_rand_array_o0o1 (
dsfmt : in out State;
Item : out w128_t_Array_1;
size : Integer)
is
pragma Suppress (Index_Check);
the_array : w128_t_Array (0 .. size - 1);
for the_array'Address use Item'Address;
i, j : Integer;
lung : aliased w128_t := dsfmt.lung;
begin
Impl.do_recursion (
the_array (0),
dsfmt.status (0),
dsfmt.status (POS1),
lung);
i := 1;
while i < N - POS1 loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
dsfmt.status (i + POS1),
lung);
i := i + 1;
end loop;
while i < N loop
Impl.do_recursion (
the_array (i),
dsfmt.status (i),
the_array (i - (N - POS1)),
lung);
i := i + 1;
end loop;
while i < size - N loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
Impl.convert_o0o1 (the_array (i - N));
i := i + 1;
end loop;
j := 0;
while j < N - (size - N) loop
dsfmt.status (j) := the_array (j + (size - N));
j := j + 1;
end loop;
while i < size loop
Impl.do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
lung);
dsfmt.status (j) := the_array (i);
Impl.convert_o0o1 (the_array (i - N));
i := i + 1;
j := j + 1;
end loop;
i := size - N;
while i < size loop
Impl.convert_o0o1 (the_array (i));
i := i + 1;
end loop;
dsfmt.lung := lung;
end gen_rand_array_o0o1;
-- This function represents a function used in the initialization by
-- init_by_array
function ini_func1 (x : Unsigned_32) return Unsigned_32 is
begin
return (x xor Interfaces.Shift_Right (x, 27)) * Unsigned_32'(1664525);
end ini_func1;
-- This function represents a function used in the initialization by
-- init_by_array
function ini_func2 (x : Unsigned_32) return Unsigned_32 is
begin
return (x xor Interfaces.Shift_Right (x, 27)) * Unsigned_32'(1566083941);
end ini_func2;
-- This function initializes the internal state array to fit the IEEE 754
-- format.
procedure initial_mask (dsfmt : in out State) is
psfmt : Unsigned_64_Array (0 .. N * 2 - 1);
for psfmt'Address use dsfmt.status'Address;
begin
for i in 0 .. N * 2 - 1 loop
psfmt (i) := (psfmt (i) and LOW_MASK) or HIGH_CONST;
end loop;
end initial_mask;
-- This function certificate the period of 2^{SFMT_MEXP}-1.
procedure period_certification (dsfmt : in out State) is
pcv : constant array (0 .. 1) of Unsigned_64 := (PCV1, PCV2);
tmp : array (0 .. 1) of Unsigned_64;
inner : Unsigned_64;
work : Unsigned_64;
begin
tmp (0) := dsfmt.lung (0) xor FIX1;
tmp (1) := dsfmt.lung (1) xor FIX2;
inner := tmp (0) and pcv (0);
inner := inner xor (tmp (1) and pcv (1));
declare
i : Natural := 32;
begin
while i > 0 loop
inner := inner xor Interfaces.Shift_Right (inner, i);
i := i / 2;
end loop;
end;
inner := inner and 1;
-- check OK
if inner = 1 then
return;
end if;
-- check NG, and modification
if (PCV2 and 1) = 1 then
dsfmt.lung (1) := dsfmt.lung (1) xor 1;
else
for i in reverse 0 .. 1 loop
work := 1;
for j in 0 .. 64 - 1 loop
if (work and pcv (i)) /= 0 then
dsfmt.lung (i) := dsfmt.lung (i) xor work;
return;
end if;
work := Interfaces.Shift_Left (work, 1);
end loop;
end loop;
end if;
end period_certification;
-- PUBLIC FUNCTIONS
procedure dsfmt_gen_rand_all (dsfmt : in out State);
procedure dsfmt_chk_init_gen_rand (
dsfmt : in out State;
seed : Unsigned_32);
procedure dsfmt_chk_init_by_array (
dsfmt : in out State;
init_key : Unsigned_32_Array);
-- This function fills the internal state array with double precision
-- floating point pseudorandom numbers of the IEEE 754 format.
procedure dsfmt_gen_rand_all (dsfmt : in out State) is
pragma Suppress (Index_Check);
i : Integer;
lung : aliased w128_t := dsfmt.lung;
begin
Impl.do_recursion (
dsfmt.status (0),
dsfmt.status (0),
dsfmt.status (POS1),
lung);
i := 1;
while i < N - POS1 loop
Impl.do_recursion (
dsfmt.status (i),
dsfmt.status (i),
dsfmt.status (i + POS1),
lung);
i := i + 1;
end loop;
while i < N loop
Impl.do_recursion (
dsfmt.status (i),
dsfmt.status (i),
dsfmt.status (i - (N - POS1)),
lung);
i := i + 1;
end loop;
dsfmt.lung := lung;
end dsfmt_gen_rand_all;
-- This function initializes the internal state array with a 32-bit integer
-- seed.
procedure dsfmt_chk_init_gen_rand (
dsfmt : in out State;
seed : Unsigned_32) is
begin
-- make sure caller program is compiled with the same MEXP
-- fprintf(stderr, "DSFMT_MEXP doesn't match with dSFMT.c\n");
declare
psfmt : Unsigned_32_Array (0 .. (N + 1) * 4 - 1); -- including lung
for psfmt'Address use dsfmt.status'Address;
begin
psfmt (idxof (0)) := seed;
for i in 1 .. (N + 1) * 4 - 1 loop
psfmt (idxof (i)) :=
1812433253
* (
psfmt (idxof (i - 1))
xor Interfaces.Shift_Right (psfmt (idxof (i - 1)), 30))
+ Unsigned_32'Mod (i);
end loop;
end;
initial_mask (dsfmt);
period_certification (dsfmt);
dsfmt.idx := N64;
end dsfmt_chk_init_gen_rand;
-- This function initializes the internal state array, with an array of
-- 32-bit integers used as the seeds
procedure dsfmt_chk_init_by_array (
dsfmt : in out State;
init_key : Unsigned_32_Array)
is
key_length : constant Natural := init_key'Length;
count : Natural;
r : Unsigned_32;
lag : Natural;
mid : Natural;
size : constant Natural := (N + 1) * 4; -- pulmonary
begin
-- make sure caller program is compiled with the same MEXP
-- fprintf(stderr, "DSFMT_MEXP doesn't match with dSFMT.c\n");
if size >= 623 then
lag := 11;
elsif size >= 68 then
lag := 7;
elsif size >= 39 then
lag := 5;
else
lag := 3;
end if;
mid := (size - lag) / 2;
memset (
dsfmt.status'Address,
16#8b#,
System.Storage_Elements.Storage_Offset (
(N + 1) * (128 / Standard'Storage_Unit))); -- including lung
if key_length + 1 > size then
count := key_length + 1;
else
count := size;
end if;
declare
psfmt32 : Unsigned_32_Array (0 .. (N + 1) * 4 - 1); -- including lung
for psfmt32'Address use dsfmt.status'Address;
begin
r :=
ini_func1 (psfmt32 (idxof (0))
xor psfmt32 (idxof (mid rem size))
xor psfmt32 (idxof ((size - 1) rem size)));
declare
Index : constant Natural := idxof (mid rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
r := r + Unsigned_32'Mod (key_length);
declare
Index : constant Natural := idxof ((mid + lag) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
psfmt32 (idxof (0)) := r;
count := count - 1;
declare
i : Natural := 1;
begin
declare
j : Natural := 0;
begin
while j < count and then j < key_length loop
r :=
ini_func1 (psfmt32 (idxof (i))
xor psfmt32 (idxof ((i + mid) rem size))
xor psfmt32 (idxof ((i + (size - 1)) rem size)));
declare
Index : constant Natural := idxof ((i + mid) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
r := r + init_key (j) + Unsigned_32'Mod (i);
declare
Index : constant Natural :=
idxof ((i + mid + lag) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
psfmt32 (idxof (i)) := r;
i := (i + 1) rem size;
j := j + 1;
end loop;
while j < count loop
r :=
ini_func1 (psfmt32 (idxof (i))
xor psfmt32 (idxof ((i + mid) rem size))
xor psfmt32 (idxof ((i + (size - 1)) rem size)));
declare
Index : constant Natural := idxof ((i + mid) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
r := r + Unsigned_32'Mod (i);
declare
Index : constant Natural :=
idxof ((i + mid + lag) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) + r;
end;
psfmt32 (idxof (i)) := r;
i := (i + 1) rem size;
j := j + 1;
end loop;
end;
for j in 0 .. size - 1 loop
r :=
ini_func2 (psfmt32 (idxof (i))
+ psfmt32 (idxof ((i + mid) rem size))
+ psfmt32 (idxof ((i + (size - 1)) rem size)));
declare
Index : constant Natural := idxof ((i + mid) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) xor r;
end;
r := r - Unsigned_32'Mod (i);
declare
Index : constant Natural := idxof ((i + mid + lag) rem size);
begin
psfmt32 (Index) := psfmt32 (Index) xor r;
end;
psfmt32 (idxof (i)) := r;
i := (i + 1) rem size;
end loop;
end;
end;
initial_mask (dsfmt);
period_certification (dsfmt);
dsfmt.idx := N64;
end dsfmt_chk_init_by_array;
-- implementation
-- This function returns the identification string. The string shows the
-- Mersenne exponent, and all parameters of this generator.
-- equivalent to dsfmt_get_idstring
function Id return String is
-- e.g. "dSFMT2-19937:117-19:ffafffffffb3f-ffdfffc90fffd"
Result : String (
1 ..
6 + 1 -- "dSFMT2-"
+ 6 + 1 + 4 + 1 + 2 + 1 -- "216091:1890-23:"
+ 13 + 1 + 13); -- "%.13x-%.13x"
Last : Natural := 0;
Error : Boolean;
begin
Result (Last + 1 .. Last + 7) := "dSFMT2-";
Last := Last + 7;
System.Formatting.Image (
Word_Unsigned (MEXP),
Result (Last + 1 .. Result'Last),
Last,
Error => Error);
Result (Last + 1) := ':';
Last := Last + 1;
System.Formatting.Image (
Word_Unsigned (POS1),
Result (Last + 1 .. Result'Last),
Last,
Error => Error);
Result (Last + 1) := '-';
Last := Last + 1;
System.Formatting.Image (
Word_Unsigned (SL1),
Result (Last + 1 .. Result'Last),
Last,
Error => Error);
Result (Last + 1) := ':';
Last := Last + 1;
if Standard'Word_Size >= 64 then -- 52?
System.Formatting.Image (
Word_Unsigned (MSK1),
Result (Last + 1 .. Result'Last),
Last,
Base => 16,
Set => System.Formatting.Lower_Case,
Width => 13,
Error => Error);
else
System.Formatting.Image (
Long_Long_Unsigned (MSK1),
Result (Last + 1 .. Result'Last),
Last,
Base => 16,
Set => System.Formatting.Lower_Case,
Width => 13,
Error => Error);
end if;
Result (Last + 1) := '-';
Last := Last + 1;
if Standard'Word_Size >= 64 then -- 52?
System.Formatting.Image (
Word_Unsigned (MSK2),
Result (Last + 1 .. Result'Last),
Last,
Base => 16,
Set => System.Formatting.Lower_Case,
Width => 13,
Error => Error);
else
System.Formatting.Image (
Long_Long_Unsigned (MSK2),
Result (Last + 1 .. Result'Last),
Last,
Base => 16,
Set => System.Formatting.Lower_Case,
Width => 13,
Error => Error);
end if;
return Result (1 .. Last);
end Id;
-- This function generates and returns double precision pseudorandom number
-- which distributes uniformly in the range [1, 2). This is the
-- primitive and faster than generating numbers in other ranges.
-- equivalent to dsfmt_genrand_close1_open2
function Random_1_To_Less_Than_2 (Gen : aliased in out Generator)
return Long_Float
is
pragma Suppress (Index_Check);
dsfmt : State renames Gen.dsfmt;
idx : Integer := dsfmt.idx;
begin
if expect (Long_Boolean (idx >= N64), False) then
dsfmt_gen_rand_all (dsfmt);
idx := 0;
end if;
declare
psfmt64 : Long_Float_Array (0 .. N * 2 - 1);
for psfmt64'Address use dsfmt.status'Address;
r : constant Long_Float := psfmt64 (idx);
begin
dsfmt.idx := idx + 1;
return r;
end;
end Random_1_To_Less_Than_2;
-- This function generates and returns double precision pseudorandom number
-- which distributes uniformly in the range [0, 1).
-- equivalent to dsfmt_genrand_close_open
function Random_0_To_Less_Than_1 (Gen : aliased in out Generator)
return Long_Float is
begin
return Random_1_To_Less_Than_2 (Gen) - 1.0;
end Random_0_To_Less_Than_1;
-- This function generates and returns double precision pseudorandom number
-- which distributes uniformly in the range (0, 1].
-- equivalent to dsfmt_genrand_open_close
function Random_Greater_Than_0_To_1 (Gen : aliased in out Generator)
return Long_Float is
begin
return 2.0 - Random_1_To_Less_Than_2 (Gen);
end Random_Greater_Than_0_To_1;
-- This function generates and returns double precision pseudorandom number
-- which distributes uniformly in the range (0, 1).
-- equivalent to dsfmt_genrand_open_open
function Random_Greater_Than_0_To_Less_Than_1 (
Gen : aliased in out Generator)
return Long_Float
is
type union_r_Tag is (d, u);
pragma Discard_Names (union_r_Tag);
type union_r (Unchecked_Tag : union_r_Tag := d) is record
case Unchecked_Tag is
when d =>
d : Long_Float;
when u =>
u : Unsigned_64;
end case;
end record;
pragma Unchecked_Union (union_r);
pragma Suppress_Initialization (union_r);
r : union_r;
begin
r.d := Random_1_To_Less_Than_2 (Gen);
r.u := r.u or 1;
return r.d - 1.0;
end Random_Greater_Than_0_To_Less_Than_1;
-- This function generates double precision floating point pseudorandom
-- numbers which distribute in the range [1, 2) to the specified array[]
-- by one call. The number of pseudorandom numbers is specified by the
-- argument size, which must be at least (SFMT_MEXP / 128) * 2 and a
-- multiple of two. The function get_min_array_size() returns this
-- minimum size. The generation by this function is much faster than the
-- following fill_array_xxx functions.
-- equivalent to dsfmt_fill_array_close1_open2
procedure Fill_Random_1_To_Less_Than_2 (
Gen : aliased in out Generator;
Item : out Long_Float_Array)
is
pragma Suppress (Range_Check);
size : constant Natural := Item'Length;
begin
if Gen.dsfmt.idx /= N64 or else size rem 2 /= 0 or else size < N64 then
-- This function can not be used after calling genrand_xxx functions,
-- without initialization.
for I in Item'Range loop
Item (I) := Random_1_To_Less_Than_2 (Gen);
end loop;
end if;
declare
the_array : w128_t_Array (0 .. 0); -- size / 2 - 1
for the_array'Address use Item'Address;
begin
gen_rand_array_c1o2 (Gen.dsfmt, the_array (0 .. 0), size / 2);
end;
end Fill_Random_1_To_Less_Than_2;
-- This function generates double precision floating point pseudorandom
-- numbers which distribute in the range [0, 1) to the specified array[]
-- by one call. This function is the same as fill_array_close1_open2()
-- except the distribution range.
-- equivalent to dsfmt_fill_array_close_open
procedure Fill_Random_0_To_Less_Than_1 (
Gen : aliased in out Generator;
Item : out Long_Float_Array)
is
pragma Suppress (Range_Check);
size : constant Natural := Item'Length;
begin
if Gen.dsfmt.idx /= N64 or else size rem 2 /= 0 or else size < N64 then
for I in Item'Range loop
Item (I) := Random_0_To_Less_Than_1 (Gen);
end loop;
end if;
declare
the_array : w128_t_Array (0 .. 0); -- size / 2 - 1
for the_array'Address use Item'Address;
begin
gen_rand_array_c0o1 (Gen.dsfmt, the_array (0 .. 0), size / 2);
end;
end Fill_Random_0_To_Less_Than_1;
-- This function generates double precision floating point pseudorandom
-- numbers which distribute in the range (0, 1] to the specified array[]
-- by one call. This function is the same as fill_array_close1_open2()
-- except the distribution range.
-- equivalent to dsfmt_fill_array_open_close
procedure Fill_Random_Greater_Than_0_To_1 (
Gen : aliased in out Generator;
Item : out Long_Float_Array)
is
pragma Suppress (Range_Check);
size : constant Natural := Item'Length;
begin
if Gen.dsfmt.idx /= N64 or else size rem 2 /= 0 or else size < N64 then
for I in Item'Range loop
Item (I) := Random_Greater_Than_0_To_1 (Gen);
end loop;
end if;
declare
the_array : w128_t_Array (0 .. 0); -- size / 2 - 1
for the_array'Address use Item'Address;
begin
gen_rand_array_o0c1 (Gen.dsfmt, the_array (0 .. 0), size / 2);
end;
end Fill_Random_Greater_Than_0_To_1;
-- This function generates double precision floating point pseudorandom
-- numbers which distribute in the range (0, 1) to the specified array[]
-- by one call. This function is the same as fill_array_close1_open2()
-- except the distribution range.
-- equivalent to dsfmt_fill_array_open_open
procedure Fill_Random_Greater_Than_0_To_Less_Than_1 (
Gen : aliased in out Generator;
Item : out Long_Float_Array)
is
pragma Suppress (Range_Check);
size : constant Natural := Item'Length;
begin
if Gen.dsfmt.idx /= N64 or else size rem 2 /= 0 or else size < N64 then
for I in Item'Range loop
Item (I) := Random_Greater_Than_0_To_Less_Than_1 (Gen);
end loop;
end if;
declare
the_array : w128_t_Array (0 .. 0); -- size / 2 - 1
for the_array'Address use Item'Address;
begin
gen_rand_array_o0o1 (Gen.dsfmt, the_array (0 .. 0), size / 2);
end;
end Fill_Random_Greater_Than_0_To_Less_Than_1;
function Initialize return Generator is
begin
return (dsfmt => Initialize);
end Initialize;
function Initialize (Initiator : Unsigned_32) return Generator is
begin
return (dsfmt => Initialize (Initiator));
end Initialize;
function Initialize (Initiator : Unsigned_32_Array) return Generator is
begin
return (dsfmt => Initialize (Initiator));
end Initialize;
procedure Reset (Gen : in out Generator) is
begin
Gen.dsfmt := Initialize;
end Reset;
procedure Reset (Gen : in out Generator; Initiator : Integer) is
begin
Gen.dsfmt := Initialize (Unsigned_32'Mod (Initiator));
end Reset;
function Initialize return State is
Init : aliased Unsigned_32_Array (0 .. N32 - 1);
begin
System.Random_Initiators.Get (
Init'Address,
Init'Size / Standard'Storage_Unit);
return Initialize (Init);
end Initialize;
-- This function initializes the internal state array with a 32-bit integer
-- seed.
-- equivalent to dsfmt_init_gen_rand
function Initialize (Initiator : Unsigned_32) return State is
begin
return Result : State do
dsfmt_chk_init_gen_rand (Result, Initiator);
end return;
end Initialize;
-- This function initializes the internal state array, with an array of
-- 32-bit integers used as the seeds.
-- equivalent to dsfmt_init_by_array
function Initialize (Initiator : Unsigned_32_Array) return State is
begin
return Result : State do
dsfmt_chk_init_by_array (Result, Initiator);
end return;
end Initialize;
procedure Save (Gen : Generator; To_State : out State) is
begin
To_State := Gen.dsfmt;
end Save;
procedure Reset (Gen : in out Generator; From_State : State) is
begin
Gen.dsfmt := From_State;
end Reset;
function Reset (From_State : State) return Generator is
begin
return (dsfmt => From_State);
end Reset;
function Image (Of_State : State) return String is
procedure Put (To : out String; Item : w128_t);
procedure Put (To : out String; Item : w128_t) is
Last : Natural := To'First - 1;
begin
for I in w128_t'Range loop
declare
E : constant Unsigned_64 := Item (I);
Previous_Last : constant Natural := Last;
Error : Boolean;
begin
if Standard'Word_Size >= 64 then
System.Formatting.Image (
Word_Unsigned (E),
To (Previous_Last + 1 .. Previous_Last + 64 / 4),
Last,
Base => 16,
Width => 64 / 4,
Error => Error);
else
System.Formatting.Image (
Long_Long_Unsigned (E),
To (Previous_Last + 1 .. Previous_Last + 64 / 4),
Last,
Base => 16,
Width => 64 / 4,
Error => Error);
end if;
pragma Check (Validate,
Check => not Error and then Last = Previous_Last + 64 / 4);
end;
Last := Last + 1;
To (Last) := ':';
end loop;
end Put;
procedure Put (To : out String; Item : Integer);
procedure Put (To : out String; Item : Integer) is
Error : Boolean;
Last : Natural;
begin
System.Formatting.Image (
Word_Unsigned (Item),
To,
Last,
Base => 16,
Width => 32 / 4,
Error => Error);
pragma Check (Validate, not Error and then Last = To'Last);
end Put;
Last : Natural := 0;
begin
return Result : String (1 .. Max_Image_Width) do
for I in w128_t_Array_N'Range loop
declare
Previous_Last : constant Natural := Last;
begin
Last := Last + 2 * (64 / 4 + 1);
Put (Result (Previous_Last + 1 .. Last), Of_State.status (I));
end;
end loop;
declare
Previous_Last : constant Natural := Last;
begin
Last := Last + 2 * (64 / 4 + 1);
Put (Result (Previous_Last + 1 .. Last), Of_State.lung);
end;
Put (Result (Last + 1 .. Result'Last), Of_State.idx);
end return;
end Image;
function Value (Coded_State : String) return State is
procedure Get (From : String; Item : out w128_t);
procedure Get (From : String; Item : out w128_t) is
Last : Natural := From'First - 1;
begin
for I in w128_t'Range loop
declare
Previous_Last : constant Natural := Last;
E : Unsigned_64;
Error : Boolean;
begin
if Standard'Word_Size >= 64 then
System.Formatting.Value (
From (Previous_Last + 1 .. Previous_Last + 64 / 4),
Last,
Word_Unsigned (E),
Base => 16,
Error => Error);
else
System.Formatting.Value (
From (Previous_Last + 1 .. Previous_Last + 64 / 4),
Last,
Long_Long_Unsigned (E),
Base => 16,
Error => Error);
end if;
if Error or else Last /= Previous_Last + 64 / 4 then
raise Constraint_Error;
end if;
Item (I) := E;
end;
Last := Last + 1;
if From (Last) /= ':' then
raise Constraint_Error;
end if;
end loop;
end Get;
procedure Get (From : String; Item : out Integer);
procedure Get (From : String; Item : out Integer) is
Last : Positive;
Error : Boolean;
begin
System.Formatting.Value (
From,
Last,
Word_Unsigned (Item),
Base => 16,
Error => Error);
if Error or else Last /= From'Last or else Item not in 0 .. N64 then
raise Constraint_Error;
end if;
end Get;
begin
if Coded_State'Length /= Max_Image_Width then
raise Constraint_Error;
end if;
return Result : State do
declare
Last : Natural := Coded_State'First - 1;
begin
for I in w128_t_Array_N'Range loop
declare
Previous_Last : constant Natural := Last;
begin
Last := Last + 2 * (64 / 4 + 1);
Get (
Coded_State (Previous_Last + 1 .. Last),
Result.status (I));
end;
end loop;
declare
Previous_Last : constant Natural := Last;
begin
Last := Last + 2 * (64 / 4 + 1);
Get (Coded_State (Previous_Last + 1 .. Last), Result.lung);
end;
Get (Coded_State (Last + 1 .. Coded_State'Last), Result.idx);
end;
end return;
end Value;
end Ada.Numerics.dSFMT;
|
DrenfongWong/tkm-rpc | Ada | 1,003 | ads | with Tkmrpc.Types;
package Tkmrpc.Request.Ike.Dh_Get_Shared_Secret is
Data_Size : constant := 8;
type Data_Type is record
Dh_Id : Types.Dh_Id_Type;
end record;
for Data_Type use record
Dh_Id at 0 range 0 .. (8 * 8) - 1;
end record;
for Data_Type'Size use Data_Size * 8;
Padding_Size : constant := Request.Body_Size - Data_Size;
subtype Padding_Range is Natural range 1 .. Padding_Size;
subtype Padding_Type is Types.Byte_Sequence (Padding_Range);
type Request_Type is record
Header : Request.Header_Type;
Data : Data_Type;
Padding : Padding_Type;
end record;
for Request_Type use record
Header at 0 range 0 .. (Request.Header_Size * 8) - 1;
Data at Request.Header_Size range 0 .. (Data_Size * 8) - 1;
Padding at Request.Header_Size + Data_Size range
0 .. (Padding_Size * 8) - 1;
end record;
for Request_Type'Size use Request.Request_Size * 8;
end Tkmrpc.Request.Ike.Dh_Get_Shared_Secret;
|
reznikmm/matreshka | Ada | 3,690 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with League.Holders.Generic_Enumerations;
package AMF.CMOF.Holders.Visibility_Kinds is
new League.Holders.Generic_Enumerations
(AMF.CMOF.CMOF_Visibility_Kind);
pragma Preelaborate (AMF.CMOF.Holders.Visibility_Kinds);
|
MinimSecure/unum-sdk | Ada | 1,119 | adb | -- Copyright 2007-2016 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package body Pck is
procedure Break_Me is
begin
null;
end Break_Me;
procedure Call_Me (Int : Integer;
Flt : Float;
Bln : Boolean;
Ary : Arr;
Chr : Character;
Sad : System.Address;
Rec : Struct)
is
begin
Break_Me;
end Call_Me;
end Pck;
|
reznikmm/matreshka | Ada | 3,414 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2017, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with WUI.Widgets.Labels;
package WUI.Labels renames WUI.Widgets.Labels;
|
zhmu/ananas | Ada | 266 | ads | package Forward_Anon is
type Object is null record;
function Get_Current return access Object;
Current_Object : constant access Object;
private
One_Object : aliased Object;
Current_Object : constant access Object := One_Object'Access;
end;
|
reznikmm/matreshka | Ada | 4,033 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Form_Default_Button_Attributes;
package Matreshka.ODF_Form.Default_Button_Attributes is
type Form_Default_Button_Attribute_Node is
new Matreshka.ODF_Form.Abstract_Form_Attribute_Node
and ODF.DOM.Form_Default_Button_Attributes.ODF_Form_Default_Button_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Form_Default_Button_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Form_Default_Button_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Form.Default_Button_Attributes;
|
reznikmm/matreshka | Ada | 4,800 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.States.Collections is
pragma Preelaborate;
package UML_State_Collections is
new AMF.Generic_Collections
(UML_State,
UML_State_Access);
type Set_Of_UML_State is
new UML_State_Collections.Set with null record;
Empty_Set_Of_UML_State : constant Set_Of_UML_State;
type Ordered_Set_Of_UML_State is
new UML_State_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_State : constant Ordered_Set_Of_UML_State;
type Bag_Of_UML_State is
new UML_State_Collections.Bag with null record;
Empty_Bag_Of_UML_State : constant Bag_Of_UML_State;
type Sequence_Of_UML_State is
new UML_State_Collections.Sequence with null record;
Empty_Sequence_Of_UML_State : constant Sequence_Of_UML_State;
private
Empty_Set_Of_UML_State : constant Set_Of_UML_State
:= (UML_State_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_State : constant Ordered_Set_Of_UML_State
:= (UML_State_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_State : constant Bag_Of_UML_State
:= (UML_State_Collections.Bag with null record);
Empty_Sequence_Of_UML_State : constant Sequence_Of_UML_State
:= (UML_State_Collections.Sequence with null record);
end AMF.UML.States.Collections;
|
reznikmm/matreshka | Ada | 5,286 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Strings;
with XML.SAX.Parse_Exceptions;
package XML.SAX.Error_Handlers is
pragma Preelaborate;
type SAX_Error_Handler is limited interface;
not overriding procedure Error
(Self : in out SAX_Error_Handler;
Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception;
Success : in out Boolean) is null;
-- A reader might use this subprogram to report a recoverable error. A
-- recoverable error corresponds to the definiton of "error" in section 1.2
-- of the XML 1.0 specification. Details of the error are stored in
-- Occurrence.
--
-- The reader must continue to provide normal parsing events after invoking
-- this subprogram.
--
-- If this subprogram sets Success to False the reader stops parsing and
-- reports an fatal error. The reader uses the function Error_String to get
-- the error message.
not overriding function Error_String
(Self : SAX_Error_Handler)
return League.Strings.Universal_String is abstract;
not overriding procedure Fatal_Error
(Self : in out SAX_Error_Handler;
Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception) is null;
-- A reader must use this subprogram to report a non-recoverable error.
-- Details of the error are stored in Occurrence.
not overriding procedure Warning
(Self : in out SAX_Error_Handler;
Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception;
Success : in out Boolean) is null;
-- A reader might use this subprogram to report a warning. Warnings are
-- conditions that are not errors or fatal errors as defined by the XML 1.0
-- specification. Details of the warning are stored in Occurrence.
--
-- If this subprogram sets Success to False the reader stops parsing and
-- reports an fatal error. The reader uses the function Error_String to get
-- the error message.
end XML.SAX.Error_Handlers;
|
sungyeon/drake | Ada | 4,628 | adb | with System.Value_Errors;
package body System.Val_Enum is
function Value_Enumeration_8 (
Names : String;
Indexes : Address;
Num : Natural;
Str : String)
return Natural
is
First : Positive;
Last : Natural;
begin
Trim (Str, First, Last);
if First <= Last then
declare
type Index_Type is mod 2 ** 8;
type Index_Array_Type is array (0 .. Num + 1) of Index_Type;
Indexes_All : Index_Array_Type;
for Indexes_All'Address use Indexes;
S : String := Str (First .. Last);
Next : Natural := Natural (Indexes_All (0));
begin
if S (First) /= ''' then
To_Upper (S);
end if;
for I in 0 .. Num loop
declare
P : constant Positive := Next;
begin
Next := Natural (Indexes_All (I + 1));
if S = Names (P .. Next - 1) then
return I;
end if;
end;
end loop;
end;
end if;
Value_Errors.Raise_Discrete_Value_Failure ("Enum", Str);
declare
Uninitialized : Natural;
pragma Unmodified (Uninitialized);
begin
return Uninitialized;
end;
end Value_Enumeration_8;
function Value_Enumeration_16 (
Names : String;
Indexes : Address;
Num : Natural;
Str : String)
return Natural
is
First : Positive;
Last : Natural;
begin
Trim (Str, First, Last);
if First <= Last then
declare
type Index_Type is mod 2 ** 16;
type Index_Array_Type is array (0 .. Num + 1) of Index_Type;
Indexes_All : Index_Array_Type;
for Indexes_All'Address use Indexes;
S : String := Str (First .. Last);
Next : Natural := Natural (Indexes_All (0));
begin
if S (First) /= ''' then
To_Upper (S);
end if;
for I in 0 .. Num loop
declare
P : constant Positive := Next;
begin
Next := Natural (Indexes_All (I + 1));
if S = Names (P .. Next - 1) then
return I;
end if;
end;
end loop;
end;
end if;
Value_Errors.Raise_Discrete_Value_Failure ("Enum", Str);
declare
Uninitialized : Natural;
pragma Unmodified (Uninitialized);
begin
return Uninitialized;
end;
end Value_Enumeration_16;
function Value_Enumeration_32 (
Names : String;
Indexes : Address;
Num : Natural;
Str : String)
return Natural
is
First : Positive;
Last : Natural;
begin
Trim (Str, First, Last);
if First <= Last then
declare
type Index_Type is mod 2 ** 32;
type Index_Array_Type is array (0 .. Num + 1) of Index_Type;
Indexes_All : Index_Array_Type;
for Indexes_All'Address use Indexes;
S : String := Str (First .. Last);
Next : Natural := Natural (Indexes_All (0));
begin
if S (First) /= ''' then
To_Upper (S);
end if;
for I in 0 .. Num loop
declare
P : constant Positive := Next;
begin
Next := Natural (Indexes_All (I + 1));
if S = Names (P .. Next - 1) then
return I;
end if;
end;
end loop;
end;
end if;
Value_Errors.Raise_Discrete_Value_Failure ("Enum", Str);
declare
Uninitialized : Natural;
pragma Unmodified (Uninitialized);
begin
return Uninitialized;
end;
end Value_Enumeration_32;
procedure Trim (S : String; First : out Positive; Last : out Natural) is
begin
First := S'First;
Last := S'Last;
while First <= Last and then S (First) = ' ' loop
First := First + 1;
end loop;
while First <= Last and then S (Last) = ' ' loop
Last := Last - 1;
end loop;
end Trim;
procedure To_Upper (S : in out String) is
begin
for I in S'Range loop
if S (I) in 'a' .. 'z' then
S (I) := Character'Val (
Character'Pos (S (I))
- (Character'Pos ('a') - Character'Pos ('A')));
end if;
end loop;
end To_Upper;
end System.Val_Enum;
|
onox/orka | Ada | 7,702 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2018 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Directories;
with Ada.Finalization;
with Ada.Streams.Stream_IO;
package body Orka.Resources.Locations.Directories is
use Ada.Streams;
type Byte_Array_File is limited new Ada.Finalization.Limited_Controlled with record
File : Ada.Streams.Stream_IO.File_Type;
Finalized : Boolean;
end record;
overriding
procedure Finalize (Object : in out Byte_Array_File);
-----------------------------------------------------------------------------
function Open_File
(File_Name : String;
Mode : Stream_IO.File_Mode) return Byte_Array_File is
begin
return Result : Byte_Array_File
:= (Ada.Finalization.Limited_Controlled with File => <>, Finalized => False) do
Stream_IO.Open (Result.File, Mode, File_Name);
end return;
end Open_File;
overriding
procedure Finalize (Object : in out Byte_Array_File) is
begin
if not Object.Finalized then
if Stream_IO.Is_Open (Object.File) then
Stream_IO.Close (Object.File);
end if;
Object.Finalized := True;
end if;
end Finalize;
function Read_File (Object : Byte_Array_File) return not null Byte_Array_Access is
File_Stream : Stream_IO.Stream_Access;
File_Size : constant Integer := Integer (Stream_IO.Size (Object.File));
subtype File_Byte_Array is Byte_Array (1 .. Stream_Element_Offset (File_Size));
Raw_Contents : Byte_Array_Access := new File_Byte_Array;
begin
File_Stream := Stream_IO.Stream (Object.File);
File_Byte_Array'Read (File_Stream, Raw_Contents.all);
return Raw_Contents;
exception
when others =>
Free (Raw_Contents);
raise;
end Read_File;
-----------------------------------------------------------------------------
function Create_File (File_Name : String) return Byte_Array_File is
begin
return Result : Byte_Array_File
:= (Ada.Finalization.Limited_Controlled with File => <>, Finalized => False) do
Stream_IO.Create (Result.File, Stream_IO.Out_File, File_Name);
end return;
end Create_File;
procedure Write_Data (Object : Byte_Array_File; Data : Byte_Array) is
File_Stream : Stream_IO.Stream_Access;
File_Size : constant Integer := Data'Length;
subtype File_Byte_Array is Byte_Array (1 .. Stream_Element_Offset (File_Size));
begin
File_Stream := Stream_IO.Stream (Object.File);
File_Byte_Array'Write (File_Stream, Data);
end Write_Data;
-----------------------------------------------------------------------------
type Directory_Location is limited new Location with record
Full_Path : SU.Unbounded_String;
end record;
overriding
function Exists (Object : Directory_Location; Path : String) return Boolean;
overriding
function Read_Data
(Object : Directory_Location;
Path : String) return Byte_Array_Pointers.Pointer;
type Writable_Directory_Location is limited
new Directory_Location and Writable_Location with null record;
overriding
procedure Write_Data
(Object : Writable_Directory_Location;
Path : String;
Data : Byte_Array);
overriding
procedure Append_Data
(Object : Writable_Directory_Location;
Path : String;
Data : Byte_Array);
-----------------------------------------------------------------------------
overriding
function Exists (Object : Directory_Location; Path : String) return Boolean is
Directory : String renames SU.To_String (Object.Full_Path);
Full_Path : constant String := Directory & Path_Separator & Path;
begin
return Ada.Directories.Exists (Full_Path);
end Exists;
overriding
function Read_Data
(Object : Directory_Location;
Path : String) return Byte_Array_Pointers.Pointer
is
Directory : String renames SU.To_String (Object.Full_Path);
Full_Path : constant String := Directory & Path_Separator & Path;
use Ada.Directories;
begin
if not Exists (Full_Path) then
raise Name_Error with "File '" & Full_Path & "' not found";
end if;
if Kind (Full_Path) /= Ordinary_File then
raise Name_Error with "Path '" & Full_Path & "' is not a regular file";
end if;
declare
File : constant Byte_Array_File := Open_File (Full_Path, Mode => Stream_IO.In_File);
Pointer : Byte_Array_Pointers.Pointer;
begin
Pointer.Set (File.Read_File);
return Pointer;
end;
end Read_Data;
overriding
procedure Write_Data
(Object : Writable_Directory_Location;
Path : String;
Data : Byte_Array)
is
Directory : String renames SU.To_String (Object.Full_Path);
Full_Path : constant String := Directory & Path_Separator & Path;
use Ada.Directories;
begin
if Exists (Full_Path) then
raise Name_Error with "File '" & Full_Path & "' already exists";
end if;
declare
File : constant Byte_Array_File := Create_File (Full_Path);
begin
File.Write_Data (Data);
end;
end Write_Data;
overriding
procedure Append_Data
(Object : Writable_Directory_Location;
Path : String;
Data : Byte_Array)
is
Directory : String renames SU.To_String (Object.Full_Path);
Full_Path : constant String := Directory & Path_Separator & Path;
use Ada.Directories;
begin
declare
File : constant Byte_Array_File :=
(if Exists (Full_Path) then
Open_File (Full_Path, Mode => Stream_IO.Append_File)
else
Create_File (Full_Path));
begin
File.Write_Data (Data);
end;
end Append_Data;
function Create_Location (Path : String) return Location_Ptr is
use Ada.Directories;
Full_Path : constant String := Full_Name (Path);
begin
if not Exists (Full_Path) then
raise Name_Error with "Directory '" & Full_Path & "' not found";
end if;
if Kind (Full_Path) /= Directory then
raise Name_Error with "Path '" & Full_Path & "' is not a directory";
end if;
return new Directory_Location'(Full_Path => SU.To_Unbounded_String (Full_Path));
end Create_Location;
function Create_Location (Path : String) return Writable_Location_Ptr is
use Ada.Directories;
Full_Path : constant String := Full_Name (Path);
begin
if not Exists (Full_Path) then
raise Name_Error with "Directory '" & Full_Path & "' not found";
end if;
if Kind (Full_Path) /= Directory then
raise Name_Error with "Path '" & Full_Path & "' is not a directory";
end if;
-- The pointer is stored in a variable to make the compiler happy
return Result : constant Writable_Location_Ptr
:= new Writable_Directory_Location'(Full_Path => SU.To_Unbounded_String (Full_Path)) do
null;
end return;
end Create_Location;
end Orka.Resources.Locations.Directories;
|
tum-ei-rcs/StratoX | Ada | 1,090 | ads | -- Institution: Technische Universitaet Muenchen
-- Department: Realtime Computer Systems (RCS)
-- Project: StratoX
-- Module: Software Configuration
--
-- Authors: Martin Becker ([email protected])
-- @summary
-- Target-specific types for the devices that are exposed
-- in hil-i2c et. al in Pixracer V1.
package HIL.Devices with SPARK_Mode is
type Device_Type_I2C is (UNKNOWN);
type Device_Type_SPI is (Barometer,
FRAM);
type Device_Type_UART is (TELE1, TELE2, GPS, CONSOLE, WIFI);
type Device_Type_GPIO is (RED_LED,
GRN_LED,
BLU_LED,
SPI_CS_BARO,
SPI_CS_FRAM);
subtype Device_Type_LED is Device_Type_GPIO range RED_LED .. BLU_LED;
-- INTERRUPT PRIOS, ALL AT ONE PLACE. Must decide who wins here.
--IRQ_PRIO_UART_LOG : constant := 251; -- if this is too low, we lose input/output
IRQ_PRIO_SDIO : constant := 250; -- sdcard: only affects performance (=DMA finish/Start signaling)
end HIL.Devices;
|
HeisenbugLtd/cache-sim | Ada | 10,186 | ads | ------------------------------------------------------------------------------
-- Copyright (C) 2012-2020 by Heisenbug Ltd.
--
-- This work is free. You can redistribute it and/or modify it under the
-- terms of the Do What The Fuck You Want To Public License, Version 2,
-- as published by Sam Hocevar. See the LICENSE file for more details.
--------------------------------------------------------------------------------
pragma License (Unrestricted);
--------------------------------------------------------------------------------
-- Provides the implementation of a simple cache.
--
-- All abstract methods from the Cache class are provided, plus a Connect
-- method to connect a cache to a secondary cache, so that a cache-hierarchy
-- can be built and properly simulated.
--
-- Fixed cache parameters like associativity, length of a cache line and the
-- number of available blocks are provided as discriminants.
-- The private methods Fetch_Line as well as address translation services
-- (Get_Block, To_Address) are declared and defined.
--
-- Assumptions made in the implementation:
-- Cache-line lengths are not expected to decrease with several levels
-- (generally spoken, a block of a lower-order cache should always be
-- contained within a block of the higher-order cache).
-- For instance, if the first level has a 64-byte granularity, and the second
-- level has a 32-byte cache-line, it would always require two (much slower)
-- accesses to load the whole cache-line of the first level. Likewise,
-- flushing a cache-line would require two distinct write operations to the
-- higher-order cache.
-- Doing such stupid thing does not make sense in the real world, so I see no
-- point in supporting it in this crappy simulation. The assumption is made
-- that a read or write access always operates on whole cache-lines
-- throughout the hierarchy.
--
-- Cache behaviour:
-- This simple cache simulates a cache similar to those found in any modern
-- micro-processor, yet there are some noteworthy differences:
--
-- 1) The strategy to flush cache-lines is to select a random line from the
-- available slots, most real-world caches employ a least-recently-used
-- strategy. So major differences between the simulated and an actual
-- performance are expected if certain pathological access pattern (like
-- forward/backward runs) are expected.
-- If such pathological cases are to be simulated, it might be better to
-- derive from this class and do a proper implementation for the
-- (protected) method Fetch_Line.
-- 2) The size of a memory access is not taken into account.
-- The cache behaves as if a single byte is requested each time.
-- In the real-word, a memory access could span across cache-lines, which
-- is not simulated here. However, it can be simulated by checking if an
-- unaligned (or large) access is attempted and then doing consecutive
-- reads accordingly.
-- This is how most processors handle unaligned accesses and as this is a
-- cache-, not a processor-simulation, you have to do it on your own if
-- you need it.
--
-- Performance Parameters:
-- The speed differences between multiple layers of caches can be influenced
-- by the Speed_Factor parameter in the Connect method.
-- The default is 8.0, as usual access time differences are in the ordner of
-- a magnitude.
-- To accomodate for the longer time when a cache line is loaded or flushed,
-- such an event is multiplied with the number of bytes in the cache-line
-- before adding it to the performance index. This might not be very precise,
-- because such loads are probably more direct (I'd expect that a cache-line
-- load is a single operation between caches), and writes are often buffered.
-- Yet, considering the much slower speed of the higher-order cache connected
-- it is probably still a good approximation. If all else fails, you can
-- still override the Perf_Index method to implement your own weighting of
-- the cache events.
--------------------------------------------------------------------------------
package Caches.Simple_Caches is
-- The basic cache class.
type Simple_Cache (Cache_Line : Line_Length;
Association : Associativity;
Num_Blocks : Full_Size;
Level_Id : Positive) is new Cache with private;
type Simple_Cache_Ptr is access all Simple_Cache'Class;
-- Overridden primitive operations.
-----------------------------------------------------------------------------
-- Initialize
--
-- Initializes the given cache. Result is a cold, empty cache.
-----------------------------------------------------------------------------
procedure Initialize (This : in out Simple_Cache);
-----------------------------------------------------------------------------
-- Flush
--
-- Flushes the given cache. Collected performance data is not erased. If
-- Recursive is True, any connected sub-level cache will be flushed, too.
-----------------------------------------------------------------------------
procedure Flush (This : in out Simple_Cache;
Recursive : in Boolean := True);
-----------------------------------------------------------------------------
-- Reset
--
-- Resets the performance data of the cache. It has no effect on the current
-- cache's state. If Recursive is True, applies to any connected sub-level
-- cache, too.
-----------------------------------------------------------------------------
procedure Reset (This : in out Simple_Cache;
Recursive : in Boolean := True);
-----------------------------------------------------------------------------
-- Read
--
-- Simulates a read access to the given address.
-----------------------------------------------------------------------------
procedure Read (This : in out Simple_Cache;
Where : in Address);
-----------------------------------------------------------------------------
-- Write
--
-- Simulates a write access to the given address.
-----------------------------------------------------------------------------
procedure Write (This : in out Simple_Cache;
Where : in Address);
-----------------------------------------------------------------------------
-- Perf_Index
--
-- Returns a float value representing the performance of the cache This. If
-- Recursive is True, any connected cache's performance value is added to
-- the performance value after correcting it via the appropriate speed
-- factor.
-----------------------------------------------------------------------------
function Perf_Index (This : in Simple_Cache;
Recursive : in Boolean := True) return Long_Float;
-- New primitive (inheritable) operations.
-----------------------------------------------------------------------------
-- Connect
--
-- Connects the given cache Next as next stage to the This one.
-- Speed_Factor is a multiplicator to be used when calculating cache
-- hierarchy performance.
-----------------------------------------------------------------------------
procedure Connect (This : in out Simple_Cache;
Next : access Cache'Class;
Speed_Factor : in Long_Float := 8.0);
private
-- Cache lines can be invalid (unused, empty), full (i.e. loaded),
-- and dirty (i.e. full, but written to it).
type Line_State is (Invalid, Full, Dirty);
-- Cache lines also store a tag indicating the upper bits of the cached
-- address.
type Cache_Line_Info is
record
State : Line_State;
Tag : Address;
end record;
-- Cache line state information for each line and # of associations.
type Cache_State is array (Full_Size range <>,
Associativity range <>) of Cache_Line_Info;
-- The cache class.
type Simple_Cache (Cache_Line : Line_Length;
Association : Associativity;
Num_Blocks : Full_Size;
Level_Id : Positive) is new Cache with
record
Next_Level : Cache_Ptr;
State : Cache_State (1 .. Num_Blocks, 1 .. Association);
end record;
-- Primitive operations with "protected" visibility.
-----------------------------------------------------------------------------
-- Get_Block
--
-- Returns block an tag number for given address with the current cache's
-- configuration.
-----------------------------------------------------------------------------
procedure Get_Block (This : in Simple_Cache;
Where : in Address;
Block : out Unsigned;
Tag : out Address);
-----------------------------------------------------------------------------
-- To_Address
--
-- Reverse function of Get_Block. Return the address associated with given
-- tag and block.
-----------------------------------------------------------------------------
function To_Address (This : in Simple_Cache;
Tag : in Address;
Block : in Unsigned) return Address;
-----------------------------------------------------------------------------
-- Fetch_Line
--
-- Simulate fetching a new cache line in the block.
-- State is the state of the cache line after being fetched.
-- Block and Tag indicate the address for the line to be fetched.
-----------------------------------------------------------------------------
procedure Fetch_Line (This : in out Simple_Cache;
Block : in Unsigned;
Tag : in Address;
State : in Line_State);
end Caches.Simple_Caches;
|
charlie5/cBound | Ada | 1,582 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_set_modifier_mapping_reply_t is
-- Item
--
type Item is record
response_type : aliased Interfaces.Unsigned_8;
status : aliased Interfaces.Unsigned_8;
sequence : aliased Interfaces.Unsigned_16;
length : aliased Interfaces.Unsigned_32;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_set_modifier_mapping_reply_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_set_modifier_mapping_reply_t.Item,
Element_Array => xcb.xcb_set_modifier_mapping_reply_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_set_modifier_mapping_reply_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_set_modifier_mapping_reply_t.Pointer,
Element_Array => xcb.xcb_set_modifier_mapping_reply_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_set_modifier_mapping_reply_t;
|
kontena/ruby-packer | Ada | 14,854 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- Sample.Menu_Demo --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998-2008,2011 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control
-- $Revision: 1.19 $
-- $Date: 2011/03/23 00:44:12 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
with Terminal_Interface.Curses.Menus.Menu_User_Data;
with Terminal_Interface.Curses.Menus.Item_User_Data;
with Sample.Manifest; use Sample.Manifest;
with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
with Sample.Menu_Demo.Handler;
with Sample.Helpers; use Sample.Helpers;
with Sample.Explanation; use Sample.Explanation;
package body Sample.Menu_Demo is
package Spacing_Demo is
procedure Spacing_Test;
end Spacing_Demo;
package body Spacing_Demo is
procedure Spacing_Test
is
function My_Driver (M : Menu;
K : Key_Code;
P : Panel) return Boolean;
procedure Set_Option_Key;
procedure Set_Select_Key;
procedure Set_Description_Key;
procedure Set_Hide_Key;
package Mh is new Sample.Menu_Demo.Handler (My_Driver);
I : Item_Array_Access := new Item_Array'
(New_Item ("January", "31 Days"),
New_Item ("February", "28/29 Days"),
New_Item ("March", "31 Days"),
New_Item ("April", "30 Days"),
New_Item ("May", "31 Days"),
New_Item ("June", "30 Days"),
New_Item ("July", "31 Days"),
New_Item ("August", "31 Days"),
New_Item ("September", "30 Days"),
New_Item ("October", "31 Days"),
New_Item ("November", "30 Days"),
New_Item ("December", "31 Days"),
Null_Item);
M : Menu := New_Menu (I);
Flip_State : Boolean := True;
Hide_Long : Boolean := False;
type Format_Code is (Four_By_1, Four_By_2, Four_By_3);
type Operations is (Flip, Reorder, Reformat, Reselect, Describe);
type Change is array (Operations) of Boolean;
pragma Pack (Change);
No_Change : constant Change := Change'(others => False);
Current_Format : Format_Code := Four_By_1;
To_Change : Change := No_Change;
function My_Driver (M : Menu;
K : Key_Code;
P : Panel) return Boolean
is
begin
if M = Null_Menu then
raise Menu_Exception;
end if;
if P = Null_Panel then
raise Panel_Exception;
end if;
To_Change := No_Change;
if K in User_Key_Code'Range then
if K = QUIT then
return True;
end if;
end if;
if K in Special_Key_Code'Range then
case K is
when Key_F4 =>
To_Change (Flip) := True;
return True;
when Key_F5 =>
To_Change (Reformat) := True;
Current_Format := Four_By_1;
return True;
when Key_F6 =>
To_Change (Reformat) := True;
Current_Format := Four_By_2;
return True;
when Key_F7 =>
To_Change (Reformat) := True;
Current_Format := Four_By_3;
return True;
when Key_F8 =>
To_Change (Reorder) := True;
return True;
when Key_F9 =>
To_Change (Reselect) := True;
return True;
when Key_F10 =>
if Current_Format /= Four_By_3 then
To_Change (Describe) := True;
return True;
else
return False;
end if;
when Key_F11 =>
Hide_Long := not Hide_Long;
declare
O : Item_Option_Set;
begin
for J in I'Range loop
Get_Options (I.all (J), O);
O.Selectable := True;
if Hide_Long then
case J is
when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
O.Selectable := False;
when others => null;
end case;
end if;
Set_Options (I.all (J), O);
end loop;
end;
return False;
when others => null;
end case;
end if;
return False;
end My_Driver;
procedure Set_Option_Key
is
O : Menu_Option_Set;
begin
if Current_Format = Four_By_1 then
Set_Soft_Label_Key (8, "");
else
Get_Options (M, O);
if O.Row_Major_Order then
Set_Soft_Label_Key (8, "O-Col");
else
Set_Soft_Label_Key (8, "O-Row");
end if;
end if;
Refresh_Soft_Label_Keys_Without_Update;
end Set_Option_Key;
procedure Set_Select_Key
is
O : Menu_Option_Set;
begin
Get_Options (M, O);
if O.One_Valued then
Set_Soft_Label_Key (9, "Multi");
else
Set_Soft_Label_Key (9, "Singl");
end if;
Refresh_Soft_Label_Keys_Without_Update;
end Set_Select_Key;
procedure Set_Description_Key
is
O : Menu_Option_Set;
begin
if Current_Format = Four_By_3 then
Set_Soft_Label_Key (10, "");
else
Get_Options (M, O);
if O.Show_Descriptions then
Set_Soft_Label_Key (10, "-Desc");
else
Set_Soft_Label_Key (10, "+Desc");
end if;
end if;
Refresh_Soft_Label_Keys_Without_Update;
end Set_Description_Key;
procedure Set_Hide_Key
is
begin
if Hide_Long then
Set_Soft_Label_Key (11, "Enab");
else
Set_Soft_Label_Key (11, "Disab");
end if;
Refresh_Soft_Label_Keys_Without_Update;
end Set_Hide_Key;
begin
Push_Environment ("MENU01");
Notepad ("MENU-PAD01");
Default_Labels;
Set_Soft_Label_Key (4, "Flip");
Set_Soft_Label_Key (5, "4x1");
Set_Soft_Label_Key (6, "4x2");
Set_Soft_Label_Key (7, "4x3");
Set_Option_Key;
Set_Select_Key;
Set_Description_Key;
Set_Hide_Key;
Set_Format (M, 4, 1);
loop
Mh.Drive_Me (M);
exit when To_Change = No_Change;
if To_Change (Flip) then
if Flip_State then
Flip_State := False;
Set_Spacing (M, 3, 2, 0);
else
Flip_State := True;
Set_Spacing (M);
end if;
elsif To_Change (Reformat) then
case Current_Format is
when Four_By_1 => Set_Format (M, 4, 1);
when Four_By_2 => Set_Format (M, 4, 2);
when Four_By_3 =>
declare
O : Menu_Option_Set;
begin
Get_Options (M, O);
O.Show_Descriptions := False;
Set_Options (M, O);
Set_Format (M, 4, 3);
end;
end case;
Set_Option_Key;
Set_Description_Key;
elsif To_Change (Reorder) then
declare
O : Menu_Option_Set;
begin
Get_Options (M, O);
O.Row_Major_Order := not O.Row_Major_Order;
Set_Options (M, O);
Set_Option_Key;
end;
elsif To_Change (Reselect) then
declare
O : Menu_Option_Set;
begin
Get_Options (M, O);
O.One_Valued := not O.One_Valued;
Set_Options (M, O);
Set_Select_Key;
end;
elsif To_Change (Describe) then
declare
O : Menu_Option_Set;
begin
Get_Options (M, O);
O.Show_Descriptions := not O.Show_Descriptions;
Set_Options (M, O);
Set_Description_Key;
end;
else
null;
end if;
end loop;
Set_Spacing (M);
Pop_Environment;
pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1)));
Delete (M);
Free (I, True);
end Spacing_Test;
end Spacing_Demo;
procedure Demo
is
-- We use this datatype only to test the instantiation of
-- the Menu_User_Data generic package. No functionality
-- behind it.
type User_Data is new Integer;
type User_Data_Access is access User_Data;
-- Those packages are only instantiated to test the usability.
-- No real functionality is shown in the demo.
package MUD is new Menu_User_Data (User_Data, User_Data_Access);
package IUD is new Item_User_Data (User_Data, User_Data_Access);
function My_Driver (M : Menu;
K : Key_Code;
P : Panel) return Boolean;
package Mh is new Sample.Menu_Demo.Handler (My_Driver);
Itm : Item_Array_Access := new Item_Array'
(New_Item ("Menu Layout Options"),
New_Item ("Demo of Hook functions"),
Null_Item);
M : Menu := New_Menu (Itm);
U1 : constant User_Data_Access := new User_Data'(4711);
U2 : User_Data_Access;
U3 : constant User_Data_Access := new User_Data'(4712);
U4 : User_Data_Access;
function My_Driver (M : Menu;
K : Key_Code;
P : Panel) return Boolean
is
Idx : constant Positive := Get_Index (Current (M));
begin
if K in User_Key_Code'Range then
if K = QUIT then
return True;
elsif K = SELECT_ITEM then
if Idx in Itm'Range then
Hide (P);
Update_Panels;
end if;
case Idx is
when 1 => Spacing_Demo.Spacing_Test;
when others => Not_Implemented;
end case;
if Idx in Itm'Range then
Top (P);
Show (P);
Update_Panels;
Update_Screen;
end if;
end if;
end if;
return False;
end My_Driver;
begin
Push_Environment ("MENU00");
Notepad ("MENU-PAD00");
Default_Labels;
Refresh_Soft_Label_Keys_Without_Update;
Set_Pad_Character (M, '|');
MUD.Set_User_Data (M, U1);
IUD.Set_User_Data (Itm.all (1), U3);
Mh.Drive_Me (M);
MUD.Get_User_Data (M, U2);
pragma Assert (U1 = U2 and U1.all = 4711);
IUD.Get_User_Data (Itm.all (1), U4);
pragma Assert (U3 = U4 and U3.all = 4712);
Pop_Environment;
Delete (M);
Free (Itm, True);
end Demo;
end Sample.Menu_Demo;
|
leonhxx/pok | Ada | 2,832 | ads | -- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2021 POK team
-- ---------------------------------------------------------------------------
-- --
-- SEMAPHORE constant and type definitions and management services --
-- --
-- ---------------------------------------------------------------------------
with APEX.Processes;
package APEX.Semaphores is
Max_Number_Of_Semaphores : constant := System_Limit_Number_Of_Semaphores;
Max_Semaphore_Value : constant := 32_767;
subtype Semaphore_Name_Type is Name_Type;
type Semaphore_Id_Type is private;
Null_Semaphore_Id : constant Semaphore_Id_Type;
type Semaphore_Value_Type is new APEX_Integer range
0 .. Max_Semaphore_Value;
type Semaphore_Status_Type is record
Current_Value : Semaphore_Value_Type;
Maximum_Value : Semaphore_Value_Type;
Waiting_Processes : APEX.Processes.Waiting_Range_Type;
end record;
procedure Create_Semaphore
(Semaphore_Name : in Semaphore_Name_Type;
Current_Value : in Semaphore_Value_Type;
Maximum_Value : in Semaphore_Value_Type;
Queuing_Discipline : in Queuing_Discipline_Type;
Semaphore_Id : out Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Wait_Semaphore
(Semaphore_Id : in Semaphore_Id_Type;
Time_Out : in System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Signal_Semaphore
(Semaphore_Id : in Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Semaphore_Id
(Semaphore_Name : in Semaphore_Name_Type;
Semaphore_Id : out Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Semaphore_Status
(Semaphore_Id : in Semaphore_Id_Type;
Semaphore_Status : out Semaphore_Status_Type;
Return_Code : out Return_Code_Type);
private
type Semaphore_Id_Type is new APEX_Integer;
Null_Semaphore_Id : constant Semaphore_Id_Type := 0;
pragma Convention (C, Semaphore_Status_Type);
-- POK BINDINGS
pragma Import (C, Create_Semaphore, "CREATE_SEMAPHORE");
pragma Import (C, Wait_Semaphore, "WAIT_SEMAPHORE");
pragma Import (C, Signal_Semaphore, "SIGNAL_SEMAPHORE");
pragma Import (C, Get_Semaphore_Id, "GET_SEMAPHORE_ID");
pragma Import (C, Get_Semaphore_Status, "GET_SEMAPHORE_STATUS");
-- END OF POK BINDINGS
end APEX.Semaphores;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.