Example #1
0
		bool Compiler::load(const char* buffer, Error& error)
		{
			error.clear();
			m_loadBuffer += buffer;
			error.state = Error::SUCCESS;
			return true;
		}
int main(){
	Error T("Testing Error Message");
	Error e;
	cout << T << endl << e << endl << "isClear(): " << (e.isClear() ? "Passed!" : "failed!") << endl;
	for (int i = 0; i < 1000000; i++){
		e = "Some error message that is really long long  long  long  long  long  long  long"
			" long  long  long  long  long  long  long  long  long  long  long  long  long";
	}
	cout << e << endl << "isClear(): " << (e.isClear() ? "Failed!" : "Passed!") << endl;
	e.message("Short Message");
	cout << e << endl << e.message() << endl << "isClear(): " << (e.isClear() ? "Failed!" : "Passed!") << endl;
	e.clear();
	cout << e << endl << "isClear(): " << (e.isClear() ? "Passed!" : "Failed!") << endl;
	return 0;
}
Example #3
0
		bool Compiler::compile(Error& error)
		{
			error.clear();
			error.step = Error::COMPILATION;
			error.state = Error::ERROR;

			m_tokenList = MUON_NEW(std::vector<parser::Token>);
			m_nodeRoot = MUON_NEW(parser::ASTNode);

			// avoid a macro, and avoid duplicating code
			auto clearVariable = [&]()
			{
				m_loadBuffer.clear();
				MUON_DELETE(m_tokenList);
				MUON_DELETE(m_nodeRoot);
			};

			if (!lexical(error))
			{
				clearVariable();
				return false;
			}

			if (!syntaxic(error))
			{
				clearVariable();
				return false;
			}

			if (!semantic(error))
			{
				clearVariable();
				return false;
			}

			clearVariable();
			error.state = Error::SUCCESS;
			return true;
		}
Example #4
0
		bool Compiler::load(const m::String& file, Error& error)
		{
			error.clear();
			error.state = Error::ERROR;
			std::ifstream stream(file.cStr());
			if (!stream)
			{
				error.message = "Couldn't open the stream!";
				return false;
			}

			if (!stream.eof())
			{
				// Get stream size
				stream.seekg(0, stream.end);
				m::u64 length = (m::u64)stream.tellg();
				stream.seekg(0, stream.beg);

				char* buffer = (char*)malloc((m::u32)length + 1);
				stream.read(buffer, length);
				buffer[stream.gcount()] = 0;
				m_loadBuffer += buffer;
				free(buffer);

				Section section = { file, length };
				if (!m_sections->empty())
				{
					section._end += m_sections->back()._end;
				}
				m_sections->push_back(section);
				error.state = Error::SUCCESS;
				return true;
			}
			error.message = "File stream seems to be empty: encountered EOF at beginning!";
			return false;
		}