⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.y

📁 CORBA上的libIDL源代码
💻 Y
📖 第 1 页 / 共 4 页
字号:
	if (!p && __IDL_is_parsing) {		yywarningv (IDL_WARNING1, "Unknown identifier `%s' in pragma version", name);		return;	}	/* We have resolved the identifier, so assign the repo id */	assert (IDL_NODE_TYPE (p) == IDLN_GENTREE);	assert (IDL_GENTREE (p).data != NULL);	assert (IDL_NODE_TYPE (IDL_GENTREE (p).data) == IDLN_IDENT);	ident = IDL_GENTREE (p).data;	if (IDL_IDENT_REPO_ID (ident) != NULL) {		char *v = strrchr (IDL_IDENT_REPO_ID (ident), ':');		if (v) {			GString *s;			*v = 0;			s = g_string_new (NULL);			g_string_sprintf (s, "%s:%d.%d",					  IDL_IDENT_REPO_ID (ident), major, minor);			g_free (IDL_IDENT_REPO_ID (ident));			IDL_IDENT_REPO_ID (ident) = s->str;			g_string_free (s, FALSE);		} else if (__IDL_is_parsing)			yywarningv (IDL_WARNING1, "Cannot find RepositoryID OMG IDL version in ID `%s'",				    IDL_IDENT_REPO_ID (ident));	} else		IDL_IDENT_REPO_ID (ident) =			IDL_ns_ident_make_repo_id (				__IDL_root_ns, p, NULL, &major, &minor);}int IDL_inhibit_get (void){	g_return_val_if_fail (__IDL_is_parsing, -1);	return __IDL_inhibits;}void IDL_inhibit_push (void){	g_return_if_fail (__IDL_is_parsing);	++__IDL_inhibits;}void IDL_inhibit_pop (void){	g_return_if_fail (__IDL_is_parsing);	if (--__IDL_inhibits < 0)		__IDL_inhibits = 0;}static void IDL_inhibit (IDL_ns ns, const char *s){	if (g_strcasecmp ("push", s) == 0)		IDL_inhibit_push ();	else if (g_strcasecmp ("pop", s) == 0)		IDL_inhibit_pop ();}void __IDL_do_pragma (const char *s){	int n;	char directive[256];	g_return_if_fail (__IDL_is_parsing);	g_return_if_fail (s != NULL);	if (sscanf (s, "%255s%n", directive, &n) < 1)		return;	s += n;	while (isspace (*s)) ++s;	if (strcmp (directive, "prefix") == 0)		IDL_ns_prefix (__IDL_root_ns, s);	else if (strcmp (directive, "ID") == 0)		IDL_ns_ID (__IDL_root_ns, s);	else if (strcmp (directive, "version") == 0)		IDL_ns_version (__IDL_root_ns, s);	else if (strcmp (directive, "inhibit") == 0)		IDL_inhibit (__IDL_root_ns, s);}static IDL_declspec_t IDL_parse_declspec (const char *strspec){	IDL_declspec_t flags = IDLF_DECLSPEC_EXIST;	if (strspec == NULL)		return flags;	if (strcmp (strspec, "inhibit") == 0)		flags |= IDLF_DECLSPEC_INHIBIT;	else if (__IDL_is_parsing)		yywarningv (IDL_WARNING1, "Ignoring unknown declspec `%s'", strspec);	return flags;}void IDL_file_set (const char *filename, int line){	IDL_fileinfo *fi;	char *orig;	g_return_if_fail (__IDL_is_parsing);	if (filename) {		__IDL_cur_filename = g_strdup (filename);		if (#ifdef HAVE_CPP_PIPE_STDIN			!strlen (__IDL_cur_filename)#else			__IDL_tmp_filename &&			!strcmp (__IDL_cur_filename, __IDL_tmp_filename)#endif			) {			g_free (__IDL_cur_filename);			__IDL_cur_filename = g_strdup (__IDL_real_filename);			__IDL_flagsi &= ~IDLFP_IN_INCLUDES;		} else			__IDL_flagsi |= IDLFP_IN_INCLUDES;		if (g_hash_table_lookup_extended (__IDL_filename_hash, __IDL_cur_filename,						  (gpointer) &orig, (gpointer) &fi)) {			g_free (__IDL_cur_filename);			__IDL_cur_filename = orig;			__IDL_cur_fileinfo = fi;		} else {			fi = g_new0 (IDL_fileinfo, 1);			__IDL_cur_fileinfo = fi;			g_hash_table_insert (__IDL_filename_hash, __IDL_cur_filename, fi);		}	}	if (__IDL_cur_line > 0)		__IDL_cur_line = line;}void IDL_file_get (const char **filename, int *line){	g_return_if_fail (__IDL_is_parsing);	if (filename)		*filename = __IDL_cur_filename;	if (line)		*line = __IDL_cur_line;}static int do_token_error (IDL_tree p, const char *message, gboolean prev){	int dienow;	char *what = NULL, *who = NULL;	assert (p != NULL);	dienow = IDL_tree_get_node_info (p, &what, &who);	assert (what != NULL);		if (who && *who)		IDL_tree_error (p, "%s %s `%s'", message, what, who);	else		IDL_tree_error (p, "%s %s", message, what);		return dienow;}static void illegal_context_type_error (IDL_tree p, const char *what){	GString *s = g_string_new (NULL);	g_string_sprintf (s, "Illegal type `%%s' for %s", what);	illegal_type_error (p, s->str);	g_string_free (s, TRUE);}static void illegal_type_error (IDL_tree p, const char *message){	GString *s;	s = IDL_tree_to_IDL_string (p, NULL, IDLF_OUTPUT_NO_NEWLINES);	yyerrorv (message, s->str);	g_string_free (s, TRUE);}static IDL_tree list_start (IDL_tree a, gboolean filter_null){	IDL_tree p;	if (!a && filter_null)		return NULL;	p = IDL_list_new (a);	return p;}static IDL_tree list_chain (IDL_tree a, IDL_tree b, gboolean filter_null){	IDL_tree p;	if (filter_null) {		if (!b)			return a;		if (!a)			return list_start (b, filter_null);	}	p = IDL_list_new (b);	a = IDL_list_concat (a, p);	return a;}static IDL_tree zlist_chain (IDL_tree a, IDL_tree b, gboolean filter_null){	if (a == NULL)		return list_start (b, filter_null);	else		return list_chain (a, b, filter_null);}static int IDL_binop_chktypes (enum IDL_binop op, IDL_tree a, IDL_tree b){	if (IDL_NODE_TYPE (a) != IDLN_BINOP &&	    IDL_NODE_TYPE (b) != IDLN_BINOP &&	    IDL_NODE_TYPE (a) != IDLN_UNARYOP &&	    IDL_NODE_TYPE (b) != IDLN_UNARYOP &&	    IDL_NODE_TYPE (a) != IDL_NODE_TYPE (b)) {		yyerror ("Invalid mix of types in constant expression");		return -1;	}	switch (op) {	case IDL_BINOP_MULT:	case IDL_BINOP_DIV:	case IDL_BINOP_ADD:	case IDL_BINOP_SUB:		break;	case IDL_BINOP_MOD:	case IDL_BINOP_SHR:	case IDL_BINOP_SHL:	case IDL_BINOP_AND:	case IDL_BINOP_OR:	case IDL_BINOP_XOR:		if ((IDL_NODE_TYPE (a) != IDLN_INTEGER ||		     IDL_NODE_TYPE (b) != IDLN_INTEGER) &&		    !(IDL_NODE_TYPE (a) == IDLN_BINOP ||		      IDL_NODE_TYPE (b) == IDLN_BINOP ||		      IDL_NODE_TYPE (a) == IDLN_UNARYOP ||		      IDL_NODE_TYPE (b) == IDLN_UNARYOP)) {			yyerror ("Invalid operation on non-integer value");			return -1;		}		break;	}	return 0;}static int IDL_unaryop_chktypes (enum IDL_unaryop op, IDL_tree a){	switch (op) {	case IDL_UNARYOP_PLUS:	case IDL_UNARYOP_MINUS:		break;	case IDL_UNARYOP_COMPLEMENT:		if (IDL_NODE_TYPE (a) != IDLN_INTEGER &&		    !(IDL_NODE_TYPE (a) == IDLN_BINOP ||		      IDL_NODE_TYPE (a) == IDLN_UNARYOP)) {			yyerror ("Operand to complement must be integer");			return -1;		}		break;	}	return 0;}static IDL_tree IDL_binop_eval_integer (enum IDL_binop op, IDL_tree a, IDL_tree b){	IDL_tree p = NULL;	assert (IDL_NODE_TYPE (a) == IDLN_INTEGER);	switch (op) {	case IDL_BINOP_MULT:		p = IDL_integer_new (IDL_INTEGER (a).value * IDL_INTEGER (b).value);		break;	case IDL_BINOP_DIV:		if (IDL_INTEGER (b).value == 0) {			yyerror ("Divide by zero in constant expression");			return NULL;		}		p = IDL_integer_new (IDL_INTEGER (a).value / IDL_INTEGER (b).value);		break;	case IDL_BINOP_ADD:		p = IDL_integer_new (IDL_INTEGER (a).value + IDL_INTEGER (b).value);		break;	case IDL_BINOP_SUB:		p = IDL_integer_new (IDL_INTEGER (a).value - IDL_INTEGER (b).value);		break;	case IDL_BINOP_MOD:		if (IDL_INTEGER (b).value == 0) {			yyerror ("Modulo by zero in constant expression");			return NULL;		}		p = IDL_integer_new (IDL_INTEGER (a).value % IDL_INTEGER (b).value);		break;	case IDL_BINOP_SHR:		p = IDL_integer_new (IDL_INTEGER (a).value >> IDL_INTEGER (b).value);		break;	case IDL_BINOP_SHL:		p = IDL_integer_new (IDL_INTEGER (a).value << IDL_INTEGER (b).value);		break;	case IDL_BINOP_AND:		p = IDL_integer_new (IDL_INTEGER (a).value & IDL_INTEGER (b).value);		break;	case IDL_BINOP_OR:		p = IDL_integer_new (IDL_INTEGER (a).value | IDL_INTEGER (b).value);		break;	case IDL_BINOP_XOR:		p = IDL_integer_new (IDL_INTEGER (a).value ^ IDL_INTEGER (b).value);		break;	}	return p;}static IDL_tree IDL_binop_eval_float (enum IDL_binop op, IDL_tree a, IDL_tree b){	IDL_tree p = NULL;	assert (IDL_NODE_TYPE (a) == IDLN_FLOAT);	switch (op) {	case IDL_BINOP_MULT:		p = IDL_float_new (IDL_FLOAT (a).value * IDL_FLOAT (b).value);		break;	case IDL_BINOP_DIV:		if (IDL_FLOAT (b).value == 0.0) {			yyerror ("Divide by zero in constant expression");			return NULL;		}		p = IDL_float_new (IDL_FLOAT (a).value / IDL_FLOAT (b).value);		break;	case IDL_BINOP_ADD:		p = IDL_float_new (IDL_FLOAT (a).value + IDL_FLOAT (b).value);		break;	case IDL_BINOP_SUB:		p = IDL_float_new (IDL_FLOAT (a).value - IDL_FLOAT (b).value);		break;	default:		break;	}	return p;}static IDL_tree IDL_binop_eval (enum IDL_binop op, IDL_tree a, IDL_tree b){	assert (IDL_NODE_TYPE (a) == IDL_NODE_TYPE (b));	switch (IDL_NODE_TYPE (a)) {	case IDLN_INTEGER: return IDL_binop_eval_integer (op, a, b);	case IDLN_FLOAT: return IDL_binop_eval_float (op, a, b);	default: return NULL;	}}static IDL_tree IDL_unaryop_eval_integer (enum IDL_unaryop op, IDL_tree a){	IDL_tree p = NULL;	assert (IDL_NODE_TYPE (a) == IDLN_INTEGER);	switch (op) {	case IDL_UNARYOP_PLUS:		p = IDL_integer_new (IDL_INTEGER (a).value);		break;	case IDL_UNARYOP_MINUS:		p = IDL_integer_new (-IDL_INTEGER (a).value);		break;	case IDL_UNARYOP_COMPLEMENT:		p = IDL_integer_new (~IDL_INTEGER (a).value);		break;	}       	return p;}static IDL_tree IDL_unaryop_eval_fixed (enum IDL_unaryop op, IDL_tree a){	IDL_tree p = NULL;	assert (IDL_NODE_TYPE (a) == IDLN_FIXED);	switch (op) {	case IDL_UNARYOP_PLUS:		p = IDL_fixed_new (IDL_FIXED (a).value);		break;	default:		break;	}       	return p;}static IDL_tree IDL_unaryop_eval_float (enum IDL_unaryop op, IDL_tree a){	IDL_tree p = NULL;	assert (IDL_NODE_TYPE (a) == IDLN_FLOAT);	switch (op) {	case IDL_UNARYOP_PLUS:		p = IDL_float_new (IDL_FLOAT (a).value);		break;	case IDL_UNARYOP_MINUS:		p = IDL_float_new (-IDL_FLOAT (a).value);		break;	default:		break;	}       	return p;}static IDL_tree IDL_unaryop_eval (enum IDL_unaryop op, IDL_tree a){	switch (IDL_NODE_TYPE (a)) {	case IDLN_INTEGER: return IDL_unaryop_eval_integer (op, a);	case IDLN_FIXED: return IDL_unaryop_eval_fixed (op, a);	case IDLN_FLOAT: return IDL_unaryop_eval_float (op, a);	default: return NULL;	}}IDL_tree IDL_resolve_const_exp (IDL_tree p, IDL_tree_type type){	gboolean resolved_value = FALSE, die = FALSE;	gboolean wrong_type = FALSE;	while (!resolved_value && !die) {		if (IDL_NODE_TYPE (p) == IDLN_IDENT) {			IDL_tree q = IDL_NODE_UP (p);						assert (q != NULL);			if (IDL_NODE_UP (q) &&			    IDL_NODE_TYPE (IDL_NODE_UP (q)) == IDLN_TYPE_ENUM) {				p = q;				die = TRUE;				break;			} else if (IDL_NODE_TYPE (q) != IDLN_CONST_DCL) {				p = q;				wrong_type = TRUE;				die = TRUE;			} else 				p = IDL_CONST_DCL (q).const_exp;		}				if (p == NULL ||		    IDL_NODE_TYPE (p) == IDLN_BINOP ||		    IDL_NODE_TYPE (p) == IDLN_UNARYOP) {			die = TRUE;			continue;		}				resolved_value = IDL_NODE_IS_LITERAL (p);	}	if (resolved_value &&	    type != IDLN_ANY &&	    IDL_NODE_TYPE (p) != type)		wrong_type = TRUE;		if (wrong_type) {		yyerror ("Invalid type for constant");		IDL_tree_error (p, "Previous resolved type declaration");		return NULL;	}	return resolved_value ? p : NULL;}void IDL_queue_new_ident_comment (const char *str){	g_return_if_fail (str != NULL);	__IDL_new_ident_comments = g_slist_append (__IDL_new_ident_comments, g_strdup (str));}/* * Local variables: * mode: C * c-basic-offset: 8 * tab-width: 8 * indent-tabs-mode: t * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -