mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	Clear up constant parsing
2008-08-14 Johan Dahlin <johan@gnome.org> * girepository/girparser.c (start_field), (start_constant), (start_type), (end_element_handler): Clear up constant parsing * tests/object.gir: Update * tools/generate.c (write_callable_info), (write_function_info), (write_callback_info), (write_constant_info), (write_signal_info), (write_vfunc_info), (write_property_info), (write_object_info), (write_interface_info): Constants/Signals are handled now. svn path=/trunk/; revision=377
This commit is contained in:
		
				
					committed by
					
						 Johan Dahlin
						Johan Dahlin
					
				
			
			
				
	
			
			
			
						parent
						
							698bcf0af5
						
					
				
				
					commit
					27314af58e
				
			
							
								
								
									
										65
									
								
								girparser.c
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								girparser.c
									
									
									
									
									
								
							| @@ -53,8 +53,10 @@ typedef enum | |||||||
|   STATE_STRUCT_FIELD, |   STATE_STRUCT_FIELD, | ||||||
|   STATE_ERRORDOMAIN,  |   STATE_ERRORDOMAIN,  | ||||||
|   STATE_UNION, |   STATE_UNION, | ||||||
|   STATE_CONSTANT, |   STATE_NAMESPACE_CONSTANT, | ||||||
|   STATE_ALIAS,  /* 25 */ |   STATE_CLASS_CONSTANT, /* 25 */ | ||||||
|  |   STATE_INTERFACE_CONSTANT, | ||||||
|  |   STATE_ALIAS | ||||||
| } ParseState; | } ParseState; | ||||||
|  |  | ||||||
| typedef struct _ParseContext ParseContext; | typedef struct _ParseContext ParseContext; | ||||||
| @@ -776,7 +778,6 @@ start_field (GMarkupParseContext *context, | |||||||
|        ctx->state == STATE_INTERFACE)) |        ctx->state == STATE_INTERFACE)) | ||||||
|     { |     { | ||||||
|       const gchar *name; |       const gchar *name; | ||||||
|       const gchar *type; |  | ||||||
|       const gchar *readable; |       const gchar *readable; | ||||||
|       const gchar *writable; |       const gchar *writable; | ||||||
|       const gchar *bits; |       const gchar *bits; | ||||||
| @@ -784,7 +785,6 @@ start_field (GMarkupParseContext *context, | |||||||
|       const gchar *offset; |       const gchar *offset; | ||||||
|        |        | ||||||
|       name = find_attribute ("name", attribute_names, attribute_values); |       name = find_attribute ("name", attribute_names, attribute_values); | ||||||
|       type = find_attribute ("c:type", attribute_names, attribute_values); |  | ||||||
|       readable = find_attribute ("readable", attribute_names, attribute_values); |       readable = find_attribute ("readable", attribute_names, attribute_values); | ||||||
|       writable = find_attribute ("writable", attribute_names, attribute_values); |       writable = find_attribute ("writable", attribute_names, attribute_values); | ||||||
|       bits = find_attribute ("bits", attribute_names, attribute_values); |       bits = find_attribute ("bits", attribute_names, attribute_values); | ||||||
| @@ -1119,19 +1119,15 @@ start_constant (GMarkupParseContext *context, | |||||||
|        ctx->state == STATE_INTERFACE)) |        ctx->state == STATE_INTERFACE)) | ||||||
|     { |     { | ||||||
|       const gchar *name; |       const gchar *name; | ||||||
|       const gchar *type; |  | ||||||
|       const gchar *value; |       const gchar *value; | ||||||
|       const gchar *deprecated; |       const gchar *deprecated; | ||||||
|        |        | ||||||
|       name = find_attribute ("name", attribute_names, attribute_values); |       name = find_attribute ("name", attribute_names, attribute_values); | ||||||
|       type = find_attribute ("c:type", attribute_names, attribute_values); |  | ||||||
|       value = find_attribute ("value", attribute_names, attribute_values); |       value = find_attribute ("value", attribute_names, attribute_values); | ||||||
|       deprecated = find_attribute ("deprecated", attribute_names, attribute_values); |       deprecated = find_attribute ("deprecated", attribute_names, attribute_values); | ||||||
|        |        | ||||||
|       if (name == NULL) |       if (name == NULL) | ||||||
| 	MISSING_ATTRIBUTE (context, error, element_name, "name"); | 	MISSING_ATTRIBUTE (context, error, element_name, "name"); | ||||||
|       else if (type == NULL) |  | ||||||
| 	MISSING_ATTRIBUTE (context, error, element_name, "c:type"); |  | ||||||
|       else if (value == NULL) |       else if (value == NULL) | ||||||
| 	MISSING_ATTRIBUTE (context, error, element_name, "value"); | 	MISSING_ATTRIBUTE (context, error, element_name, "value"); | ||||||
|       else  |       else  | ||||||
| @@ -1143,7 +1139,7 @@ start_constant (GMarkupParseContext *context, | |||||||
| 	  ((GIrNode *)constant)->name = g_strdup (name); | 	  ((GIrNode *)constant)->name = g_strdup (name); | ||||||
| 	  constant->value = g_strdup (value); | 	  constant->value = g_strdup (value); | ||||||
|  |  | ||||||
| 	  constant->type = parse_type (ctx, type); | 	  ctx->current_typed = (GIrNode*) constant; | ||||||
|  |  | ||||||
| 	  if (deprecated && strcmp (deprecated, "1") == 0) | 	  if (deprecated && strcmp (deprecated, "1") == 0) | ||||||
| 	    constant->deprecated = TRUE; | 	    constant->deprecated = TRUE; | ||||||
| @@ -1163,7 +1159,22 @@ start_constant (GMarkupParseContext *context, | |||||||
| 	      iface = (GIrNodeInterface *)ctx->current_node; | 	      iface = (GIrNodeInterface *)ctx->current_node; | ||||||
| 	      iface->members = g_list_append (iface->members, constant); | 	      iface->members = g_list_append (iface->members, constant); | ||||||
| 	    } | 	    } | ||||||
| 	  state_switch (ctx, STATE_CONSTANT); |  | ||||||
|  | 	  switch (ctx->state) | ||||||
|  | 	    { | ||||||
|  | 	    case STATE_NAMESPACE: | ||||||
|  | 	      state_switch (ctx, STATE_NAMESPACE_CONSTANT); | ||||||
|  | 	      break; | ||||||
|  | 	    case STATE_CLASS: | ||||||
|  | 	      state_switch (ctx, STATE_CLASS_CONSTANT); | ||||||
|  | 	      break; | ||||||
|  | 	    case STATE_INTERFACE: | ||||||
|  | 	      state_switch (ctx, STATE_INTERFACE_CONSTANT); | ||||||
|  | 	      break; | ||||||
|  | 	    default: | ||||||
|  | 	      g_assert_not_reached (); | ||||||
|  | 	      break; | ||||||
|  | 	    } | ||||||
| 	} | 	} | ||||||
|        |        | ||||||
|       return TRUE; |       return TRUE; | ||||||
| @@ -1351,7 +1362,10 @@ start_type (GMarkupParseContext *context, | |||||||
| 	ctx->state == STATE_CLASS_FIELD || | 	ctx->state == STATE_CLASS_FIELD || | ||||||
| 	ctx->state == STATE_INTERFACE_FIELD || | 	ctx->state == STATE_INTERFACE_FIELD || | ||||||
| 	ctx->state == STATE_INTERFACE_PROPERTY || | 	ctx->state == STATE_INTERFACE_PROPERTY || | ||||||
| 	ctx->state == STATE_BOXED_FIELD | 	ctx->state == STATE_BOXED_FIELD || | ||||||
|  | 	ctx->state == STATE_NAMESPACE_CONSTANT || | ||||||
|  | 	ctx->state == STATE_CLASS_CONSTANT || | ||||||
|  | 	ctx->state == STATE_INTERFACE_CONSTANT | ||||||
| 	)) | 	)) | ||||||
|     return FALSE; |     return FALSE; | ||||||
|  |  | ||||||
| @@ -1373,8 +1387,7 @@ start_type (GMarkupParseContext *context, | |||||||
|     { |     { | ||||||
|     case G_IR_NODE_PARAM: |     case G_IR_NODE_PARAM: | ||||||
|       { |       { | ||||||
| 	GIrNodeParam *param; | 	GIrNodeParam *param = (GIrNodeParam *)ctx->current_typed; | ||||||
| 	param = (GIrNodeParam *)ctx->current_typed; |  | ||||||
| 	param->type = parse_type (ctx, name); | 	param->type = parse_type (ctx, name); | ||||||
|       } |       } | ||||||
|       break; |       break; | ||||||
| @@ -1390,6 +1403,12 @@ start_type (GMarkupParseContext *context, | |||||||
| 	property->type = parse_type (ctx, name); | 	property->type = parse_type (ctx, name); | ||||||
|       } |       } | ||||||
|       break; |       break; | ||||||
|  |     case G_IR_NODE_CONSTANT: | ||||||
|  |       { | ||||||
|  | 	GIrNodeConstant *constant = (GIrNodeConstant *)ctx->current_typed; | ||||||
|  | 	constant->type = parse_type (ctx, name); | ||||||
|  |       } | ||||||
|  |       break; | ||||||
|     default: |     default: | ||||||
|       g_printerr("current node is %d\n", ctx->current_node->type); |       g_printerr("current node is %d\n", ctx->current_node->type); | ||||||
|       g_assert_not_reached (); |       g_assert_not_reached (); | ||||||
| @@ -2308,11 +2327,29 @@ end_element_handler (GMarkupParseContext *context, | |||||||
|       if (require_end_element (context, ctx, "requires", element_name, error)) |       if (require_end_element (context, ctx, "requires", element_name, error)) | ||||||
|         state_switch (ctx, STATE_INTERFACE); |         state_switch (ctx, STATE_INTERFACE); | ||||||
|       break; |       break; | ||||||
|     case STATE_CONSTANT: |     case STATE_NAMESPACE_CONSTANT: | ||||||
|  |     case STATE_CLASS_CONSTANT: | ||||||
|  |     case STATE_INTERFACE_CONSTANT: | ||||||
|  |       if (strcmp ("type", element_name) == 0) | ||||||
|  | 	break; | ||||||
|       if (require_end_element (context, ctx, "constant", element_name, error)) |       if (require_end_element (context, ctx, "constant", element_name, error)) | ||||||
| 	{ | 	{ | ||||||
| 	  ctx->current_node = NULL; | 	  ctx->current_node = NULL; | ||||||
|  | 	  switch (ctx->state) | ||||||
|  | 	    { | ||||||
|  | 	    case STATE_NAMESPACE_CONSTANT: | ||||||
| 	      state_switch (ctx, STATE_NAMESPACE); | 	      state_switch (ctx, STATE_NAMESPACE); | ||||||
|  | 	      break; | ||||||
|  | 	    case STATE_CLASS_CONSTANT: | ||||||
|  | 	      state_switch (ctx, STATE_CLASS); | ||||||
|  | 	      break; | ||||||
|  | 	    case STATE_INTERFACE_CONSTANT: | ||||||
|  | 	      state_switch (ctx, STATE_INTERFACE); | ||||||
|  | 	      break; | ||||||
|  | 	    default: | ||||||
|  | 	      g_assert_not_reached (); | ||||||
|  | 	      break; | ||||||
|  | 	    } | ||||||
| 	} | 	} | ||||||
|       break; |       break; | ||||||
|     default: |     default: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user