mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 13:41:03 +00:00 
			
		
		
		
	Refactor some object type checking code with cast_to
				
					
				
			Less stringly typed logic, and less String allocations and comparisons.
This commit is contained in:
		
							parent
							
								
									0154ce2c8d
								
							
						
					
					
						commit
						317cd0b19a
					
				
					 29 changed files with 140 additions and 171 deletions
				
			
		|  | @ -519,7 +519,7 @@ void GDScriptParser::parse_program() { | |||
| 		// Check for @tool annotation.
 | ||||
| 		AnnotationNode *annotation = parse_annotation(AnnotationInfo::SCRIPT | AnnotationInfo::CLASS_LEVEL); | ||||
| 		if (annotation != nullptr) { | ||||
| 			if (annotation->name == "@tool") { | ||||
| 			if (annotation->name == SNAME("@tool")) { | ||||
| 				// TODO: don't allow @tool anywhere else. (Should all script annotations be the first thing?).
 | ||||
| 				_is_tool = true; | ||||
| 				if (previous.type != GDScriptTokenizer::Token::NEWLINE) { | ||||
|  | @ -573,7 +573,7 @@ void GDScriptParser::parse_program() { | |||
| 		// Check for @icon annotation.
 | ||||
| 		AnnotationNode *annotation = parse_annotation(AnnotationInfo::SCRIPT | AnnotationInfo::CLASS_LEVEL); | ||||
| 		if (annotation != nullptr) { | ||||
| 			if (annotation->name == "@icon") { | ||||
| 			if (annotation->name == SNAME("@icon")) { | ||||
| 				if (previous.type != GDScriptTokenizer::Token::NEWLINE) { | ||||
| 					push_error(R"(Expected newline after "@icon" annotation.)"); | ||||
| 				} | ||||
|  | @ -3503,7 +3503,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node | |||
| 	// This is called after the analyzer is done finding the type, so this should be set here.
 | ||||
| 	DataType export_type = variable->get_datatype(); | ||||
| 
 | ||||
| 	if (p_annotation->name == "@export") { | ||||
| 	if (p_annotation->name == SNAME("@export")) { | ||||
| 		if (variable->datatype_specifier == nullptr && variable->initializer == nullptr) { | ||||
| 			push_error(R"(Cannot use simple "@export" annotation with variable without type or initializer, since type can't be inferred.)", p_annotation); | ||||
| 			return false; | ||||
|  | @ -3528,7 +3528,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node | |||
| 				variable->export_info.hint_string = Variant::get_type_name(export_type.builtin_type); | ||||
| 				break; | ||||
| 			case GDScriptParser::DataType::NATIVE: | ||||
| 				if (ClassDB::is_parent_class(export_type.native_type, "Resource")) { | ||||
| 				if (ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) { | ||||
| 					variable->export_info.type = Variant::OBJECT; | ||||
| 					variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE; | ||||
| 					variable->export_info.hint_string = export_type.native_type; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Rémi Verschelde
						Rémi Verschelde