error.h

来自「一个可视化的编译器」· C头文件 代码 · 共 71 行

H
71
字号
/// <author> 任晶磊 </author>
/// <update> 2008-3-1 </update>
///	<E-mail> renjinglei@163.com </E-mail>

#ifndef ERROR_H
#define ERROR_H

#include <list>
#include <string>
#include <iostream>
#include <sstream>

namespace C0
{
	namespace Interpreter
	{
		using std::string;
		using std::list;

		class Error
		{
			string fileName;
			int lineNum;
			int charNum;
			string reference;
		public:
			Error(const string& fileName, int lineNum, int charNum, const string& reference)
				:fileName(fileName), lineNum(lineNum), charNum(charNum), reference(reference){}

			string ToString()
			{
				std::stringstream sstr;
				sstr << fileName << "(" << lineNum << ")";
				string location;
				sstr >> location;
				return location + " : " + reference;
			}
		};

		class ErrorLog
		{
			list<Error> errors;
		public:
			void Record(const string& fileName, int lineNum, int charNum, const string& reference)
			{
				Error error(fileName, lineNum, charNum, reference);
				errors.push_back(error);
			}
			
			bool Empty()
			{
				return errors.empty();
			}

			int Count()
			{
				return (int)errors.size();
			}

			void Print()
			{
				for (list<Error>::iterator it = errors.begin(); it != errors.end(); ++it)
				{
					std::cout << it->ToString() << std::endl;
				}
			}
		};
	}
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?