Ver Fonte

* output style more like the coding style fpc sources commonly are using

git-svn-id: trunk@13823 -
florian há 16 anos atrás
pai
commit
81813fb64f
2 ficheiros alterados com 46 adições e 42 exclusões
  1. 22 20
      utils/h2pas/h2pas.pas
  2. 24 22
      utils/h2pas/h2pas.y

+ 22 - 20
utils/h2pas/h2pas.pas

@@ -319,7 +319,7 @@ program h2pas;
          flag_index:=0;
          flag_index:=0;
          writeln(outfile);
          writeln(outfile);
          writeln(outfile,aktspace,'const');
          writeln(outfile,aktspace,'const');
-         shift(3);
+         shift(2);
          while not eof(tempfile) do
          while not eof(tempfile) do
            begin
            begin
               readln(tempfile,line);
               readln(tempfile,line);
@@ -362,7 +362,7 @@ program h2pas;
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         writeln(implemfile,';');
                         writeln(implemfile,';');
                         writeln(implemfile,aktspace,'begin');
                         writeln(implemfile,aktspace,'begin');
-                        shift(3);
+                        shift(2);
                         write(implemfile,aktspace,name,':=(a.flag',flag_index);
                         write(implemfile,aktspace,name,':=(a.flag',flag_index);
                         writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
                         writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
                         popshift;
                         popshift;
@@ -385,7 +385,7 @@ program h2pas;
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         writeln(implemfile,');');
                         writeln(implemfile,');');
                         writeln(implemfile,aktspace,'begin');
                         writeln(implemfile,aktspace,'begin');
-                        shift(3);
+                        shift(2);
                         write(implemfile,aktspace,'a.flag',flag_index,':=');
                         write(implemfile,aktspace,'a.flag',flag_index,':=');
                         write(implemfile,'a.flag',flag_index,' or ');
                         write(implemfile,'a.flag',flag_index,' or ');
                         writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
                         writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
@@ -563,8 +563,6 @@ program h2pas;
                end;
                end;
              t_funcname :
              t_funcname :
                begin
                begin
-                  if not compactmode then
-                   shift(2);
                   if if_nb>0 then
                   if if_nb>0 then
                     begin
                     begin
                        writeln(outfile,aktspace,'var');
                        writeln(outfile,aktspace,'var');
@@ -581,7 +579,7 @@ program h2pas;
                        if_nb:=0;
                        if_nb:=0;
                     end;
                     end;
                   writeln(outfile,aktspace,'begin');
                   writeln(outfile,aktspace,'begin');
-                  shift(3);
+                  shift(2);
                   write(outfile,aktspace);
                   write(outfile,aktspace);
                   write_all_ifexpr(outfile,p^.p2);
                   write_all_ifexpr(outfile,p^.p2);
                   write_expr(outfile,p^.p1);
                   write_expr(outfile,p^.p1);
@@ -1059,7 +1057,7 @@ program h2pas;
                         writeln(outfile,'packed record')
                         writeln(outfile,'packed record')
                       else
                       else
                         writeln(outfile,'record');
                         writeln(outfile,'record');
-                      shift(3);
+                      shift(2);
                       hp1:=p^.p1;
                       hp1:=p^.p1;
 
 
                       (* walk through all members *)
                       (* walk through all members *)
@@ -1192,7 +1190,7 @@ program h2pas;
                         writeln(outfile,'record');
                         writeln(outfile,'record');
                       shift(2);
                       shift(2);
                       writeln(outfile,aktspace,'case longint of');
                       writeln(outfile,aktspace,'case longint of');
-                      shift(3);
+                      shift(2);
                       l:=0;
                       l:=0;
                       hp1:=p^.p1;
                       hp1:=p^.p1;
 
 
@@ -1623,7 +1621,7 @@ begin
          end;
          end;
          block_type:=bt_var;
          block_type:=bt_var;
          
          
-         shift(3);
+         shift(2);
          
          
          IsExtern:=assigned(yyv[yysp-4])and(yyv[yysp-4]^.str='extern');
          IsExtern:=assigned(yyv[yysp-4])and(yyv[yysp-4]^.str='extern');
          (* walk through all declarations *)
          (* walk through all declarations *)
@@ -1807,7 +1805,7 @@ begin
          end;
          end;
          block_type:=bt_var;
          block_type:=bt_var;
          
          
-         shift(3);
+         shift(2);
          
          
          IsExtern:=assigned(yyv[yysp-5])and(yyv[yysp-5]^.str='extern');
          IsExtern:=assigned(yyv[yysp-5])and(yyv[yysp-5]^.str='extern');
          (* walk through all declarations *)
          (* walk through all declarations *)
