mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Parse complex import directives.
This commit is contained in:
+21
-5
@@ -129,23 +129,39 @@ private:
|
||||
|
||||
/**
|
||||
* Import directive for referencing other files / source objects.
|
||||
* Example: import "abc.sol"
|
||||
* Example: import "abc.sol" // imports all symbols of "abc.sol" into current scope
|
||||
* Source objects are identified by a string which can be a file name but does not have to be.
|
||||
* Other ways to use it:
|
||||
* import "abc" as x; // creates symbol "x" that contains all symbols in "abc"
|
||||
* import * as x from "abc"; // same as above
|
||||
* import {a as b, c} from "abc"; // creates new symbols "b" and "c" referencing "a" and "c" in "abc", respectively.
|
||||
*/
|
||||
class ImportDirective: public ASTNode
|
||||
{
|
||||
public:
|
||||
ImportDirective(SourceLocation const& _location, ASTPointer<ASTString> const& _identifier):
|
||||
ASTNode(_location), m_identifier(_identifier) {}
|
||||
ImportDirective(
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<ASTString> const& _path,
|
||||
ASTPointer<ASTString> const& _unitAlias,
|
||||
std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>>&& _symbolAliases
|
||||
):
|
||||
ASTNode(_location), m_path(_path), m_unitAlias(_unitAlias), m_symbolAliases(_symbolAliases) {}
|
||||
|
||||
virtual void accept(ASTVisitor& _visitor) override;
|
||||
virtual void accept(ASTConstVisitor& _visitor) const override;
|
||||
|
||||
ASTString const& identifier() const { return *m_identifier; }
|
||||
ASTString const& path() const { return *m_path; }
|
||||
virtual ImportAnnotation& annotation() const override;
|
||||
|
||||
private:
|
||||
ASTPointer<ASTString> m_identifier;
|
||||
ASTPointer<ASTString> m_path;
|
||||
/// The alias for the module itself. If present, import the whole unit under that name and
|
||||
/// ignore m_symbolAlias.
|
||||
ASTPointer<ASTString> m_unitAlias;
|
||||
/// The aliases for the specific symbols to import. If non-empty import the specific symbols.
|
||||
/// If the second component is empty, import the identifier unchanged.
|
||||
/// If both m_unitAlias and m_symbolAlias are empty, import all symbols into the current scope.
|
||||
std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>> m_symbolAliases;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,7 +91,7 @@ Json::Value const& ASTJsonConverter::json()
|
||||
|
||||
bool ASTJsonConverter::visit(ImportDirective const& _node)
|
||||
{
|
||||
addJsonNode("Import", { make_pair("file", _node.identifier())});
|
||||
addJsonNode("Import", { make_pair("file", _node.path())});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ void ASTPrinter::print(ostream& _stream)
|
||||
|
||||
bool ASTPrinter::visit(ImportDirective const& _node)
|
||||
{
|
||||
writeLine("ImportDirective \"" + _node.identifier() + "\"");
|
||||
writeLine("ImportDirective \"" + _node.path() + "\"");
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user