-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate experimental analysis pass for type class registration
- Loading branch information
Showing
8 changed files
with
174 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
libsolidity/experimental/analysis/TypeClassRegistration.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
This file is part of solidity. | ||
solidity is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
solidity is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
|
||
#include <libsolidity/experimental/analysis/TypeClassRegistration.h> | ||
|
||
#include <libsolidity/experimental/analysis/Analysis.h> | ||
|
||
#include <liblangutil/ErrorReporter.h> | ||
#include <liblangutil/Exceptions.h> | ||
|
||
using namespace solidity::frontend::experimental; | ||
using namespace solidity::langutil; | ||
|
||
TypeClassRegistration::TypeClassRegistration(Analysis& _analysis): | ||
m_analysis(_analysis), | ||
m_errorReporter(_analysis.errorReporter()), | ||
m_typeSystem(_analysis.typeSystem()) | ||
{ | ||
} | ||
|
||
bool TypeClassRegistration::analyze(SourceUnit const& _sourceUnit) | ||
{ | ||
_sourceUnit.accept(*this); | ||
return !m_errorReporter.hasErrors(); | ||
} | ||
|
||
bool TypeClassRegistration::visit(TypeClassDefinition const& _typeClassDefinition) | ||
{ | ||
Type typeVar = m_typeSystem.freshTypeVariable({}); | ||
|
||
std::variant<TypeClass, std::string> typeClassOrError = m_typeSystem.declareTypeClass( | ||
typeVar, | ||
_typeClassDefinition.name(), | ||
&_typeClassDefinition | ||
); | ||
|
||
m_analysis.annotation<TypeClassRegistration>(_typeClassDefinition).typeClass = std::visit( | ||
util::GenericVisitor{ | ||
[](TypeClass _class) -> TypeClass { return _class; }, | ||
[&](std::string _error) -> TypeClass { | ||
m_errorReporter.fatalTypeError(4767_error, _typeClassDefinition.location(), _error); | ||
util::unreachable(); | ||
} | ||
}, | ||
typeClassOrError | ||
); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
This file is part of solidity. | ||
solidity is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
solidity is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with solidity. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
#pragma once | ||
|
||
#include <libsolidity/ast/ASTVisitor.h> | ||
#include <libsolidity/experimental/ast/TypeSystem.h> | ||
|
||
namespace solidity::langutil | ||
{ | ||
class ErrorReporter; | ||
} | ||
|
||
namespace solidity::frontend::experimental | ||
{ | ||
|
||
class Analysis; | ||
class TypeSystem; | ||
|
||
class TypeClassRegistration: public ASTConstVisitor | ||
{ | ||
public: | ||
struct Annotation | ||
{ | ||
// Type classes. | ||
std::optional<TypeClass> typeClass; | ||
}; | ||
struct GlobalAnnotation | ||
{ | ||
}; | ||
|
||
TypeClassRegistration(Analysis& _analysis); | ||
|
||
bool analyze(SourceUnit const& _sourceUnit); | ||
|
||
private: | ||
bool visit(TypeClassDefinition const& _typeClassDefinition) override; | ||
|
||
Analysis& m_analysis; | ||
langutil::ErrorReporter& m_errorReporter; | ||
TypeSystem& m_typeSystem; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters