This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Tested under i686-linux, committed on mainline. Fix bug box when compiling code with new object.method notation: gcc -c -gnat05 demo2.adb -- with Instr; use Instr; with Instr.Child; use Instr.Child; with Ada.Text_IO; use Ada.Text_IO; with Instr.Child; use Instr.Child; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Strings.Unbounded; procedure Demo2 is use Dash_Board; procedure Print_Dash_Board (L : Vector); procedure Print_Dash_Board (L : Vector) is L1 : Cursor := First (L); begin while L1 /= No_Element loop Element (L1).Display_Value; Next (L1); end loop; New_Line; end Print_Dash_Board; Inc, Sec : Integer; function "+" (Source : String) return Ada.Strings.Unbounded.Unbounded_String renames Ada.Strings.Unbounded.To_Unbounded_String; DB : Vector := new Speedometer' (+"Speed", 45) & new Gauge' (+"Fuel", 60) & new Graphic_Gauge' (+"Water", 80, others => <>) & new Graphic_Gauge' (+"Oil", 40, others => <>) & new Clock' (+"Time in NY", 12, 15, 0) & new Chronometer' (+"Chrono", 0, 0, 0 ) & new Accurate_Clock'(+"Time in Paris", 6, 15, 0, 0); begin loop Print_Dash_board (DB); Put ("Give a time increment in milliseconds (0 to terminate) :"); Get (Inc); exit when Inc <= 0; Sec := Inc / 1000; Increment (ClockP (Element (DB, 5)), Sec); ClockP (Element (DB, 5)).Increment (Sec); Increment (ClockP (Element (DB, 6)), Sec); Increment (ClockP (Element (DB, 7)), Inc); Gauge (Element (DB, 2).all).Value := Percent (Float (Gauge (Element (DB, 2).all).Value) * (1.0 - Float (Sec) / 3600.0)); Graphic_Gauge (Element (DB, 3).all).Value := Percent (Float (Graphic_Gauge (Element (DB, 3).all).Value) * (1.0 - Float (Sec) / 600.0)); Speedometer (Element (DB, 1).all).Value := Speedometer (Element (DB, 1).all).Value + 2; end loop; exception when Others => Put_Line ("I think that's enough for today... Bye"); end Demo2; package Instr.Child is type Accurate_Clock is new Clock with record MilliSec : Thousand := 0; end record; procedure Display_Value (C : access Accurate_Clock); procedure Increment (C : access Accurate_Clock; inc : Integer := 1); end; with Ada.Containers.Vectors; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Instr is -- Instruments for a Dashboard -- -- Instrument ---- Speedometer -- | -- ---- Gauge ---- Graphic_Gauge -- | -- ---- Clock ---- Chronometer ----------------- -- Root Type -- ----------------- type Instrument is tagged record Name : Ada.Strings.Unbounded.Unbounded_String; end record; type InstrumentP is access all Instrument; type Obj is access all Instrument'Class; package Dash_Board is new Ada.Containers.Vectors (Positive, Obj); procedure Display_Value (I : access Instrument); -- update the state of the instrument after millisec has lapsed ------------------- -- Speedometer -- ------------------- subtype Speed is Integer range 0 .. 85; -- mph type Speedometer is new Instrument with record Value : Speed; end record; procedure Display_Value (S : access Speedometer); ----------------- -- Gauges -- ----------------- subtype Percent is Integer range 0 .. 100; type Gauge is new Instrument with record Value : Percent; end record; procedure Display_Value (G : access Gauge); type Graphic_Gauge is new Gauge with record Size : Integer := 20; Fill : Character := '*'; Empty : Character := '.'; end record; procedure Display_Value (G : access Graphic_Gauge); ----------------- -- Clocks -- ----------------- subtype Sixty is Integer range 0 .. 60; subtype Twenty_Four is Integer range 0 .. 24; subtype Thousand is Integer range 0 .. 1000; type Clock is new Instrument with record Seconds : Sixty := 0; Minutes : Sixty := 0; Hours : Twenty_Four := 0; end record; type ClockP is access all Clock; procedure Display_Value (C : access Clock); procedure Init (C : access Clock'Class; H : Twenty_Four := 0; M, S : Sixty := 0); procedure Increment (C : access Clock; Inc : Integer := 1); type Chronometer is new Clock with null record; procedure Display_Value (C : access Chronometer); end Instr; 2005-03-17 Javier Miranda <miranda@adacore.com> * sem_ch4.adb (Try_Primitive_Operation, Class_Wide_Operation and Try_Object_Operation): Analyze the object that is accessible through the prefix of the subprogram call before we apply the transformation of the object-operation notation.
Attachment:
difs.15
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |