在Ada中编译时,put_Line在a-textio.ads错误时不可见且不可见

时间:2016-01-26 05:40:50

标签: ada

我正在尝试使用Ada制作合并算法。 我必须创建一个通用过程并使用任务实现mergesort的并行执行。 但是在编译代码时我遇到了以下错误:

mergesortproc.adb:92:17: "put_Line" is not visible
mergesortproc.adb:92:17: non-visible declaration at a-textio.ads:264
mergesortproc.adb:92:17: non-visible declaration at a-textio.ads:260
mergesortproc.adb:94:25: "put" is not visible (more references follow)
mergesortproc.adb:94:25: non-visible declaration at a-tiinio.ads:75, instance at a-inteio.ads:18
mergesortproc.adb:94:25: non-visible declaration at a-tiinio.ads:65, instance at a-inteio.ads:18
mergesortproc.adb:94:25: non-visible declaration at a-tiinio.ads:59, instance at a-inteio.ads:18
mergesortproc.adb:94:25: non-visible declaration at a-textio.ads:243
mergesortproc.adb:94:25: non-visible declaration at a-textio.ads:242
mergesortproc.adb:94:25: non-visible declaration at a-textio.ads:209
mergesortproc.adb:94:25: non-visible declaration at a-textio.ads:208
gnatmake: "mergesort.adb" compilation error

请在此处找到我的代码: 的 mergesort.adb:

with Ada.Text_Io;use Ada.Text_Io;
with Ada.Integer_Text_Io;use Ada.Integer_Text_Io;
with mergesortproc;

procedure mergesort is
    type LIMIT_RANGE is new INTEGER range 1..10;
    type MY_INT is new INTEGER;
    type INT_ARRAY is array(LIMIT_RANGE) of MY_INT;
    procedure MergeSort_Int is new mergesortproc(LIMIT_RANGE,MY_INT, INT_ARRAY);

    Inp : INT_ARRAY := (10, 5, 4 ,9 ,45, 21, 5, 54, 66, 81);
    Outp: INT_ARRAY;

begin
    MergeSort_Int(Inp,Outp);
end mergesort;

mergesortproc.adb:

procedure mergesortproc(Input_Array : MY_ARRAY; Output_Array : out MY_ARRAY) is

no_indexes : SUBSCRIPT := Input_Array'LENGTH;
First: SUBSCRIPT := Input_Array'first;
mid : SUBSCRIPT := no_indexes / 2;
Last : SUBSCRIPT := Input_Array'last;
Array_A, ARRAY_B : MY_ARRAY;
index :SUBSCRIPT := 0;
Result1,Result2 : MY_ARRAY;

task type merge_sort is
    entry set_indexes(F,L,I: SUBSCRIPT);
    entry get_array(Result: out MY_ARRAY);
end merge_sort;

type domergesort is access merge_sort;

mytasks : array(1..no_indexes) of domergesort;

task body merge_sort is
    First_loc : SUBSCRIPT;
    Last_loc : SUBSCRIPT;
    mid_loc : SUBSCRIPT;
    Loc_Index, Loc_Index1, Loc_Index2 : SUBSCRIPT;
    loc_Result: MY_ARRAY;
    Loc_ArrayA, Loc_ArrayB : MY_ARRAY;
    ind1, ind2 : SUBSCRIPT := 0;
begin
    accept set_indexes(F,L,I: in SUBSCRIPT) do
        First_loc := F;
        Last_loc := L;
        Loc_Index := I;
    end set_indexes;

    if First_loc = Last_loc then
        loc_Result(Last_loc) := Input_Array(Last_loc);
    else
        mid_loc := (First_loc + Last_loc)/2;
        Loc_Index1 := Loc_Index + 2;
        mytasks(Loc_Index1).set_indexes(First_loc ,mid_loc,Loc_Index1);
        Loc_Index2 := Loc_Index + 2;
        mytasks(Loc_Index2).set_indexes(mid_loc + 1,Last_loc,Loc_Index2);

        mytasks(Loc_Index1).get_array(Loc_ArrayA);
        mytasks(Loc_Index2).get_array(Loc_ArrayB);

        for count1 in Loc_ArrayA'first..Loc_ArrayA'Last loop
            for count2 in count1+1..Loc_ArrayA'Last loop
                if Loc_ArrayA(count1) > Loc_ArrayA(count1+1) then
                    Loc_ArrayA(count1) := Loc_ArrayA(count1+1);
                end if;
            end loop;
        end loop;
        for count1 in Loc_ArrayB'first..Loc_ArrayB'Last loop
            for count2 in count1+1..Loc_ArrayB'Last loop
                if Loc_ArrayB(count1) > Loc_ArrayB(count1+1) then
                    Loc_ArrayB(count1) := Loc_ArrayB(count1+1);
                end if;
            end loop;
        end loop;

        for count1 in Loc_ArrayA'first.. Loc_ArrayA'LENGTH + Loc_ArrayB'LENGTH loop
            if ind1 < Loc_ArrayA'LENGTH and ind2 < Loc_ArrayB'LENGTH then
                if Loc_ArrayA(ind1) < Loc_ArrayB(ind2) then
                    loc_Result(count1) := Loc_ArrayA(ind1);
                    ind1 := ind1 + 1;
                else
                    loc_Result(count1) := Loc_ArrayB(ind2);
                    ind2 := ind2 + 1;
                end if;
            elsif ind1 = Loc_ArrayA'LENGTH then
                loc_Result(count1) := Loc_ArrayB(ind2);
                ind2 := ind2 + 1;
            else
                loc_Result(count1) := Loc_ArrayA(ind1);
                ind1 := ind1 + 1;
            end if;
        end loop;

    end if;

    accept get_array(Result : out MY_ARRAY) do
        for index in loc_Result'first..loc_Result'last loop
        Result(index) := loc_Result(index);
        end loop;
    end get_array;

end merge_sort;

begin
if no_indexes = 1 then
    put_Line ("The array has only one element");
    for index in Input_Array'first..Input_Array'last loop
        put(Input_Array(index));
    end loop;
    return;
else
    mytasks(1) := new merge_sort;
    mytasks(2) := new merge_sort;
    mid :=no_indexes/2;
    index := index + 1;
    mytasks(1).set_indexes(First,Mid, index);
    index := index + 1;
    mytasks(2).set_indexes(Mid+1,Last, index);

    mytasks(1).get_array(Result1);
    ARRAY_A := Result1;
    mytasks(2).get_array(Result2);
    ARRAY_B := Result2;
end if;

put("The sorted array is");
for index in ARRAY_A'first..ARRAY_A'last loop
    put(Array_A(index));
end loop;
for index in ARRAY_B'first..ARRAY_B'last loop
    put(Array_B(index));
end loop;
end mergesortproc;

mergesortproc.ads:

generic
    type SUBSCRIPT is range <>;
    type MY_TYPE is range <>;
    type MY_ARRAY is array (SUBSCRIPT) of MY_TYPE;
    procedure mergesortproc(Input_Array : MY_ARRAY; Output_Array : out MY_ARRAY);

请告诉我为什么我会遇到这个问题。代码尚未完成。但我相信如果不是这个问题,至少应该执行。 我已阅读其他一些有相同问题的帖子,但在通用软件包中。 它没有多大帮助。

1 个答案:

答案 0 :(得分:2)

mergesortproc.adb中没有with Ada.Text_IO; use Ada.Text_IO;,仅在mergesort.adb中