Replace vera++ with clang-format (#4518)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
+1
-1
@@ -250,7 +250,7 @@ def amalgamate_jerry_core(output_dir):
|
||||
amalgamate(
|
||||
base_dir=JERRY_CORE,
|
||||
input_files=[
|
||||
os.path.join(JERRY_CORE, 'api', 'jerry.c'),
|
||||
os.path.join(JERRY_CORE, 'api', 'jerryscript.c'),
|
||||
# Add the global built-in by default to include some common items
|
||||
# to avoid problems with common built-in headers
|
||||
os.path.join(JERRY_CORE, 'ecma', 'builtin-objects', 'ecma-builtins.c'),
|
||||
|
||||
@@ -23,4 +23,4 @@ ${SUDO} apt-get install -q -y \
|
||||
make cmake \
|
||||
gcc gcc-multilib \
|
||||
doxygen \
|
||||
cppcheck vera++ python pylint python-serial
|
||||
cppcheck clang-format-10 python pylint python-serial
|
||||
|
||||
@@ -18,7 +18,7 @@ brew update
|
||||
|
||||
PKGS="
|
||||
cmake
|
||||
cppcheck vera++
|
||||
cppcheck clang-format-10
|
||||
"
|
||||
|
||||
for pkg in $PKGS
|
||||
|
||||
Executable
+137
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import multiprocessing
|
||||
import subprocess
|
||||
from os import path
|
||||
from glob import glob
|
||||
import sys
|
||||
import re
|
||||
|
||||
from settings import PROJECT_DIR
|
||||
|
||||
RE_CLANG_FORMAT_VERSION = re.compile(
|
||||
r".*clang-format version (?P<version>\d{2})\.")
|
||||
RE_DIRECTIVE_COMMENT = re.compile(r"^#\s*(else|endif)$", re.MULTILINE)
|
||||
RE_FUNCTION_NAME_COMMENT = re.compile(
|
||||
r"^\}(?!(?:\s\/\*\s\w+\s\*\/$|\s?\w*;))", re.MULTILINE)
|
||||
|
||||
CLANG_FORMAT_MIN_VERSION = 10
|
||||
|
||||
FOLDERS = ["jerry-core",
|
||||
"jerry-ext",
|
||||
"jerry-port",
|
||||
"jerry-math",
|
||||
"jerry-main",
|
||||
"tests/unit-core",
|
||||
"tests/unit-ext",
|
||||
"tests/unit-math"]
|
||||
|
||||
|
||||
def get_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--fix', action='store_true', dest='fix',
|
||||
help='fix source code stlye')
|
||||
parser.add_argument('--clang-format', dest='clang_format', default='clang-format-%d' % CLANG_FORMAT_MIN_VERSION,
|
||||
help='path to clang-format executable')
|
||||
|
||||
script_args = parser.parse_args()
|
||||
return script_args
|
||||
|
||||
|
||||
def check_clang_format(args, source_file_name):
|
||||
cmd = [args.clang_format]
|
||||
|
||||
if args.fix:
|
||||
cmd.append('-i')
|
||||
else:
|
||||
cmd.extend(['--dry-run', '--Werror'])
|
||||
|
||||
cmd.append(source_file_name)
|
||||
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
_, error = proc.communicate()
|
||||
|
||||
if proc.returncode == 0:
|
||||
return 0
|
||||
|
||||
print(error.decode('utf8'))
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
def check_comments(regexps, source_file_name):
|
||||
failed = 0
|
||||
|
||||
with open(source_file_name, encoding='utf-8') as source_file:
|
||||
data = source_file.read()
|
||||
|
||||
for regexp in regexps:
|
||||
for match in re.finditer(regexp, data):
|
||||
failed += 1
|
||||
print("Invalid/Missing comment in %s:%d" %
|
||||
(source_file_name, data.count('\n', 0, match.start()) + 1))
|
||||
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
def run_pass(pool, process, process_args):
|
||||
return sum(pool.starmap(process, process_args))
|
||||
|
||||
|
||||
def check_clang_format_version(args):
|
||||
try:
|
||||
out = subprocess.check_output([args.clang_format, '--version'])
|
||||
match = RE_CLANG_FORMAT_VERSION.match(out.decode('utf8'))
|
||||
|
||||
if match and int(match.group('version')) >= CLANG_FORMAT_MIN_VERSION:
|
||||
return 0
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
def main(args):
|
||||
if check_clang_format_version(args) != 0:
|
||||
print("clang-format >= %d is not installed." %
|
||||
CLANG_FORMAT_MIN_VERSION)
|
||||
return 1
|
||||
|
||||
pool = multiprocessing.Pool()
|
||||
failed = 0
|
||||
|
||||
for folder in FOLDERS:
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
files = sum(([glob(path.join(PROJECT_DIR, folder, "**/*.%s" % e), recursive=True)
|
||||
for e in ['c', 'h']]), [])
|
||||
|
||||
failed += run_pass(pool, check_clang_format,
|
||||
[(args, sourece_file) for sourece_file in files])
|
||||
failed += run_pass(pool, check_comments,
|
||||
[([RE_DIRECTIVE_COMMENT, RE_FUNCTION_NAME_COMMENT], sourece_file) for sourece_file in files])
|
||||
|
||||
pool.close()
|
||||
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(get_arguments()))
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
JERRY_CORE_FILES=`find ./jerry-core -name "*.c" -or -name "*.h"`
|
||||
JERRY_EXT_FILES=`find ./jerry-ext -name "*.c" -or -name "*.h"`
|
||||
JERRY_PORT_FILES=`find ./jerry-port -name "*.c" -or -name "*.h"`
|
||||
JERRY_MATH_FILES=`find ./jerry-math -name "*.c" -or -name "*.h"`
|
||||
JERRY_MAIN_FILES=`find ./jerry-main -name "*.c" -or -name "*.h"`
|
||||
UNIT_TEST_FILES=`find ./tests/unit-* -name "*.c" -or -name "*.h"`
|
||||
|
||||
if [ -n "$1" ]
|
||||
then
|
||||
MANUAL_CHECK_FILES=`find $1 -name "*.c" -or -name "*.h"`
|
||||
fi
|
||||
|
||||
vera++ -r tools/vera++ -p jerry \
|
||||
-e --no-duplicate \
|
||||
$MANUAL_CHECK_FILES $JERRY_CORE_FILES $JERRY_EXT_FILES $JERRY_PORT_FILES $JERRY_MATH_FILES $JERRY_MAIN_FILES $UNIT_TEST_FILES
|
||||
@@ -23,17 +23,17 @@ except ImportError:
|
||||
|
||||
import argparse
|
||||
import fileinput
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from settings import PROJECT_DIR
|
||||
from settings import FORMAT_SCRIPT, PROJECT_DIR
|
||||
|
||||
|
||||
MAGIC_STRINGS_INI = os.path.join(PROJECT_DIR, 'jerry-core', 'lit', 'lit-magic-strings.ini')
|
||||
MAGIC_STRINGS_INC_H = os.path.join(PROJECT_DIR, 'jerry-core', 'lit', 'lit-magic-strings.inc.h')
|
||||
|
||||
|
||||
def debug_dump(obj):
|
||||
def deepcopy(obj):
|
||||
if isinstance(obj, (list, tuple)):
|
||||
@@ -172,7 +172,7 @@ def calculate_magic_string_guards(defs, uses, debug=False):
|
||||
# guard1 = A and B and C and D and E and F
|
||||
# guard2 = A and B and C
|
||||
# then guard1 or guard2 == guard2.
|
||||
guards = [set(guard_tuple) for guard_tuple in uses[str_ref].keys()]
|
||||
guards = [set(guard_tuple) for guard_tuple in sorted(uses[str_ref].keys())]
|
||||
for i, guard_i in enumerate(guards):
|
||||
if guard_i is None:
|
||||
continue
|
||||
@@ -230,7 +230,7 @@ def generate_magic_string_defs(gen_file, defs):
|
||||
for str_ref, str_value, guards in defs:
|
||||
if last_guards != guards:
|
||||
if () not in last_guards:
|
||||
print('#endif', file=gen_file)
|
||||
print('#endif /* {guards} */'.format(guards=guards_to_str(last_guards)), file=gen_file)
|
||||
if () not in guards:
|
||||
print('#if {guards}'.format(guards=guards_to_str(guards)), file=gen_file)
|
||||
|
||||
@@ -240,7 +240,7 @@ def generate_magic_string_defs(gen_file, defs):
|
||||
last_guards = guards
|
||||
|
||||
if () not in last_guards:
|
||||
print('#endif', file=gen_file)
|
||||
print('#endif /* {guards} */'.format(guards=guards_to_str(last_guards)), file=gen_file)
|
||||
|
||||
|
||||
def generate_first_magic_strings(gen_file, defs):
|
||||
@@ -258,7 +258,7 @@ def generate_first_magic_strings(gen_file, defs):
|
||||
continue
|
||||
print('#elif {guards}'.format(guards=guards_to_str(guards)), file=gen_file)
|
||||
elif () in guards and () not in last_guards:
|
||||
print('#else', file=gen_file)
|
||||
print('#else /* !({guards}) */'.format(guards=guards_to_str(last_guards)), file=gen_file)
|
||||
|
||||
print('LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE ({size}, {str_ref})'
|
||||
.format(size=size, str_ref=str_ref), file=gen_file)
|
||||
@@ -269,8 +269,7 @@ def generate_first_magic_strings(gen_file, defs):
|
||||
last_guards = guards
|
||||
|
||||
if () not in last_guards:
|
||||
print('#endif', file=gen_file)
|
||||
|
||||
print('#endif /* {guards} */'.format(guards=guards_to_str(last_guards)), file=gen_file)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='lit-magic-strings.inc.h generator')
|
||||
@@ -287,6 +286,7 @@ def main():
|
||||
generate_magic_string_defs(gen_file, extended_defs)
|
||||
generate_first_magic_strings(gen_file, extended_defs)
|
||||
|
||||
subprocess.call([FORMAT_SCRIPT, '--fix'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
+3
-3
@@ -188,8 +188,8 @@ def get_arguments():
|
||||
help='Run doxygen')
|
||||
parser.add_argument('--check-pylint', action='store_true',
|
||||
help='Run pylint')
|
||||
parser.add_argument('--check-vera', action='store_true',
|
||||
help='Run vera check')
|
||||
parser.add_argument('--check-format', action='store_true',
|
||||
help='Run format check')
|
||||
parser.add_argument('--check-license', action='store_true',
|
||||
help='Run license check')
|
||||
parser.add_argument('--check-magic-strings', action='store_true',
|
||||
@@ -504,7 +504,7 @@ def main(options):
|
||||
Check(options.check_cppcheck, run_check, [settings.CPPCHECK_SCRIPT]),
|
||||
Check(options.check_doxygen, run_check, [settings.DOXYGEN_SCRIPT]),
|
||||
Check(options.check_pylint, run_check, [settings.PYLINT_SCRIPT]),
|
||||
Check(options.check_vera, run_check, [settings.VERA_SCRIPT]),
|
||||
Check(options.check_format, run_check, [settings.FORMAT_SCRIPT]),
|
||||
Check(options.check_license, run_check, [settings.LICENSE_SCRIPT]),
|
||||
Check(options.check_magic_strings, run_check, [settings.MAGIC_STRINGS_SCRIPT]),
|
||||
Check(options.jerry_debugger, run_jerry_debugger_tests, options),
|
||||
|
||||
+1
-1
@@ -33,5 +33,5 @@ PYLINT_SCRIPT = path.join(TOOLS_DIR, 'check-pylint.sh')
|
||||
SIGNED_OFF_SCRIPT = path.join(TOOLS_DIR, 'check-signed-off.sh')
|
||||
TEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-test-suite.py')
|
||||
TEST262_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-test-suite-test262.py')
|
||||
VERA_SCRIPT = path.join(TOOLS_DIR, 'check-vera.sh')
|
||||
FORMAT_SCRIPT = path.join(TOOLS_DIR, 'check-format.py')
|
||||
UNITTEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-unittests.py')
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
set rules {
|
||||
jerry_always_curly
|
||||
jerry_braces_on_separate_line
|
||||
jerry_braces_same_line_or_column
|
||||
jerry_comment_function_end
|
||||
jerry_funcname_space_parentheses
|
||||
jerry_identifier_no_space_bracket
|
||||
jerry_indentation
|
||||
jerry_max_line_length
|
||||
jerry_no_space_after_opening_parentheses
|
||||
jerry_no_space_before_closing_parentheses
|
||||
jerry_no_tabs
|
||||
jerry_no_trailing_spaces
|
||||
jerry_no_leading_or_trailing_empty_line
|
||||
jerry_no_consecutive_empty_lines
|
||||
jerry_pointer_declarator_space
|
||||
jerry_switch_case
|
||||
jerry_typecast_space_parentheses
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
foreach file_name [getSourceFileNames] {
|
||||
set state "control"
|
||||
set do_marks {}
|
||||
set prev_tok_type ""
|
||||
set prev_ctrl ""
|
||||
set expect_while false
|
||||
set expect_open_brace false
|
||||
set paren_count 0
|
||||
|
||||
foreach token [getTokens $file_name 1 0 -1 -1 {if do while else for leftparen rightparen semicolon leftbrace rightbrace}] {
|
||||
set tok_val [lindex $token 0]
|
||||
set line_num [lindex $token 1]
|
||||
set col_num [lindex $token 2]
|
||||
set tok_type [lindex $token 3]
|
||||
|
||||
if {$state == "expression"} {
|
||||
# puts "expression $paren_count $tok_type ($line_num , $col_num)"
|
||||
if {$tok_type == "leftparen"} {
|
||||
incr paren_count
|
||||
} elseif {$tok_type == "rightparen"} {
|
||||
incr paren_count -1
|
||||
if {$paren_count == 0} {
|
||||
set state "control"
|
||||
set expect_open_brace true
|
||||
} elseif {$paren_count < 0 } {
|
||||
report $file_name $line_num "unexpected right parentheses"
|
||||
}
|
||||
} elseif {$tok_type != "semicolon"} {
|
||||
report $file_name $line_num "unexpected token: $tok_type"
|
||||
}
|
||||
} else {
|
||||
if {$expect_open_brace == true} {
|
||||
if {$tok_type == "if" && $prev_tok_type == "else"} {
|
||||
# empty
|
||||
} elseif {$tok_type != "leftbrace"} {
|
||||
report $file_name [lindex $prev_ctrl 1] "brace after \'[lindex $prev_ctrl 3]\' required"
|
||||
}
|
||||
set expect_open_brace false
|
||||
}
|
||||
|
||||
if {$tok_type == "while" && ($expect_while == true || [lindex $prev_ctrl 3] == "do")} {
|
||||
set expect_while false
|
||||
set prev_ctrl ""
|
||||
} elseif {$tok_type in {if for while}} {
|
||||
set state "expression"
|
||||
set prev_ctrl $token
|
||||
} elseif {$tok_type in {do else}} {
|
||||
set expect_open_brace true
|
||||
set prev_ctrl $token
|
||||
} elseif {$tok_type == "leftbrace"} {
|
||||
if {[lindex $prev_ctrl 3] == "do"} {
|
||||
lappend do_marks 1
|
||||
} else {
|
||||
lappend do_marks 0
|
||||
}
|
||||
set prev_ctrl ""
|
||||
} elseif {$tok_type == "rightbrace"} {
|
||||
if {[llength $do_marks] > 0} {
|
||||
if {[lindex $do_marks end] == 1} {
|
||||
set expect_while true
|
||||
}
|
||||
set do_marks [lreplace $do_marks end end]
|
||||
} else {
|
||||
report $file_name $line_num "unmatched brace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set prev_tok_type $tok_type
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
foreach file_name [getSourceFileNames] {
|
||||
set state "normal"
|
||||
set lines {}
|
||||
set cols {}
|
||||
set struct_marks {}
|
||||
set expect_struct_name false
|
||||
set prev_tok ""
|
||||
set def_start false
|
||||
set expect_newline false
|
||||
set check_newline true
|
||||
|
||||
foreach token [getTokens $file_name 1 0 -1 -1 {}] {
|
||||
set tok_val [lindex $token 0]
|
||||
set line_num [lindex $token 1]
|
||||
set col_num [lindex $token 2]
|
||||
set tok_type [lindex $token 3]
|
||||
|
||||
if {$state == "macro"} {
|
||||
if {$col_num == 0} {
|
||||
set state "normal"
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if {$tok_type in {space ccomment cppcomment newline}} {
|
||||
continue
|
||||
}
|
||||
|
||||
if {$tok_type == "pp_define"} {
|
||||
set state "macro"
|
||||
set prev_tok ""
|
||||
set def_start false
|
||||
continue
|
||||
}
|
||||
|
||||
if {$expect_struct_name == true} {
|
||||
if {$tok_type == "identifier" && $line_num != [lindex $prev_tok 1]} {
|
||||
report $file_name $line_num "type name should be on the same line with the rightbrace"
|
||||
}
|
||||
set expect_struct_name false
|
||||
}
|
||||
|
||||
# check that rightbrace and typename (in struct, union and enum definitons) are on the same line
|
||||
if {$tok_type in {struct enum union}} {
|
||||
set def_start true
|
||||
} elseif {$tok_type == "semicolon"} {
|
||||
set def_start false
|
||||
} elseif {$tok_type == "leftbrace"} {
|
||||
lappend cols $col_num
|
||||
lappend lines $line_num
|
||||
if {$def_start == true} {
|
||||
lappend struct_marks 1
|
||||
set def_start false
|
||||
} elseif {[lindex $prev_tok 3] == "assign"} {
|
||||
lappend struct_marks 2
|
||||
set check_newline false
|
||||
} else {
|
||||
lappend struct_marks 0
|
||||
}
|
||||
} elseif {$tok_type == "rightbrace"} {
|
||||
if {[llength $lines] > 0} {
|
||||
if {[lindex $struct_marks end] == 1} {
|
||||
set expect_struct_name true
|
||||
set check_newline false
|
||||
} elseif {[lindex $struct_marks end] == 2} {
|
||||
set check_newline false
|
||||
}
|
||||
set lines [lreplace $lines end end]
|
||||
set cols [lreplace $cols end end]
|
||||
set struct_marks [lreplace $struct_marks end end]
|
||||
} else {
|
||||
report $file_name $line_num "unmatched brace"
|
||||
}
|
||||
}
|
||||
|
||||
# check that braces are on separate lines
|
||||
if {$check_newline == true} {
|
||||
if {$expect_newline == true} {
|
||||
if {$tok_type == "semicolon"} {
|
||||
# empty
|
||||
} elseif {[lindex $prev_tok 1] == $line_num} {
|
||||
report $file_name $line_num "brace should be placed on a separate line"
|
||||
} else {
|
||||
set expect_newline false
|
||||
}
|
||||
} elseif {$tok_type in {leftbrace rightbrace}} {
|
||||
if {[lindex $prev_tok 1] == $line_num} {
|
||||
report $file_name $line_num "brace should be placed on a separate line"
|
||||
}
|
||||
set expect_newline true
|
||||
}
|
||||
} else {
|
||||
set check_newline true
|
||||
}
|
||||
|
||||
set prev_tok $token
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
foreach file_name [getSourceFileNames] {
|
||||
set state "normal"
|
||||
set lines {}
|
||||
set cols {}
|
||||
|
||||
foreach token [getTokens $file_name 1 0 -1 -1 {}] {
|
||||
set tok_val [lindex $token 0]
|
||||
set line_num [lindex $token 1]
|
||||
set col_num [lindex $token 2]
|
||||
set tok_type [lindex $token 3]
|
||||
|
||||
if {$state == "macro"} {
|
||||
if {$col_num == 0} {
|
||||
set state "normal"
|
||||
} else {
|
||||
set prev_tok_line $line_num
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if {$tok_type in {space ccomment cppcomment newline}} {
|
||||
continue
|
||||
}
|
||||
|
||||
if {$tok_type == "pp_define"} {
|
||||
set state "macro"
|
||||
continue
|
||||
}
|
||||
|
||||
if {$tok_type == "leftbrace"} {
|
||||
lappend cols $col_num
|
||||
lappend lines $line_num
|
||||
} elseif {$tok_type == "rightbrace"} {
|
||||
if {[llength $lines] > 0} {
|
||||
if {[lindex $lines end] != $line_num && [lindex $cols end] != $col_num} {
|
||||
report $file_name $line_num "matching braces should be on the same line or column"
|
||||
}
|
||||
set lines [lreplace $lines end end]
|
||||
set cols [lreplace $cols end end]
|
||||
} else {
|
||||
report $file_name $line_num "unmatched brace"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
foreach fileName [getSourceFileNames] {
|
||||
set funcStart 0
|
||||
set funcName ""
|
||||
set lineNumber 1
|
||||
foreach line [getAllLines $fileName] {
|
||||
if {[regexp {^((static |const )*\w+ )*\w+ \(.*[,\)]} $line]} {
|
||||
set type {}
|
||||
set modifier {}
|
||||
if {$funcStart == 0} {
|
||||
regexp {^((static |const )*\w+ )*(\w+) \(} $line matched type modifier funcName
|
||||
}
|
||||
}
|
||||
|
||||
if {[regexp {^\{$} $line]} {
|
||||
set funcStart 1
|
||||
}
|
||||
|
||||
if {$funcStart == 1} {
|
||||
if {[regexp {^\}$} $line] && [string length $funcName] != 0} {
|
||||
report $fileName $lineNumber "missing comment at the end of function: /* $funcName */"
|
||||
set funcStart 0
|
||||
} elseif {[regexp {^\} /\*\s*\w+\s*\*/$} $line] && [string length $funcName] != 0} {
|
||||
set comment {}
|
||||
regexp {^\} /\*\s*(\w+)\s*\*/$} $line -> comment
|
||||
if {$comment != $funcName} {
|
||||
report $fileName $lineNumber "comment missmatch. (Current: $comment, Expected: $funcName) "
|
||||
}
|
||||
set funcStart 0
|
||||
} elseif {[regexp {^\}.*;?$} $line]} {
|
||||
set funcStart 0
|
||||
}
|
||||
}
|
||||
|
||||
incr lineNumber
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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]
|
||||
|
||||
if {[regexp {^\s*#[ ]*define} $line]} {
|
||||
return
|
||||
}
|
||||
|
||||
set line [string range $line $col_start $col_end]
|
||||
|
||||
if {[regexp {([[:alnum:]][\s]{2,}\()|([[:alnum:]]\()} $line]} {
|
||||
report $file $line_num "there should be exactly one space before left 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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 {[[:alnum:]_][\s]+\[} $line]} {
|
||||
report $file $line_num "there should be no spaces between identifier and left bracket"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Indentation
|
||||
|
||||
foreach fileName [getSourceFileNames] {
|
||||
set indent 0
|
||||
set lastCheckedLineNumber -1
|
||||
set is_in_comment "no"
|
||||
set is_in_pp_define "no"
|
||||
set is_in_class "no"
|
||||
set is_in_template "no"
|
||||
set parentheses_level 0
|
||||
set template_brackets_level 0
|
||||
|
||||
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
|
||||
set type [lindex $token 3]
|
||||
set lineNumber [lindex $token 1]
|
||||
|
||||
if {$is_in_comment == "yes"} {
|
||||
set is_in_comment "no"
|
||||
}
|
||||
|
||||
if {$type == "newline"} {
|
||||
set is_in_pp_define "no"
|
||||
} elseif {$type == "class"} {
|
||||
set is_in_class "yes"
|
||||
} elseif {$type == "template"} {
|
||||
set is_in_template "yes"
|
||||
} elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} {
|
||||
set is_in_class "no"
|
||||
} elseif {$type == "ccomment"} {
|
||||
set is_in_comment "yes"
|
||||
} elseif {[string first "pp_" $type] == 0} {
|
||||
if {$type == "pp_define"} {
|
||||
set is_in_pp_define "yes"
|
||||
}
|
||||
|
||||
set lastCheckedLineNumber $lineNumber
|
||||
} elseif {$type == "space"} {
|
||||
} elseif {$type != "eof"} {
|
||||
if {$type == "rightbrace" && $indent > 0} {
|
||||
incr indent -2
|
||||
}
|
||||
|
||||
if {$is_in_pp_define == "no" && $is_in_comment == "no" && $parentheses_level == 0 &&
|
||||
$is_in_template == "no"} {
|
||||
set line [getLine $fileName $lineNumber]
|
||||
|
||||
if {$lineNumber != $lastCheckedLineNumber} {
|
||||
if {[regexp {^[[:blank:]]*} $line match]} {
|
||||
set real_indent [string length $match]
|
||||
if {$indent != $real_indent} {
|
||||
if {[regexp {^[[:blank:]]*(private:|public:|protected:)} $line]} {
|
||||
if {$indent != $real_indent + 2} {
|
||||
set exp_indent [expr {$indent - 2}]
|
||||
report $fileName $lineNumber "Indentation: $real_indent -> $exp_indent. Line: '$line'"
|
||||
}
|
||||
} elseif {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} {
|
||||
report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if {$lineNumber == $lastCheckedLineNumber} {
|
||||
if {$type == "leftbrace"} {
|
||||
if {![regexp {^[[:blank:]]*\{[[:blank:]]*$} $line]
|
||||
&& ![regexp {[^\{=]=[^\{=]\{.*\},?} $line]} {
|
||||
report $fileName $lineNumber "Left brace is not the only non-space character in the line: '$line'"
|
||||
}
|
||||
}
|
||||
if {$type == "rightbrace"} {
|
||||
if {![regexp {^.* = .*\{.*\}[,;]?$} $line]
|
||||
&& ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} {
|
||||
report $fileName $lineNumber "Right brace is not first non-space character in the line: '$line'"
|
||||
}
|
||||
}
|
||||
}
|
||||
if {$type == "rightbrace"} {
|
||||
if {![regexp {^[[:blank:]]*\};?((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line]
|
||||
&& ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} {
|
||||
report $fileName $lineNumber "Right brace is not the only non-space character in the line and \
|
||||
is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if {$type == "leftbrace"} {
|
||||
if {![regexp {^extern "C"} [getLine $fileName [expr {$lineNumber - 1}]]]} {
|
||||
incr indent 2
|
||||
}
|
||||
} elseif {$type == "leftparen"} {
|
||||
incr parentheses_level 1
|
||||
} elseif {$type == "rightparen"} {
|
||||
incr parentheses_level -1
|
||||
}
|
||||
|
||||
if {$is_in_template == "yes"} {
|
||||
if {$type == "less"} {
|
||||
incr template_brackets_level
|
||||
} elseif {$type == "greater"} {
|
||||
incr template_brackets_level -1
|
||||
if {$template_brackets_level == 0} {
|
||||
set is_in_template "no"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set lastCheckedLineNumber $lineNumber
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set maxLen 120
|
||||
|
||||
foreach f [getSourceFileNames] {
|
||||
set lineNumber 1
|
||||
foreach line [getAllLines $f] {
|
||||
if {[string length $line] > $maxLen} {
|
||||
report $f $lineNumber "line is longer than ${maxLen} characters"
|
||||
}
|
||||
incr lineNumber
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set maxEmptyLines 1
|
||||
|
||||
foreach f [getSourceFileNames] {
|
||||
set lineNumber 1
|
||||
set emptyCount 0
|
||||
set reported false
|
||||
foreach line [getAllLines $f] {
|
||||
if {[string trim $line] == ""} {
|
||||
incr emptyCount
|
||||
if {$emptyCount > $maxEmptyLines && $reported == "false"} {
|
||||
report $f $lineNumber "too many consecutive empty lines"
|
||||
set reported true
|
||||
}
|
||||
} else {
|
||||
set emptyCount 0
|
||||
set reported false
|
||||
}
|
||||
incr lineNumber
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
foreach f [getSourceFileNames] {
|
||||
set lineCount [getLineCount $f]
|
||||
if {$lineCount > 0} {
|
||||
set firstLine [getLine $f 1]
|
||||
if {[string trim $firstLine] == ""} {
|
||||
report $f 1 "leading empty line(s)"
|
||||
}
|
||||
|
||||
set lastLine [getLine $f $lineCount]
|
||||
if {[string trim $lastLine] == ""} {
|
||||
report $f $lineCount "trailing empty line(s)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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 {\(+[[:blank:]]} $line]} {
|
||||
report $file $line_num "there should be no blank characters after opening 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# 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 {\t} $line]} {
|
||||
report $f $lineNumber "tabs are not allowed"
|
||||
}
|
||||
incr lineNumber
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# 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 {[[:blank:]]$} $line]} {
|
||||
report $f $lineNumber "trailing space is not allowed"
|
||||
}
|
||||
incr lineNumber
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# switch-case
|
||||
|
||||
foreach fileName [getSourceFileNames] {
|
||||
set is_in_comment "no"
|
||||
set is_in_pp_define "no"
|
||||
|
||||
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
|
||||
set type [lindex $token 3]
|
||||
set lineNumber [lindex $token 1]
|
||||
|
||||
if {$is_in_comment == "yes"} {
|
||||
set is_in_comment "no"
|
||||
}
|
||||
|
||||
if {$type == "newline"} {
|
||||
set is_in_pp_define "no"
|
||||
} elseif {$type == "ccomment"} {
|
||||
set is_in_comment "yes"
|
||||
} elseif {[string first "pp_" $type] == 0} {
|
||||
if {$type == "pp_define"} {
|
||||
set is_in_pp_define "yes"
|
||||
}
|
||||
} elseif {$type == "space"} {
|
||||
} elseif {$type != "eof"} {
|
||||
if {$is_in_pp_define == "no" && $type == "switch"} {
|
||||
set next_token_start [lindex $token 2]
|
||||
incr next_token_start 1
|
||||
set line_num 0
|
||||
set state "switch"
|
||||
set case_block "no"
|
||||
set seen_braces 0
|
||||
foreach next_token [getTokens $fileName $lineNumber $next_token_start -1 -1 {}] {
|
||||
set next_token_type [lindex $next_token 3]
|
||||
set next_token_value [lindex $next_token 0]
|
||||
if {$state == "switch"} {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
set state "first-case"
|
||||
continue
|
||||
} else {
|
||||
# TODO: check switch
|
||||
continue
|
||||
}
|
||||
} elseif {$state == "first-case"} {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "case"} {
|
||||
set state "case"
|
||||
continue
|
||||
} elseif {$next_token_type == "default"} {
|
||||
set state "default"
|
||||
continue
|
||||
} else {
|
||||
# Macros magic: give up
|
||||
break
|
||||
}
|
||||
} elseif {$state == "case"} {
|
||||
if {$next_token_type == "space"} {
|
||||
set state "space-after-case"
|
||||
continue
|
||||
} else {
|
||||
report $fileName [lindex $next_token 1] "There should be single space character after 'case' keyword (state $state)"
|
||||
}
|
||||
} elseif {$state == "space-after-case"} {
|
||||
if {$next_token_type != "identifier" && $next_token_type != "intlit" && $next_token_type != "charlit" && $next_token_type != "sizeof"} {
|
||||
report $fileName [lindex $next_token 1] "There should be single space character after 'case' keyword (state $state, next_token_type $next_token_type)"
|
||||
} else {
|
||||
set state "case-label"
|
||||
continue
|
||||
}
|
||||
} elseif {$state == "case-label" || $state == "default"} {
|
||||
set case_block "no"
|
||||
if {$next_token_type != "colon"} {
|
||||
continue
|
||||
} else {
|
||||
set state "colon"
|
||||
continue
|
||||
}
|
||||
} elseif {$state == "after-colon-preprocessor"} {
|
||||
if {$next_token_type == "newline"} {
|
||||
set state "colon"
|
||||
}
|
||||
} elseif {$state == "colon"} {
|
||||
if {$next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "ccomment"} {
|
||||
if {[string match "*FALL*" $next_token_value]} {
|
||||
set state "fallthru"
|
||||
set line_num [lindex $next_token 1]
|
||||
continue
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} elseif {$next_token_type == "case"} {
|
||||
set state "case"
|
||||
continue
|
||||
} elseif {$next_token_type == "default"} {
|
||||
set state "default"
|
||||
continue
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
set case_block "yes"
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
} elseif {$next_token_type == "identifier"} {
|
||||
if {[string compare "JERRY_UNREACHABLE" $next_token_value] == 0
|
||||
|| [string first "JERRY_UNIMPLEMENTED" $next_token_value] == 0} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
} else {
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
}
|
||||
} elseif {$next_token_type == "break"
|
||||
|| $next_token_type == "continue"
|
||||
|| $next_token_type == "return"} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
} elseif {[string first "pp_" $next_token_type] == 0} {
|
||||
set state "after-colon-preprocessor"
|
||||
} else {
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
}
|
||||
} elseif {$state == "wait-for-semicolon"} {
|
||||
if {$next_token_type == "semicolon"} {
|
||||
set state "break"
|
||||
}
|
||||
continue
|
||||
} elseif {$state == "wait-for-break"} {
|
||||
if {$next_token_type == "case" || $next_token_type == "default"} {
|
||||
report $fileName [lindex $next_token 1] "Missing break, continue or FALLTHRU comment before case (state $state)"
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
set state "inside-braces"
|
||||
incr seen_braces 1
|
||||
continue
|
||||
} elseif {$next_token_type == "rightbrace"} {
|
||||
if {$case_block == "yes"} {
|
||||
set state "case-blocks-end"
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} elseif {[string compare "JERRY_UNREACHABLE" $next_token_value] == 0
|
||||
|| [string first "JERRY_UNIMPLEMENTED" $next_token_value] == 0} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
} elseif {$next_token_type == "ccomment" && [string match "*FALL*" $next_token_value]} {
|
||||
set state "fallthru"
|
||||
set line_num [lindex $next_token 1]
|
||||
continue
|
||||
} elseif {$next_token_type == "break"
|
||||
|| $next_token_type == "continue"
|
||||
|| $next_token_type == "return"
|
||||
|| $next_token_type == "goto"} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
}
|
||||
continue
|
||||
} elseif {$state == "break" || $state == "fallthru"} {
|
||||
if {$case_block == "no"} {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "case"} {
|
||||
set state "case"
|
||||
continue
|
||||
} elseif {$next_token_type == "default"} {
|
||||
set state "default"
|
||||
continue
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
set state "inside-braces"
|
||||
incr seen_braces 1
|
||||
continue
|
||||
} elseif {$next_token_type == "rightbrace"} {
|
||||
lappend switch_ends [lindex $next_token 1]
|
||||
break
|
||||
} elseif {$next_token_type == "break"
|
||||
|| $next_token_type == "continue"
|
||||
|| $next_token_type == "return"} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
} else {
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "case"} {
|
||||
set state "case"
|
||||
continue
|
||||
} elseif {$next_token_type == "default"} {
|
||||
set state "default"
|
||||
continue
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
set state "inside-braces"
|
||||
incr seen_braces 1
|
||||
continue
|
||||
} elseif {$next_token_type == "rightbrace"} {
|
||||
set state "after-rightbrace"
|
||||
continue
|
||||
} elseif {$next_token_type == "break"
|
||||
|| $next_token_type == "continue"
|
||||
|| $next_token_type == "return"} {
|
||||
set state "wait-for-semicolon"
|
||||
continue
|
||||
} else {
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
}
|
||||
}
|
||||
} elseif {$state == "inside-braces"} {
|
||||
if {$next_token_type == "rightbrace"} {
|
||||
incr seen_braces -1
|
||||
if {$seen_braces == 0} {
|
||||
set state "wait-for-break"
|
||||
continue
|
||||
}
|
||||
} elseif {$next_token_type == "leftbrace"} {
|
||||
incr seen_braces 1
|
||||
}
|
||||
continue
|
||||
} elseif {$state == "after-rightbrace-preprocessor"} {
|
||||
if {$next_token_type == "newline"} {
|
||||
set state "after-rightbrace"
|
||||
}
|
||||
} elseif {$state == "after-rightbrace"} {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "case"} {
|
||||
set state "case"
|
||||
continue
|
||||
} elseif {$next_token_type == "default"} {
|
||||
set state "default"
|
||||
continue
|
||||
} elseif {$next_token_type == "rightbrace"} {
|
||||
lappend switch_ends [lindex $next_token 1]
|
||||
break
|
||||
} elseif {[string first "pp_" $next_token_type] == 0} {
|
||||
set state "after-rightbrace-preprocessor"
|
||||
} else {
|
||||
report $fileName [lindex $next_token 1] "There should be 'case' or 'default' (state $state)"
|
||||
}
|
||||
} elseif {$state == "case-blocks-end-preprocessor"} {
|
||||
if {$next_token_type == "newline"} {
|
||||
set state "case-blocks-end"
|
||||
}
|
||||
} elseif {$state == "case-blocks-end"} {
|
||||
if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} {
|
||||
continue
|
||||
} elseif {$next_token_type == "rightbrace"} {
|
||||
lappend switch_ends [lindex $next_token 1]
|
||||
break
|
||||
} elseif {[string first "pp_" $next_token_type] == 0} {
|
||||
set state "case-blocks-end-preprocessor"
|
||||
} else {
|
||||
report $fileName [lindex $next_token 1] "Missing break, continue or FALLTHRU comment before rightbrace (state $state)"
|
||||
}
|
||||
} else {
|
||||
report $fileName [lindex $next_token 1] "Unknown state: $state"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/tclsh
|
||||
|
||||
# Copyright JS Foundation and other contributors, http://js.foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
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\(&~=]} $line]} {
|
||||
report $file $line_num "there should be exactly one space after right 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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user