1#!/usr/bin/env python3 2 3# Copyright 2020 The SwiftShader Authors. All Rights Reserved. 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# Scan all source files for problems that are inconvenient or impossible 18# to guard against using static assertions in c++ 19 20import glob 21import sys 22import re 23 24def main(rootdir): 25 filelist = [] 26 for x in [rootdir +"/**/*.cpp", rootdir + "/**/*.hpp"]: 27 filelist += glob.glob(x, recursive=True) 28 29 # Regex for Memset< template use as base class (must be the first, 30 # thus, there must not be a ',' before it) 31 memset_template_check = re.compile(",\s*Memset\s*<") 32 33 # Regex for Memset( template use as initializer (must be the first, 34 # thus, there must not be a ',' before it) 35 memset_call_check = re.compile(",\s*Memset\s*\(") 36 37 retval = 0 38 39 tb = 0 40 for fn in filelist: 41 with open(fn, encoding="utf-8") as f: 42 contents = f.read(); 43 if memset_template_check.search(contents) != None: 44 print("ERROR: " + fn + " has illegal memset<> template use: must always be the first base class.") 45 retval = 1 46 if memset_call_check.search(contents) != None: 47 print("ERROR: " + fn + " has illegal memset<> template use: not called as the first initializer.") 48 retval = 1 49 50 sys.exit(retval) 51 52if len(sys.argv) < 2: 53 print("Give source directory as parameter.") 54 sys.exit(1) 55main(sys.argv[1])