• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/tclsh
2
3# Copyright JS Foundation and other contributors, http://js.foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17proc check_part_of_the_file {file line_num col_start col_end} {
18    if {$col_start == $col_end} {
19        return
20    }
21    set line [getLine $file $line_num]
22
23    if {[regexp {^\s*#[ ]*define} $line]} {
24        return
25    }
26
27    set line [string range $line $col_start $col_end]
28
29    if {[regexp {([[:alnum:]][\s]{2,}\()|([[:alnum:]]\()} $line]} {
30        report $file $line_num "there should be exactly one space before left parentheses"
31    }
32}
33
34foreach fileName [getSourceFileNames] {
35    set checkLine 1
36    set checkColStart 0
37    set seenOmitToken false
38    foreach token [getTokens $fileName 1 0 -1 -1 {}] {
39        set lineNumber [lindex $token 1]
40        set colNumber [lindex $token 2]
41        set tokenType [lindex $token 3]
42
43        if {$checkLine != $lineNumber} {
44            if {!$seenOmitToken} {
45                check_part_of_the_file $fileName $checkLine $checkColStart end
46            }
47            set checkColStart $colNumber
48            set checkLine $lineNumber
49        } elseif {$seenOmitToken} {
50            set checkColStart $colNumber
51        }
52
53        if {$tokenType in {ccomment cppcomment stringlit}} {
54            check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
55            set seenOmitToken true
56        } else {
57            set seenOmitToken false
58        }
59    }
60}
61