[m-rev.] for review: Do not escape character strings in internal atom representation.
Peter Wang
novalazy at gmail.com
Mon May 26 12:21:47 AEST 2014
Branches: master, 14.01
The internal representation of a character constant as an atom term
should not use escaped character syntax; the escaping should occur
when writing the external representation only.
compiler/hlds_out_mode.m:
compiler/intermod.m:
compiler/prog_util.m:
compiler/type_constraints.m:
compiler/typecheck.m:
Fix instances of the bug.
tests/valid/Mercury.options
tests/valid/Mmakefile
tests/valid/intermod_char.m
tests/valid/intermod_char2.m
Add test case. The .opt file was invalid because the character
in the clause head was doubly-escaped.
diff --git a/compiler/hlds_out_mode.m b/compiler/hlds_out_mode.m
index 9583d96..70e9e6e 100644
--- a/compiler/hlds_out_mode.m
+++ b/compiler/hlds_out_mode.m
@@ -544,7 +544,7 @@ cons_id_and_args_to_term_full(ConsId, ArgTerms, Term) :-
Term = term.functor(term.string(String), [], Context)
;
ConsId = char_const(Char),
- SymName = unqualified(term_io.escaped_char(Char)),
+ SymName = unqualified(string.from_char(Char)),
construct_qualified_term(SymName, [], Term)
;
ConsId = impl_defined_const(String),
diff --git a/compiler/intermod.m b/compiler/intermod.m
index 5118f22..296ce1c 100644
--- a/compiler/intermod.m
+++ b/compiler/intermod.m
@@ -1935,7 +1935,7 @@ strip_headvar_unifications_from_goal_list([Goal | Goals0], HeadVars,
RHSTerm = term.functor(term.float(Float), [], Context)
;
ConsId = char_const(Char),
- RHSTerm = term.functor(term.atom(term_io.escaped_char(Char)),
+ RHSTerm = term.functor(term.atom(string.from_char(Char)),
[], Context)
;
ConsId = string_const(String),
diff --git a/compiler/prog_util.m b/compiler/prog_util.m
index 71ae7b6..03cb053 100644
--- a/compiler/prog_util.m
+++ b/compiler/prog_util.m
@@ -595,7 +595,7 @@ cons_id_and_args_to_term(float_const(Float), [], Term) :-
term.context_init(Context),
Term = term.functor(term.float(Float), [], Context).
cons_id_and_args_to_term(char_const(Char), [], Term) :-
- SymName = unqualified(term_io.escaped_char(Char)),
+ SymName = unqualified(string.from_char(Char)),
construct_qualified_term(SymName, [], Term).
cons_id_and_args_to_term(string_const(String), [], Term) :-
term.context_init(Context),
diff --git a/compiler/type_constraints.m b/compiler/type_constraints.m
index 6cd6fc1..6a565c9 100644
--- a/compiler/type_constraints.m
+++ b/compiler/type_constraints.m
@@ -2115,7 +2115,7 @@ builtin_atomic_type(int_const(_), builtin_type_int).
builtin_atomic_type(float_const(_), builtin_type_float).
builtin_atomic_type(string_const(_), builtin_type_string).
builtin_atomic_type(cons(unqualified(String), 0, _), builtin_type_char) :-
- term_io.string_is_escaped_char(_, String).
+ string.char_to_string(_, String).
builtin_atomic_type(impl_defined_const(Name), Type) :-
(
( Name = "file"
diff --git a/compiler/typecheck.m b/compiler/typecheck.m
index 01b0132..e6c2149 100644
--- a/compiler/typecheck.m
+++ b/compiler/typecheck.m
@@ -2561,10 +2561,6 @@ builtin_atomic_type(cons(unqualified(String), 0, _), "character") :-
% We are before post-typecheck, so character constants have not yet been
% converted to char_consts.
%
- % XXX We cannot use "term_io.string_is_escaped_char(_, String)"
- % because the characters in String have already had any backslash
- % characters in them processed by now.
- %
% XXX The parser should have a separate term.functor representation
% for character constants, which should be converted to char_consts
% during the term to item translation.
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 87627be..08994a9 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -74,6 +74,8 @@ MCFLAGS-inhibit_warn_test = --inhibit-warnings --halt-at-warn
MCFLAGS-instmap_generic_failure = --local-constraint-propagation
MCFLAGS-intermod_bug_nested = --intermodule-optimization
MCFLAGS-intermod_bug_nested.parser = --intermodule-optimization
+MCFLAGS-intermod_char = --intermodule-optimization
+MCFLAGS-intermod_char2 = --intermodule-optimization
MCFLAGS-intermod_dcg_bug2 = --intermodule-optimization
MCFLAGS-intermod_dcg_bug = --intermodule-optimization
MCFLAGS-intermod_impure2 = --intermodule-optimization
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index f4feefb..b75e2d1 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -147,6 +147,7 @@ OTHER_PROGS= \
inst_perf_bug_1 \
int64 \
intermod_bug_nested \
+ intermod_char \
intermod_dcg_bug \
intermod_impure \
intermod_lambda \
diff --git a/tests/valid/intermod_char.m b/tests/valid/intermod_char.m
new file mode 100644
index 0000000..e44674e
--- /dev/null
+++ b/tests/valid/intermod_char.m
@@ -0,0 +1,22 @@
+% Character constants in clause heads were doubly-escaped in .opt files.
+
+:- module intermod_char.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module intermod_char2.
+
+main(!IO) :-
+ ( p('\r') ->
+ true
+ ;
+ true
+ ).
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sts=4 sw=4 et
diff --git a/tests/valid/intermod_char2.m b/tests/valid/intermod_char2.m
new file mode 100644
index 0000000..22f75a1
--- /dev/null
+++ b/tests/valid/intermod_char2.m
@@ -0,0 +1,14 @@
+:- module intermod_char2.
+:- interface.
+
+:- import_module char.
+
+:- pred p(char::in) is semidet.
+
+:- implementation.
+
+p('\r').
+p('\n').
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sts=4 sw=4 et
--
1.8.4
More information about the reviews
mailing list