gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
cyclic_include_check.py
Go to the documentation of this file.
1 # This script checks for possible cyclic includes.
2 # Currently does not ignore comments, and might therefore give false positives
3 
4 import os
5 
6 IncludeDirs = [
7  './Core/include',
8 # './ModelBit/include',
9  './Utils/include',
10  './Printers/include',
11  './ScannerBit/include',
12  './Backends/include',
13  './ColliderBit/include',
14  './DarkBit/include',
15  './FlavBit/include',
16  './ExampleBit_A/include',
17  './ExampleBit_B/include',
18  './Example_SUSYspecBit/include'
19 ]
20 
21 def checkLoop(fle, ref, prev):
22  global includes
23  if ref in includes[fle]:
24  prev2 = prev+[fle,ref]
25  return prev2
26  for p in prev:
27  if p in includes[fle]:
28  prev2 = prev+[fle,p]
29  return prev2
30  for inc in includes[fle]:
31  if inc in includes:
32  prev2 = prev+[fle]
33  loop = checkLoop(inc,ref, prev2)
34  if loop != None:
35  return loop
36  return None
37 
38 print 'Checking for cyclic includes...'
39 print 'Note: Comments are currently not ignored. Might give false positives.'
40 
41 files = []
42 for d in IncludeDirs:
43  fs = os.listdir(d)
44  for f in fs:
45  if '.h' in f:
46  files.append([d,f])
47 
48 includes = {}
49 
50 for f in files:
51  includes[f[1]] = []
52  infile = open(f[0]+'/'+f[1])
53  inp = infile.read()
54  infile.close()
55  lines = inp.splitlines()
56  for line in lines:
57  if '#include' in line:
58  lineL = line.split()
59  for st in lineL:
60  if '.h' in st:
61  st2 = st.replace("\"","" ).replace(">","" ).replace("<","" )
62  includes[f[1]].append(st2)
63 
64 for f in includes:
65  prev = []
66  loop = checkLoop(f,f,prev)
67  if loop != None:
68  if loop[0] == loop[-1]:
69  print 'Possible cyclic include found in '+f+':'
70  print loop
71  print
72 
def checkLoop(fle, ref, prev)