Exemplo n.º 1
0
static LineInfo GetFileInfo(SourceLocation loc) {
  std::ifstream stream(loc.filename);

  if (!stream.good()) {
    throw InternalCompilerError(StringBuilder(
        "Can't reopen file '", loc.filename, "' after error found in it."));
  }

  // We need to iterate through the file to get the line number information.
  // Can't store this in SourceLocation because it needs to be as small as
  // possible. This is fine, because we would only need to do it once for bad
  // input in a compilation pass, and we are already at *at least* O(n) on the
  // file length
  int lineCount = 0;
  std::array<char, 256> lineArray;

  while (stream.tellg() < loc.offset) {
    lineCount++;
    stream.getline(&lineArray[0], 256);
  }

  std::string line(&lineArray[0]);

  int lineOffset = line.size() - (stream.tellg() - loc.offset);
  return LineInfo(loc.filename, line, lineCount, lineOffset);
}
ModifierDefinition const& CompilerContext::functionModifier(string const& _name) const
{
	solAssert(!m_inheritanceHierarchy.empty(), "No inheritance hierarchy set.");
	for (ContractDefinition const* contract: m_inheritanceHierarchy)
		for (ModifierDefinition const* modifier: contract->functionModifiers())
			if (modifier->name() == _name)
				return *modifier;
	BOOST_THROW_EXCEPTION(InternalCompilerError()
		<< errinfo_comment("Function modifier " + _name + " not found."));
}