Home | History | Annotate | Download | only in preprocessor
      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         ERROR,
     25         WARNING
     26     };
     27     enum ID
     28     {
     29         ERROR_BEGIN,
     30         INTERNAL_ERROR,
     31         OUT_OF_MEMORY,
     32         INVALID_CHARACTER,
     33         INVALID_NUMBER,
     34         INTEGER_OVERFLOW,
     35         FLOAT_OVERFLOW,
     36         TOKEN_TOO_LONG,
     37         INVALID_EXPRESSION,
     38         DIVISION_BY_ZERO,
     39         EOF_IN_COMMENT,
     40         UNEXPECTED_TOKEN,
     41         DIRECTIVE_INVALID_NAME,
     42         MACRO_NAME_RESERVED,
     43         MACRO_REDEFINED,
     44         MACRO_PREDEFINED_REDEFINED,
     45         MACRO_PREDEFINED_UNDEFINED,
     46         MACRO_UNTERMINATED_INVOCATION,
     47         MACRO_TOO_FEW_ARGS,
     48         MACRO_TOO_MANY_ARGS,
     49         CONDITIONAL_ENDIF_WITHOUT_IF,
     50         CONDITIONAL_ELSE_WITHOUT_IF,
     51         CONDITIONAL_ELSE_AFTER_ELSE,
     52         CONDITIONAL_ELIF_WITHOUT_IF,
     53         CONDITIONAL_ELIF_AFTER_ELSE,
     54         CONDITIONAL_UNTERMINATED,
     55         INVALID_EXTENSION_NAME,
     56         INVALID_EXTENSION_BEHAVIOR,
     57         INVALID_EXTENSION_DIRECTIVE,
     58         INVALID_VERSION_NUMBER,
     59         INVALID_VERSION_DIRECTIVE,
     60         VERSION_NOT_FIRST_STATEMENT,
     61         INVALID_LINE_NUMBER,
     62         INVALID_FILE_NUMBER,
     63         INVALID_LINE_DIRECTIVE,
     64         ERROR_END,
     65 
     66         WARNING_BEGIN,
     67         EOF_IN_DIRECTIVE,
     68         CONDITIONAL_UNEXPECTED_TOKEN,
     69         UNRECOGNIZED_PRAGMA,
     70         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