1//
2// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "DiagnosticsBase.h"
8
9#include <cassert>
10
11namespace pp
12{
13
14Diagnostics::~Diagnostics()
15{
16}
17
18void Diagnostics::report(ID id,
19                         const SourceLocation &loc,
20                         const std::string &text)
21{
22    // TODO(alokp): Keep a count of errors and warnings.
23    print(id, loc, text);
24}
25
26Diagnostics::Severity Diagnostics::severity(ID id)
27{
28    if ((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END))
29        return PP_ERROR;
30
31    if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END))
32        return PP_WARNING;
33
34    assert(false);
35    return PP_ERROR;
36}
37
38std::string Diagnostics::message(ID id)
39{
40    switch (id)
41    {
42      // Errors begin.
43      case PP_INTERNAL_ERROR:
44        return "internal error";
45      case PP_OUT_OF_MEMORY:
46        return "out of memory";
47      case PP_INVALID_CHARACTER:
48        return "invalid character";
49      case PP_INVALID_NUMBER:
50        return "invalid number";
51      case PP_INTEGER_OVERFLOW:
52        return "integer overflow";
53      case PP_FLOAT_OVERFLOW:
54        return "float overflow";
55      case PP_TOKEN_TOO_LONG:
56        return "token too long";
57      case PP_INVALID_EXPRESSION:
58        return "invalid expression";
59      case PP_DIVISION_BY_ZERO:
60        return "division by zero";
61      case PP_EOF_IN_COMMENT:
62        return "unexpected end of file found in comment";
63      case PP_UNEXPECTED_TOKEN:
64        return "unexpected token";
65      case PP_DIRECTIVE_INVALID_NAME:
66        return "invalid directive name";
67      case PP_MACRO_NAME_RESERVED:
68        return "macro name is reserved";
69      case PP_MACRO_REDEFINED:
70        return "macro redefined";
71      case PP_MACRO_PREDEFINED_REDEFINED:
72        return "predefined macro redefined";
73      case PP_MACRO_PREDEFINED_UNDEFINED:
74        return "predefined macro undefined";
75      case PP_MACRO_UNTERMINATED_INVOCATION:
76        return "unterminated macro invocation";
77      case PP_MACRO_TOO_FEW_ARGS:
78        return "Not enough arguments for macro";
79      case PP_MACRO_TOO_MANY_ARGS:
80        return "Too many arguments for macro";
81      case PP_CONDITIONAL_ENDIF_WITHOUT_IF:
82        return "unexpected #endif found without a matching #if";
83      case PP_CONDITIONAL_ELSE_WITHOUT_IF:
84        return "unexpected #else found without a matching #if";
85      case PP_CONDITIONAL_ELSE_AFTER_ELSE:
86        return "unexpected #else found after another #else";
87      case PP_CONDITIONAL_ELIF_WITHOUT_IF:
88        return "unexpected #elif found without a matching #if";
89      case PP_CONDITIONAL_ELIF_AFTER_ELSE:
90        return "unexpected #elif found after #else";
91      case PP_CONDITIONAL_UNTERMINATED:
92        return "unexpected end of file found in conditional block";
93      case PP_INVALID_EXTENSION_NAME:
94        return "invalid extension name";
95      case PP_INVALID_EXTENSION_BEHAVIOR:
96        return "invalid extension behavior";
97      case PP_INVALID_EXTENSION_DIRECTIVE:
98        return "invalid extension directive";
99      case PP_INVALID_VERSION_NUMBER:
100        return "invalid version number";
101      case PP_INVALID_VERSION_DIRECTIVE:
102        return "invalid version directive";
103      case PP_VERSION_NOT_FIRST_STATEMENT:
104        return "#version directive must occur before anything else, "
105               "except for comments and white space";
106      case PP_INVALID_LINE_NUMBER:
107        return "invalid line number";
108      case PP_INVALID_FILE_NUMBER:
109        return "invalid file number";
110      case PP_INVALID_LINE_DIRECTIVE:
111        return "invalid line directive";
112      // Errors end.
113      // Warnings begin.
114      case PP_EOF_IN_DIRECTIVE:
115        return "unexpected end of file found in directive";
116      case PP_CONDITIONAL_UNEXPECTED_TOKEN:
117        return "unexpected token after conditional expression";
118      case PP_UNRECOGNIZED_PRAGMA:
119        return "unrecognized pragma";
120      // Warnings end.
121      default:
122        assert(false);
123        return "";
124    }
125}
126
127}  // namespace pp
128