Adding Libraries as source units

This commit is contained in:
Lefteris Karapetsas 2015-02-20 18:15:34 +01:00
parent 75498a48d8
commit 7b709c7c8a
2 changed files with 9 additions and 6 deletions

View File

@ -58,14 +58,15 @@ CompilerStack::CompilerStack(bool _addStandardSources):
m_addStandardSources(_addStandardSources), m_parseSuccessful(false)
{
if (m_addStandardSources)
addSources(StandardSources);
addSources(StandardSources, true); // add them as libraries
}
bool CompilerStack::addSource(string const& _name, string const& _content)
bool CompilerStack::addSource(string const& _name, string const& _content, bool _isLibrary)
{
bool existed = m_sources.count(_name) != 0;
reset(true);
m_sources[_name].scanner = make_shared<Scanner>(CharStream(expanded(_content)), _name);
m_sources[_name].isLibrary = _isLibrary;
return existed;
}
@ -328,6 +329,7 @@ void CompilerStack::resolveImports()
};
for (auto const& sourcePair: m_sources)
if (!sourcePair.second.isLibrary)
toposort(&sourcePair.second);
swap(m_sourceOrder, sourceOrder);

View File

@ -64,8 +64,8 @@ public:
/// Adds a source object (e.g. file) to the parser. After this, parse has to be called again.
/// @returns true if a source object by the name already existed and was replaced.
void addSources(std::map<std::string, std::string> const& _nameContents) { for (auto const& i: _nameContents) addSource(i.first, i.second); }
bool addSource(std::string const& _name, std::string const& _content);
void addSources(std::map<std::string, std::string> const& _nameContents, bool _isLibrary = false) { for (auto const& i: _nameContents) addSource(i.first, i.second, _isLibrary); }
bool addSource(std::string const& _name, std::string const& _content, bool _isLibrary = false);
void setSource(std::string const& _sourceCode);
/// Parses all source units that were added
void parse();
@ -125,7 +125,8 @@ private:
std::shared_ptr<Scanner> scanner;
std::shared_ptr<SourceUnit> ast;
std::string interface;
void reset() { scanner.reset(); ast.reset(); interface.clear(); }
bool isLibrary;
void reset() { scanner.reset(); ast.reset(); interface.clear(); isLibrary = false;}
};
struct Contract