mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 23:35:25 +00:00
Estimated hours taken: 16 Branches: main compiler/aditi_builtin_ops.m: compiler/bytecode.m: compiler/bytecode_backend.m: compiler/bytecode_gen.m: compiler/c_util.m: compiler/code_gen.m: compiler/deep_profiling.m: compiler/deforest.m: compiler/dependency_graph.m: compiler/fact_table.m: compiler/follow_code.m: compiler/handle_options.m: compiler/hlds_out.m: compiler/il_peephole.m: compiler/ilasm.m: compiler/java_util.m: compiler/liveness.m: compiler/magic.m: compiler/magic_util.m: compiler/make.dependencies.m: compiler/make.m: compiler/make.module_dep_file.m: compiler/make.program_target.m: compiler/make.util.m: compiler/matching.m: compiler/name_mangle.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/options.m: compiler/options_file.m: compiler/prog_io.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/saved_vars.m: compiler/source_file_map.m: compiler/stack_alloc.m: compiler/stack_layout.m: compiler/stratify.m: compiler/switch_detection.m: compiler/term_errors.m: compiler/type_ctor_info.m: compiler/unify_proc.m: compiler/unique_modes.m: Bring these modules up to date with our coding guidelines. Use predmode syntax for declarations. Use state variable syntax where appropriate, and reorder arguments where this is needed for the use of state variable syntax. Remove module qualification from the names of defined predicates when the module qualification was used inconsistently (causing problems for the use of tags) or was causing problems with indentation. There are no changes in algorithms.
188 lines
6.5 KiB
Mathematica
188 lines
6.5 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2002-2004 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% File: java_util.m
|
|
% Main authors: juliensf, mjwybrow.
|
|
|
|
% This module defines utility routines that are used by the
|
|
% Java backend. Much of the code below is similar to that in c_util.m;
|
|
% changes made to this module may require changes to c_util.m.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module ml_backend__java_util.
|
|
:- interface.
|
|
|
|
:- import_module backend_libs__builtin_ops.
|
|
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Succeeds iff the given string matches a reserved
|
|
% word in Java.
|
|
%
|
|
:- pred java_util__is_keyword(string::in) is semidet.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% The following predicates all take as input an operator,
|
|
% check if it is an operator of the specified kind,
|
|
% and if so, return the name of the corresponding Java operator
|
|
% that can be used to implement it.
|
|
%
|
|
|
|
% The operator returned will be either a prefix operator
|
|
% or function name. The operand needs
|
|
% to be placed in parentheses after the operator name.
|
|
%
|
|
:- pred java_util__unary_prefix_op(unary_op::in, string::out) is det.
|
|
|
|
% The operator returned will be <, >, etc.;
|
|
% it can be used in the form:
|
|
% `<string_object>.CompareTo(<Arg1>, <Arg2>) <Op> 0'.
|
|
%
|
|
:- pred java_util__string_compare_op(binary_op::in, string::out) is semidet.
|
|
|
|
% The operator returned will be +, *, etc.;
|
|
% the arguments should be floats and the result will be a float.
|
|
%
|
|
:- pred java_util__float_op(binary_op::in, string::out) is semidet.
|
|
|
|
% The operator returned will be <, >, etc.;
|
|
% the arguments should be floats and the result will be a boolean.
|
|
%
|
|
:- pred java_util__float_compare_op(binary_op::in, string::out) is semidet.
|
|
|
|
% The operator returned will be an infix operator.
|
|
% The arguments should be integer or booleans
|
|
% and the result will be an integer or a boolean.
|
|
%
|
|
:- pred java_util__binary_infix_op(binary_op::in, string::out) is semidet.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module parse_tree__error_util.
|
|
|
|
:- import_module list.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Tags are not used in the Java back-end, as such, all of the tagging
|
|
% operators except for `tag' return no-ops. The `tag' case is handled
|
|
% seperately in mlds_to_java__output_std_unop.
|
|
%
|
|
java_util__unary_prefix_op(mktag, "/* mktag */ ").
|
|
java_util__unary_prefix_op(unmktag, "/* unmktag */ ").
|
|
java_util__unary_prefix_op(strip_tag, "/* strip_tag */ ").
|
|
java_util__unary_prefix_op(mkbody, "/* mkbody */ ").
|
|
java_util__unary_prefix_op(unmkbody, "/* unmkbody */ ").
|
|
java_util__unary_prefix_op(hash_string, "mercury.String.hash_1_f_0").
|
|
java_util__unary_prefix_op(bitwise_complement, "~").
|
|
java_util__unary_prefix_op((not), "!").
|
|
java_util__unary_prefix_op(tag, ""). % This case is never used.
|
|
|
|
java_util__string_compare_op(str_eq, "==").
|
|
java_util__string_compare_op(str_ne, "!=").
|
|
java_util__string_compare_op(str_le, "<=").
|
|
java_util__string_compare_op(str_ge, ">=").
|
|
java_util__string_compare_op(str_lt, "<").
|
|
java_util__string_compare_op(str_gt, ">").
|
|
|
|
java_util__float_compare_op(float_eq, "==").
|
|
java_util__float_compare_op(float_ne, "!=").
|
|
java_util__float_compare_op(float_le, "<=").
|
|
java_util__float_compare_op(float_ge, ">=").
|
|
java_util__float_compare_op(float_lt, "<").
|
|
java_util__float_compare_op(float_gt, ">").
|
|
|
|
java_util__float_op(float_plus, "+").
|
|
java_util__float_op(float_minus, "-").
|
|
java_util__float_op(float_times, "*").
|
|
java_util__float_op(float_divide, "/").
|
|
|
|
java_util__binary_infix_op(+, "+").
|
|
java_util__binary_infix_op(-, "-").
|
|
java_util__binary_infix_op(*, "*").
|
|
java_util__binary_infix_op(/, "/").
|
|
java_util__binary_infix_op(mod, "%").
|
|
java_util__binary_infix_op(<<, "<<").
|
|
java_util__binary_infix_op(>>, ">>").
|
|
java_util__binary_infix_op(&, "&").
|
|
java_util__binary_infix_op('|', "|").
|
|
java_util__binary_infix_op(^, "^").
|
|
java_util__binary_infix_op(and, "&&").
|
|
java_util__binary_infix_op(or, "||").
|
|
java_util__binary_infix_op(eq, "==").
|
|
java_util__binary_infix_op(ne, "!=").
|
|
java_util__binary_infix_op(<, "<").
|
|
java_util__binary_infix_op(>, ">").
|
|
java_util__binary_infix_op(<=, "<=").
|
|
java_util__binary_infix_op(>=, ">=").
|
|
|
|
%------------------------------------------------------------------------------%
|
|
|
|
java_util__is_keyword("abstract").
|
|
java_util__is_keyword("boolean").
|
|
java_util__is_keyword("break").
|
|
java_util__is_keyword("byte").
|
|
java_util__is_keyword("case").
|
|
java_util__is_keyword("catch").
|
|
java_util__is_keyword("char").
|
|
java_util__is_keyword("class").
|
|
java_util__is_keyword("const").
|
|
java_util__is_keyword("continue").
|
|
java_util__is_keyword("default").
|
|
java_util__is_keyword("do").
|
|
java_util__is_keyword("double").
|
|
java_util__is_keyword("else").
|
|
java_util__is_keyword("extends").
|
|
java_util__is_keyword("false").
|
|
java_util__is_keyword("final").
|
|
java_util__is_keyword("finally").
|
|
java_util__is_keyword("float").
|
|
java_util__is_keyword("for").
|
|
java_util__is_keyword("goto").
|
|
java_util__is_keyword("if").
|
|
java_util__is_keyword("implements").
|
|
java_util__is_keyword("import").
|
|
java_util__is_keyword("instanceof").
|
|
java_util__is_keyword("int").
|
|
java_util__is_keyword("interface").
|
|
java_util__is_keyword("long").
|
|
java_util__is_keyword("native").
|
|
java_util__is_keyword("new").
|
|
java_util__is_keyword("null").
|
|
java_util__is_keyword("package").
|
|
java_util__is_keyword("private").
|
|
java_util__is_keyword("protected").
|
|
java_util__is_keyword("public").
|
|
java_util__is_keyword("return").
|
|
java_util__is_keyword("short").
|
|
java_util__is_keyword("static").
|
|
java_util__is_keyword("strictfp").
|
|
java_util__is_keyword("super").
|
|
java_util__is_keyword("switch").
|
|
java_util__is_keyword("synchronized").
|
|
java_util__is_keyword("this").
|
|
java_util__is_keyword("throw").
|
|
java_util__is_keyword("throws").
|
|
java_util__is_keyword("transient").
|
|
java_util__is_keyword("true").
|
|
java_util__is_keyword("try").
|
|
java_util__is_keyword("void").
|
|
java_util__is_keyword("volatile").
|
|
java_util__is_keyword("while").
|
|
|
|
:- func this_file = string.
|
|
this_file = "java_util.m".
|
|
|
|
:- end_module java_util.
|
|
%-----------------------------------------------------------------------------%
|