function-overloading.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Copyright (c) Contributors to the Open 3D Engine Project.
  5. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. SPDX-License-Identifier: Apache-2.0 OR MIT
  7. """
  8. import sys
  9. import os
  10. from clr import *
  11. sys.path.append("..")
  12. import testfuncs
  13. ''' the test looks like this↓ so we want to verify symbols and their referencess
  14. int func(int i) {..} // 1
  15. int func(float f) {..} // 2
  16. float4 main() : SV_Target0
  17. {
  18. g_func(1); // ref to 1
  19. g_func(1.5); // ref to 2
  20. '''
  21. def execTest(thefile, compilerPath, silent):
  22. '''return number of successes'''
  23. symbols, ok = testfuncs.buildAndGetSymbols(thefile, compilerPath, silent)
  24. # check the specific stuff we want to verify with this test
  25. if ok:
  26. try:
  27. ok = symbols["Symbol '/g_func'"]['kind'] == 'OverloadSet'
  28. ok = ok and symbols["Symbol '/g_func(?int)'"]['kind'] == 'Function'
  29. ok = ok and symbols["Symbol '/g_func(?float)'"]['kind'] == 'Function'
  30. ok = ok and symbols["Symbol '/g_func(?int)'"]['return type']['core']['name'] == '?int'
  31. ok = ok and symbols["Symbol '/g_func(?int)'"]['parameters'][0]["name"] == 'i'
  32. ok = ok and symbols["Symbol '/g_func(?int)'"]['parameters'][0]["type"]["core"]["name"] == '?int'
  33. ok = ok and symbols["Symbol '/g_func(?float)'"]['parameters'][0]["name"] == 'f'
  34. ok = ok and symbols["Symbol '/g_func(?float)'"]['parameters'][0]["type"]["core"]["name"] == '?float'
  35. ok = ok and symbols["Symbol '/g_func(?int)/i'"]['kind'] == 'Variable'
  36. ok = ok and symbols["Symbol '/g_func(?int)/i'"]['type']['core']['name'] == '?int'
  37. ok = ok and symbols["Symbol '/g_func(?float)/f'"]['kind'] == 'Variable'
  38. ok = ok and symbols["Symbol '/g_func(?float)/f'"]['type']['core']['name'] == '?float'
  39. ok = ok and len(symbols["Symbol '/f'"]['references']) == 1 # one unsolved ref, because f()
  40. ok = ok and len(symbols["Symbol '/f(?int,?float)'"]['references']) == 2 # one decl site. one call site
  41. ok = ok and len(symbols["Symbol '/f(?int)'"]['references']) == 2 # one decl site. one call site
  42. ok = ok and symbols["Symbol '/f(?int,?float)'"]['references'][1]['line'] == 28
  43. ok = ok and symbols["Symbol '/f(?int)'"]['references'][1]['line'] == 27
  44. ok = ok and symbols["Symbol '/f'"]['references'][0]['line'] == 26
  45. if not ok:
  46. print (style.DIM + fg.YELLOW + "ERR: all expected symbol founds, but their semantic understanding seems off" + style.RESET_ALL)
  47. else:
  48. print (style.BRIGHT + "OK! all symbols semantics correctly understood" + style.RESET_ALL)
  49. except Exception as e:
  50. print (fg.RED + "Err: Parsed --dumpsym may lack some expected keys" + style.RESET_ALL, e)
  51. return 1 if ok else 0
  52. result = 0 # to define for sub-tests
  53. resultFailed = 0
  54. def doTests(compiler, silent, azdxcpath):
  55. global result
  56. global resultFailed
  57. # Working directory should have been set to this script's directory by the calling parent
  58. # You can get it once doTests() is called, but not during initialization of the module,
  59. # because at that time it will still be set to the working directory of the calling script
  60. workDir = os.getcwd()
  61. if execTest(os.path.join(workDir, "function-overloading.azsl"), compiler, silent): result += 1
  62. else: resultFailed += 1
  63. if __name__ == "__main__":
  64. print ("please call from testapp.py")