Fix: code-related vera++ rules should not be enforced in comments

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss 2016-03-19 01:05:56 +01:00
parent 57db5ca918
commit 48dca0af35
2 changed files with 80 additions and 17 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,12 +15,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[regexp {[[:graph:]][[:blank:]]+\)} $line]} {
report $f $lineNumber "there should be no blank characters before closing parentheses"
}
incr lineNumber
proc check_part_of_the_file {file line_num col_start col_end} {
if {$col_start == $col_end} {
return
}
set line [getLine $file $line_num]
set line [string range $line $col_start $col_end]
if {[regexp {[[:graph:]][[:blank:]]+\)} $line]} {
report $file $line_num "there should be no blank characters before closing parentheses"
}
}
foreach fileName [getSourceFileNames] {
set checkLine 1
set checkColStart 0
set seenOmitToken false
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set lineNumber [lindex $token 1]
set colNumber [lindex $token 2]
set tokenType [lindex $token 3]
if {$checkLine != $lineNumber} {
if {!$seenOmitToken} {
check_part_of_the_file $fileName $checkLine $checkColStart end
}
set checkColStart $colNumber
set checkLine $lineNumber
} elseif {$seenOmitToken} {
set checkColStart $colNumber
}
if {$tokenType in {ccomment cppcomment stringlit}} {
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
set seenOmitToken true
} else {
set seenOmitToken false
}
}
}

View File

@ -15,14 +15,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[regexp {\w\*\s\w+} $line]
|| [regexp {\w\*\)} $line]
|| [regexp {\w\*$} $line]} {
report $f $lineNumber "there should be a space between the referenced type and the pointer declarator."
}
incr lineNumber
proc check_part_of_the_file {file line_num col_start col_end} {
if {$col_start == $col_end} {
return
}
set line [getLine $file $line_num]
set line [string range $line $col_start $col_end]
if {[regexp {\w\*\s\w+} $line]
|| [regexp {\w\*\)} $line]
|| [regexp {\w\*$} $line]} {
report $file $line_num "there should be a space between the referenced type and the pointer declarator."
}
}
foreach fileName [getSourceFileNames] {
set checkLine 1
set checkColStart 0
set seenOmitToken false
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set lineNumber [lindex $token 1]
set colNumber [lindex $token 2]
set tokenType [lindex $token 3]
if {$checkLine != $lineNumber} {
if {!$seenOmitToken} {
check_part_of_the_file $fileName $checkLine $checkColStart end
}
set checkColStart $colNumber
set checkLine $lineNumber
} elseif {$seenOmitToken} {
set checkColStart $colNumber
}
if {$tokenType in {ccomment cppcomment stringlit}} {
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
set seenOmitToken true
} else {
set seenOmitToken false
}
}
}