ada

How to convert a Ada.Real_TIme.Time to a string?

痴心易碎 提交于 2019-12-23 18:14:58
问题 I would like to write a Ada.Real_Time.Time in a file, How can I do that? Thanks 回答1: Package Ada.Real_time doesn't provide a method for the direct format. I'd advise you to look at Ada.Calendar.Formatting. You have a method Clock like in Ada.Real_time. Indeed, there is a method Image(parameters : Time), which returns a String. For more details : Package: Ada.Calendar.Formatting 回答2: You can use Ada.Real_Time.Split to convert an Ada.Real_Time.Time into (a) the number of seconds since the epoch

How can I find the `'First` and `'Last` expressions for a string field in a record using ASIS

瘦欲@ 提交于 2019-12-23 18:09:43
问题 I'm using ASIS to analyse a big Ada project. One of the things I need to do is to find the 'First and 'Last expressions for a string field in a record variable. My problem occurs when I have a Discrete_Range , which is not A_Discrete_Simple_Expression_Range (for which one can use the functions Lower_Bound and Upper_Bound directly), but instead A_Discrete_Range_Attribute_Reference . The source example which I'm analysing basically looks like this: with Ada.Text_IO; procedure Minimal_Example is

Custom 'image attribute in Ada?

断了今生、忘了曾经 提交于 2019-12-23 10:50:08
问题 So I have a thing. type Thing is new record ...elements... end record; I have a function which stringifies it. function ToString(t: Thing) returns string; I would like to be able to tell Ada to use this function for Thing'image , so that users of my library don't have to think about whether they're using a builtin type or a Thing. However, the obvious syntax: for Thing'image use ToString; ...doesn't work. Is there a way to do this? 回答1: I don’t know why the language doesn’t support this, and

How to use user input variable as parameter for generic package?

独自空忆成欢 提交于 2019-12-23 09:44:43
问题 In Stack.adb I have specified two parameters (Size and Type). I want to create a stack that is of the exact data type that a user specifies within my multistack.adb file. I can't seem to find a way to create a new package or instantiation of a stack with a user-defined variable for the stack type. Before I go on, code is below (To avoid a wall of code, I have taken out some unrelated lines): Stack.adb : GENERIC SIZE : Integer; --size of stack TYPE Item IS PRIVATE; --type of stack multistack

Creating Ada record with one field

可紊 提交于 2019-12-23 09:36:57
问题 I've define a type: type Foo is record bar : Positive; end record; I want to create a function that returns an instance of the record: function get_foo return Foo is return (1); end get_foo; But Ada won't let me, saying "positional aggregate cannot have one argument". Stupidly trying, I've added another dumb field to the record, and then return (1, DOESNT_MATTER); works! How do I tell Ada that's not a positional aggregate, but an attempt to create a record? 回答1: The positional aggregate

How to build a static library from Ada source that's callable from C++ code?

心不动则不痛 提交于 2019-12-23 09:22:11
问题 I need to build a static library with a bunch of code written in Ada that can be called from code written in C/C++. I've searched through internet and got some knowledge about gnatmake , gnatbind and gnatlink , but still can't get the job done correctly. Also, I've read there are tools that relies upon some kind of project file. I'm not interested in those, I just need a bunch of commands to write in a Makefile . 回答1: This answer assumes you’re using the GCC toolchain. The big hurdle is that

Ada: Getting user input to a String(1..10) and filling the rest with whitespace

让人想犯罪 __ 提交于 2019-12-23 08:56:40
问题 I have defined subtype String10 is String(1..10); and I am attempting to get keyboard input to it without having to manually enter whitespace before hitting enter. I tried get_line() but from some reason it wouldn't actually wait for input before outputting the get put() command, and I also think it will just leave whatever was in the string before there and not fill it with white space. I know about and have used Bounded_String and Unbounded_String, but I am wondering if there is a way to

Abstraction over container iterators

空扰寡人 提交于 2019-12-23 04:12:34
问题 I'm talking about Ada 2012 here. I'll let the code speak first: with Ada.Containers.Hashed_Maps; with Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Hash_Case_Insensitive; with Ada.Strings.Unbounded.Equal_Case_Insensitive; package Environments is type Environment is tagged private; function Variable ( E : in Environment; Name : in Ada.Strings.Unbounded.Unbounded_String ) return Ada.Strings.Unbounded.Unbounded_String with Inline; procedure Set_Variable ( E : in out Environment; Name : in

Abstraction over container iterators

点点圈 提交于 2019-12-23 04:12:20
问题 I'm talking about Ada 2012 here. I'll let the code speak first: with Ada.Containers.Hashed_Maps; with Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Hash_Case_Insensitive; with Ada.Strings.Unbounded.Equal_Case_Insensitive; package Environments is type Environment is tagged private; function Variable ( E : in Environment; Name : in Ada.Strings.Unbounded.Unbounded_String ) return Ada.Strings.Unbounded.Unbounded_String with Inline; procedure Set_Variable ( E : in out Environment; Name : in

How to write gnatcheck rules

陌路散爱 提交于 2019-12-22 22:19:53
问题 Is it possible to write your own gnatcheck rules, and if so, can someone point me to a good reference? I am searching for a particular "style" that is being used, and would love if I could simply write a rule that says if you see said style, it will throw up a warning, or an error, this way we can flag when this isn't following a particular standard. 回答1: A bit of background may be helpful here. While the style checks hold out a lot of promise for enforcing user style guidelines, that isn't