src/CompileContext.cpp
author David Anderson <dvander@alliedmods.net>
Sun Sep 16 23:15:13 2012 -0700 (2012-09-16)
changeset 192 23a804fa1d3e
parent 92 e3974e7360e9
permissions -rw-r--r--
Allow structs to contain arrays.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #include <stdio.h>
    19 #include "Scanner.h"
    20 #include "CompileContext.h"
    21 #include "Zone.h"
    22 #include "Spaces-inl.h"
    23 #include "Heap-inl.h"
    24 
    25 using namespace ke;
    26 
    27 CompileContext::CompileContext(Zone *zone, const char *file)
    28   : zone_(zone),
    29     failures_(0),
    30     file_(file)
    31 {
    32 }
    33 
    34 CompileContext::~CompileContext()
    35 {
    36     if (failures_)
    37         zone_->endCompilationErrors();
    38 }
    39 
    40 void
    41 CompileContext::reportErrorVa(const SourcePosition &pos, Message msg, va_list ap)
    42 {
    43     if (!failures_)
    44         zone_->beginCompilationErrors(file_);
    45 
    46     zone_->reportCompilationError(msg, pos.line, pos.col, ap);
    47 
    48     failures_++;
    49 }
    50 
    51 void
    52 CompileContext::reportError(const SourcePosition &pos, Message msg, ...)
    53 {
    54     va_list ap;
    55     va_start(ap, msg);
    56     reportErrorVa(pos, msg, ap);
    57     va_end(ap);
    58 }