mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Support experimental feature pragma
This commit is contained in:
parent
279e64ae75
commit
fbcc5f4ee5
@ -33,9 +33,10 @@ bool SyntaxChecker::checkSyntax(ASTNode const& _astRoot)
|
|||||||
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(SourceUnit const&)
|
bool SyntaxChecker::visit(SourceUnit const& _sourceUnit)
|
||||||
{
|
{
|
||||||
m_versionPragmaFound = false;
|
m_versionPragmaFound = false;
|
||||||
|
m_sourceUnit = &_sourceUnit;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,15 +58,36 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit)
|
|||||||
|
|
||||||
m_errorReporter.warning(_sourceUnit.location(), errorString);
|
m_errorReporter.warning(_sourceUnit.location(), errorString);
|
||||||
}
|
}
|
||||||
|
m_sourceUnit = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(PragmaDirective const& _pragma)
|
bool SyntaxChecker::visit(PragmaDirective const& _pragma)
|
||||||
{
|
{
|
||||||
solAssert(!_pragma.tokens().empty(), "");
|
solAssert(!_pragma.tokens().empty(), "");
|
||||||
solAssert(_pragma.tokens().size() == _pragma.literals().size(), "");
|
solAssert(_pragma.tokens().size() == _pragma.literals().size(), "");
|
||||||
if (_pragma.tokens()[0] != Token::Identifier || _pragma.literals()[0] != "solidity")
|
if (_pragma.tokens()[0] != Token::Identifier)
|
||||||
m_errorReporter.syntaxError(_pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\"");
|
m_errorReporter.syntaxError(_pragma.location(), "Invalid pragma \"" + _pragma.literals()[0] + "\"");
|
||||||
|
else if (_pragma.literals()[0] == "experimental")
|
||||||
|
{
|
||||||
|
solAssert(m_sourceUnit, "");
|
||||||
|
vector<string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
|
||||||
|
if (literals.size() == 0)
|
||||||
|
m_errorReporter.syntaxError(
|
||||||
|
_pragma.location(),
|
||||||
|
"At least one experimental feature or the wildcard symbol \"*\" is required."
|
||||||
|
);
|
||||||
else
|
else
|
||||||
|
for (string const literal: literals)
|
||||||
|
{
|
||||||
|
if (literal.empty())
|
||||||
|
m_errorReporter.syntaxError(_pragma.location(), "Empty experimental feature name is invalid.");
|
||||||
|
else if (m_sourceUnit->annotation().experimentalFeatures.count(literal))
|
||||||
|
m_errorReporter.syntaxError(_pragma.location(), "Duplicate experimental feature name.");
|
||||||
|
else
|
||||||
|
m_sourceUnit->annotation().experimentalFeatures.insert(literal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_pragma.literals()[0] == "solidity")
|
||||||
{
|
{
|
||||||
vector<Token::Value> tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end());
|
vector<Token::Value> tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end());
|
||||||
vector<string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
|
vector<string> literals(_pragma.literals().begin() + 1, _pragma.literals().end());
|
||||||
@ -81,6 +103,8 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
|
|||||||
);
|
);
|
||||||
m_versionPragmaFound = true;
|
m_versionPragmaFound = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
m_errorReporter.syntaxError(_pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\"");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@ private:
|
|||||||
bool m_versionPragmaFound = false;
|
bool m_versionPragmaFound = false;
|
||||||
|
|
||||||
int m_inLoopDepth = 0;
|
int m_inLoopDepth = 0;
|
||||||
|
|
||||||
|
SourceUnit const* m_sourceUnit = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,8 @@ struct SourceUnitAnnotation: ASTAnnotation
|
|||||||
std::string path;
|
std::string path;
|
||||||
/// The exported symbols (all global symbols).
|
/// The exported symbols (all global symbols).
|
||||||
std::map<ASTString, std::vector<Declaration const*>> exportedSymbols;
|
std::map<ASTString, std::vector<Declaration const*>> exportedSymbols;
|
||||||
|
/// Experimental feature pragmas.
|
||||||
|
std::set<ASTString> experimentalFeatures;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ImportAnnotation: ASTAnnotation
|
struct ImportAnnotation: ASTAnnotation
|
||||||
|
Loading…
Reference in New Issue
Block a user