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