@@ -1849,7 +1847,7 @@ begin
          writeln(outfile,aktspace,'type');
          writeln(outfile,aktspace,'type');
          block_type:=bt_type;
          block_type:=bt_type;
          end;
          end;
-         shift(3);
+         shift(2);
          if ( yyv[yysp-1]^.p2  <> nil ) then
          if ( yyv[yysp-1]^.p2  <> nil ) then
          begin
          begin
          (* write new type name *)
          (* write new type name *)
@@ -1905,7 +1903,7 @@ begin
          TN:=TypeName(yyv[yysp-1]^.p);
          TN:=TypeName(yyv[yysp-1]^.p);
          if Uppercase(tn)<>Uppercase(pn) then
          if Uppercase(tn)<>Uppercase(pn) then
          begin
          begin
-         shift(3);
+         shift(2);
          writeln(outfile,aktspace,PN,' = ',TN,';');
          writeln(outfile,aktspace,PN,' = ',TN,';');
          popshift;
          popshift;
          end;
          end;
@@ -1926,7 +1924,7 @@ begin
          block_type:=bt_type;
          block_type:=bt_type;
          end;
          end;
          no_pop:=assigned(yyv[yysp-7]) and (yyv[yysp-7]^.str='no_pop');
          no_pop:=assigned(yyv[yysp-7]) and (yyv[yysp-7]^.str='no_pop');
-         shift(3);
+         shift(2);
          (* walk through all declarations *)
          (* walk through all declarations *)
          hp:=yyv[yysp-6];
          hp:=yyv[yysp-6];
          if assigned(hp) then
          if assigned(hp) then
@@ -1974,7 +1972,7 @@ begin
          else
          else
          writeln(outfile);
          writeln(outfile);
          no_pop:=assigned(yyv[yysp-2]) and (yyv[yysp-2]^.str='no_pop');
          no_pop:=assigned(yyv[yysp-2]) and (yyv[yysp-2]^.str='no_pop');
-         shift(3);
+         shift(2);
          (* Get the name to write the type definition for, try
          (* Get the name to write the type definition for, try
          to use the tag name first *)
          to use the tag name first *)
          if assigned(yyv[yysp-3]^.p2) then
          if assigned(yyv[yysp-3]^.p2) then
@@ -2051,7 +2049,7 @@ begin
          end
          end
          else
          else
          writeln(outfile);
          writeln(outfile);
-         shift(3);
+         shift(2);
          (* write as pointer *)
          (* write as pointer *)
          writeln(outfile,'(* generic typedef  *)');
          writeln(outfile,'(* generic typedef  *)');
          writeln(outfile,aktspace,yyv[yysp-1]^.p,' = pointer;');
          writeln(outfile,aktspace,yyv[yysp-1]^.p,' = pointer;');
@@ -2090,6 +2088,9 @@ begin
          writeln(implemfile,aktspace,'{ return type might be wrong }   ');
          writeln(implemfile,aktspace,'{ return type might be wrong }   ');
          end;
          end;
          end;
          end;
+         if block_type<>bt_func then
+         writeln(outfile);
+         
          block_type:=bt_func;
          block_type:=bt_func;
          write(outfile,aktspace,'function ',yyv[yysp-5]^.p);
          write(outfile,aktspace,'function ',yyv[yysp-5]^.p);
          write(implemfile,aktspace,'function ',yyv[yysp-5]^.p);
          write(implemfile,aktspace,'function ',yyv[yysp-5]^.p);
@@ -2158,11 +2159,12 @@ begin
          begin
          begin
          if block_type<>bt_const then
          if block_type<>bt_const then
          begin
          begin
+         if block_type<>bt_func then
          writeln(outfile);
          writeln(outfile);
          writeln(outfile,aktspace,'const');
          writeln(outfile,aktspace,'const');
          end;
          end;
          block_type:=bt_const;
          block_type:=bt_const;
-         shift(3);
+         shift(2);
          write(outfile,aktspace,yyv[yysp-3]^.p);
          write(outfile,aktspace,yyv[yysp-3]^.p);
          write(outfile,' = ');
          write(outfile,' = ');
          flush(outfile);
          flush(outfile);
@@ -2176,6 +2178,8 @@ begin
          end
          end
          else
          else
          begin
          begin
+         if block_type<>bt_func then
+         writeln(outfile);
          if not stripinfo then
          if not stripinfo then
          begin
          begin
          writeln (outfile,aktspace,'{ was #define dname def_expr }');
          writeln (outfile,aktspace,'{ was #define dname def_expr }');
@@ -2187,11 +2191,9 @@ begin
          shift(2);
          shift(2);
          if not assigned(yyv[yysp-1]^.p3) then
          if not assigned(yyv[yysp-1]^.p3) then
          begin
          begin
-         writeln(outfile,' : longint;');
-         writeln(outfile,aktspace,'  { return type might be wrong }');
+         writeln(outfile,' : longint; { return type might be wrong }');
          flush(outfile);
          flush(outfile);
-         writeln(implemfile,' : longint;');
-         writeln(implemfile,aktspace,'  { return type might be wrong }');
+         writeln(implemfile,' : longint; { return type might be wrong }');
          end
          end
          else
          else
          begin
          begin

+ 24 - 22
utils/h2pas/h2pas.y

@@ -315,7 +315,7 @@ program h2pas;
          flag_index:=0;
          flag_index:=0;
          writeln(outfile);
          writeln(outfile);
          writeln(outfile,aktspace,'const');
          writeln(outfile,aktspace,'const');
-         shift(3);
+         shift(2);
          while not eof(tempfile) do
          while not eof(tempfile) do
            begin
            begin
               readln(tempfile,line);
               readln(tempfile,line);
@@ -358,7 +358,7 @@ program h2pas;
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         writeln(implemfile,';');
                         writeln(implemfile,';');
                         writeln(implemfile,aktspace,'begin');
                         writeln(implemfile,aktspace,'begin');
-                        shift(3);
+                        shift(2);
                         write(implemfile,aktspace,name,':=(a.flag',flag_index);
                         write(implemfile,aktspace,name,':=(a.flag',flag_index);
                         writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
                         writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
                         popshift;
                         popshift;
@@ -381,7 +381,7 @@ program h2pas;
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
                         writeln(implemfile,');');
                         writeln(implemfile,');');
                         writeln(implemfile,aktspace,'begin');
                         writeln(implemfile,aktspace,'begin');
-                        shift(3);
+                        shift(2);
                         write(implemfile,aktspace,'a.flag',flag_index,':=');
                         write(implemfile,aktspace,'a.flag',flag_index,':=');
                         write(implemfile,'a.flag',flag_index,' or ');
                         write(implemfile,'a.flag',flag_index,' or ');
                         writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
                         writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
@@ -559,8 +559,6 @@ program h2pas;
                end;
                end;
              t_funcname :
              t_funcname :
                begin
                begin
-                  if not compactmode then
-                   shift(2);
                   if if_nb>0 then
                   if if_nb>0 then
                     begin
                     begin
                        writeln(outfile,aktspace,'var');
                        writeln(outfile,aktspace,'var');
@@ -577,7 +575,7 @@ program h2pas;
                        if_nb:=0;
                        if_nb:=0;
                     end;
                     end;
                   writeln(outfile,aktspace,'begin');
                   writeln(outfile,aktspace,'begin');
-                  shift(3);
+                  shift(2);
                   write(outfile,aktspace);
                   write(outfile,aktspace);
                   write_all_ifexpr(outfile,p^.p2);
                   write_all_ifexpr(outfile,p^.p2);
                   write_expr(outfile,p^.p1);
                   write_expr(outfile,p^.p1);
@@ -1055,7 +1053,7 @@ program h2pas;
                         writeln(outfile,'packed record')
                         writeln(outfile,'packed record')
                       else
                       else
                         writeln(outfile,'record');
                         writeln(outfile,'record');
-                      shift(3);
+                      shift(2);
                       hp1:=p^.p1;
                       hp1:=p^.p1;
 
 
                       (* walk through all members *)
                       (* walk through all members *)
@@ -1188,7 +1186,7 @@ program h2pas;
                         writeln(outfile,'record');
                         writeln(outfile,'record');
                       shift(2);
                       shift(2);
                       writeln(outfile,aktspace,'case longint of');
                       writeln(outfile,aktspace,'case longint of');
-                      shift(3);
+                      shift(2);
                       l:=0;
                       l:=0;
                       hp1:=p^.p1;
                       hp1:=p^.p1;
 
 
@@ -1545,7 +1543,7 @@ declaration :
                end;
                end;
              block_type:=bt_var;
              block_type:=bt_var;
 
 
-             shift(3);
+             shift(2);
 
 
              IsExtern:=assigned($1)and($1^.str='extern');
              IsExtern:=assigned($1)and($1^.str='extern');
              (* walk through all declarations *)
              (* walk through all declarations *)
@@ -1728,7 +1726,7 @@ declaration :
                end;
                end;
              block_type:=bt_var;
              block_type:=bt_var;
 
 
-             shift(3);
+             shift(2);
 
 
              IsExtern:=assigned($1)and($1^.str='extern');
              IsExtern:=assigned($1)and($1^.str='extern');
              (* walk through all declarations *)
              (* walk through all declarations *)
@@ -1769,7 +1767,7 @@ declaration :
             writeln(outfile,aktspace,'type');
             writeln(outfile,aktspace,'type');
             block_type:=bt_type;
             block_type:=bt_type;
          end;
          end;
-       shift(3);
+       shift(2);
        if ( yyv[yysp-1]^.p2  <> nil ) then
        if ( yyv[yysp-1]^.p2  <> nil ) then
          begin
          begin
            (* write new type name *)
            (* write new type name *)
@@ -1824,7 +1822,7 @@ declaration :
        TN:=TypeName($4^.p);
        TN:=TypeName($4^.p);
        if Uppercase(tn)<>Uppercase(pn) then
        if Uppercase(tn)<>Uppercase(pn) then
         begin
         begin
-          shift(3);
+          shift(2);
           writeln(outfile,aktspace,PN,' = ',TN,';');
           writeln(outfile,aktspace,PN,' = ',TN,';');
           popshift;
           popshift;
         end;
         end;
@@ -1844,7 +1842,7 @@ declaration :
             block_type:=bt_type;
             block_type:=bt_type;
          end;
          end;
        no_pop:=assigned($4) and ($4^.str='no_pop');
        no_pop:=assigned($4) and ($4^.str='no_pop');
-       shift(3);
+       shift(2);
        (* walk through all declarations *)
        (* walk through all declarations *)
        hp:=$5;
        hp:=$5;
        if assigned(hp) then
        if assigned(hp) then
@@ -1891,7 +1889,7 @@ declaration :
        else
        else
          writeln(outfile);
          writeln(outfile);
        no_pop:=assigned($3) and ($3^.str='no_pop');
        no_pop:=assigned($3) and ($3^.str='no_pop');
-       shift(3);
+       shift(2);
        (* Get the name to write the type definition for, try
        (* Get the name to write the type definition for, try
           to use the tag name first *)
           to use the tag name first *)
        if assigned($2^.p2) then
        if assigned($2^.p2) then
@@ -1967,7 +1965,7 @@ declaration :
          end
          end
        else
        else
          writeln(outfile);
          writeln(outfile);
-       shift(3);
+       shift(2);
        (* write as pointer *)
        (* write as pointer *)
        writeln(outfile,'(* generic typedef  *)');
        writeln(outfile,'(* generic typedef  *)');
        writeln(outfile,aktspace,$2^.p,' = pointer;');
        writeln(outfile,aktspace,$2^.p,' = pointer;');
@@ -2007,6 +2005,9 @@ define_dec :
              writeln(implemfile,aktspace,'{ return type might be wrong }   ');
              writeln(implemfile,aktspace,'{ return type might be wrong }   ');
            end;
            end;
         end;
         end;
+       if block_type<>bt_func then
+         writeln(outfile);
+
        block_type:=bt_func;
        block_type:=bt_func;
        write(outfile,aktspace,'function ',$2^.p);
        write(outfile,aktspace,'function ',$2^.p);
        write(implemfile,aktspace,'function ',$2^.p);
        write(implemfile,aktspace,'function ',$2^.p);
@@ -2072,11 +2073,12 @@ define_dec :
          begin
          begin
             if block_type<>bt_const then
             if block_type<>bt_const then
               begin
               begin
-                 writeln(outfile);
-                 writeln(outfile,aktspace,'const');
+                if block_type<>bt_func then
+                  writeln(outfile);
+                writeln(outfile,aktspace,'const');
               end;
               end;
             block_type:=bt_const;
             block_type:=bt_const;
-            shift(3);
+            shift(2);
             write(outfile,aktspace,$2^.p);
             write(outfile,aktspace,$2^.p);
             write(outfile,' = ');
             write(outfile,' = ');
             flush(outfile);
             flush(outfile);
@@ -2090,6 +2092,8 @@ define_dec :
          end
          end
        else
        else
          begin
          begin
+            if block_type<>bt_func then
+              writeln(outfile);
             if not stripinfo then
             if not stripinfo then
              begin
              begin
                writeln (outfile,aktspace,'{ was #define dname def_expr }');
                writeln (outfile,aktspace,'{ was #define dname def_expr }');
@@ -2101,11 +2105,9 @@ define_dec :
             shift(2);
             shift(2);
             if not assigned($4^.p3) then
             if not assigned($4^.p3) then
               begin
               begin
-                 writeln(outfile,' : longint;');
-                 writeln(outfile,aktspace,'  { return type might be wrong }');
+                 writeln(outfile,' : longint; { return type might be wrong }');
                  flush(outfile);
                  flush(outfile);
-                 writeln(implemfile,' : longint;');
-                 writeln(implemfile,aktspace,'  { return type might be wrong }');
+                 writeln(implemfile,' : longint; { return type might be wrong }');
               end
               end
             else
             else
               begin
               begin