Patchwork [Ada] Enforce style check for all binary operators

login
register
mail settings
Submitter Arnaud Charlet
Date July 18, 2014, 9:23 a.m.
Message ID <20140718092339.GA32320@adacore.com>
Download mbox | patch
Permalink /patch/371378/
State New
Headers show

Comments

Arnaud Charlet - July 18, 2014, 9:23 a.m.
Add two missing style checks for token spacing for binary operators when
switches -gnatyt, -gnatyy or -gnatyg is used.
Preserve previous behavior with debug switch -gnatd.Q

Test:
$ gcc -c pkg.ads -gnatyt -gnatl -gnatd7

Compiling: pkg.ads

     1. package Pkg is
     2.    One : constant := 1;
     3.    type Entier is range 0 .. 16-One;
                                       |
        >>> (style) space required

     4.    AB : constant String := "A"&"B";
                                      |
        >>> (style) space required

     5. end Pkg;

 5 lines: No errors, 2 warnings

Invoking
   gcc -c pkg.ads -gnatyt -gnatd.Q
should not report any warning.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-07-18  Vincent Celier  <celier@adacore.com>

	* par-ch4.adb (Simple_Expression): Add missing style check
	for binary adding operators.
	(Term): Add missing style check for multiplying operators.

Patch

Index: debug.adb
===================================================================
--- debug.adb	(revision 212725)
+++ debug.adb	(working copy)
@@ -134,7 +134,7 @@ 
    --  d.N  Add node to all entities
    --  d.O  Dump internal SCO tables
    --  d.P  Previous (non-optimized) handling of length comparisons
-   --  d.Q
+   --  d.Q  Previous (incomplete) style check for binary operators
    --  d.R  Restrictions in ali files in positional form
    --  d.S  Force Optimize_Alignment (Space)
    --  d.T  Force Optimize_Alignment (Time)
Index: par-ch4.adb
===================================================================
--- par-ch4.adb	(revision 212656)
+++ par-ch4.adb	(working copy)
@@ -2152,6 +2152,11 @@ 
                exit when Token not in Token_Class_Binary_Addop;
                Tokptr := Token_Ptr;
                Node2 := New_Op_Node (P_Binary_Adding_Operator, Tokptr);
+
+               if Style_Check and then not Debug_Flag_Dot_QQ then
+                  Style.Check_Binary_Operator;
+               end if;
+
                Scan; -- past operator
                Set_Left_Opnd (Node2, Node1);
                Node1 := P_Term;
@@ -2406,6 +2411,11 @@ 
          exit when Token not in Token_Class_Mulop;
          Tokptr := Token_Ptr;
          Node2 := New_Op_Node (P_Multiplying_Operator, Tokptr);
+
+         if Style_Check and then not Debug_Flag_Dot_QQ then
+            Style.Check_Binary_Operator;
+         end if;
+
          Scan; -- past operator
          Set_Left_Opnd (Node2, Node1);
          Set_Right_Opnd (Node2, P_Factor);