📄 grant.c
字号:
{ MYSTRING *result = newstring (""); MYSTRING *mode_string; int count = 0; int stopat = list_length (args) - 3; /* do the argument modes */ for ( ; args != NULL_TREE; args = TREE_CHAIN (args), count++) { tree argmode = TREE_VALUE (args); tree attribute = TREE_PURPOSE (args); if (argmode == void_type_node) continue; /* if we have exceptions don't process last 2 arguments */ if (TYPE_RAISES_EXCEPTIONS (type) && count == stopat) break; if (attribute == ridpointers[(int) RID_LOC]) argmode = TREE_TYPE (argmode); mode_string = get_type_selective (argmode, all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } /* return type */ { tree retn_type = TREE_TYPE (type); if (retn_type != NULL_TREE && TREE_CODE (retn_type) != VOID_TYPE) { mode_string = get_type_selective (retn_type, all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } } return result;}/* output a mode (or type). */static MYSTRING *decode_mode (type) tree type;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; switch ((enum chill_tree_code)TREE_CODE (type)) { case TYPE_DECL: if (DECL_NAME (type)) { APPEND (result, IDENTIFIER_POINTER (DECL_NAME (type))); return result; } type = TREE_TYPE (type); break; case IDENTIFIER_NODE: APPEND (result, IDENTIFIER_POINTER (type)); return result; case LANG_TYPE: /* LANG_TYPE are only used until satisfy is done, as place-holders for 'READ T', NEWMODE/SYNMODE modes, parameterised modes, and old-fashioned CHAR(N). */ if (TYPE_READONLY (type)) APPEND (result, "READ "); mode_string = get_type (TREE_TYPE (type)); APPEND (result, mode_string->str); if (TYPE_DOMAIN (type) != NULL_TREE) { /* Parameterized mode, or old-fashioned CHAR(N) string declaration.. */ APPEND (result, "("); mode_string = decode_constant (TYPE_DOMAIN (type)); APPEND (result, mode_string->str); APPEND (result, ")"); } FREE (mode_string); break; case ARRAY_TYPE: mode_string = grant_array_type (type); APPEND (result, mode_string->str); FREE (mode_string); break; case BOOLEAN_TYPE: APPEND (result, "BOOL"); break; case CHAR_TYPE: APPEND (result, "CHAR"); break; case ENUMERAL_TYPE: mode_string = print_enumeral (type); APPEND (result, mode_string->str); FREE (mode_string); break; case FUNCTION_TYPE: { tree args = TYPE_ARG_TYPES (type); APPEND (result, "PROC ("); mode_string = print_proc_tail (type, args, 0); APPEND (result, mode_string->str); FREE (mode_string); } break; case INTEGER_TYPE: mode_string = print_integer_type (type); APPEND (result, mode_string->str); FREE (mode_string); break; case RECORD_TYPE: if (CH_IS_INSTANCE_MODE (type)) { APPEND (result, "INSTANCE"); return result; } else if (CH_IS_BUFFER_MODE (type) || CH_IS_EVENT_MODE (type)) { tree bufsize = max_queue_size (type); APPEND (result, CH_IS_BUFFER_MODE (type) ? "BUFFER " : "EVENT "); if (bufsize != NULL_TREE) { APPEND (result, "("); mode_string = decode_constant (bufsize); APPEND (result, mode_string->str); APPEND (result, ") "); FREE (mode_string); } if (CH_IS_BUFFER_MODE (type)) { mode_string = decode_mode (buffer_element_mode (type)); APPEND (result, mode_string->str); FREE (mode_string); } break; } else if (CH_IS_ACCESS_MODE (type)) { tree indexmode, recordmode, dynamic; APPEND (result, "ACCESS"); recordmode = access_recordmode (type); indexmode = access_indexmode (type); dynamic = access_dynamic (type); if (indexmode != void_type_node) { mode_string = decode_mode (indexmode); APPEND (result, " ("); APPEND (result, mode_string->str); APPEND (result, ")"); FREE (mode_string); } if (recordmode != void_type_node) { mode_string = decode_mode (recordmode); APPEND (result, " "); APPEND (result, mode_string->str); FREE (mode_string); } if (dynamic != integer_zero_node) APPEND (result, " DYNAMIC"); break; } else if (CH_IS_TEXT_MODE (type)) { tree indexmode, dynamic, length; APPEND (result, "TEXT ("); length = text_length (type); indexmode = text_indexmode (type); dynamic = text_dynamic (type); mode_string = decode_constant (length); APPEND (result, mode_string->str); FREE (mode_string); APPEND (result, ")"); if (indexmode != void_type_node) { APPEND (result, " "); mode_string = decode_mode (indexmode); APPEND (result, mode_string->str); FREE (mode_string); } if (dynamic != integer_zero_node) APPEND (result, " DYNAMIC"); return result; } mode_string = print_struct (type); APPEND (result, mode_string->str); FREE (mode_string); break; case POINTER_TYPE: if (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE) APPEND (result, "PTR"); else { if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) { mode_string = get_type (TREE_TYPE (type)); APPEND (result, mode_string->str); FREE (mode_string); } else { APPEND (result, "REF "); mode_string = get_type (TREE_TYPE (type)); APPEND (result, mode_string->str); FREE (mode_string); } } break; case REAL_TYPE: if (TREE_INT_CST_LOW (TYPE_SIZE (type)) == 32) APPEND (result, "REAL"); else APPEND (result, "LONG_REAL"); break; case SET_TYPE: if (CH_BOOLS_TYPE_P (type)) mode_string = grant_array_type (type); else { APPEND (result, "POWERSET "); mode_string = get_type (TYPE_DOMAIN (type)); } APPEND (result, mode_string->str); FREE (mode_string); break; case REFERENCE_TYPE: mode_string = get_type (TREE_TYPE (type)); APPEND (result, mode_string->str); FREE (mode_string); break; default: APPEND (result, "/* ---- not implemented ---- */"); break; } return (result);}static treefind_in_decls (id, all_decls) tree id; tree all_decls;{ tree wrk; for (wrk = all_decls; wrk != NULL_TREE; wrk = TREE_CHAIN (wrk)) { if (DECL_NAME (wrk) == id || DECL_POSTFIX (wrk) == id) return wrk; } return NULL_TREE;}static intin_ridpointers (id) tree id;{ int i; for (i = RID_UNUSED; i < RID_MAX; i++) { if (id == ridpointers[i]) return 1; } return 0;}static voidgrant_seized_identifier (decl) tree decl;{ seizefile_list *wrk = selective_seizes; MYSTRING *mode_string; CH_ALREADY_GRANTED (decl) = 1; /* comes from a SPEC MODULE in the module */ if (DECL_SEIZEFILE (decl) == NULL_TREE) return; /* search file already in process */ while (wrk != 0) { if (wrk->filename == DECL_SEIZEFILE (decl)) break; wrk = wrk->next; } if (!wrk) { wrk = (seizefile_list *)xmalloc (sizeof (seizefile_list)); wrk->next = selective_seizes; selective_seizes = wrk; wrk->filename = DECL_SEIZEFILE (decl); wrk->seizes = newstring ("<> USE_SEIZE_FILE \""); APPEND (wrk->seizes, IDENTIFIER_POINTER (DECL_SEIZEFILE (decl))); APPEND (wrk->seizes, "\" <>\n"); } APPEND (wrk->seizes, "SEIZE "); mode_string = decode_prefix_rename (decl); APPEND (wrk->seizes, mode_string->str); FREE (mode_string); APPEND (wrk->seizes, ";\n");}static MYSTRING *decode_mode_selective (type, all_decls) tree type; tree all_decls;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; tree decl; switch ((enum chill_tree_code)TREE_CODE (type)) { case TYPE_DECL: /* FIXME: could this ever happen ?? */ if (DECL_NAME (type)) { FREE (result); result = decode_mode_selective (DECL_NAME (type), all_decls); return result; } break; case IDENTIFIER_NODE: if (in_ridpointers (type)) /* it's a predefined, we must not search the whole list */ return result; decl = find_in_decls (type, all_decls); if (decl != NULL_TREE) { if (CH_ALREADY_GRANTED (decl)) /* already processed */ return result; if (TREE_CODE (decl) == ALIAS_DECL && DECL_POSTFIX (decl) != NULL_TREE) { /* If CH_DECL_GRANTED, decl was granted into this scope, and so wasn't in the source code. */ if (!CH_DECL_GRANTED (decl)) { grant_seized_identifier (decl); } } else { result = decode_decl (decl); mode_string = decode_decl_selective (decl, all_decls); if (mode_string->len) { PREPEND (result, mode_string->str); } FREE (mode_string); } } return result; case LANG_TYPE: mode_string = get_type_selective (TREE_TYPE (type), all_decls); APPEND (result, mode_string->str); FREE (mode_string); break; case ARRAY_TYPE: mode_string = grant_array_type_selective (type, all_decls); APPEND (result, mode_string->str); FREE (mode_string); break; case BOOLEAN_TYPE: return result; break; case CHAR_TYPE: return result; break; case ENUMERAL_TYPE: mode_string = print_enumeral_selective (type, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); break; case FUNCTION_TYPE: { tree args = TYPE_ARG_TYPES (type); mode_string = print_proc_tail_selective (type, args, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } break; case INTEGER_TYPE: mode_string = print_integer_selective (type, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); break; case RECORD_TYPE: if (CH_IS_INSTANCE_MODE (type)) { return result; } else if (CH_IS_BUFFER_MODE (type) || CH_IS_EVENT_MODE (type)) { tree bufsize = max_queue_size (type); if (bufsize != NULL_TREE) { mode_string = decode_constant_selective (bufsize, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } if (CH_IS_BUFFER_MODE (type)) { mode_string = decode_mode_selective (buffer_element_mode (type), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } break; } else if (CH_IS_ACCESS_MODE (type)) { tree indexmode = access_indexmode (type); tree recordmode = access_recordmode (type); if (indexmode != void_type_node) { mode_string = decode_mode_selective (indexmode, all_decls); if (mode_string->len) { if (result->len && result->str[result->len - 1] != '\n') APPEND (result, ";\n"); APPEND (result, mode_string->str); } FREE (mode_string); } if (recordmode != void_type_node) { mode_string = decode_mode_selective (recordmode, all_decls); if (mode_string->len) { if (result->len && result->str[result->len - 1] != '\n') APPEND (result, ";\n"); APPEND (result, mode_string->str); } FREE (mode_string); } break; } else if (CH_IS_TEXT_MODE (type)) { tree indexmode = text_indexmode (type); tree length = text_length (type); mode_string = decode_constant_selective (length, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); if (indexmode != void_type_node) { mode_string = decode_mode_selective (indexmode, all_decls); if (mode_string->len) { if (result->len && result->str[result->len - 1] != '\n') APPEND (result, ";\n"); APPEND (result, mode_string->str); } FREE (mode_string); } break; } mode_string = print_struct_selective (type, all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); break; case POINTER_TYPE: if (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE) break; else { if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) { mode_string = get_type_selective (TREE_TYPE (type), all_decls);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -