1*03ce13f7SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*03ce13f7SAndroid Build Coastguard Worker 3*03ce13f7SAndroid Build Coastguard Worker# Copyright 2020 The SwiftShader Authors. All Rights Reserved. 4*03ce13f7SAndroid Build Coastguard Worker# 5*03ce13f7SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*03ce13f7SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*03ce13f7SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*03ce13f7SAndroid Build Coastguard Worker# 9*03ce13f7SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*03ce13f7SAndroid Build Coastguard Worker# 11*03ce13f7SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*03ce13f7SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*03ce13f7SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*03ce13f7SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*03ce13f7SAndroid Build Coastguard Worker# limitations under the License. 16*03ce13f7SAndroid Build Coastguard Worker# 17*03ce13f7SAndroid Build Coastguard Worker# Scan all source files for problems that are inconvenient or impossible 18*03ce13f7SAndroid Build Coastguard Worker# to guard against using static assertions in c++ 19*03ce13f7SAndroid Build Coastguard Worker 20*03ce13f7SAndroid Build Coastguard Workerimport glob 21*03ce13f7SAndroid Build Coastguard Workerimport sys 22*03ce13f7SAndroid Build Coastguard Workerimport re 23*03ce13f7SAndroid Build Coastguard Worker 24*03ce13f7SAndroid Build Coastguard Workerdef main(rootdir): 25*03ce13f7SAndroid Build Coastguard Worker filelist = [] 26*03ce13f7SAndroid Build Coastguard Worker for x in [rootdir +"/**/*.cpp", rootdir + "/**/*.hpp"]: 27*03ce13f7SAndroid Build Coastguard Worker filelist += glob.glob(x, recursive=True) 28*03ce13f7SAndroid Build Coastguard Worker 29*03ce13f7SAndroid Build Coastguard Worker # Regex for Memset< template use as base class (must be the first, 30*03ce13f7SAndroid Build Coastguard Worker # thus, there must not be a ',' before it) 31*03ce13f7SAndroid Build Coastguard Worker memset_template_check = re.compile(",\s*Memset\s*<") 32*03ce13f7SAndroid Build Coastguard Worker 33*03ce13f7SAndroid Build Coastguard Worker # Regex for Memset( template use as initializer (must be the first, 34*03ce13f7SAndroid Build Coastguard Worker # thus, there must not be a ',' before it) 35*03ce13f7SAndroid Build Coastguard Worker memset_call_check = re.compile(",\s*Memset\s*\(") 36*03ce13f7SAndroid Build Coastguard Worker 37*03ce13f7SAndroid Build Coastguard Worker retval = 0 38*03ce13f7SAndroid Build Coastguard Worker 39*03ce13f7SAndroid Build Coastguard Worker tb = 0 40*03ce13f7SAndroid Build Coastguard Worker for fn in filelist: 41*03ce13f7SAndroid Build Coastguard Worker with open(fn, encoding="utf-8") as f: 42*03ce13f7SAndroid Build Coastguard Worker contents = f.read(); 43*03ce13f7SAndroid Build Coastguard Worker if memset_template_check.search(contents) != None: 44*03ce13f7SAndroid Build Coastguard Worker print("ERROR: " + fn + " has illegal memset<> template use: must always be the first base class.") 45*03ce13f7SAndroid Build Coastguard Worker retval = 1 46*03ce13f7SAndroid Build Coastguard Worker if memset_call_check.search(contents) != None: 47*03ce13f7SAndroid Build Coastguard Worker print("ERROR: " + fn + " has illegal memset<> template use: not called as the first initializer.") 48*03ce13f7SAndroid Build Coastguard Worker retval = 1 49*03ce13f7SAndroid Build Coastguard Worker 50*03ce13f7SAndroid Build Coastguard Worker sys.exit(retval) 51*03ce13f7SAndroid Build Coastguard Worker 52*03ce13f7SAndroid Build Coastguard Workerif len(sys.argv) < 2: 53*03ce13f7SAndroid Build Coastguard Worker print("Give source directory as parameter.") 54*03ce13f7SAndroid Build Coastguard Worker sys.exit(1) 55*03ce13f7SAndroid Build Coastguard Workermain(sys.argv[1])