blob: 3e22e1f1c579dfcc1ca65bf248401b4dee699408 [file] [log] [blame]
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001//
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
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00007#include "DiagnosticsBase.h"
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00008
9#include <cassert>
10
11namespace pp
12{
13
alokp@chromium.org964b7192012-05-17 21:12:27 +000014Diagnostics::~Diagnostics()
15{
16}
17
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000018void 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 > ERROR_BEGIN) && (id < ERROR_END))
29 return ERROR;
30
31 if ((id > WARNING_BEGIN) && (id < WARNING_END))
32 return WARNING;
33
34 assert(false);
35 return ERROR;
36}
37
alokp@chromium.org6b495712012-06-29 00:06:58 +000038std::string Diagnostics::message(ID id)
39{
40 switch (id)
41 {
42 // Errors begin.
43 case INTERNAL_ERROR:
44 return "internal error";
45 case OUT_OF_MEMORY:
46 return "out of memory";
47 case INVALID_CHARACTER:
48 return "invalid character";
49 case INVALID_NUMBER:
50 return "invalid number";
alokp@chromium.org2e818912012-06-29 21:26:03 +000051 case INTEGER_OVERFLOW:
52 return "integer overflow";
53 case FLOAT_OVERFLOW:
54 return "float overflow";
alokp@chromium.orgc022c3a2012-07-09 15:56:42 +000055 case TOKEN_TOO_LONG:
56 return "token too long";
alokp@chromium.org6b495712012-06-29 00:06:58 +000057 case INVALID_EXPRESSION:
58 return "invalid expression";
59 case DIVISION_BY_ZERO:
60 return "division by zero";
61 case EOF_IN_COMMENT:
62 return "unexpected end of file found in comment";
alokp@chromium.org6b495712012-06-29 00:06:58 +000063 case UNEXPECTED_TOKEN:
64 return "unexpected token";
65 case DIRECTIVE_INVALID_NAME:
66 return "invalid directive name";
67 case MACRO_NAME_RESERVED:
68 return "macro name is reserved";
69 case MACRO_REDEFINED:
70 return "macro redefined";
71 case MACRO_PREDEFINED_REDEFINED:
72 return "predefined macro redefined";
73 case MACRO_PREDEFINED_UNDEFINED:
74 return "predefined macro undefined";
75 case MACRO_UNTERMINATED_INVOCATION:
76 return "unterminated macro invocation";
77 case MACRO_TOO_FEW_ARGS:
78 return "Not enough arguments for macro";
79 case MACRO_TOO_MANY_ARGS:
80 return "Too many arguments for macro";
81 case CONDITIONAL_ENDIF_WITHOUT_IF:
82 return "unexpected #endif found without a matching #if";
83 case CONDITIONAL_ELSE_WITHOUT_IF:
84 return "unexpected #else found without a matching #if";
85 case CONDITIONAL_ELSE_AFTER_ELSE:
86 return "unexpected #else found after another #else";
87 case CONDITIONAL_ELIF_WITHOUT_IF:
88 return "unexpected #elif found without a matching #if";
89 case CONDITIONAL_ELIF_AFTER_ELSE:
90 return "unexpected #elif found after #else";
91 case CONDITIONAL_UNTERMINATED:
92 return "unexpected end of file found in conditional block";
93 case INVALID_EXTENSION_NAME:
94 return "invalid extension name";
95 case INVALID_EXTENSION_BEHAVIOR:
96 return "invalid extension behavior";
97 case INVALID_EXTENSION_DIRECTIVE:
98 return "invalid extension directive";
99 case INVALID_VERSION_NUMBER:
100 return "invalid version number";
101 case INVALID_VERSION_DIRECTIVE:
102 return "invalid version directive";
alokp@chromium.orgd0d9f872012-07-03 16:06:40 +0000103 case VERSION_NOT_FIRST_STATEMENT:
104 return "#version directive must occur before anything else, "
105 "except for comments and white space";
alokp@chromium.org6b495712012-06-29 00:06:58 +0000106 case INVALID_LINE_NUMBER:
107 return "invalid line number";
108 case INVALID_FILE_NUMBER:
109 return "invalid file number";
110 case INVALID_LINE_DIRECTIVE:
111 return "invalid line directive";
112 // Errors end.
113 // Warnings begin.
alokp@chromium.org390209a2012-07-03 16:12:48 +0000114 case EOF_IN_DIRECTIVE:
115 return "unexpected end of file found in directive";
alokp@chromium.org6b495712012-06-29 00:06:58 +0000116 case CONDITIONAL_UNEXPECTED_TOKEN:
117 return "unexpected token after conditional expression";
118 case UNRECOGNIZED_PRAGMA:
119 return "unrecognized pragma";
120 // Warnings end.
121 default:
122 assert(false);
123 return "";
124 }
125}
126
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000127} // namespace pp