Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Move interface to global/errors into glue layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain Buclaw committed Oct 1, 2013
1 parent eb77529 commit b2a4421
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 1,862 deletions.
6 changes: 6 additions & 0 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2013-10-01 Iain Buclaw <ibuclaw@gdcproject.org>

* d-objfile.cc(cvtLocToloc_t): Rename to get_linemap.
* d-glue.cc: New source to provide interface for defined globals and
error handling called from the front-end.

2013-09-16 Iain Buclaw <ibuclaw@gdcproject.org>

* d-codegen.cc(IRState::call): Rename to d_build_call.
Expand Down
4 changes: 2 additions & 2 deletions gcc/d/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ D_DMD_OBJS := \
d/hdrgen.dmd.o d/identifier.dmd.o \
d/imphint.dmd.o d/import.dmd.o d/init.dmd.o d/inline.dmd.o \
d/interpret.dmd.o d/json.dmd.o d/lexer.dmd.o \
d/macro.dmd.o d/mangle.dmd.o d/mars.dmd.o d/mtype.dmd.o d/module.dmd.o \
d/macro.dmd.o d/mangle.dmd.o d/mtype.dmd.o d/module.dmd.o \
d/opover.dmd.o d/optimize.dmd.o d/parse.dmd.o d/rmem.dmd.o d/root.dmd.o \
d/sapply.dmd.o d/scope.dmd.o d/speller.dmd.o d/statement.dmd.o \
d/staticassert.dmd.o d/stringtable.dmd.o d/struct.dmd.o d/template.dmd.o \
Expand All @@ -129,7 +129,7 @@ D_GLUE_OBJS = d/d-lang.glue.o d/d-decls.glue.o d/d-codegen.glue.o \
d/d-gt.cglue.o d/d-builtins.cglue.o d/d-asmstmt.glue.o \
d/d-incpath.glue.o d/d-ctype.glue.o d/d-elem.glue.o \
d/d-toir.glue.o d/d-typinf.glue.o d/d-port.glue.o \
d/d-target.glue.o
d/d-target.glue.o d/d-glue.glue.o

# ALL_D_COMPILER_FLAGS causes issues -- c++ <complex.h> instead of C <complex.h>
# Not all DMD sources depend on d-dmd-gcc.h
Expand Down
268 changes: 268 additions & 0 deletions gcc/d/d-glue.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
// d-glue.cc -- D frontend for GCC.
// Copyright (C) 2013 Free Software Foundation, Inc.

// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.

// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.

// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.

#include "d-system.h"
#include "d-objfile.h"

#include "mars.h"
#include "module.h"

Global global;

void
Global::init (void)
{
this->mars_ext = "d";
this->sym_ext = "d";
this->hdr_ext = "di";
this->doc_ext = "html";
this->ddoc_ext = "ddoc";
this->json_ext = "json";
this->map_ext = "map";

this->obj_ext = "o";
this->lib_ext = "a";
this->dll_ext = "so";

this->version = "v"
#include "verstr.h"
;

this->compiler.vendor = "GNU D";
this->main_d = "__main.d";

memset (&this->params, 0, sizeof (Param));
}

unsigned
Global::startGagging (void)
{
this->gag++;
return this->gaggedErrors;
}

bool
Global::endGagging (unsigned oldGagged)
{
bool anyErrs = (this->gaggedErrors != oldGagged);
this->gag--;

// Restore the original state of gagged errors; set total errors
// to be original errors + new ungagged errors.
this->errors -= (this->gaggedErrors - oldGagged);
this->gaggedErrors = oldGagged;

return anyErrs;
}

bool
Global::isSpeculativeGagging (void)
{
if (!this->gag)
return false;

if (this->gag != this->speculativeGag)
return false;

return true;
}

char *
Loc::toChars (void)
{
OutBuffer buf;

if (this->filename)
buf.printf ("%s", this->filename);

if (this->linnum)
buf.printf (":%u", this->linnum);

buf.writeByte (0);

return (char *)buf.extractData();
}

Loc::Loc (Module *mod, unsigned linnum)
{
this->linnum = linnum;
this->filename = mod ? mod->srcfile->toChars() : NULL;
}

bool
Loc::equals (const Loc& loc)
{
if (this->linnum != loc.linnum)
return false;

if (!FileName::equals (this->filename, loc.filename))
return false;

return true;
}


// Print a hard error message.

void
error (Loc loc, const char *format, ...)
{
va_list ap;
va_start (ap, format);
verror (loc, format, ap);
va_end (ap);
}

void
error (const char *filename, unsigned linnum, const char *format, ...)
{
Loc loc;
va_list ap;

loc.filename = CONST_CAST (char *, filename);
loc.linnum = linnum;

va_start (ap, format);
verror (loc, format, ap);
va_end (ap);
}

void
verror (Loc loc, const char *format, va_list ap,
const char *p1, const char *p2, const char *)
{
if (!global.gag)
{
location_t location = get_linemap (loc);
char *msg;

// Build string and emit.
if (p2)
format = concat (p2, " ", format, NULL);

if (p1)
format = concat (p1, " ", format, NULL);

vasprintf (&msg, format, ap);
error_at (location, msg);

// Moderate blizzard of cascading messages
if (global.errors >= 20)
fatal();
}
else
global.gaggedErrors++;

global.errors++;
}

// Print supplementary message about the last error.
// Doesn't increase error count.

void
errorSupplemental (Loc loc, const char *format, ...)
{
va_list ap;
va_start (ap, format);
verrorSupplemental (loc, format, ap);
va_end (ap);
}

void
verrorSupplemental (Loc loc, const char *format, va_list ap)
{
if (!global.gag)
{
location_t location = get_linemap (loc);
char *msg;

vasprintf (&msg, format, ap);
inform (location, msg);
}
}

// Print a warning message.

void
warning (Loc loc, const char *format, ...)
{
va_list ap;
va_start (ap, format);
vwarning (loc, format, ap);
va_end (ap);
}

void
vwarning (Loc loc, const char *format, va_list ap)
{
if (global.params.warnings && !global.gag)
{
location_t location = get_linemap (loc);
char *msg;

vasprintf (&msg, format, ap);
warning_at (location, 0, msg);

// Warnings don't count if gagged.
if (global.params.warnings == 1)
global.warnings++;
}
}

// Print a deprecation message.

void
deprecation (Loc loc, const char *format, ...)
{
va_list ap;
va_start (ap, format);
vdeprecation (loc, format, ap);
va_end (ap);
}

void
vdeprecation (Loc loc, const char *format, va_list ap,
const char *p1, const char *p2)
{
if (global.params.useDeprecated == 0)
verror (loc, format, ap, p1, p2);
else if (global.params.useDeprecated == 2 && !global.gag)
{
location_t location = get_linemap (loc);
char *msg;

// Build string and emit.
if (p2)
format = concat (p2, " ", format, NULL);

if (p1)
format = concat (p1, " ", format, NULL);

vasprintf (&msg, format, ap);
warning_at (location, OPT_Wdeprecated, msg);
}
}

// Call this after printing out fatal error messages to clean up and exit
// the compiler.

void
fatal (void)
{
exit (FATAL_EXIT_CODE);
}

10 changes: 5 additions & 5 deletions gcc/d/d-objfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,8 @@ d_finish_module (void)
}
}

static location_t
cvtLocToloc_t (const Loc loc)
location_t
get_linemap (const Loc loc)
{
location_t gcc_location;

Expand All @@ -1413,7 +1413,7 @@ void
set_input_location (const Loc& loc)
{
if (loc.filename)
input_location = cvtLocToloc_t (loc);
input_location = get_linemap (loc);
}

// Set the decl T source location to LOC.
Expand All @@ -1424,7 +1424,7 @@ set_decl_location (tree t, const Loc& loc)
// DWARF2 will often crash if the DECL_SOURCE_FILE is not set. It's
// easier the error here.
gcc_assert (loc.filename);
DECL_SOURCE_LOCATION (t) = cvtLocToloc_t (loc);
DECL_SOURCE_LOCATION (t) = get_linemap (loc);
}

// Some D Declarations don't have the loc set, this searches DECL's parents
Expand Down Expand Up @@ -1462,7 +1462,7 @@ void
set_function_end_locus (const Loc& loc)
{
if (loc.filename)
cfun->function_end_locus = cvtLocToloc_t (loc);
cfun->function_end_locus = get_linemap (loc);
else
cfun->function_end_locus = DECL_SOURCE_LOCATION (cfun->decl);
}
Expand Down
1 change: 1 addition & 0 deletions gcc/d/d-objfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum TemplateEmission
TEprivate
};

extern location_t get_linemap (const Loc loc);
extern void set_input_location (const Loc& loc);

extern void set_decl_location (tree t, const Loc& loc);
Expand Down
Loading

0 comments on commit b2a4421

Please sign in to comment.