Skip to content

Commit

Permalink
add the ability to disable syntax deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Dec 10, 2014
1 parent 6730574 commit 1ef4558
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
5 changes: 5 additions & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ end

_repl_start = Condition()

function syntax_deprecation_warnings(warn::Bool)
ccall(:jl_parse_depwarn, Void, (Cint,), warn)
warn
end

function parse_input_line(s::AbstractString)
# s = bytestring(s)
# (expr, pos) = parse(s, 1)
Expand Down
15 changes: 15 additions & 0 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,18 @@ end

warn(err::Exception; prefix="ERROR: ", kw...) =
warn(sprint(io->showerror(io,err)), prefix=prefix; kw...)

# Julia compiler options struct
immutable JLCompilerOpts
build_path::Ptr{Cchar}
code_coverage::Int8
malloc_log::Int8
check_bounds::Int8
dumpbitcode::Int8
int_literals::Cint
compile_enabled::Int8
opt_level::Int8
no_depwarn::Int8
end

compileropts() = unsafe_load(cglobal(:jl_compileropts, JLCompilerOpts))
10 changes: 10 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static builtinspec_t julia_flisp_ast_ext[] = {
{ NULL, NULL }
};

extern void jl_parse_depwarn(int warn);

DLLEXPORT void jl_init_frontend(void)
{
fl_init(4*1024*1024);
Expand All @@ -136,6 +138,9 @@ DLLEXPORT void jl_init_frontend(void)
false_sym = symbol("false");
fl_error_sym = symbol("error");
fl_null_sym = symbol("null");

// Enable / disable syntax deprecation warnings
jl_parse_depwarn((int)jl_compileropts.depwarn);
}

DLLEXPORT void jl_lisp_prompt(void)
Expand Down Expand Up @@ -507,6 +512,11 @@ void jl_stop_parsing(void)
fl_applyn(0, symbol_value(symbol("jl-parser-close-stream")));
}

DLLEXPORT void jl_parse_depwarn(int warn)
{
fl_applyn(1, symbol_value(symbol("jl-parser-depwarn")), warn? FL_T : FL_F);
}

extern int jl_lineno;

jl_value_t *jl_parse_next(void)
Expand Down
3 changes: 2 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ jl_compileropts_t jl_compileropts = { NULL, // build_path
JL_COMPILEROPT_DUMPBITCODE_OFF,
0, // int_literals
JL_COMPILEROPT_COMPILE_DEFAULT,
0 // opt_level
0, // opt_level
1, // depwarn
};

int jl_boot_file_loaded = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
(set! *filename-stack* (cdr *filename-stack*))
(set! *ts-stack* (cdr *ts-stack*)))

(define *depwarn* #t)
(define (jl-parser-depwarn w)
(set! *depwarn* (eq? w #t)))

(define (jl-parser-next)
(let* ((err (parser-wrap
(lambda ()
Expand Down
23 changes: 12 additions & 11 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,18 @@
;; --- misc ---

(define (syntax-deprecation-warning s what instead)
(io.write
*stderr*
(string
#\newline "WARNING: deprecated syntax \"" what "\""
(if (eq? current-filename 'none)
""
(string " at " current-filename ":" (input-port-line (ts:port s))))
"."
(if (equal? instead "")
""
(string #\newline "Use \"" instead "\" instead." #\newline)))))
(if *depwarn*
(io.write
*stderr*
(string
#\newline "WARNING: deprecated syntax \"" what "\""
(if (eq? current-filename 'none)
""
(string " at " current-filename ":" (input-port-line (ts:port s))))
"."
(if (equal? instead "")
""
(string #\newline "Use \"" instead "\" instead." #\newline))))))

;; --- parser ---

Expand Down
2 changes: 2 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ void jl_init_restored_modules();
// front end interface
DLLEXPORT jl_value_t *jl_parse_input_line(const char *str);
DLLEXPORT jl_value_t *jl_parse_string(const char *str, int pos0, int greedy);
DLLEXPORT void jl_parse_depwarn(int warn);
int jl_start_parsing_file(const char *fname);
void jl_stop_parsing(void);
jl_value_t *jl_parse_next(void);
Expand Down Expand Up @@ -1336,6 +1337,7 @@ typedef struct {
int int_literals;
int8_t compile_enabled;
int8_t opt_level;
int8_t depwarn;
} jl_compileropts_t;

extern DLLEXPORT jl_compileropts_t jl_compileropts;
Expand Down
7 changes: 6 additions & 1 deletion ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static const char *opts =
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n"
" -O, --optimize Run time-intensive code optimizations\n"
" --int-literals={32|64} Select integer literal size independent of platform\n"
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n";
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n"
" --no-depwarn Turn off deprecated syntax warnings\n";

void parse_opts(int *argcp, char ***argvp)
{
Expand All @@ -106,6 +107,7 @@ void parse_opts(int *argcp, char ***argvp)
{ "int-literals", required_argument, 0, 301 },
{ "dump-bitcode", required_argument, 0, 302 },
{ "compile", required_argument, 0, 303 },
{ "no-depwarn", optional_argument, 0, 304 },
{ 0, 0, 0, 0 }
};
int c;
Expand Down Expand Up @@ -198,6 +200,9 @@ void parse_opts(int *argcp, char ***argvp)
exit(1);
}
break;
case 304:
jl_compileropts.depwarn = 0;
break;
default:
ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c);
ios_printf(ios_stderr, "This is a bug, please report it.\n");
Expand Down

0 comments on commit 1ef4558

Please sign in to comment.