Replace /* */ comments with // comments in util.

util/mdemangle.c:
util/mfiltercc.c:
util/mkinit_common.c:
util/pad_backslash.c:
    As above. The other .c files in util already used // comments.
This commit is contained in:
Zoltan Somogyi
2023-03-19 00:16:22 +11:00
parent d9046a19d2
commit 2315f1660e
4 changed files with 274 additions and 389 deletions

View File

@@ -1,37 +1,34 @@
/*
** vim: ft=c ts=4 sw=4 et
*/
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
// vim: ft=c ts=4 sw=4 et
//---------------------------------------------------------------------------//
//
// Copyright (C) 1995-2006, 2008 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: mdemangle.c
// Author: fjh
//
// A mercury symbol demangler.
// This is used to convert error messages from the linker back
// into a form that users can understand.
//
// This is implemented in C to minimize startup time and memory usage.
//
// BEWARE:
// This code is duplicated in profiler/demangle.m and profiler/mdemangle.m.
// Any changes here will need to be duplicated there and vice versa.
//
//---------------------------------------------------------------------------//
/*
** Copyright (C) 1995-2006, 2008 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: mdemangle.c
** Author: fjh
**
** A mercury symbol demangler.
** This is used to convert error messages from the linker back
** into a form that users can understand.
**
** This is implemented in C to minimize startup time and memory usage.
**
** BEWARE:
** This code is duplicated in profiler/demangle.m and profiler/mdemangle.m.
** Any changes here will need to be duplicated there and vice versa.
*/
/* mercury_std.h includes mercury_regs.h, and must precede system headers */
// mercury_std.h includes mercury_regs.h, and must precede system headers.
#include "mercury_std.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/* We used this for the size of fixed-length buffers in a few places <sigh> */
// We used this for the size of fixed-length buffers in a few places <sigh>.
#define MAX_SYMBOL_LENGTH 1000
static void demangle(const char *name);
@@ -51,25 +48,19 @@ static MR_bool strip_suffix(const char *str, char **end,
const char *suffix);
static MR_bool strip_leading_integer(char **start_ptr, int *num);
/*
** Bloody SunOS 4.x doesn't have memmove()...
** Using memcpy() may not work, but it doesn't really matter
** if the demangler doesn't work 100% correctly on SunOS 4.x.
*/
// Bloody SunOS 4.x doesn't have memmove()...
// Using memcpy() may not work, but it doesn't really matter
// if the demangler doesn't work 100% correctly on SunOS 4.x.
#ifndef MR_HAVE_MEMMOVE
#define memmove memcpy
#endif
/*
** This option indicates whether we should output verbose
** explanations of linker error messages.
*/
// This option indicates whether we should output verbose
// explanations of linker error messages.
MR_bool explain_link_errors = MR_FALSE;
/*
** This variable gets set if the symbols MR_grade_* or MR_mercury_grade
** were found. If it gets set, then we print out the error message below.
*/
// This variable gets set if the symbols MR_grade_* or MR_mercury_grade
// were found. If it gets set, then we print out the error message below.
char *found_grade_symbol = NULL;
const char probably_grade_error[] =
@@ -84,7 +75,7 @@ main(int argc, char **argv)
{
const char *progname = argv[0];
/* We should use getopt_long(), but for one option, that is overkill. */
// We should use getopt_long(), but for one option, that is overkill.
while (argc > 1 && argv[1][0] == '-') {
if (strcmp(argv[1], "-e") == 0 ||
strcmp(argv[1], "--explain-link-errors") == 0)
@@ -103,19 +94,14 @@ main(int argc, char **argv)
if (argc > 1) {
int i;
/*
** Invoke demangle() on each command line argument.
*/
// Invoke demangle() on each command line argument.
for (i = 1; i < argc; i++) {
demangle(argv[i]);
putchar('\n');
}
} else {
/*
** Copy stdin to stdout, calling demangle() for every valid
** C identifier in the input.
*/
// Copy stdin to stdout, calling demangle() for every valid
// C identifier in the input.
for (;;) {
char buf[MAX_SYMBOL_LENGTH];
size_t len;
@@ -154,18 +140,16 @@ main(int argc, char **argv)
return 0;
}
/*
** demangle():
** Convert a mangled Mercury identifier into human-readable form
** and then print it to stdout.
*/
// demangle():
// Convert a mangled Mercury identifier into human-readable form
// and then print it to stdout.
static void
demangle(const char *orig_name)
{
static const char entry[] = "_entry_";
static const char mercury[] = "mercury__";
static const char func_prefix[] = "fn__"; /* added for functions */
static const char func_prefix[] = "fn__"; // added for functions
static const char unify1[] = "__Unify___";
static const char unify2[] = "__Unify____";
static const char compare1[] = "__Compare___";
@@ -182,14 +166,12 @@ demangle(const char *orig_name)
static const char func[] = "func__";
static const char porf[] = "pred_or_func__";
/*
** XXX This is out-of-date. The compiler now generates names
** such as UnusedArgs__p__[1].
*/
static const char ua_suffix[] = "__ua"; /* added by unused_args.m */
static const char ua_suffix2[] = "__uab"; /* added by unused_args.m */
// XXX This is out-of-date. The compiler now generates names
// such as UnusedArgs__p__[1].
static const char ua_suffix[] = "__ua"; // added by unused_args.m
static const char ua_suffix2[] = "__uab"; // added by unused_args.m
static const char ho_suffix[] = "__ho"; /* added by higher_order.m */
static const char ho_suffix[] = "__ho"; // added by higher_order.m
static const char mercury_common[] = "mercury_common_";
static const char mercury_data[] = "mercury_data_";
@@ -237,21 +219,21 @@ demangle(const char *orig_name)
char name[MAX_SYMBOL_LENGTH];
char *start = name;
const char *module = ""; /* module name */
const char *module = ""; // module name
char *end = name + strlen(orig_name);
char *position; /* current position in string */
char *position; // current position in string
int mode_num;
int mode_num2;
int arity;
MR_bool high_level = MR_TRUE;
MR_bool matched = MR_FALSE;
const char *pred_or_func; /* either "predicate" or "function" */
const char *pred_or_func; // either "predicate" or "function"
MR_bool unused_args = MR_FALSE;
/* does this proc have any unused arguments */
// does this proc have any unused arguments
MR_bool unused_args_extra = MR_FALSE;
/* __uab suffix rather than __ua */
// __uab suffix rather than __ua
int unused_args_num = 0;
MR_bool higher_order = MR_FALSE; /* has this proc been specialized */
MR_bool higher_order = MR_FALSE; // has this proc been specialized?
int higher_order_num = 0;
int internal = -1;
char *name_before_prefixes = NULL;
@@ -270,25 +252,21 @@ demangle(const char *orig_name)
const char *class_arg;
const char *type_spec_sub;
/*
** Copy orig_name to a local buffer which we can modify,
** making sure that we don't overflow the buffer.
*/
// Copy orig_name to a local buffer which we can modify,
// making sure that we don't overflow the buffer.
if (strlen(orig_name) >= sizeof(name)) {
goto too_long;
}
strcpy(name, orig_name);
/*
** Skip any leading underscore inserted by the C compiler
** (but don't skip it if it came from the `_entry_' prefix).
*/
// Skip any leading underscore inserted by the C compiler
// (but don't skip it if it came from the `_entry_' prefix).
if (*start == '_' && strncmp(start, entry, strlen(entry)) != 0) {
start++;
}
/* Check for `MR_grade_*' and `MR_runtime_grade'. */
// Check for `MR_grade_*' and `MR_runtime_grade'.
if (strncmp(start, MR_grade, strlen(MR_grade)) == 0 ||
strcmp(start, MR_runtime_grade) == 0)
{
@@ -301,23 +279,19 @@ demangle(const char *orig_name)
goto wrong_format;
}
/* Skip the `_entry_' prefix, if any. */
// Skip the `_entry_' prefix, if any.
strip_prefix(&start, entry);
/* Strip off the `mercury__' prefix, if any. */
// Strip off the `mercury__' prefix, if any.
if (strip_prefix(&start, mercury)) {
matched = MR_TRUE;
}
/*
** Code for dealing with predicate symbols.
*/
// Code for dealing with predicate symbols.
/*
** Get integer from end of string (it might be the mode number,
** it might be the internal label number). We'll assume its mode
** number for the moment.
*/
// Get integer from end of string (it might be the mode number,
// it might be the internal label number). We'll assume its mode
// number for the moment.
if (!cut_trailing_integer(start, &end, &mode_num)) {
goto not_plain_mercury;
@@ -327,11 +301,9 @@ demangle(const char *orig_name)
goto not_plain_mercury;
}
/*
** If we got to an `i', that means it is an internal label of the form
** `mercury__append_3_0_i1'. In that case, save the internal label number
** and then get the mode number.
*/
// If we got to an `i', that means it is an internal label of the form
// `mercury__append_3_0_i1'. In that case, save the internal label number
// and then get the mode number.
if (*--end == 'i') {
internal = mode_num;
@@ -348,7 +320,7 @@ demangle(const char *orig_name)
goto not_plain_mercury;
}
/* Strip off the `fn__' prefix, if any. */
// Strip off the `fn__' prefix, if any.
if (strip_prefix(&start, func_prefix)) {
high_level = MR_FALSE;
pred_or_func = "function";
@@ -361,10 +333,8 @@ demangle(const char *orig_name)
matched = MR_TRUE;
pred_or_func = "predicate";
} else {
/*
** It is not a function. But it could be either an LLDS predicate,
** or an MLDS compiler-generated predicate.
*/
// It is not a function. But it could be either an LLDS predicate,
// or an MLDS compiler-generated predicate.
high_level = (strstr(start, unify2) ||
strstr(start, compare2) ||
strstr(start, index2));
@@ -375,9 +345,7 @@ demangle(const char *orig_name)
goto not_plain_mercury;
}
/*
** Scan back past the arity number and then parse it.
*/
// Scan back past the arity number and then parse it.
if (!cut_trailing_underscore_integer(start, &end, &arity)) {
goto not_plain_mercury;
@@ -388,12 +356,10 @@ demangle(const char *orig_name)
trailing_context_1, trailing_context_1_hl_suffixes);
}
/*
** Now start processing from the start of the string again. Check whether
** the start of the string matches the name of one of the special
** compiler-generated predicates; if so, set the `category' to the
** appropriate value and then skip past the prefix.
*/
// Now start processing from the start of the string again. Check whether
// the start of the string matches the name of one of the special
// compiler-generated predicates; if so, set the `category' to the
// appropriate value and then skip past the prefix.
if (strip_prefix(&start, unify1)) {
category = UNIFY;
@@ -405,12 +371,10 @@ demangle(const char *orig_name)
if (mode_num != 0) goto not_plain_mercury;
} else {
category = ORDINARY;
/*
** For ordinary predicates, we should have matched against something
** by now --
** either the "mercury__" prefix, for LLDS mangling,
** or the "_f" or "_p" suffix, for MLDS mangling.
*/
// For ordinary predicates, we should have matched against something
// by now --
// either the "mercury__" prefix, for LLDS mangling,
// or the "_f" or "_p" suffix, for MLDS mangling.
if (!matched) {
goto not_plain_mercury;
}
@@ -420,16 +384,14 @@ demangle(const char *orig_name)
start++;
}
/* Fix any ascii codes mangled in the predicate name. */
// Fix any ascii codes mangled in the predicate name.
start = fix_mangled_ascii(start, &end);
/*
** Process the mangling introduced by unused_args.m.
** This involves stripping off the `__ua<m>' or `__uab<m>' added to
** the end of the predicate/function name, where m is the mode number.
*/
// Process the mangling introduced by unused_args.m.
// This involves stripping off the `__ua<m>' or `__uab<m>' added to
// the end of the predicate/function name, where m is the mode number.
position = end; /* save end of name */
position = end; // save end of name
do {
if (position == start) {
@@ -438,7 +400,7 @@ demangle(const char *orig_name)
position--;
} while (MR_isdigit(*position));
/* get the mode number */
// Get the mode number.
if (check_for_suffix(start, position, ua_suffix,
sizeof(ua_suffix), &mode_num2))
{
@@ -457,11 +419,9 @@ demangle(const char *orig_name)
mode_num = mode_num2 % 10000;
}
/*
** Process the mangling introduced by higher_order.m.
** This involves stripping off the `__ho<n>' where
** n is a unique identifier for this specialized version
*/
// Process the mangling introduced by higher_order.m.
// This involves stripping off the `__ho<n>' where
// n is a unique identifier for this specialized version
position = end;
@@ -479,17 +439,13 @@ demangle(const char *orig_name)
higher_order = MR_TRUE;
}
/*
** Cut off the string before the start of the arity number,
** and the unused_args and specialization information,
** i.e. at the end of the predicate name or type name.
*/
// Cut off the string before the start of the arity number,
// and the unused_args and specialization information,
// i.e. at the end of the predicate name or type name.
*end = '\0';
/*
** Make sure special predicates with unused_args
** are reported correctly.
*/
// Make sure special predicates with unused_args
// are reported correctly.
if (unused_args && category != ORDINARY) {
if (!cut_trailing_integer(start, &end, &arity)) {
@@ -501,12 +457,10 @@ demangle(const char *orig_name)
module = strip_module_name(&start, end, trailing_context_1, NULL);
}
/*
** Look for "IntroducedFrom" or "DeforestationIn" or "AccFrom"
** or "TypeSpecOf".
** XXX This don't yet handle multiple prefixes. If we get an error after
** this point, just treat predicate name as an ordinary predicate.
*/
// Look for "IntroducedFrom" or "DeforestationIn" or "AccFrom"
// or "TypeSpecOf".
// XXX This don't yet handle multiple prefixes. If we get an error after
// this point, just treat predicate name as an ordinary predicate.
name_before_prefixes = start;
if (category == ORDINARY) {
if (strip_prefix(&start, introduced)) {
@@ -550,7 +504,7 @@ demangle(const char *orig_name)
type_spec_sub = start;
start++;
/* Handle matched brackets in type names. */
// Handle matched brackets in type names.
while (start < end) {
if (*start == '[') {
nest_level++;
@@ -568,14 +522,12 @@ demangle(const char *orig_name)
category = ORDINARY;
start = name_before_prefixes;
} else {
/*
** The compiler adds a redundant mode number to the
** predicate name to avoid creating two predicates
** with the same name (deep profiling doesn't like that).
** It isn't used here, so we just ignore it. The compiler
** also adds a version number for the argument order used
** for specialized versions, which can also be ignored.
*/
// The compiler adds a redundant mode number to the
// predicate name to avoid creating two predicates
// with the same name (deep profiling doesn't like that).
// It isn't used here, so we just ignore it. The compiler
// also adds a version number for the argument order used
// for specialized versions, which can also be ignored.
*end_of_lambda_pred_name = '\0';
start = lambda_pred_name;
@@ -617,9 +569,7 @@ demangle(const char *orig_name)
}
}
/*
** Now, finally, we can print the demangled symbol name.
*/
// Now, finally, we can print the demangled symbol name.
printf("<");
switch(category) {
@@ -690,21 +640,17 @@ demangle(const char *orig_name)
printf(">");
return;
/*
** Code to deal with mercury_data items.
*/
// Code to deal with mercury_data items.
not_plain_mercury:
/*
** Undo any in-place modifications done while trying to demangle
** predicate names.
*/
// Undo any in-place modifications done while trying to demangle
// predicate names.
strcpy(name, orig_name);
start = name;
end = name + strlen(name);
/* Skip any leading underscore inserted by the C compiler. */
// Skip any leading underscore inserted by the C compiler.
if (*start == '_') {
start++;
}
@@ -718,17 +664,17 @@ not_plain_mercury:
}
if (strip_prefix(&start, mercury_data)) {
/* LLDS */
// LLDS
high_level = MR_FALSE;
if (strip_prefix(&start, base_typeclass_info)) {
goto typeclass_info;
}
/* Also try the old format, in case we're demangling old files. */
// Also try the old format, in case we're demangling old files.
if (strip_prefix(&start, underscores_base_typeclass_info)) {
goto typeclass_info;
}
} else {
/* MLDS */
// MLDS
high_level = MR_TRUE;
if (strip_prefix(&start, base_typeclass_info)) {
goto typeclass_info;
@@ -738,10 +684,8 @@ not_plain_mercury:
module = strip_module_name(&start, end, trailing_context_2, NULL);
if (high_level) {
/*
** For MLDS, the module name gets duplicated (XXX why?)
** So here we must replace `foo.foo' with just `foo'.
*/
// For MLDS, the module name gets duplicated (XXX why?)
// So here we must replace `foo.foo' with just `foo'.
size_t half_len;
half_len = strlen(module) / 2;
@@ -820,13 +764,11 @@ not_plain_mercury:
return;
typeclass_info:
/*
** Parse the class name and class arity, which have the following layout:
** <module-qualified class name>__arity<arity>__
*/
// Parse the class name and class arity, which have the following layout:
// <module-qualified class name>__arity<arity>__
class_name = strip_module_name(&start, end, trailing_context_3, NULL);
/* XXX fix_mangled_ascii() */
// XXX fix_mangled_ascii()
if (!(strip_prefix(&start, arity_string)
&& strip_leading_integer(&start, &class_arity)
&& strip_prefix(&start, "__")))
@@ -834,12 +776,10 @@ typeclass_info:
goto wrong_format;
}
/*
** Parse the class argument types, which each have the following layout:
** <module-qualified type name>__arity<arity>__
**
** We store the human-readable formatted output in class_arg_buf as we go.
*/
// Parse the class argument types, which each have the following layout:
// <module-qualified type name>__arity<arity>__
//
// We store the human-readable formatted output in class_arg_buf as we go.
fix_mangled_ascii(start, &end);
strcpy(class_arg_buf, "");
@@ -859,7 +799,7 @@ typeclass_info:
class_arg, arity);
}
/* Now print the results. */
// Now print the results.
printf("<instance declaration for %s(%s)>", class_name, class_arg_buf);
return;
@@ -874,29 +814,25 @@ wrong_format:
too_long:
fputs(orig_name, stdout);
return;
} /* end demangle() */
} // end demangle()
/*
** Remove a module name prefix.
** Just keep munching up double-underscores until we get to something
** that matches the specified trailing context, at which point we stop,
** or until there are no double-underscores left.
*/
// Remove a module name prefix.
// Just keep munching up double-underscores until we get to something
// that matches the specified trailing context, at which point we stop,
// or until there are no double-underscores left.
static const char *
strip_module_name(char **start_ptr, char *end,
const char *special_prefixes[], const char *special_suffixes[])
{
const char *module; /* module name */
char *module_end; /* end of the module name */
const char *module; // module name
char *module_end; // end of the module name
char *next_double_underscore;
char *start;
start = *start_ptr;
/*
** Strip off the module name
*/
// Strip off the module name
module = start;
module_end = start;
while ((next_double_underscore = strstr(start, "__")) != NULL) {
@@ -904,7 +840,7 @@ strip_module_name(char **start_ptr, char *end,
int i;
MR_bool stop;
/* Check for special cases. */
// Check for special cases.
stop = MR_FALSE;
for (i = 0; special_prefixes[i] != NULL; i++) {
if (strncmp(start, special_prefixes[i],
@@ -929,10 +865,8 @@ strip_module_name(char **start_ptr, char *end,
len = next_double_underscore - start;
if (module != module_end) {
/*
** Append a module qualifier, and shift the module name
** into the right place.
*/
// Append a module qualifier, and shift the module name
// into the right place.
*module_end = ':';
module_end++;
@@ -953,12 +887,10 @@ strip_module_name(char **start_ptr, char *end,
return module;
}
/*
** Remove the prefix from a string, if it has it.
** Returns MR_TRUE if the string has that prefix, and *str will then point
** to the rest of that string. If the string doesn't have that prefix,
** *str will be unchanged, and the function will return MR_FALSE.
*/
// Remove the prefix from a string, if it has it.
// Returns MR_TRUE if the string has that prefix, and *str will then point
// to the rest of that string. If the string doesn't have that prefix,
// *str will be unchanged, and the function will return MR_FALSE.
static MR_bool
strip_prefix(char **str, const char *prefix)
@@ -975,11 +907,9 @@ strip_prefix(char **str, const char *prefix)
return MR_FALSE;
}
/*
** Remove the suffix from a string, if it has it.
** Returns MR_TRUE if the string between start and *end has the specified
** suffix, and sets *end to point to the beginning of the suffix.
*/
// Remove the suffix from a string, if it has it.
// Returns MR_TRUE if the string between start and *end has the specified
// suffix, and sets *end to point to the beginning of the suffix.
static MR_bool
strip_suffix(const char *start, char **end, const char *suffix)
@@ -996,13 +926,11 @@ strip_suffix(const char *start, char **end, const char *suffix)
return MR_FALSE;
}
/*
** If the string pointed to by *start_ptr starts with an integer,
** then advance *start_ptr past the leading integer, store the value
** of the integer in the int pointed to by `num', and return true;
** otherwise leave *start_ptr unchanged and return false.
** (The string itself is always left unchanged.)
*/
// If the string pointed to by *start_ptr starts with an integer,
// then advance *start_ptr past the leading integer, store the value
// of the integer in the int pointed to by `num', and return true;
// otherwise leave *start_ptr unchanged and return false.
// (The string itself is always left unchanged.)
static MR_bool
strip_leading_integer(char **start_ptr, int *num)
@@ -1033,16 +961,14 @@ strip_leading_integer(char **start_ptr, int *num)
}
}
/*
** Remove trailing integer (at the supplied `real_end' of the string),
** and return it in the int pointed to by `num'. We return true if there is
** an integer at the end, and false if there is not. If we return false,
** the string will not be cut. `real_end' is updated with the new end
** of the string.
**
** Requires *str to contain more than just a number; doesn't work
** if the trailing integer starts at the first character of str.
*/
// Remove trailing integer (at the supplied `real_end' of the string),
// and return it in the int pointed to by `num'. We return true if there is
// an integer at the end, and false if there is not. If we return false,
// the string will not be cut. `real_end' is updated with the new end
// of the string.
//
// Requires *str to contain more than just a number; doesn't work
// if the trailing integer starts at the first character of str.
static MR_bool
cut_trailing_integer(char *str, char **real_end, int *num)
@@ -1067,12 +993,10 @@ cut_trailing_integer(char *str, char **real_end, int *num)
return MR_TRUE;
}
/*
** Same as cut_trailing_integer, but move end back past the underscore as well.
** If cut_trailing_underscore_integer returns MR_TRUE, the `real_end' will be
** moved back before the underscore and the integer. If it returns MR_FALSE,
** the `real_end' is unchanged.
*/
// Same as cut_trailing_integer, but move end back past the underscore as well.
// If cut_trailing_underscore_integer returns MR_TRUE, the `real_end' will be
// moved back before the underscore and the integer. If it returns MR_FALSE,
// the `real_end' is unchanged.
static MR_bool
cut_trailing_underscore_integer(char *str, char **real_end, int *num)
@@ -1093,10 +1017,8 @@ cut_trailing_underscore_integer(char *str, char **real_end, int *num)
return MR_TRUE;
}
/*
** Scan for `__' and return a pointer to the first `_'.
** Returns MR_TRUE if `__' was found, MR_FALSE otherwise.
*/
// Scan for `__' and return a pointer to the first `_'.
// Returns MR_TRUE if `__' was found, MR_FALSE otherwise.
static MR_bool
find_double_underscore(char **start, char *end)
@@ -1115,15 +1037,13 @@ find_double_underscore(char **start, char *end)
return MR_TRUE;
}
/*
** The compiler changes all names starting with `f_' so that they start with
** `f__' instead, and uses names starting with `f_' for mangled names
** which are either descriptions (such as `f_greater_than' for `>')
** or sequences of decimal representations of ASCII codes separated by
** underscores. If the name starts with `f__', we must change it back to
** start with `f_'. Otherwise, if it starts with `f_' we must convert
** the mnemonic or list of ASCII codes back into an identifier.
*/
// The compiler changes all names starting with `f_' so that they start with
// `f__' instead, and uses names starting with `f_' for mangled names
// which are either descriptions (such as `f_greater_than' for `>')
// or sequences of decimal representations of ASCII codes separated by
// underscores. If the name starts with `f__', we must change it back to
// start with `f_'. Otherwise, if it starts with `f_' we must convert
// the mnemonic or list of ASCII codes back into an identifier.
static char *
fix_mangled_ascii(char *str, char **real_end)
@@ -1132,29 +1052,23 @@ fix_mangled_ascii(char *str, char **real_end)
end = *real_end;
/*
** If it starts with `f__', replace that with `f_'.
*/
// If it starts with `f__', replace that with `f_'.
if (strncmp(str, "f__" , 3) == 0) {
str++;
*str = 'f';
return str;
}
/*
** If it starts with `f_' followed by a mnemonic description,
** then replace that with its unmangled version
*/
// If it starts with `f_' followed by a mnemonic description,
// then replace that with its unmangled version
if (strncmp(str, "f_", 2) == 0 &&
fix_mangled_special_case(str, real_end))
{
return str;
}
/*
** Otherwise, if it starts with `f_' we must convert the list of
** ASCII codes back into an identifier.
*/
// Otherwise, if it starts with `f_' we must convert the list of
// ASCII codes back into an identifier.
if (strncmp(str, "f_", 2) == 0) {
char buf[MAX_SYMBOL_LENGTH];
char *num;
@@ -1179,7 +1093,7 @@ fix_mangled_ascii(char *str, char **real_end)
num = next_num + 1;
}
/* Copy anything after the mangled string. */
// Copy anything after the mangled string.
while (num < end) {
buf[count++] = *num++;
}
@@ -1198,10 +1112,8 @@ fix_mangled_special_case(char *str, char **real_end)
const char *mangled_name;
const char *unmangled_name;
} translations[] = {
/*
** Beware: we assume that the unmangled name is always shorter
** than the mangled name.
*/
// Beware: we assume that the unmangled name is always shorter
// than the mangled name.
{ "f_not_equal", "\\=" },
{ "f_greater_or_equal", ">=" },
{ "f_less_or_equal", "=<" },
@@ -1224,9 +1136,7 @@ fix_mangled_special_case(char *str, char **real_end)
int i;
/*
** Check for the special cases listed in the table above.
*/
// Check for the special cases listed in the table above.
for (i = 0; i < num_translations; i++) {
const char *mangled;
size_t mangled_len;
@@ -1266,4 +1176,4 @@ check_for_suffix(char *start, char *position, const char *suffix,
);
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//

View File

@@ -1,25 +1,21 @@
/*
** vim: ft=c ts=4 sw=4 et
*/
/*---------------------------------------------------------------------------*/
/*
** Copyright (C) 2010, 2012 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: mfiltercc.c
** Author: wangp.
**
** This is a last ditch effort to filter out warning messages from the
** C compiler that we cannot (yet) figure out how to silence in a better way.
**
** This program must *not* #include any of the header files in the runtime
** directory.
**
*/
//---------------------------------------------------------------------------//
// vim: ft=c ts=4 sw=4 et
//---------------------------------------------------------------------------//
//
// Copyright (C) 2010, 2012 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: mfiltercc.c
// Author: wangp.
//
// This is a last ditch effort to filter out warning messages from the
// C compiler that we cannot (yet) figure out how to silence in a better way.
//
// This program must *not* #include any of the header files in the runtime
// directory.
//
//---------------------------------------------------------------------------//
#include <string.h>
#include <stdio.h>
@@ -60,12 +56,10 @@ main(void)
static int
drop_line(const char *line)
{
/*
** gcc 4.x produces the message (in English locales, with varying quotes):
** foo.c:42: warning: 'mercury__foo__...' used but never defined
**
** gcc 4.6 onwards also add " [enabled by default]"
*/
// gcc 4.x produces the message (in English locales, with varying quotes):
// foo.c:42: warning: 'mercury__foo__...' used but never defined
//
// gcc 4.6 onwards also add " [enabled by default]"
const char *p;
p = strstr(line, "mercury__");
@@ -75,4 +69,4 @@ drop_line(const char *line)
return strstr(p, " used but never defined") != NULL;
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//

View File

@@ -1,21 +1,19 @@
/*
** vim:sw=4 ts=4 expandtab
*/
/*
** Copyright (C) 1995-2007 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.
*/
//---------------------------------------------------------------------------//
// vim:sw=4 ts=4 expandtab
//---------------------------------------------------------------------------//
//
// Copyright (C) 1995-2007 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: mkinit_common.c
// Main authors: zs, fjh
//
// Common code previously shared by mkinit.c and mkinit_erl.c.
//
//---------------------------------------------------------------------------//
/*
** File: mkinit_common.c
** Main authors: zs, fjh
**
** Common code previously shared by mkinit.c and mkinit_erl.c.
**
*/
/* mercury_std.h includes mercury_regs.h, and must precede system headers */
// mercury_std.h includes mercury_regs.h, and must precede system headers.
#include "mercury_conf.h"
#include "mercury_std.h"
#include "mercury_array_macros.h"
@@ -35,7 +33,7 @@
#include <unistd.h>
#endif
/* --- global variables --- */
// --- global variables ---
const char *MR_progname = NULL;
int num_errors = 0;
@@ -44,23 +42,23 @@ char **files = NULL;
static int size_of_files;
/* List of directories to search for init files */
// List of directories to search for init files.
static String_List *init_file_dirs = NULL;
/* Pointer to tail of the init_file_dirs list */
// Pointer to tail of the init_file_dirs list.
static String_List **init_file_dirs_tail = &init_file_dirs;
/* --- adjustable limits --- */
#define MAXFILENAME 4096 /* maximum file name length */
#define NUMFILES 128 /* initial size of files array */
#define FACTOR 2 /* factor to increase files array by */
// --- adjustable limits ---
#define MAXFILENAME 4096 // maximum file name length
#define NUMFILES 128 // initial size of files array
#define FACTOR 2 // factor to increase files array by
/* --- function prototypes --- */
// --- function prototypes ---
static char *find_init_file(const char *base_name);
static MR_bool file_exists(const char *filename);
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
void
process_file_list_file(char *filename)
@@ -75,7 +73,7 @@ process_file_list_file(char *filename)
num_errors++;
return;
}
/* initialize the files structure, if required */
// Initialize the files structure, if required.
if (files == NULL) {
num_files = 0;
size_of_files = NUMFILES;
@@ -83,7 +81,7 @@ process_file_list_file(char *filename)
}
while ((line = read_line(filename, fp, MAXFILENAME)) != NULL) {
/* Ignore blank lines */
// Ignore blank lines.
if (line[0] != '\0') {
if (num_files >= size_of_files) {
size_of_files *= FACTOR;
@@ -102,13 +100,12 @@ process_file_list_file(char *filename)
}
}
/*---------------------------------------------------------------------------*/
/*
** If the `-o' option was used to specify the output file,
** and the file name specified is not `-' (which we take to mean stdout),
** then reassign stdout to the specified file.
*/
//---------------------------------------------------------------------------//
//
// If the `-o' option was used to specify the output file,
// and the file name specified is not `-' (which we take to mean stdout),
// then reassign stdout to the specified file.
//
void
set_output_file(const char *output_file_name)
@@ -124,11 +121,9 @@ set_output_file(const char *output_file_name)
}
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
/*
** Add the directory name to the end of the search path for `.init' files.
*/
// Add the directory name to the end of the search path for `.init' files.
void
add_init_file_dir(const char *dir_name)
@@ -143,11 +138,9 @@ add_init_file_dir(const char *dir_name)
init_file_dirs_tail = &tmp_slist->next;
}
/*
** Scan the list of files for ones not found in the current directory,
** and replace them with their full path equivalent if they are found
** in the list of search directories.
*/
// Scan the list of files for ones not found in the current directory,
// and replace them with their full path equivalent if they are found
// in the list of search directories.
void
do_path_search(char **lfiles, int lnum_files)
@@ -163,15 +156,13 @@ do_path_search(char **lfiles, int lnum_files)
}
}
/*
** Search the init file directory list to locate the file.
** If the file is in the current directory or is not in any of the
** search directories, then return NULL. Otherwise return the full
** path name to the file.
**
** It is the caller's responsibility to free the returned buffer
** holding the full path name when it is no longer needed.
*/
// Search the init file directory list to locate the file.
// If the file is in the current directory or is not in any of the
// search directories, then return NULL. Otherwise return the full
// path name to the file.
//
// It is the caller's responsibility to free the returned buffer
// holding the full path name when it is no longer needed.
static char *
find_init_file(const char *base_name)
@@ -184,7 +175,7 @@ find_init_file(const char *base_name)
size_t len;
if (file_exists(base_name)) {
/* File is in current directory, so no search required */
// File is in current directory, so no search required.
return NULL;
}
@@ -207,13 +198,11 @@ find_init_file(const char *base_name)
free(filename);
}
/* Did not find file */
// Did not find file.
return NULL;
}
/*
** Check whether a file exists.
*/
// Check whether a file exists.
static MR_bool
file_exists(const char *filename)
@@ -235,14 +224,12 @@ file_exists(const char *filename)
#endif
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
/*
** Read a line from a file, and return a pointer to a malloc'd buffer
** holding the line (without the final newline). If EOF occurs on a
** nonempty line, treat the EOF as a newline; if EOF occurs on an empty
** line, return NULL.
*/
// Read a line from a file, and return a pointer to a malloc'd buffer
// holding the line (without the final newline). If EOF occurs on a
// nonempty line, treat the EOF as a newline; if EOF occurs on an empty
// line, return NULL.
char *
read_line(const char *filename, FILE *fp, size_t max)
@@ -310,7 +297,7 @@ get_line(FILE *file, char *line, int line_max)
return num_chars;
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
void *
checked_malloc(size_t size)
@@ -359,16 +346,14 @@ checked_strdupcat(const char *str, const char *suffix)
return mem;
}
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
#ifndef MR_HAVE_STRERROR
/*
** Apparently SunOS 4.1.3 doesn't have strerror()
** (!%^&!^% non-ANSI systems, grumble...)
**
** This code is duplicated in runtime/mercury_prof.c.
*/
// Apparently SunOS 4.1.3 doesn't have strerror()
// (!%^&!^% non-ANSI systems, grumble...)
//
// This code is duplicated in runtime/mercury_prof.c.
extern int sys_nerr;
extern char *sys_errlist[];
@@ -388,4 +373,4 @@ strerror(int errnum)
#endif
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//

View File

@@ -1,28 +1,25 @@
/*
** vim: sw=4 ts=4 expandtab
*/
/*
** Copyright (C) 2006 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: move_backslash.c
** Author: zs
**
** Given an input stream in which some lines end with backslashes, pad those
** lines with spaces so that the backslashes are in column 77.
**
*/
/*---------------------------------------------------------------------------*/
//---------------------------------------------------------------------------//
// vim: sw=4 ts=4 expandtab
//---------------------------------------------------------------------------//
//
// Copyright (C) 2006 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: move_backslash.c
// Author: zs
//
// Given an input stream in which some lines end with backslashes, pad those
// lines with spaces so that the backslashes are in column 77.
//
//---------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/* options and arguments, set by parse_options() */
// options and arguments, set by parse_options().
static int target_column = 77;
static void usage(void);
@@ -115,4 +112,3 @@ process(FILE *fp)
cur_column++;
}
}
}