mirror of
				https://github.com/smyalygames/FiniteVolumeGPU.git
				synced 2025-10-31 20:27:40 +01:00 
			
		
		
		
	feat(gpu): add function to find includes in C/C++ files
This commit is contained in:
		
							parent
							
								
									5eab354968
								
							
						
					
					
						commit
						ecfdaaa39e
					
				| @ -1,3 +1,4 @@ | ||||
| import re | ||||
| from pathlib import Path | ||||
| 
 | ||||
| 
 | ||||
| @ -6,3 +7,22 @@ def get_project_root() -> Path: | ||||
|     Gets the root directory of the project. | ||||
|     """ | ||||
|     return Path(__file__).parent.parent.parent | ||||
| 
 | ||||
| 
 | ||||
| def get_includes(file: str, local: bool = False) -> list[str]: | ||||
|     """ | ||||
|     Finds all the includes used in C/C++ in a string from a file. | ||||
| 
 | ||||
|     Args: | ||||
|         file: The text of the code. | ||||
|         local: Only gets the includes that are explicitly defined as being local | ||||
|             (includes with quotes instead of ``<>``) | ||||
| 
 | ||||
|     Returns: | ||||
|         A list of the includes (without ``#include ""``) from the given string. | ||||
|     """ | ||||
|     pattern = '^\\W*#include\\W+(.+?)\\W*$' | ||||
|     if local: | ||||
|         pattern = '^\\W*#include\\s+"(.+?)"\\W*$' | ||||
| 
 | ||||
|     return re.findall(pattern, file, re.M) | ||||
|  | ||||
| @ -5,7 +5,7 @@ import re | ||||
| import logging | ||||
| from hashlib import md5 | ||||
| 
 | ||||
| from GPUSimulators.common.utils import get_project_root | ||||
| from GPUSimulators.common.utils import get_project_root, get_includes | ||||
| 
 | ||||
| 
 | ||||
| class Context(object): | ||||
| @ -83,7 +83,7 @@ class Context(object): | ||||
|                 kernel_hasher.update(str(modified).encode('utf-8')) | ||||
| 
 | ||||
|                 # Find all the includes | ||||
|                 includes = re.findall('^\\W*#include\\W+(.+?)\\W*$', file_str, re.M) | ||||
|                 includes = get_includes(file_str) | ||||
| 
 | ||||
|             # Iterate through everything that looks like is an ``include`` | ||||
|             for include_file in includes: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Anthony Berg
						Anthony Berg