3 ###########################################################################
5 # Copyright 2013 BMW Car IT GmbH
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 ###########################################################################
21 import sys, re, string
22 from common_modules.common import *
24 def check_single_statement_on_line(filename, file_contents, clean_file_contents, file_lines, clean_file_lines):
26 Checks if there are several statements on the same line
29 open_parantheses_count = 0
31 for i in range(len(file_lines)):
32 line = clean_file_lines[i]
34 open_parantheses_count += line.count("(") - line.count(")")
36 #check if there are several semicolons on the line and that is not in the middle of a for statement
37 if line.count(";") > 1 and open_parantheses_count == 0:
38 #check that there is NO right parentheses after semicolon
39 if line.rfind(";") > line.rfind(")"):
40 log_warning(filename, i + 1, "several statements on same line", file_lines[i].strip(" "))
42 if __name__ == "__main__":
43 targets = sys.argv[1:]
44 targets = get_all_files(targets)
48 \t**** No input provided ****
49 \tTakes a list of files/directories as input and performs specific style checking on all files/directories.
51 \tGives warnings if a line contains several statements.
56 if t[-2:] == ".h" or t[-4:] == ".cpp" or t[-2] == ".c":
57 file_contents, clean_file_contents, file_lines, clean_file_lines = read_file(t)
58 check_single_statement_on_line(t, file_contents, clean_file_contents, file_lines, clean_file_lines)