checker: add more checks for hash_stmt (#6615)
							parent
							
								
									60296c8900
								
							
						
					
					
						commit
						314fae7446
					
				|  | @ -629,6 +629,7 @@ pub: | ||||||
| 	pos token.Position | 	pos token.Position | ||||||
| pub mut: | pub mut: | ||||||
| 	val string | 	val string | ||||||
|  | 	kind string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
|  |  | ||||||
|  | @ -2462,7 +2462,9 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { | ||||||
| 			c.error('Hash statements are not allowed in the main module. Please place them in a separate module.', | 			c.error('Hash statements are not allowed in the main module. Please place them in a separate module.', | ||||||
| 				node.pos) | 				node.pos) | ||||||
| 		} | 		} | ||||||
| 	} else if node.val.starts_with('include') { | 		return | ||||||
|  | 	} | ||||||
|  | 	if node.kind == 'include' { | ||||||
| 		mut flag := node.val[8..] | 		mut flag := node.val[8..] | ||||||
| 		if flag.contains('@VROOT') { | 		if flag.contains('@VROOT') { | ||||||
| 			vroot := util.resolve_vroot(flag, c.file.path) or { | 			vroot := util.resolve_vroot(flag, c.file.path) or { | ||||||
|  | @ -2471,7 +2473,13 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { | ||||||
| 			} | 			} | ||||||
| 			node.val = 'include $vroot' | 			node.val = 'include $vroot' | ||||||
| 		} | 		} | ||||||
| 	} else if node.val.starts_with('flag') { | 		flag_no_comment := flag.all_before('//').trim_space() | ||||||
|  | 		if !((flag_no_comment.starts_with('"') && flag_no_comment.ends_with('"')) || | ||||||
|  | 			(flag_no_comment.starts_with('<') && flag_no_comment.ends_with('>'))) { | ||||||
|  | 			c.error('including C files should use either `"header_file.h"` or `<header_file.h>` quoting', | ||||||
|  | 				node.pos) | ||||||
|  | 		} | ||||||
|  | 	} else if node.kind == 'flag' { | ||||||
| 		// #flag linux -lm
 | 		// #flag linux -lm
 | ||||||
| 		mut flag := node.val[5..] | 		mut flag := node.val[5..] | ||||||
| 		// expand `@VROOT` to its absolute path
 | 		// expand `@VROOT` to its absolute path
 | ||||||
|  | @ -2490,6 +2498,10 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { | ||||||
| 		c.table.parse_cflag(flag, c.mod, c.pref.compile_defines_all) or { | 		c.table.parse_cflag(flag, c.mod, c.pref.compile_defines_all) or { | ||||||
| 			c.error(err, node.pos) | 			c.error(err, node.pos) | ||||||
| 		} | 		} | ||||||
|  | 	} else { | ||||||
|  | 		if node.kind != 'define' { | ||||||
|  | 			c.warn('expected `#include`, `#flag` or `#define` not $node.val', node.pos) | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -959,18 +959,18 @@ fn (mut g Gen) stmt(node ast.Stmt) { | ||||||
| 		} | 		} | ||||||
| 		ast.HashStmt { | 		ast.HashStmt { | ||||||
| 			// #include etc
 | 			// #include etc
 | ||||||
| 			typ := node.val.all_before(' ') | 			if node.kind == 'include' { | ||||||
| 			if typ == 'include' { |  | ||||||
| 				if node.val.contains('.m') { | 				if node.val.contains('.m') { | ||||||
| 					// Objective C code import, include it after V types, so that e.g. `string` is
 | 					// Objective C code import, include it after V types, so that e.g. `string` is
 | ||||||
| 					// available there
 | 					// available there
 | ||||||
|  | 					g.definitions.writeln('// added by module `$node.mod`:') | ||||||
| 					g.definitions.writeln('#$node.val') | 					g.definitions.writeln('#$node.val') | ||||||
| 				} else { | 				} else { | ||||||
| 					g.includes.writeln('// added by module `$node.mod`:') | 					g.includes.writeln('// added by module `$node.mod`:') | ||||||
| 					g.includes.writeln('#$node.val') | 					g.includes.writeln('#$node.val') | ||||||
| 				} | 				} | ||||||
| 			} | 			} else if node.kind == 'define' { | ||||||
| 			if typ == 'define' { | 				g.includes.writeln('// defined by module `$node.mod`:') | ||||||
| 				g.includes.writeln('#$node.val') | 				g.includes.writeln('#$node.val') | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -11,19 +11,23 @@ import vweb.tmpl | ||||||
| 
 | 
 | ||||||
| // #flag darwin -I.
 | // #flag darwin -I.
 | ||||||
| const ( | const ( | ||||||
| 	supported_platforms  = ['windows', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', | 	supported_platforms  = ['windows', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', 'netbsd', | ||||||
| 		'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | 		'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | ||||||
| 	supported_ccompilers = ['tinyc', 'clang', 'mingw', 'msvc', 'gcc'] | 	supported_ccompilers = ['tinyc', 'clang', 'mingw', 'msvc', 'gcc'] | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // // #include, #flag, #v
 | // // #include, #flag, #v
 | ||||||
| fn (mut p Parser) hash() ast.HashStmt { | fn (mut p Parser) hash() ast.HashStmt { | ||||||
| 	mut val := p.tok.lit | 	mut pos := p.prev_tok.position() | ||||||
|  | 	val := p.tok.lit | ||||||
|  | 	kind := val.all_before(' ') | ||||||
| 	p.next() | 	p.next() | ||||||
|  | 	//p.trace('a.v', 'kind: ${kind:-10s} | pos: ${pos:-45s} | hash: $val')
 | ||||||
| 	return ast.HashStmt{ | 	return ast.HashStmt{ | ||||||
| 		val: val |  | ||||||
| 		mod: p.mod | 		mod: p.mod | ||||||
| 		pos: p.prev_tok.position() | 		val: val | ||||||
|  | 		kind: kind | ||||||
|  | 		pos: pos | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue