📄 errors.h
字号:
/*
* File: errors.h
* --------------
* This file defines an error-reporting class with a set of already
* implemented static methods for reporting the standard Decaf errors.
* You should report all errors via this class so that your error
* messages will have the same wording/spelling as ours and thus
* diff can easily compare the two. If needed, you can add new
* methods if you have some fancy error-reporting, but for the most
* part, you will just use the class as given.
*/
#ifndef _H_errors
#define _H_errors
#include <string>
#include "location.h"
/*
* General notes on using this class
* ----------------------------------
* Each of the methods in thie class matches one of the standard Decaf
* errors and reports a specific problem such as an unterminated string,
* type mismatch, declaration conflict, etc. You will call these methods
* to report problems encountered during the analysis phases. All methods
* on this class are static, thus you can invoke methods directly via
* the class name, e.g.
*
* if (missingEnd) ReportError::UntermString(&yylloc, str);
*
* For each method, the first argument is the pointer to the position
* structure that identifies where the problem is (usually this is the
* location of the offending token). You can pass NULL for the argument
* if there is no appropriate position to point out. Some of the methods
* require additional arguments as the information to be printed with
* the error message. Those arguments are not optional.
*/
class ReportError
{
public:
// Errors used by preprocessor
static void UntermComment();
static void InvalidDirective(int linenum);
// Errors used by scanner
static void LongIdentifier(yyltype *loc, const char *ident);
static void UntermString(yyltype *loc, const char *str);
static void UnrecogChar(yyltype *loc, char ch);
// Generic method to report a printf-style error message
static void Formatted(yyltype *loc, const char *format, ...);
// Returns number of error messages printed
static int NumErrors() { return numErrors; }
private:
static void UnderlineErrorInLine(const char *line, yyltype *pos);
static void OutputError(yyltype *loc, const char *msg);
static int numErrors;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -