Skip to content

Slides/131 replace field and element in other courses #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ How Did We Get Here? - Solution
loop
declare
Pieces : Strings_T := Split (Get_Line (File));
Element : Element_T;
Component : Component_T;
begin
Element.Line_Number := Integer (Line (File) - 1);
Element.Category := Convert (Pieces (1).all);
Element.Description := Pieces (2);
Element.Quantity := Convert (Pieces (3).all);
Element.Cost := Convert (Pieces (4).all);
Database_Count := Database_Count + 1;
Database (Database_Count) := Element;
Component.Line_Number := Integer (Line (File) - 1);
Component.Category := Convert (Pieces (1).all);
Component.Description := Pieces (2);
Component.Quantity := Convert (Pieces (3).all);
Component.Cost := Convert (Pieces (4).all);
Database_Count := Database_Count + 1;
Database (Database_Count) := Component;
exception
when The_Err : others =>
Put_Line ("Load failure: " & Exception_Name (The_Err));
Expand Down
34 changes: 17 additions & 17 deletions courses/advanced_exception_analysis/labs/source/src/parser.adb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ with Strings; use Strings;

package body Parser is

type Element_T is record
type Component_T is record
Line_Number : Integer;
Category : Category_T;
Description : String_T;
Quantity : Quantity_T;
Cost : Cost_T;
end record;

Database : array (1 .. 10) of Element_T;
Database : array (1 .. 10) of Component_T;
Database_Count : Integer := 0;

procedure Load (Filename : String) is
Expand All @@ -23,29 +23,29 @@ package body Parser is
while not End_Of_File (File)
loop
declare
Pieces : Strings_T := Split (Get_Line (File));
Element : Element_T;
Pieces : Strings_T := Split (Get_Line (File));
Component : Component_T;
begin
Element.Line_Number := Integer (Line (File) - 1);
Element.Category := Convert (Pieces (1).all);
Element.Description := Pieces (2);
Element.Quantity := Convert (Pieces (3).all);
Element.Cost := Convert (Pieces (4).all);
Database_Count := Database_Count + 1;
Database (Database_Count) := Element;
Component.Line_Number := Integer (Line (File) - 1);
Component.Category := Convert (Pieces (1).all);
Component.Description := Pieces (2);
Component.Quantity := Convert (Pieces (3).all);
Component.Cost := Convert (Pieces (4).all);
Database_Count := Database_Count + 1;
Database (Database_Count) := Component;
end;
end loop;
end Load;

procedure Print is
begin
for Element of Database (1 .. Database_Count)
for Component of Database (1 .. Database_Count)
loop
Put (Element.Line_Number'Image & ": ");
Put (Element.Description.all & " (");
Put (Convert (Element.Category) & ") ");
Put (Convert (Element.Quantity) & " at $");
Put_Line (Convert (Element.Cost));
Put (Component.Line_Number'Image & ": ");
Put (Component.Description.all & " (");
Put (Convert (Component.Category) & ") ");
Put (Convert (Component.Quantity) & " at $");
Put_Line (Convert (Component.Cost));
end loop;
end Print;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Arrays Interfacing
Arrays From Ada to C
----------------------

* An Ada array is a composite data structure containing 2 components: Bounds and Components
* An Ada array is a composite data structure containing 2 parts: Bounds and Components

- **Fat pointers**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Standard Library Queues Implementations
* Priority implementations

- :ada:`Unbounded_Priority_Queues`
- :ada:`Bounded_Priotiry_Queues`
- :ada:`Bounded_Priority_Queues`
- As :ada:`protected` types
- Elements provide :ada:`Get_Priority`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Command Line
GPRbuild Command Line
-----------------------

* Made up of three elements
* Made up of three components

* Main project file (required)
* Switches (optional)
Expand Down
2 changes: 1 addition & 1 deletion courses/gnat_studio/010_gnat_studio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Data Window

+ Name of the expression or variable

+ Components / elements can be expanded
+ Components / components can be expanded

+ Value
+ Type (Ada type definition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ package body Values.Operations is
Result := V1.E - V2.E;
end case;

-- Create an integer Value by setting the field "E" of the record
-- Create an integer Value by setting the component "E" of the record
-- to Result.

Stack.Push (new Value_Info'(E => Result));
Expand Down
4 changes: 2 additions & 2 deletions courses/gnat_studio/labs/source/struct/values.adb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ package body Values is
end if;

return new Value_Info'(E => Int_Val);
-- Allocate a new Value_Info (which is a record with one field)
-- on the heap and initialize its only field "E" to be "Int_Val".
-- Allocate a new Value_Info (which is a record with one component)
-- on the heap and initialize its only component "E" to be "Int_Val".
-- NOTE: the ' in Value_Info'(...) must be there.
end Read;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ package body Values.Operations is
Result := V1.E - V2.E;
end case;

-- Create an integer Value by setting the field "E" of the record
-- Create an integer Value by setting the component "E" of the record
-- to Result.

Stack.Push (new Value_Info'(E => Result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ package body Values is
end if;

return new Value_Info'(E => Int_Val);
-- Allocate a new Value_Info (which is a record with one field)
-- on the heap and initialize its only field "E" to be "Int_Val".
-- Allocate a new Value_Info (which is a record with one component)
-- on the heap and initialize its only component "E" to be "Int_Val".
-- NOTE: the ' in Value_Info'(...) must be there.
end Read;

Expand Down
6 changes: 3 additions & 3 deletions courses/gnatsas/labs/check_040_lkql.lab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Step 3 - Implement First Criteria

1. Implement the first criteria: **No use of any arithmetic or bitwise operator on the type**.

a. Need to fetch all operators - use global :lkql:`select` with :lkql:`BinOp` and :lkql:`UnOp` node kind patterns. (Field :lkql:`f_op` contains the kind of the operator.)
a. Need to fetch all operators - use global :lkql:`select` with :lkql:`BinOp` and :lkql:`UnOp` node kind patterns. (Component :lkql:`f_op` contains the kind of the operator.)

.. code:: lkql

Expand Down Expand Up @@ -247,9 +247,9 @@ Step 6 - Improve Types Filter

1. Update the :lkql:`types` function to also return types used as source type in conversions

* LAL field **f_suffix**
* LAL component **f_suffix**

* Returns **ParamAssocList** with a single element - source expression
* Returns **ParamAssocList** with a single component - source expression
* Use on type conversion nodes to get source of conversions

.. code:: lkql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package body Coupling_Metrics_Dependency is
function Set
(A, B : Integer)
return Record_T is
((Field1 => A,
Field2 => B));
((Component1 => A,
Component2 => B));
function Get
(A : Record_T)
return Integer is (A.Field1 * A.Field2);
return Integer is (A.Component1 * A.Component2);
function Add
(A, B : Record_T)
return Record_T is
((Field1 => A.Field1 + B.Field1,
Field2 => A.Field2 + B.Field2));
((Component1 => A.Component1 + B.Component1,
Component2 => A.Component2 + B.Component2));

end Coupling_Metrics_Dependency;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package Coupling_Metrics_Dependency is

private
type Record_T is tagged record
Field1, Field2 : Integer;
Component1, Component2 : Integer;
end record;

end Coupling_Metrics_Dependency;
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ package body Values.Operations is
Result := V1.E - V2.E;
end case;

-- Create an integer Value by setting the field "E" of the record
-- Create an integer Value by setting the component "E" of the record
-- to Result.

Stack.Push (new Value_Info'(E => Result));
Expand Down
4 changes: 2 additions & 2 deletions courses/gnatsas/labs/sas_060_tutorial/struct/values.adb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ package body Values is
end if;

return new Value_Info'(E => Int_Val);
-- Allocate a new Value_Info (which is a record with one field)
-- on the heap and initialize its only field "E" to be "Int_Val".
-- Allocate a new Value_Info (which is a record with one component)
-- on the heap and initialize its only component "E" to be "Int_Val".
-- NOTE: the ' in Value_Info'(...) must be there.
end Read;

Expand Down
2 changes: 1 addition & 1 deletion courses/gnatsas/metric_010_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ Coupling Metrics Code Example
function Add (A, B : Record_T) return Record_T;
private
type Record_T is tagged record
Field1, Field2 : Integer;
Component1, Component2 : Integer;
end record;
end Coupling_Metrics_Dependency;

Expand Down
42 changes: 21 additions & 21 deletions courses/spark_for_ada_programmers/10_advanced_proof.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ Classical Loop Invariants
* Known best loop invariants for some loops

- Initialization loops - initialize the collection
- Mapping loops - map each element of the collection
- Validation loops - check each element of the collection
- Counting loops - count elements with a property
- Search loops - search element with a property
- Maximize loops - search element that maximizes a property
- Update loops - update each element of the collection
- Mapping loops - map each component of the collection
- Validation loops - check each component of the collection
- Counting loops - count components with a property
- Search loops - search component with a property
- Maximize loops - search component that maximizes a property
- Update loops - update each component of the collection

|

Expand Down Expand Up @@ -596,11 +596,11 @@ Bounded Formal Containers

- Discriminant :ada:`Capacity` fixes maximum size

* Element type must have known size (:dfn:`definite` type)
* Component type must have known size (:dfn:`definite` type)

* Container type itself is definite

- Bounded container can be element of another formal container
- Bounded container can be component of another formal container

-----------------------------
Unbounded Formal Containers
Expand All @@ -612,16 +612,16 @@ Unbounded Formal Containers

* Use dynamic memory allocation

- For each element in the container
- For each component in the container
- For growing the container

* Use controlled types for dynamic memory reclamation

* Element type may have unknown size (:dfn:`indefinite` type)
* Component type may have unknown size (:dfn:`indefinite` type)

* Container type itself is definite

- Unbounded container can be element of another formal container
- Unbounded container can be component of another formal container

------------------------------
Loops Over Formal Containers
Expand All @@ -645,7 +645,7 @@ Loops Over Formal Containers
V.Replace_Element (J, 0);
end loop;

* Iteration over elements (no update!)
* Iteration over components (no update!)

.. code:: ada

Expand All @@ -670,13 +670,13 @@ Loop Invariants Over Formal Containers

+ Functional model of the container
+ Mapping from cursors to positions
+ Sequence of elements/keys of the container
+ Sequence of components/keys of the container

|

* Iteration over elements
* Iteration over components

- Impossible to access previous elements
- Impossible to access previous components
- Use iteration over positions instead

-----------------------------------
Expand All @@ -696,16 +696,16 @@ Formal Model of Formal Containers
- Given by function :ada:`Model`
- Returns a different type

+ A sequence of elements for formal lists
+ A set of elements for formal sets
+ A map from keys to elements for maps
+ A sequence of components for formal lists
+ A set of components for formal sets
+ A map from keys to components for maps

* Mapping from cursors to positions

- Given by function :ada:`Positions`
- Positions in the iteration sequence

* Sequence of elements/keys of the container
* Sequence of components/keys of the container

- Corresponds to the iteration sequence
- Given by different functions
Expand All @@ -732,7 +732,7 @@ Difficulties with Loops Over Formal Containers

* Container structure may be modified in the loop

- When inserting or deleting elements
- When inserting or deleting components
- In general, need to know position of corresponding cursor

+ Relative to current cursor: e.g. previous/next cursor
Expand All @@ -756,7 +756,7 @@ Functional Containers

- No bounds on cardinality
- No cursors for iteration
- No order of elements in sets and maps
- No order of components in sets and maps
- Functional: cannot modify them, rather create a new one

* They are easy to handle for proof
Expand Down
Loading
Loading