|
| 1 | +#!/usr/bin/tclsh |
| 2 | + |
| 3 | +# Copyright 2014-2015 Samsung Electronics Co., Ltd. |
| 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 | + |
| 17 | +# Indentation |
| 18 | + |
| 19 | +foreach fileName [getSourceFileNames] { |
| 20 | + set indent 0 |
| 21 | + set lastCheckedLineNumber -1 |
| 22 | + set is_in_comment "no" |
| 23 | + set is_in_pp_define "no" |
| 24 | + set is_in_class "no" |
| 25 | + set parentheses_level 0 |
| 26 | + |
| 27 | + foreach token [getTokens $fileName 1 0 -1 -1 {}] { |
| 28 | + set type [lindex $token 3] |
| 29 | + set lineNumber [lindex $token 1] |
| 30 | + |
| 31 | + if {$is_in_comment == "yes"} { |
| 32 | + set is_in_comment "no" |
| 33 | + } |
| 34 | + |
| 35 | + if {$type == "newline"} { |
| 36 | + set is_in_pp_define "no" |
| 37 | + } elseif {$type == "class"} { |
| 38 | + set is_in_class "yes" |
| 39 | + } elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} { |
| 40 | + set is_in_class "no" |
| 41 | + } elseif {$type == "ccomment"} { |
| 42 | + set is_in_comment "yes" |
| 43 | + } elseif {[string first "pp_" $type] == 0} { |
| 44 | + if {$type == "pp_define"} { |
| 45 | + set is_in_pp_define "yes" |
| 46 | + } |
| 47 | + |
| 48 | + set lastCheckedLineNumber $lineNumber |
| 49 | + } elseif {$type == "space"} { |
| 50 | + } elseif {$type != "eof"} { |
| 51 | + if {$type == "rightbrace"} { |
| 52 | + incr indent -2 |
| 53 | + } |
| 54 | + |
| 55 | + if {$is_in_pp_define == "no" && $is_in_comment == "no" && $is_in_class == "no" && $parentheses_level == 0} { |
| 56 | + set line [getLine $fileName $lineNumber] |
| 57 | + |
| 58 | + if {$lineNumber != $lastCheckedLineNumber} { |
| 59 | + if {[string length $line] == 0} { |
| 60 | + } |
| 61 | + |
| 62 | + if {[regexp {^[[:blank:]]*} $line match]} { |
| 63 | + set real_indent [string length $match] |
| 64 | + if {$indent != $real_indent} { |
| 65 | + if {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} { |
| 66 | + report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'" |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if {$lineNumber == $lastCheckedLineNumber} { |
| 73 | + if {$type == "leftbrace"} { |
| 74 | + if {![regexp {^[[:blank:]]*\{[[:blank:]]*$} $line] |
| 75 | + && ![regexp {[^\{=]=[^\{=]\{.*\},?} $line]} { |
| 76 | + report $fileName $lineNumber "Left brace is not the only non-space character in the line: '$line'" |
| 77 | + } |
| 78 | + } |
| 79 | + if {$type == "rightbrace"} { |
| 80 | + if {![regexp {^.* = .*\{.*\}[,;]?$} $line] |
| 81 | + && ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} { |
| 82 | + report $fileName $lineNumber "Right brace is not first non-space character in the line: '$line'" |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + if {$type == "rightbrace"} { |
| 87 | + if {![regexp {^[[:blank:]]*\}((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line] |
| 88 | + && ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} { |
| 89 | + report $fileName $lineNumber "Right brace is not the only non-space character in the line and \ |
| 90 | + is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'" |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + if {$type == "leftbrace"} { |
| 96 | + incr indent 2 |
| 97 | + } elseif {$type == "leftparen"} { |
| 98 | + incr parentheses_level 1 |
| 99 | + } elseif {$type == "rightparen"} { |
| 100 | + incr parentheses_level -1 |
| 101 | + } |
| 102 | + |
| 103 | + set lastCheckedLineNumber $lineNumber |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments