srclexer.py (77de67d5) srclexer.py (7d9fa7c3)
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 289 unchanged lines hidden (view full) ---

298 buf += c
299
300 if command == 'define':
301 self.handleMacroDefine(buf)
302 elif command == 'include':
303 self.handleMacroInclude(buf)
304 elif command == 'ifdef':
305 defineName = buf.strip()
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 289 unchanged lines hidden (view full) ---

298 buf += c
299
300 if command == 'define':
301 self.handleMacroDefine(buf)
302 elif command == 'include':
303 self.handleMacroInclude(buf)
304 elif command == 'ifdef':
305 defineName = buf.strip()
306 if self.defines.has_key(defineName):
306 if defineName in self.defines:
307 self.visibilityStack.append(SrcLexer.VISIBLE)
308 else:
309 self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
310
311 elif command == 'ifndef':
312 defineName = buf.strip()
307 self.visibilityStack.append(SrcLexer.VISIBLE)
308 else:
309 self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
310
311 elif command == 'ifndef':
312 defineName = buf.strip()
313 if self.defines.has_key(defineName):
313 if defineName in self.defines:
314 self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
315 else:
316 self.visibilityStack.append(SrcLexer.VISIBLE)
317
318 elif command == 'if':
319 if self.evalCodeVisibility(buf):
320 self.visibilityStack.append(SrcLexer.VISIBLE)
321 else:

--- 24 unchanged lines hidden (view full) ---

346 raise ParseError ('')
347 self.visibilityStack.pop()
348
349 elif command == 'undef':
350 pass
351 elif command in ['error', 'pragma']:
352 pass
353 else:
314 self.visibilityStack.append(SrcLexer.INVISIBLE_PRE)
315 else:
316 self.visibilityStack.append(SrcLexer.VISIBLE)
317
318 elif command == 'if':
319 if self.evalCodeVisibility(buf):
320 self.visibilityStack.append(SrcLexer.VISIBLE)
321 else:

--- 24 unchanged lines hidden (view full) ---

346 raise ParseError ('')
347 self.visibilityStack.pop()
348
349 elif command == 'undef':
350 pass
351 elif command in ['error', 'pragma']:
352 pass
353 else:
354 print "'%s' '%s'"%(command, buf)
355 print self.filepath
354 print("'%s' '%s'"%(command, buf))
355 print(self.filepath)
356 sys.exit(0)
357
358 return i
359
360
361 def evalCodeVisibility (self, buf):
362 try:
363 return eval(buf)

--- 38 unchanged lines hidden (view full) ---

402 if self.debug:
403 progress ("%s found\n"%headerPath)
404
405 if headerPath in self.headerDict:
406 if self.debug:
407 progress ("%s already included\n"%headerPath)
408 return
409
356 sys.exit(0)
357
358 return i
359
360
361 def evalCodeVisibility (self, buf):
362 try:
363 return eval(buf)

--- 38 unchanged lines hidden (view full) ---

402 if self.debug:
403 progress ("%s found\n"%headerPath)
404
405 if headerPath in self.headerDict:
406 if self.debug:
407 progress ("%s already included\n"%headerPath)
408 return
409
410 if SrcLexer.headerCache.has_key(headerPath):
410 if headerPath in SrcLexer.headerCache:
411 if self.debug:
412 progress ("%s in cache\n"%headerPath)
411 if self.debug:
412 progress ("%s in cache\n"%headerPath)
413 for key in SrcLexer.headerCache[headerPath].defines.keys():
413 for key in list(SrcLexer.headerCache[headerPath].defines.keys()):
414 self.defines[key] = SrcLexer.headerCache[headerPath].defines[key]
415 return
416
417 chars = open(headerPath, 'r').read()
418 mclexer = SrcLexer(chars, headerPath)
419 mclexer.copyProperties(self)
420 mclexer.parentLexer = self
421 mclexer.tokenize()
422 hdrData = HeaderData()
423 hdrData.tokens = mclexer.getTokens()
424 headerDefines = mclexer.getDefines()
414 self.defines[key] = SrcLexer.headerCache[headerPath].defines[key]
415 return
416
417 chars = open(headerPath, 'r').read()
418 mclexer = SrcLexer(chars, headerPath)
419 mclexer.copyProperties(self)
420 mclexer.parentLexer = self
421 mclexer.tokenize()
422 hdrData = HeaderData()
423 hdrData.tokens = mclexer.getTokens()
424 headerDefines = mclexer.getDefines()
425 for key in headerDefines.keys():
425 for key in list(headerDefines.keys()):
426 defines[key] = headerDefines[key]
427 hdrData.defines[key] = headerDefines[key]
428
429 self.headerDict[headerPath] = True
430 SrcLexer.headerCache[headerPath] = hdrData
431
432 # Update the list of headers that have already been expaneded.
426 defines[key] = headerDefines[key]
427 hdrData.defines[key] = headerDefines[key]
428
429 self.headerDict[headerPath] = True
430 SrcLexer.headerCache[headerPath] = hdrData
431
432 # Update the list of headers that have already been expaneded.
433 for key in mclexer.headerDict.keys():
433 for key in list(mclexer.headerDict.keys()):
434 self.headerDict[key] = True
435
436 if self.debug:
437 progress ("defines found in header %s:\n"%headerSub)
434 self.headerDict[key] = True
435
436 if self.debug:
437 progress ("defines found in header %s:\n"%headerSub)
438 for key in defines.keys():
438 for key in list(defines.keys()):
439 progress (" '%s'\n"%key)
440
439 progress (" '%s'\n"%key)
440
441 for key in defines.keys():
441 for key in list(defines.keys()):
442 self.defines[key] = defines[key]
443
444
445 def slash (self, i):
446 if not self.isCodeVisible():
447 return i
448
449 if i < self.bufsize - 1 and self.chars[i+1] == '/':

--- 59 unchanged lines hidden ---
442 self.defines[key] = defines[key]
443
444
445 def slash (self, i):
446 if not self.isCodeVisible():
447 return i
448
449 if i < self.bufsize - 1 and self.chars[i+1] == '/':

--- 59 unchanged lines hidden ---