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#ifndef COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
8#define COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
9
10#include <string>
11
12namespace angle
13{
14
15namespace pp
16{
17
18struct SourceLocation;
19
20// Base class for reporting diagnostic messages.
21// Derived classes are responsible for formatting and printing the messages.
22class Diagnostics
23{
24 public:
25 enum ID
26 {
27 PP_ERROR_BEGIN,
28 PP_INTERNAL_ERROR,
29 PP_OUT_OF_MEMORY,
30 PP_INVALID_CHARACTER,
31 PP_INVALID_NUMBER,
32 PP_INTEGER_OVERFLOW,
33 PP_FLOAT_OVERFLOW,
34 PP_TOKEN_TOO_LONG,
35 PP_INVALID_EXPRESSION,
36 PP_DIVISION_BY_ZERO,
37 PP_EOF_IN_COMMENT,
38 PP_UNEXPECTED_TOKEN,
39 PP_DIRECTIVE_INVALID_NAME,
40 PP_MACRO_NAME_RESERVED,
41 PP_MACRO_REDEFINED,
42 PP_MACRO_PREDEFINED_REDEFINED,
43 PP_MACRO_PREDEFINED_UNDEFINED,
44 PP_MACRO_UNTERMINATED_INVOCATION,
45 PP_MACRO_UNDEFINED_WHILE_INVOKED,
46 PP_MACRO_TOO_FEW_ARGS,
47 PP_MACRO_TOO_MANY_ARGS,
48 PP_MACRO_DUPLICATE_PARAMETER_NAMES,
49 PP_MACRO_INVOCATION_CHAIN_TOO_DEEP,
50 PP_CONDITIONAL_ENDIF_WITHOUT_IF,
51 PP_CONDITIONAL_ELSE_WITHOUT_IF,
52 PP_CONDITIONAL_ELSE_AFTER_ELSE,
53 PP_CONDITIONAL_ELIF_WITHOUT_IF,
54 PP_CONDITIONAL_ELIF_AFTER_ELSE,
55 PP_CONDITIONAL_UNTERMINATED,
56 PP_CONDITIONAL_UNEXPECTED_TOKEN,
57 PP_INVALID_EXTENSION_NAME,
58 PP_INVALID_EXTENSION_BEHAVIOR,
59 PP_INVALID_EXTENSION_DIRECTIVE,
60 PP_INVALID_VERSION_NUMBER,
61 PP_INVALID_VERSION_DIRECTIVE,
62 PP_VERSION_NOT_FIRST_STATEMENT,
63 PP_VERSION_NOT_FIRST_LINE_ESSL3,
64 PP_INVALID_LINE_NUMBER,
65 PP_INVALID_FILE_NUMBER,
66 PP_INVALID_LINE_DIRECTIVE,
67 PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
68 PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3,
69 PP_UNDEFINED_SHIFT,
70 PP_TOKENIZER_ERROR,
71 PP_ERROR_END,
72
73 PP_WARNING_BEGIN,
74 PP_EOF_IN_DIRECTIVE,
75 PP_UNRECOGNIZED_PRAGMA,
76 PP_NON_PP_TOKEN_BEFORE_EXTENSION_WEBGL,
77 PP_WARNING_MACRO_NAME_RESERVED,
78 PP_WARNING_END
79 };
80
81 virtual ~Diagnostics();
82
83 void report(ID id, const SourceLocation &loc, const std::string &text);
84
85 protected:
86 bool isError(ID id);
87 const char *message(ID id);
88
89 virtual void print(ID id, const SourceLocation &loc, const std::string &text) = 0;
90};
91
92} // namespace pp
93
94} // namespace angle
95
96#endif // COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
97