-- The function spec must be on a single line
--- There can only be a single statement, contained on a single line,
--- not counting any pragma Assert statements.
+-- There can only be a single return statement, not counting any pragma
+-- Assert statements, possibly followed by a comment.
--- This single statement must either be a function call with simple,
--- single token arguments, or it must be a membership test of the form
--- a in b, where a and b are single tokens.
+-- This single statement must either contain a function call with simple,
+-- single token arguments, or it must contain a membership test of the form
+-- a in b, where a and b are single tokens, or it must contain an equality
+-- or inequality test of single tokens, or it must contain a disjunction of
+-- the preceding constructs.
-- For functions that are not inlined, there is no restriction on the body,
-- and XEINFO generates a direct reference in the C header file which allows
pragma Inline (Is_Static_Type);
pragma Inline (Is_Statically_Allocated);
pragma Inline (Is_Subprogram);
+ pragma Inline (Is_Subprogram_Or_Entry);
+ pragma Inline (Is_Subprogram_Or_Generic_Subprogram);
pragma Inline (Is_Tag);
pragma Inline (Is_Tagged_Type);
pragma Inline (Is_Task_Type);
pragma Inline (Is_Protected_Component);
pragma Inline (Is_Protected_Record_Type);
pragma Inline (Is_String_Type);
- pragma Inline (Is_Subprogram_Or_Entry);
- pragma Inline (Is_Subprogram_Or_Generic_Subprogram);
pragma Inline (Is_Task_Record_Type);
pragma Inline (Is_Volatile);
pragma Inline (Is_Wrapper_Package);
Get_Cmnt : constant Pattern := BreakX ('-') * A & "--";
Get_Expr : constant Pattern := wsp & "return " & Break (';') * Expr;
Chek_End : constant Pattern := wsp & "end" & BreakX (';') & ';';
+ Get_B0 : constant Pattern := BreakX (' ') * A & " or else " & Rest * B;
Get_B1 : constant Pattern := BreakX (' ') * A & " in " & Rest * B;
Get_B2 : constant Pattern := BreakX (' ') * A & " = " & Rest * B;
Get_B3 : constant Pattern := BreakX (' ') * A & " /= " & Rest * B;
- Get_B4 : constant Pattern := BreakX (' ') * A & " or else " & Rest * B;
To_Paren : constant Pattern := wsp * Filler & '(';
Get_Fml : constant Pattern := Break (" :") * Formal & wsp & ':' & wsp
& BreakX (" );") * Formaltyp;
procedure Sethead (Line : in out VString; Term : String);
-- Process function header into C
+ procedure Translate_Expr (Expr : in out VString);
+ -- Translate expression from Ada to C
+
-------------
-- Badfunc --
-------------
end if;
end Sethead;
+ --------------------
+ -- Translate_Expr --
+ --------------------
+
+ procedure Translate_Expr (Expr : in out VString) is
+ M : Match_Result;
+
+ begin
+ Match (Expr, Get_B1, M);
+ Replace (M, "IN (" & A & ", " & B & ')');
+ Match (Expr, Get_B2, M);
+ Replace (M, A & " == " & B);
+ Match (Expr, Get_B3, M);
+ Replace (M, A & " != " & B);
+ end Translate_Expr;
+
-- Start of processing for XEinfo
begin
Badfunc;
end if;
- Match (Expr, Get_B1, M);
- Replace (M, "IN (" & A & ", " & B & ')');
- Match (Expr, Get_B2, M);
- Replace (M, A & " == " & B);
- Match (Expr, Get_B3, M);
- Replace (M, A & " != " & B);
- Match (Expr, Get_B4, M);
- Replace (M, A & " || " & B);
+ -- Process expression
+
+ if Match (Expr, Get_B0, M) then
+ declare
+ Saved_A : VString := A;
+ Saved_B : VString := B;
+ begin
+ Translate_Expr (Saved_A);
+ Translate_Expr (Saved_B);
+ Replace (M, Saved_A & " || " & Saved_B);
+ end;
+ else
+ Translate_Expr (Expr);
+ end if;
+
Put_Line (Ofile, "");
Sethead (Fline, "");
Put_Line (Ofile, C & " { return " & Expr & "; }");