[t][TT #1119] Convert t/op/bitwise.t to PIR
[parrot.git] / src / warnings.c
blob8d8ba10aba89d77995c0bf853100891cdd393f5b
1 /*
2 Copyright (C) 2001-2009, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/warnings.c - Warning and error reporting
9 =head1 DESCRIPTION
11 Parrot C<STRING> and C string versions of a function to print warning/error
12 messages.
14 =over 4
16 =cut
20 #include "parrot/parrot.h"
22 #include "pmc/pmc_context.h"
24 #include <stdarg.h>
26 /* HEADERIZER HFILE: include/parrot/warnings.h */
28 /* HEADERIZER BEGIN: static */
29 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
31 static INTVAL print_warning(PARROT_INTERP, ARGIN_NULLOK(STRING *msg))
32 __attribute__nonnull__(1);
34 #define ASSERT_ARGS_print_warning __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
35 PARROT_ASSERT_ARG(interp))
36 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
37 /* HEADERIZER END: static */
41 =item C<void print_pbc_location(PARROT_INTERP)>
43 Prints the bytecode location of the warning or error to C<Parrot_io_STDERR>.
45 =cut
49 PARROT_EXPORT
50 void
51 print_pbc_location(PARROT_INTERP)
53 ASSERT_ARGS(print_pbc_location)
54 Interp * const tracer = (interp->pdb && interp->pdb->debugger) ?
55 interp->pdb->debugger :
56 interp;
57 Parrot_io_eprintf(tracer, "%Ss\n",
58 Parrot_Context_infostr(interp, CURRENT_CONTEXT(interp)));
63 =item C<static INTVAL print_warning(PARROT_INTERP, STRING *msg)>
65 Prints the warning message and the bytecode location.
67 =cut
71 static INTVAL
72 print_warning(PARROT_INTERP, ARGIN_NULLOK(STRING *msg))
74 ASSERT_ARGS(print_warning)
75 if (!msg)
76 Parrot_io_puts(interp, Parrot_io_STDERR(interp), "Unknown warning\n");
77 else {
78 Parrot_io_putps(interp, Parrot_io_STDERR(interp), msg);
79 if (string_ord(interp, msg, -1) != '\n')
80 Parrot_io_eprintf(interp, "%c", '\n');
82 print_pbc_location(interp);
83 return 1;
88 =back
90 =head2 Parrot Warnings Interface
92 =over 4
94 =item C<INTVAL Parrot_warn(PARROT_INTERP, INTVAL warnclass, const char *message,
95 ...)>
97 The Parrot C string warning/error reporter.
99 Returns 2 on error, 1 on success.
101 C<message, ..> can be a C<Parrot_vsprintf_c()> format with arguments.
103 =cut
107 PARROT_EXPORT
108 PARROT_IGNORABLE_RESULT
109 INTVAL
110 Parrot_warn(PARROT_INTERP, INTVAL warnclass,
111 ARGIN(const char *message), ...)
113 ASSERT_ARGS(Parrot_warn)
114 if (!PARROT_WARNINGS_test(interp, warnclass))
115 return 2;
116 else {
117 STRING *targ;
118 va_list args;
120 va_start(args, message);
121 targ = Parrot_vsprintf_c(interp, message, args);
122 va_end(args);
123 return print_warning(interp, targ);
129 =back
131 =head1 SEE ALSO
133 F<include/parrot/warnings.h>.
135 =cut
141 * Local variables:
142 * c-file-style: "parrot"
143 * End:
144 * vim: expandtab shiftwidth=4: