Commit b5bf8269 by Jari Komppa Committed by Jari Komppa

Add script to verify proper Memset template use

Since there does not seem to be any elegant way of checking whether a class is the first base class in c++ (given that the 2009 c++ proposal n2965 was rejected), this python script does it by scanning all source files for illegal patterns. The python file was implemented in a way to enable easy addition of further checks, should need arise. Bug: b/152253831 Change-Id: I25701a3302579700ccb6222141843d27f38d9069 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49788 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarJari Komppa <jari@siru.fi>
parent 959f4198
...@@ -84,6 +84,10 @@ function run_check_build_files() { ...@@ -84,6 +84,10 @@ function run_check_build_files() {
go run ${TESTS_DIR}/check_build_files/main.go --root="${ROOT_DIR}" go run ${TESTS_DIR}/check_build_files/main.go --root="${ROOT_DIR}"
} }
function run_scan_sources() {
python3 ${TESTS_DIR}/scan_sources/main.py ${SRC_DIR}
}
# Ensure we are clean to start out with. # Ensure we are clean to start out with.
check "git workspace must be clean" true check "git workspace must be clean" true
...@@ -102,5 +106,8 @@ check gofmt run_gofmt ...@@ -102,5 +106,8 @@ check gofmt run_gofmt
# Check build files. # Check build files.
check "build files don't reference non-existent files" run_check_build_files check "build files don't reference non-existent files" run_check_build_files
# Check source files.
check scan_sources run_scan_sources
echo echo
echo "${green}All check completed successfully.${normal}" echo "${green}All check completed successfully.${normal}"
#!/usr/bin/env python3
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# 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.
#
# Scan all source files for problems that are inconvenient or impossible
# to guard against using static assertions in c++
import glob
import sys
import re
def main(rootdir):
filelist = []
for x in [rootdir +"/**/*.cpp", rootdir + "/**/*.hpp"]:
filelist += glob.glob(x, recursive=True)
# Regex for Memset< template use as base class (must be the first,
# thus, there must not be a ',' before it)
memset_template_check = re.compile(",\s*Memset\s*<")
# Regex for Memset( template use as initializer (must be the first,
# thus, there must not be a ',' before it)
memset_call_check = re.compile(",\s*Memset\s*\(")
retval = 0
tb = 0
for fn in filelist:
with open(fn, encoding="utf-8") as f:
contents = f.read();
if memset_template_check.search(contents) != None:
print("ERROR: " + fn + " has illegal memset<> template use: must always be the first base class.")
retval = 1
if memset_call_check.search(contents) != None:
print("ERROR: " + fn + " has illegal memset<> template use: not called as the first initializer.")
retval = 1
sys.exit(retval)
if len(sys.argv) < 2:
print("Give source directory as parameter.")
sys.exit(1)
main(sys.argv[1])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment