--- p/predef.c.orig Tue Jun 17 21:25:11 2003 +++ p/predef.c Thu Jun 26 00:59:18 2003 @@ -2472,14 +2472,52 @@ case p_Copy: case p_SubStr: + if (length == 2 && r_num == p_Copy) + chk_dialect_1 ("`%s' with only two arguments is", GNU_PASCAL, r_name); + STRIP_TYPE_NOPS (val); + val = fold (val); + STRIP_TYPE_NOPS (val2); + val2 = fold (val2); + if (length > 2) + { + STRIP_TYPE_NOPS (val3); + val3 = fold (val3); + } + if ((TREE_CODE (val) == STRING_CST || TREE_CODE (val) == INTEGER_CST) + && TREE_CODE (val2) == INTEGER_CST + && (length == 2 || TREE_CODE (val3) == INTEGER_CST)) + { + int l, m, n; + val = char_may_be_string (val); + assert (TREE_CODE (val) == STRING_CST); + l = TREE_STRING_LENGTH (val) - 1; + if (TREE_INT_CST_HIGH (val2) || TREE_INT_CST_LOW (val2) <= 0 || TREE_INT_CST_LOW (val2) > l + 1) + { + errstr = "argument 2 to `%s' out of range"; + break; + } + m = TREE_INT_CST_LOW (val2); + n = l - m + 1; + if (length > 2) + { + if (TREE_INT_CST_HIGH (val3) || TREE_INT_CST_LOW (val3) > n) + { + errstr = "argument 3 to `%s' out of range"; + break; + } + n = TREE_INT_CST_LOW (val3); + } + retval = build_string_constant (TREE_STRING_POINTER (val) + m - 1, n); + procflag = 0; + break; + } + else { int truncate = r_num == p_Copy; tree l0, l; /* If 3rd parameter is missing, pass MaxInt and let the RTS truncate */ if (length == 2) { - if (r_num == p_Copy) - chk_dialect_1 ("`%s' with only two arguments is", GNU_PASCAL, r_name); truncate = 1; apar = chainon (apar, build_tree_list (NULL_TREE, integer_maxint_node)); } --- p/expressions.c.orig Thu Jun 19 20:33:03 2003 +++ p/expressions.c Thu Jun 26 00:22:20 2003 @@ -3306,6 +3306,12 @@ for (t = params; t; t = TREE_CHAIN (t)) CHK_EM (TREE_VALUE (t)); + if (!current_function_decl) + { + error ("cannot call routine from a global declaration"); + return error_mark_node; + } + orig_type = TREE_TYPE (function); /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */ --- p/declarations.c.orig Mon Jun 16 17:54:30 2003 +++ p/declarations.c Thu Jun 26 00:24:01 2003 @@ -3064,7 +3064,12 @@ tree type; { tree var = declare_variable (get_unique_identifier (name_template), type, NULL_TREE, VQ_IMPLICIT); - init_any (var, 0); + + if (!current_function_decl) + error ("cannot evaluate this expression from a global declaration"); + else + init_any (var, 0); + /* In case the size of this variable can only be determined at run time, labels in this level will need fixups even if we thought they wouldn't need any. @@@@@@@ What to do?