Exemple #1
0
	void addError(Error::Type _type, std::string const& _description, SourceLocation const& _location = SourceLocation())
	{
		auto err = make_shared<Error>(_type);
		if (!_location.isEmpty())
			*err << errinfo_sourceLocation(_location);
		*err << errinfo_comment(_description);
		errors.push_back(err);
	}
string Assembly::locationFromSources(StringMap const& _sourceCodes, SourceLocation const& _location) const
{
	if (_location.isEmpty() || _sourceCodes.empty() || _location.start >= _location.end || _location.start < 0)
		return "";

	auto it = _sourceCodes.find(*_location.sourceName);
	if (it == _sourceCodes.end())
		return "";

	string const& source = it->second;
	if (size_t(_location.start) >= source.size())
		return "";

	string cut = source.substr(_location.start, _location.end - _location.start);
	auto newLinePos = cut.find_first_of("\n");
	if (newLinePos != string::npos)
		cut = cut.substr(0, newLinePos) + "...";

	return cut;
}