Skip to content

Commit 9bce5f9

Browse files
authored
Merge pull request ethereum#14538 from ethereum/experimentalAnalysisBasicInfrastructure
New Analysis basic infrastructure
2 parents 64a0f62 + 14aed39 commit 9bce5f9

File tree

16 files changed

+320
-148
lines changed

16 files changed

+320
-148
lines changed

liblangutil/Scanner.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,15 +1019,28 @@ std::tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
10191019
while (isIdentifierPart(m_char) || (m_char == '.' && m_kind == ScannerKind::Yul))
10201020
addLiteralCharAndAdvance();
10211021
literal.complete();
1022+
10221023
auto const token = TokenTraits::fromIdentifierOrKeyword(m_tokens[NextNext].literal);
1023-
if (m_kind == ScannerKind::Yul)
1024+
switch (m_kind)
10241025
{
1026+
case ScannerKind::Solidity:
1027+
// Turn experimental Solidity keywords that are not keywords in legacy Solidity into identifiers.
1028+
if (TokenTraits::isExperimentalSolidityOnlyKeyword(std::get<0>(token)))
1029+
return std::make_tuple(Token::Identifier, 0, 0);
1030+
break;
1031+
case ScannerKind::Yul:
10251032
// Turn Solidity identifier into a Yul keyword
10261033
if (m_tokens[NextNext].literal == "leave")
10271034
return std::make_tuple(Token::Leave, 0, 0);
10281035
// Turn non-Yul keywords into identifiers.
10291036
if (!TokenTraits::isYulKeyword(std::get<0>(token)))
10301037
return std::make_tuple(Token::Identifier, 0, 0);
1038+
break;
1039+
case ScannerKind::ExperimentalSolidity:
1040+
// Turn legacy Solidity keywords that are not keywords in experimental Solidity into identifiers.
1041+
if (!TokenTraits::isExperimentalSolidityKeyword(std::get<0>(token)))
1042+
return std::make_tuple(Token::Identifier, 0, 0);
1043+
break;
10311044
}
10321045
return token;
10331046
}

liblangutil/Scanner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class ParserRecorder;
6969
enum class ScannerKind
7070
{
7171
Solidity,
72-
Yul
72+
Yul,
73+
ExperimentalSolidity
7374
};
7475

7576
enum class ScannerError

liblangutil/Token.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ namespace solidity::langutil
268268
/* Yul-specific tokens, but not keywords. */ \
269269
T(Leave, "leave", 0) \
270270
\
271+
T(NonExperimentalEnd, nullptr, 0) /* used as non-experimental enum end marker */ \
272+
T(ExperimentalEnd, nullptr, 0) /* used as experimental enum end marker */ \
271273
/* Illegal token - not able to scan. */ \
272274
T(Illegal, "ILLEGAL", 0) \
273275
\
@@ -323,6 +325,39 @@ namespace TokenTraits
323325
tok == Token::TrueLiteral || tok == Token::FalseLiteral || tok == Token::HexStringLiteral || tok == Token::Hex;
324326
}
325327

328+
constexpr bool isExperimentalSolidityKeyword(Token token)
329+
{
330+
return
331+
token == Token::Assembly ||
332+
token == Token::Contract ||
333+
token == Token::External ||
334+
token == Token::Fallback ||
335+
token == Token::Pragma ||
336+
token == Token::Import ||
337+
token == Token::As ||
338+
token == Token::Function ||
339+
token == Token::Let ||
340+
token == Token::Return ||
341+
token == Token::Type ||
342+
token == Token::If ||
343+
token == Token::Else ||
344+
token == Token::Do ||
345+
token == Token::While ||
346+
token == Token::For ||
347+
token == Token::Continue ||
348+
token == Token::Break;
349+
// TODO: see isExperimentalSolidityKeyword below
350+
// || (token > Token::NonExperimentalEnd && token < Token::ExperimentalEnd);
351+
}
352+
353+
constexpr bool isExperimentalSolidityOnlyKeyword(Token)
354+
{
355+
// TODO: use token > Token::NonExperimentalEnd && token < Token::ExperimentalEnd
356+
// as soon as other experimental tokens are added. For now the comparison generates
357+
// a warning from clang because it is always false.
358+
return false;
359+
}
360+
326361
bool isYulKeyword(std::string const& _literal);
327362

328363
Token AssignmentToBinaryOp(Token op);

libsolidity/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ set(sources
101101
codegen/ir/IRLValue.h
102102
codegen/ir/IRVariable.cpp
103103
codegen/ir/IRVariable.h
104+
experimental/analysis/Analysis.cpp
105+
experimental/analysis/Analysis.h
104106
formal/ArraySlicePredicate.cpp
105107
formal/ArraySlicePredicate.h
106108
formal/BMC.cpp
@@ -186,4 +188,3 @@ set(sources
186188

187189
add_library(solidity ${sources})
188190
target_link_libraries(solidity PUBLIC yul evmasm langutil smtutil solutil Boost::boost fmt::fmt-header-only Threads::Threads)
189-
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
This file is part of solidity.
3+
4+
solidity is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
solidity is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with solidity. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
// SPDX-License-Identifier: GPL-3.0
18+
#include <libsolidity/experimental/analysis/Analysis.h>
19+
20+
#include <liblangutil/ErrorReporter.h>
21+
22+
using namespace solidity::langutil;
23+
using namespace solidity::frontend::experimental;
24+
25+
bool Analysis::check(std::vector<std::shared_ptr<SourceUnit const>> const&)
26+
{
27+
m_errorReporter.error(
28+
6547_error,
29+
Error::Type::UnimplementedFeatureError,
30+
SourceLocation{},
31+
"Experimental Analysis is not implemented yet."
32+
);
33+
return false;
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
This file is part of solidity.
3+
4+
solidity is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
solidity is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with solidity. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
// SPDX-License-Identifier: GPL-3.0
18+
#pragma once
19+
20+
#include <vector>
21+
#include <memory>
22+
23+
namespace solidity::frontend
24+
{
25+
class SourceUnit;
26+
}
27+
28+
namespace solidity::langutil
29+
{
30+
class ErrorReporter;
31+
}
32+
33+
namespace solidity::frontend::experimental
34+
{
35+
36+
class Analysis
37+
{
38+
public:
39+
Analysis(langutil::ErrorReporter& _errorReporter):
40+
m_errorReporter(_errorReporter)
41+
{}
42+
43+
bool check(std::vector<std::shared_ptr<SourceUnit const>> const& _sourceUnits);
44+
45+
private:
46+
langutil::ErrorReporter& m_errorReporter;
47+
};
48+
49+
}

0 commit comments

Comments
 (0)