📄 grant.c
字号:
mode_string = decode_mode (TREE_TYPE (type)); APPEND (result, mode_string->str); FREE (mode_string); APPEND (result, "("); mode_string = decode_constant (TYPE_MIN_VALUE (type)); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_TYPE (type) != ridpointers[(int) RID_BIN]) { APPEND (result, ":"); mode_string = decode_constant (TYPE_MAX_VALUE (type)); APPEND (result, mode_string->str); FREE (mode_string); } APPEND (result, ")"); return result; } /* We test TYPE_MAIN_VARIANT because pushdecl often builds a copy of a built-in type node, which is logically id- entical but has a different address, and the same TYPE_MAIN_VARIANT. */ /* FIXME this should not be needed! */ base_type = TREE_TYPE (type) ? TREE_TYPE (type) : type; if (TREE_UNSIGNED (base_type)) { if (base_type == chill_unsigned_type_node || TYPE_MAIN_VARIANT(base_type) == TYPE_MAIN_VARIANT (chill_unsigned_type_node)) name_ptr = "UINT"; else if (base_type == long_integer_type_node || TYPE_MAIN_VARIANT(base_type) == TYPE_MAIN_VARIANT (long_unsigned_type_node)) name_ptr = "ULONG"; else if (type == unsigned_char_type_node || TYPE_MAIN_VARIANT(base_type) == TYPE_MAIN_VARIANT (unsigned_char_type_node)) name_ptr = "UBYTE"; else if (type == duration_timing_type_node || TYPE_MAIN_VARIANT (base_type) == TYPE_MAIN_VARIANT (duration_timing_type_node)) name_ptr = "DURATION"; else if (type == abs_timing_type_node || TYPE_MAIN_VARIANT (base_type) == TYPE_MAIN_VARIANT (abs_timing_type_node)) name_ptr = "TIME"; else name_ptr = "UINT"; } else { if (base_type == chill_integer_type_node || TYPE_MAIN_VARIANT (base_type) == TYPE_MAIN_VARIANT (chill_integer_type_node)) name_ptr = "INT"; else if (base_type == long_integer_type_node || TYPE_MAIN_VARIANT (base_type) == TYPE_MAIN_VARIANT (long_integer_type_node)) name_ptr = "LONG"; else if (type == signed_char_type_node || TYPE_MAIN_VARIANT (base_type) == TYPE_MAIN_VARIANT (signed_char_type_node)) name_ptr = "BYTE"; else name_ptr = "INT"; } APPEND (result, name_ptr); /* see if we have a range */ if (TREE_TYPE (type) != NULL) { mode_string = decode_constant (TYPE_MIN_VALUE (type)); APPEND (result, mode_string->str); FREE (mode_string); APPEND (result, ":"); mode_string = decode_constant (TYPE_MAX_VALUE (type)); APPEND (result, mode_string->str); FREE (mode_string); } return result;}static treefind_enum_parent (enumname, all_decls) tree enumname; tree all_decls;{ tree wrk; for (wrk = all_decls; wrk != NULL_TREE; wrk = TREE_CHAIN (wrk)) { if (TREE_TYPE (wrk) != NULL_TREE && TREE_CODE (wrk) != CONST_DECL && TREE_CODE (TREE_TYPE (wrk)) == ENUMERAL_TYPE) { tree list; for (list = TYPE_VALUES (TREE_TYPE (wrk)); list != NULL_TREE; list = TREE_CHAIN (list)) { if (DECL_NAME (TREE_VALUE (list)) == enumname) return wrk; } } } return NULL_TREE;}static MYSTRING *print_integer_selective (type, all_decls) tree type; tree all_decls;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; if (TREE_TYPE (type)) { mode_string = decode_mode_selective (TREE_TYPE (type), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); if (TREE_TYPE (type) == ridpointers[(int)RID_RANGE] && TREE_CODE (TYPE_MIN_VALUE (type)) == IDENTIFIER_NODE && TREE_CODE (TYPE_MAX_VALUE (type)) == IDENTIFIER_NODE) { /* we have a range of a set. Find parant mode and write it to SPEC MODULE. This will loose if the parent mode was SEIZED from another file.*/ tree minparent = find_enum_parent (TYPE_MIN_VALUE (type), all_decls); tree maxparent = find_enum_parent (TYPE_MAX_VALUE (type), all_decls); if (minparent != NULL_TREE) { if (! CH_ALREADY_GRANTED (minparent)) { mode_string = decode_decl (minparent); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); CH_ALREADY_GRANTED (minparent) = 1; } } if (minparent != maxparent && maxparent != NULL_TREE) { if (!CH_ALREADY_GRANTED (maxparent)) { mode_string = decode_decl (maxparent); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); CH_ALREADY_GRANTED (maxparent) = 1; } } } else { mode_string = decode_constant_selective (TYPE_MIN_VALUE (type), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); mode_string = decode_constant_selective (TYPE_MAX_VALUE (type), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } return result; } /* see if we have a range */ if (TREE_TYPE (type) != NULL) { mode_string = decode_constant_selective (TYPE_MIN_VALUE (type), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); mode_string = decode_constant_selective (TYPE_MAX_VALUE (type), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } return result;}static MYSTRING *print_struct (type) tree type;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; tree fields; if (chill_varying_type_p (type)) { mode_string = grant_array_type (type); APPEND (result, mode_string->str); FREE (mode_string); } else { fields = TYPE_FIELDS (type); APPEND (result, "STRUCT ("); while (fields != NULL_TREE) { if (TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) { tree variants; /* Format a tagged variant record type. */ APPEND (result, " CASE "); if (TYPE_TAGFIELDS (TREE_TYPE (fields)) != NULL_TREE) { tree tag_list = TYPE_TAGFIELDS (TREE_TYPE (fields)); for (;;) { tree tag_name = DECL_NAME (TREE_VALUE (tag_list)); APPEND (result, IDENTIFIER_POINTER (tag_name)); tag_list = TREE_CHAIN (tag_list); if (tag_list == NULL_TREE) break; APPEND (result, ", "); } } APPEND (result, " OF\n"); variants = TYPE_FIELDS (TREE_TYPE (fields)); /* Each variant is a FIELD_DECL whose type is an anonymous struct within the anonymous union. */ while (variants != NULL_TREE) { tree tag_list = TYPE_TAG_VALUES (TREE_TYPE (variants)); tree struct_elts = TYPE_FIELDS (TREE_TYPE (variants)); while (tag_list != NULL_TREE) { tree tag_values = TREE_VALUE (tag_list); APPEND (result, " ("); while (tag_values != NULL_TREE) { mode_string = get_tag_value (TREE_VALUE (tag_values)); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_CHAIN (tag_values) != NULL_TREE) { APPEND (result, ",\n "); tag_values = TREE_CHAIN (tag_values); } else break; } APPEND (result, ")"); tag_list = TREE_CHAIN (tag_list); if (tag_list) APPEND (result, ","); else break; } APPEND (result, " : "); while (struct_elts != NULL_TREE) { mode_string = decode_decl (struct_elts); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_CHAIN (struct_elts) != NULL_TREE) APPEND (result, ",\n "); struct_elts = TREE_CHAIN (struct_elts); } variants = TREE_CHAIN (variants); if (variants != NULL_TREE && TREE_CHAIN (variants) == NULL_TREE && DECL_NAME (variants) == ELSE_VARIANT_NAME) { tree else_elts = TYPE_FIELDS (TREE_TYPE (variants)); APPEND (result, "\n ELSE "); while (else_elts != NULL_TREE) { mode_string = decode_decl (else_elts); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_CHAIN (else_elts) != NULL_TREE) APPEND (result, ",\n "); else_elts = TREE_CHAIN (else_elts); } break; } if (variants != NULL_TREE) APPEND (result, ",\n"); } APPEND (result, "\n ESAC"); } else { mode_string = decode_decl (fields); APPEND (result, mode_string->str); FREE (mode_string); } fields = TREE_CHAIN (fields); if (fields != NULL_TREE) APPEND (result, ",\n "); } APPEND (result, ")"); } return result;}static MYSTRING *print_struct_selective (type, all_decls) tree type; tree all_decls;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; tree fields; if (chill_varying_type_p (type)) { mode_string = grant_array_type_selective (type, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } else { fields = TYPE_FIELDS (type); while (fields != NULL_TREE) { if (TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) { tree variants; /* Format a tagged variant record type. */ variants = TYPE_FIELDS (TREE_TYPE (fields)); /* Each variant is a FIELD_DECL whose type is an anonymous struct within the anonymous union. */ while (variants != NULL_TREE) { tree tag_list = TYPE_TAG_VALUES (TREE_TYPE (variants)); tree struct_elts = TYPE_FIELDS (TREE_TYPE (variants)); while (tag_list != NULL_TREE) { tree tag_values = TREE_VALUE (tag_list); while (tag_values != NULL_TREE) { mode_string = get_tag_value_selective (TREE_VALUE (tag_values), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); if (TREE_CHAIN (tag_values) != NULL_TREE) tag_values = TREE_CHAIN (tag_values); else break; } tag_list = TREE_CHAIN (tag_list); if (!tag_list) break; } while (struct_elts != NULL_TREE) { mode_string = decode_decl_selective (struct_elts, all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); struct_elts = TREE_CHAIN (struct_elts); } variants = TREE_CHAIN (variants); if (variants != NULL_TREE && TREE_CHAIN (variants) == NULL_TREE && DECL_NAME (variants) == ELSE_VARIANT_NAME) { tree else_elts = TYPE_FIELDS (TREE_TYPE (variants)); while (else_elts != NULL_TREE) { mode_string = decode_decl_selective (else_elts, all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); else_elts = TREE_CHAIN (else_elts); } break; } } } else { mode_string = decode_decl_selective (fields, all_decls); APPEND (result, mode_string->str); FREE (mode_string); } fields = TREE_CHAIN (fields); } } return result;}static MYSTRING *print_proc_exceptions (ex) tree ex;{ MYSTRING *result = newstring (""); if (ex != NULL_TREE) { APPEND (result, "\n EXCEPTIONS ("); for ( ; ex != NULL_TREE; ex = TREE_CHAIN (ex)) { APPEND (result, IDENTIFIER_POINTER (TREE_VALUE (ex))); if (TREE_CHAIN (ex) != NULL_TREE) APPEND (result, ",\n "); } APPEND (result, ")"); } return result;}static MYSTRING *print_proc_tail (type, args, print_argnames) tree type; tree args; int print_argnames;{ 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++) { char buf[20]; tree argmode = TREE_VALUE (args); tree attribute = TREE_PURPOSE (args); if (argmode == void_type_node) continue; /* if we have exceptions don't print last 2 arguments */ if (TYPE_RAISES_EXCEPTIONS (type) && count == stopat) break; if (count) APPEND (result, ",\n "); if (print_argnames) { sprintf(buf, "arg%d ", count); APPEND (result, buf); } if (attribute == ridpointers[(int) RID_LOC]) argmode = TREE_TYPE (argmode); mode_string = get_type (argmode); APPEND (result, mode_string->str); FREE (mode_string); if (attribute != NULL_TREE) { sprintf (buf, " %s", IDENTIFIER_POINTER (attribute)); APPEND (result, buf); } } APPEND (result, ")"); /* return type */ { tree retn_type = TREE_TYPE (type); if (retn_type != NULL_TREE && TREE_CODE (retn_type) != VOID_TYPE) { mode_string = get_type (retn_type); APPEND (result, "\n RETURNS ("); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_CODE (retn_type) == REFERENCE_TYPE) APPEND (result, " LOC"); APPEND (result, ")"); } } mode_string = print_proc_exceptions (TYPE_RAISES_EXCEPTIONS (type)); APPEND (result, mode_string->str); FREE (mode_string); return result;}static MYSTRING *print_proc_tail_selective (type, args, all_decls) tree type; tree args; tree all_decls;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -