📄 decl.c
字号:
fputs (" ", file); if (DECL_WEAK_NAME (node)) fprintf (file, "weak_name "); if (CH_DECL_SIGNAL (node)) fprintf (file, "decl_signal "); print_node (file, "tasking_code", (tree)DECL_TASKING_CODE_DECL (node), indent + 4);}voidprint_lang_type (file, node, indent) FILE *file; tree node; int indent;{ tree temp; indent_to (file, indent + 3); if (CH_IS_BUFFER_MODE (node)) fprintf (file, "buffer_mode "); if (CH_IS_EVENT_MODE (node)) fprintf (file, "event_mode "); if (CH_IS_EVENT_MODE (node) || CH_IS_BUFFER_MODE (node)) { temp = max_queue_size (node); if (temp) print_node_brief (file, "qsize", temp, indent + 4); }}voidprint_lang_identifier (file, node, indent) FILE *file; tree node; int indent;{ print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); print_node (file, "outer", IDENTIFIER_OUTER_VALUE (node), indent + 4); print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); print_node (file, "signal_dest", IDENTIFIER_SIGNAL_DEST (node), indent + 4); indent_to (file, indent + 3); if (IDENTIFIER_SIGNAL_DATA(node)) fprintf (file, "signal_data ");}/* initialise non-value struct */static intinit_nonvalue_struct (expr) tree expr;{ tree type = TREE_TYPE (expr); tree field; int res = 0; if (CH_IS_BUFFER_MODE (type)) { expand_expr_stmt ( build_chill_modify_expr ( build_component_ref (expr, get_identifier ("__buffer_data")), null_pointer_node)); return 1; } else if (CH_IS_EVENT_MODE (type)) { expand_expr_stmt ( build_chill_modify_expr ( build_component_ref (expr, get_identifier ("__event_data")), null_pointer_node)); return 1; } else if (CH_IS_ASSOCIATION_MODE (type)) { expand_expr_stmt ( build_chill_modify_expr (expr, chill_convert_for_assignment (type, association_init_value, "association"))); return 1; } else if (CH_IS_ACCESS_MODE (type)) { init_access_location (expr, type); return 1; } else if (CH_IS_TEXT_MODE (type)) { init_text_location (expr, type); return 1; } for (field = TYPE_FIELDS (type); field != NULL_TREE; field = TREE_CHAIN (field)) { type = TREE_TYPE (field); if (CH_TYPE_NONVALUE_P (type)) { tree exp = build_component_ref (expr, DECL_NAME (field)); if (TREE_CODE (type) == RECORD_TYPE) res |= init_nonvalue_struct (exp); else if (TREE_CODE (type) == ARRAY_TYPE) res |= init_nonvalue_array (exp); } } return res;}/* initialize non-value array *//* do it with DO FOR unique-id IN expr; ... OD; */static intinit_nonvalue_array (expr) tree expr;{ tree tmpvar = get_unique_identifier ("NONVALINIT"); tree type; int res = 0; push_loop_block (); build_loop_iterator (tmpvar, expr, NULL_TREE, NULL_TREE, 0, 1, 0); nonvalue_begin_loop_scope (); build_loop_start (NULL_TREE); tmpvar = lookup_name (tmpvar); type = TREE_TYPE (tmpvar); if (CH_TYPE_NONVALUE_P (type)) { if (TREE_CODE (type) == RECORD_TYPE) res |= init_nonvalue_struct (tmpvar); else if (TREE_CODE (type) == ARRAY_TYPE) res |= init_nonvalue_array (tmpvar); } build_loop_end (); nonvalue_end_loop_scope (); pop_loop_block (); return res;}/* This excessive piece of code sets DECL_NESTING_LEVEL (DECL) to LEVEL. */voidset_nesting_level (decl, level) tree decl; int level;{ static tree *small_ints = NULL; static int max_small_ints = 0; if (level < 0) decl->decl.vindex = NULL_TREE; else { if (level >= max_small_ints) { int new_max = level + 20; if (small_ints == NULL) small_ints = (tree*)xmalloc (new_max * sizeof(tree)); else small_ints = (tree*)xrealloc (small_ints, new_max * sizeof(tree)); while (max_small_ints < new_max) small_ints[max_small_ints++] = NULL_TREE; } if (small_ints[level] == NULL_TREE) { push_obstacks (&permanent_obstack, &permanent_obstack); small_ints[level] = build_int_2 (level, 0); pop_obstacks (); } /* set DECL_NESTING_LEVEL */ decl->decl.vindex = small_ints[level]; }}/* OPT_EXTERNAL is non-zero when the declaration is at module level. * OPT_EXTERNAL == 2 means implicitly grant it. */voiddo_decls (names, type, opt_static, lifetime_bound, opt_init, opt_external) tree names; tree type; int opt_static; int lifetime_bound; tree opt_init; int opt_external;{ if (names == NULL_TREE || TREE_CODE (names) == TREE_LIST) { for (; names != NULL_TREE; names = TREE_CHAIN (names)) do_decl (TREE_VALUE (names), type, opt_static, lifetime_bound, opt_init, opt_external); } else if (TREE_CODE (names) != ERROR_MARK) do_decl (names, type, opt_static, lifetime_bound, opt_init, opt_external);}treedo_decl (name, type, is_static, lifetime_bound, opt_init, opt_external) tree name, type; int is_static; int lifetime_bound; tree opt_init; int opt_external;{ tree decl; if (current_function_decl == global_function_decl && ! lifetime_bound /*&& opt_init != NULL_TREE*/) seen_action = 1; if (pass < 2) { push_obstacks (&permanent_obstack, &permanent_obstack); decl = make_node (VAR_DECL); DECL_NAME (decl) = name; TREE_TYPE (decl) = type; DECL_ASSEMBLER_NAME (decl) = name; /* Try to put things in common when possible. Tasking variables must go into common. */ DECL_COMMON (decl) = 1; DECL_EXTERNAL (decl) = opt_external > 0; TREE_PUBLIC (decl) = opt_external > 0; TREE_STATIC (decl) = is_static; if (pass == 0) { /* We have to set this here, since we build the decl w/o calling `build_decl'. */ DECL_INITIAL (decl) = opt_init; pushdecl (decl); finish_decl (decl); } else { save_decl (decl); pop_obstacks (); } DECL_INITIAL (decl) = opt_init; if (opt_external > 1 || in_pseudo_module) push_granted (DECL_NAME (decl), decl); } else /* pass == 2 */ { tree temp = NULL_TREE; int init_it = 0; decl = get_next_decl (); if (name != DECL_NAME (decl)) abort (); type = TREE_TYPE (decl); push_obstacks_nochange (); if (TYPE_READONLY_PROPERTY (type)) { if (CH_TYPE_NONVALUE_P (type)) { error_with_decl (decl, "`%s' must not be declared readonly"); opt_init = NULL_TREE; /* prevent subsequent errors */ } else if (opt_init == NULL_TREE && !opt_external) error("declaration of readonly variable without initialization"); } TREE_READONLY (decl) = TYPE_READONLY (type); if (!opt_init && chill_varying_type_p (type)) { tree fixed_part_type = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (type))); if (fixed_part_type != NULL_TREE && TREE_CODE (fixed_part_type) != ERROR_MARK) { if (CH_CHARS_TYPE_P (fixed_part_type)) opt_init = build_chill_string (0, ""); else opt_init = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); lifetime_bound = 1; } } if (opt_init) { if (CH_TYPE_NONVALUE_P (type)) { error_with_decl (decl, "no initialisation allowed for `%s'"); temp = NULL_TREE; } else if (TREE_CODE (type) == REFERENCE_TYPE) { /* A loc-identity declaration */ if (! CH_LOCATION_P (opt_init)) { error_with_decl (decl, "value for loc-identity `%s' is not a location"); temp = NULL_TREE; } else if (! CH_READ_COMPATIBLE (TREE_TYPE (type), TREE_TYPE (opt_init))) { error_with_decl (decl, "location for `%s' not read-compatible"); temp = NULL_TREE; } else temp = convert (type, opt_init); } else { /* Normal location declaration */ char place[80]; sprintf (place, "`%.60s' initializer", IDENTIFIER_POINTER (DECL_NAME (decl))); temp = chill_convert_for_assignment (type, opt_init, place); } } else if (CH_TYPE_NONVALUE_P (type)) { temp = NULL_TREE; init_it = 1; } DECL_INITIAL (decl) = NULL_TREE; if (temp != NULL_TREE && TREE_CODE (temp) != ERROR_MARK) { /* The same for stack variables (assuming no nested modules). */ if (lifetime_bound || !is_static) { if (is_static && ! TREE_CONSTANT (temp)) error_with_decl (decl, "nonconstant initializer for `%s'"); else DECL_INITIAL (decl) = temp; } } finish_decl (decl); /* Initialize the variable unless initialized statically. */ if ((!is_static || ! lifetime_bound) && temp != NULL_TREE && TREE_CODE (temp) != ERROR_MARK) { int was_used = TREE_USED (decl); emit_line_note (input_filename, lineno); expand_expr_stmt (build_chill_modify_expr (decl, temp)); /* Don't let the initialization count as "using" the variable. */ TREE_USED (decl) = was_used; if (current_function_decl == global_function_decl) build_constructor = 1; } else if (init_it && TREE_CODE (type) != ERROR_MARK) { /* Initialize variables with non-value type */ int was_used = TREE_USED (decl); int something_initialised = 0; emit_line_note (input_filename, lineno); if (TREE_CODE (type) == RECORD_TYPE) something_initialised = init_nonvalue_struct (decl); else if (TREE_CODE (type) == ARRAY_TYPE) something_initialised = init_nonvalue_array (decl); if (! something_initialised) { error ("do_decl: internal error: don't know what to initialize"); abort (); } /* Don't let the initialization count as "using" the variable. */ TREE_USED (decl) = was_used; if (current_function_decl == global_function_decl) build_constructor = 1; } } return decl;}/* * ARGTYPES is a tree_list of formal argument types. TREE_VALUE * is the type tree for each argument, while the attribute is in * TREE_PURPOSE. */treebuild_chill_function_type (return_type, argtypes, exceptions, recurse_p) tree return_type, argtypes, exceptions, recurse_p;{ tree ftype, arg; if (exceptions != NULL_TREE) { /* if we have exceptions we add 2 arguments, callers filename and linenumber. These arguments will be added automatically when calling a function which may raise exceptions. */ argtypes = chainon (argtypes, build_tree_list (NULL_TREE, ridpointers[(int) RID_PTR])); argtypes = chainon (argtypes, build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]));} /* Indicate the argument list is complete. */ argtypes = chainon (argtypes, build_tree_list (NULL_TREE, void_type_node)); /* INOUT and OUT parameters must be a REFERENCE_TYPE since we'll be passing a temporary's address at call time. */ for (arg = argtypes; arg; arg = TREE_CHAIN (arg)) if (TREE_PURPOSE (arg) == ridpointers[(int) RID_LOC] || TREE_PURPOSE (arg) == ridpointers[(int) RID_OUT] || TREE_PURPOSE (arg) == ridpointers[(int) RID_INOUT] ) TREE_VALUE (arg) = build_chill_reference_type (TREE_VALUE (arg)); /* Cannot use build_function_type, because if does hash-canonlicalization. */ ftype = make_node (FUNCTION_TYPE); TREE_TYPE (ftype) = return_type ? return_type : void_type_node ; TYPE_ARG_TYPES (ftype) = argtypes; if (exceptions) ftype = build_exception_variant (ftype, exceptions); if (recurse_p) sorry ("RECURSIVE PROCs"); return ftype;}/* * ARGTYPES is a tree_list of formal argument types. */treepush_extern_function (name, typespec, argtypes, exceptions, granting) tree name, typespec, argtypes, exceptions; int granting ATTRIBUTE_UNUSED;/*If 0 do pushdecl(); if 1 do push_granted()*/{ tree ftype, fndecl; push_obstacks_nochange (); end_temporary_allocation (); if (pass < 2) { ftype = build_chill_function_type (typespec, argtypes, exceptions, NULL_TREE); fndecl = build_decl (FUNCTION_DECL, name, ftype); DECL_EXTERNAL(fndecl) = 1; TREE_STATIC (fndecl) = 1; TREE_PUBLIC (fndecl) = 1; if (pass == 0) { pushdecl (fndecl); finish_decl (fndecl); } else { save_decl (fndecl);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -