[Prolint-cvs] prolint/rules ifparens.p,NONE,1.1 rules.d,1.19,1.20
                
                Brought to you by:
                
                    johnallengreen,
                    
                
                    jurjen
                    
                
            
            
        
        
        
    | 
     
      
      
      From: <ju...@us...> - 2003-12-02 10:35:58
      
     
   | 
Update of /cvsroot/prolint/prolint/rules
In directory sc8-pr-cvs1:/tmp/cvs-serv8099/rules
Modified Files:
	rules.d 
Added Files:
	ifparens.p 
Log Message:
new rule "ifparens"
--- NEW FILE: ifparens.p ---
/* -----------------------------------------------------------------------------
   file    :  prolint/rules/ifparens.p
   purpose :  find IF functions (not statements) that should better be
              surrounded by parentheses
   -----------------------------------------------------------------------------
    Copyright (C) 2003 Jurjen Dijkstra
    This file is part of Prolint.
    Prolint is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    Prolint is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
    License along with Prolint; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   --------------------------------------------------------------------------------- */
  
{prolint/ruleparams.i}  
   RUN searchNode {&insuper} (hTopnode,           /* "Program_root" node          */
                              "InspectNode":U,    /* name of callback procedure   */
                              "IF":U).           /* list of nodetypes to search for */
RETURN.
PROCEDURE InspectNode :
/* InspectNode is where the actual rule is implemented.
   it is called from SearchNode */
   DEFINE INPUT  PARAMETER theNode        AS INTEGER NO-UNDO.
   DEFINE OUTPUT PARAMETER AbortSearch    AS LOGICAL NO-UNDO INITIAL NO.
   DEFINE OUTPUT PARAMETER SearchChildren AS LOGICAL NO-UNDO INITIAL YES.
                             
   DEFINE VARIABLE child    AS INTEGER NO-UNDO.
   DEFINE VARIABLE nodetype AS CHARACTER NO-UNDO.
   /* is "IF" a statehead? If yes, then it is not a function -> return. */
   IF parserAttrGet(theNode, "statehead":U)<>"" THEN
      RETURN.
   
   ASSIGN
     child       = parserGetHandle()
     nodetype    = parserNodeFirstChild(theNode,child).  /* boolean expression */
   IF "THEN":U = parserNodeNextSibling(child,child) THEN DO:
      nodetype    = parserNodeNextSibling(child,child).   /* the 'then' value */
      IF "ELSE":U = parserNodeNextSibling(child,child) THEN DO:
         nodetype    = parserNodeNextSibling(child,child).   /* the 'else' value */
         IF parserAttrGet(child, "operator":U)<>"" THEN
         RUN PublishResult {&insuper} (compilationunit,
                                       parserGetNodeFilename(theNode),
                                       parserGetNodeLine(theNode),
                                       "IF function is confusing, use parentheses":T,
                                       rule_id).
      END.
   END.
   /* release every proparse handle that was declared in this context */
   parserReleaseHandle(child).
    
END PROCEDURE.                            
Index: rules.d
===================================================================
RCS file: /cvsroot/prolint/prolint/rules/rules.d,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** rules.d	23 Oct 2003 17:43:01 -0000	1.19
--- rules.d	1 Dec 2003 22:10:28 -0000	1.20
***************
*** 20,23 ****
--- 20,24 ----
  "ifindent1" 8 yes no no no yes "IF statement with indenting that could indicate a bug"
  "ifindent2" 2 yes no no no yes "IF statement with questionable indenting or couldn't check"
+ "ifparens" 8 yes no no no no "IF function is confusing, use parentheses"
  "matches" 9 yes no no no yes "Find all 'MATCHES' statements."
  "maxchar" 7 yes no no no no "string constant too long for Tranman"
 |