/* **********************************************************************************
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 *
 * This source code is subject to terms and conditions of the Shared Source License
 * for IronPython. A copy of the license can be found in the License.html file
 * at the root of this distribution. If you can not locate the Shared Source License
 * for IronPython, please send an email to ironpy@microsoft.com.
 * By using this source code in any fashion, you are agreeing to be bound by
 * the terms of the Shared Source License for IronPython.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * **********************************************************************************/

using IronPython.Hosting;

namespace IronPython.Compiler {
    public class CompilerContext {
        /// <summary>
        /// Error reporting for the compiler
        /// </summary>
        private CompilerSink sink;

        /// <summary>
        /// from __future__ import division
        /// </summary>
        private bool trueDivision;

        private const int DefaultErrorCode = -1;

        public bool TrueDivision {
            get {
                return trueDivision;
            }
            internal set {
                trueDivision = value;
            }
        }

        public CompilerSink Sink {
            get { return sink; }
        }

        public CompilerContext()
            : this(new SimpleParserSink()) {
        }

        public CompilerContext(CompilerSink sink) {
            this.sink = sink;
        }

        public void AddError(string path, string message, string lineText, int startLine, int startColumn,
                             int endLine, int endColumn, Severity severity) {
            sink.AddError(path, message, lineText, startLine, startColumn, endLine, endColumn, DefaultErrorCode, severity);
        }

        public void AddError(string path, string message, Node node) {
            AddError(path, message, node, Severity.Error);
        }

        public void AddError(string path, string message, Node node, Severity severity) {
            sink.AddError(path, message, string.Empty, node.start.line, node.start.column, node.end.line, node.end.column, DefaultErrorCode, severity);
        }
    }
}
