use normal style for comments

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-01 16:12:32 +02:00
parent 72515254fe
commit 426f673b0a
184 changed files with 3 additions and 1789 deletions
-4
View File
@@ -1,14 +1,10 @@
//!
//! The Yul IR parser error.
//!
use std::collections::BTreeSet;
use crate::yul::lexer::token::location::Location;
///
/// The Yul IR parser error.
///
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
/// An invalid token received from the lexer.
@@ -1,6 +1,4 @@
//!
//! The YUL source code identifier.
//!
use serde::Deserialize;
use serde::Serialize;
@@ -13,9 +11,7 @@ use crate::yul::lexer::token::Token;
use crate::yul::lexer::Lexer;
use crate::yul::parser::r#type::Type;
///
/// The YUL source code identifier.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Identifier {
/// The location.
@@ -27,9 +23,7 @@ pub struct Identifier {
}
impl Identifier {
///
/// A shortcut constructor.
///
pub fn new(location: Location, inner: String) -> Self {
Self {
location,
@@ -38,9 +32,7 @@ impl Identifier {
}
}
///
/// A shortcut constructor for a typed identifier.
///
pub fn new_with_type(location: Location, inner: String, r#type: Option<Type>) -> Self {
Self {
location,
@@ -49,9 +41,7 @@ impl Identifier {
}
}
///
/// Parses the identifier list where the types cannot be specified.
///
pub fn parse_list(
lexer: &mut Lexer,
mut initial: Option<Token>,
@@ -82,9 +72,7 @@ impl Identifier {
}
}
///
/// Parses the identifier list where the types may be optionally specified.
///
pub fn parse_typed_list(
lexer: &mut Lexer,
mut initial: Option<Token>,
-4
View File
@@ -1,6 +1,4 @@
//!
//! The YUL code block.
//!
pub mod error;
pub mod identifier;
@@ -11,9 +9,7 @@ use crate::yul::lexer::error::Error as LexerError;
use crate::yul::lexer::token::Token;
use crate::yul::lexer::Lexer;
///
/// Returns the `token` value if it is `Some(_)`, otherwise takes the next token from the `stream`.
///
pub fn take_or_next(mut token: Option<Token>, lexer: &mut Lexer) -> Result<Token, LexerError> {
match token.take() {
Some(token) => Ok(token),
@@ -1,6 +1,4 @@
//!
//! The assignment expression statement.
//!
use std::collections::HashSet;
@@ -18,9 +16,7 @@ use crate::yul::parser::error::Error as ParserError;
use crate::yul::parser::identifier::Identifier;
use crate::yul::parser::statement::expression::Expression;
///
/// The Yul assignment expression statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Assignment {
/// The location.
@@ -32,9 +28,7 @@ pub struct Assignment {
}
impl Assignment {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -107,9 +101,7 @@ impl Assignment {
}
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
self.initializer.get_missing_libraries()
}
@@ -1,6 +1,4 @@
//!
//! The source code block.
//!
use std::collections::HashSet;
@@ -18,9 +16,7 @@ use crate::yul::parser::statement::assignment::Assignment;
use crate::yul::parser::statement::expression::Expression;
use crate::yul::parser::statement::Statement;
///
/// The Yul source code block.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Block {
/// The location.
@@ -30,9 +26,7 @@ pub struct Block {
}
impl Block {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -124,9 +118,7 @@ impl Block {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut libraries = HashSet::new();
for statement in self.statements.iter() {
@@ -1,6 +1,4 @@
//!
//! The YUL code.
//!
use std::collections::HashSet;
@@ -16,9 +14,7 @@ use crate::yul::lexer::Lexer;
use crate::yul::parser::error::Error as ParserError;
use crate::yul::parser::statement::block::Block;
///
/// The YUL code entity, which is the first block of the object.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Code {
/// The location.
@@ -28,9 +24,7 @@ pub struct Code {
}
impl Code {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -55,9 +49,7 @@ impl Code {
Ok(Self { location, block })
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
self.block.get_missing_libraries()
}
@@ -1,6 +1,4 @@
//!
//! The function call subexpression.
//!
pub mod name;
pub mod verbatim;
@@ -24,9 +22,7 @@ use crate::yul::parser::statement::expression::Expression;
use self::name::Name;
///
/// The Yul function call subexpression.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct FunctionCall {
/// The location.
@@ -38,9 +34,7 @@ pub struct FunctionCall {
}
impl FunctionCall {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -98,9 +92,7 @@ impl FunctionCall {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut libraries = HashSet::new();
@@ -122,9 +114,7 @@ impl FunctionCall {
libraries
}
///
/// Converts the function call into an LLVM value.
///
pub fn into_llvm<'ctx, D>(
mut self,
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
@@ -1013,9 +1003,7 @@ impl FunctionCall {
}
}
///
/// Pops the specified number of arguments, converted into their LLVM values.
///
fn pop_arguments_llvm<'ctx, D, const N: usize>(
&mut self,
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
@@ -1032,9 +1020,7 @@ impl FunctionCall {
Ok(arguments.try_into().expect("Always successful"))
}
///
/// Pops the specified number of arguments.
///
fn pop_arguments<'ctx, D, const N: usize>(
&mut self,
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
@@ -1,13 +1,9 @@
//!
//! The function name.
//!
use serde::Deserialize;
use serde::Serialize;
///
/// The function name.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Name {
/// The user-defined function.
@@ -147,14 +143,12 @@ pub enum Name {
StaticCall,
/// create new contract with code `mem[p…(p+n))` and send `v` wei and return the new address
///
/// Passes bytecode to the system contracts.
Create,
/// create new contract with code `mem[p…(p+n))` at address
/// `keccak256(0xff . this . s . keccak256(mem[p…(p+n)))` and send `v` wei and return the
/// new address, where `0xff` is a 1-byte value, this is the current contracts address as a
/// 20-byte value and `s` is a big-endian 256-bit value
///
/// Passes bytecode to the system contracts.
Create2,
/// returns the size in the data area
@@ -230,9 +224,7 @@ pub enum Name {
}
impl Name {
///
/// Tries parsing the verbatim instruction.
///
fn parse_verbatim(input: &str) -> Option<Self> {
let verbatim = input.strip_prefix("verbatim")?;
let regex = regex::Regex::new(r"_(\d+)i_(\d+)o").expect("Always valid");
@@ -1,12 +1,8 @@
//!
//! Translates the verbatim simulations.
//!
use crate::yul::parser::statement::expression::function_call::FunctionCall;
///
/// Translates the verbatim simulations.
///
pub fn verbatim<'ctx, D>(
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
call: &mut FunctionCall,
@@ -1,6 +1,4 @@
//!
//! The YUL source code literal.
//!
use inkwell::values::BasicValue;
use num::Num;
@@ -21,9 +19,7 @@ use crate::yul::lexer::Lexer;
use crate::yul::parser::error::Error as ParserError;
use crate::yul::parser::r#type::Type;
///
/// Represents a literal in YUL without differentiating its type.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Literal {
/// The location.
@@ -35,9 +31,7 @@ pub struct Literal {
}
impl Literal {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -75,9 +69,7 @@ impl Literal {
})
}
///
/// Converts the literal into its LLVM.
///
pub fn into_llvm<'ctx, D>(
self,
context: &revive_llvm_context::EraVMContext<'ctx, D>,
@@ -1,6 +1,4 @@
//!
//! The expression statement.
//!
pub mod function_call;
pub mod literal;
@@ -22,9 +20,7 @@ use crate::yul::parser::identifier::Identifier;
use self::function_call::FunctionCall;
use self::literal::Literal;
///
/// The Yul expression statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Expression {
/// The function call subexpression.
@@ -36,9 +32,7 @@ pub enum Expression {
}
impl Expression {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -81,9 +75,7 @@ impl Expression {
}
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
match self {
Self::FunctionCall(inner) => inner.get_missing_libraries(),
@@ -92,9 +84,7 @@ impl Expression {
}
}
///
/// Returns the statement location.
///
pub fn location(&self) -> Location {
match self {
Self::FunctionCall(inner) => inner.location,
@@ -103,9 +93,7 @@ impl Expression {
}
}
///
/// Converts the expression into an LLVM value.
///
pub fn into_llvm<'ctx, D>(
self,
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
@@ -1,6 +1,4 @@
//!
//! The for-loop statement.
//!
use std::collections::HashSet;
@@ -14,9 +12,7 @@ use crate::yul::lexer::Lexer;
use crate::yul::parser::statement::block::Block;
use crate::yul::parser::statement::expression::Expression;
///
/// The Yul for-loop statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ForLoop {
/// The location.
@@ -32,9 +28,7 @@ pub struct ForLoop {
}
impl ForLoop {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
let location = token.location;
@@ -56,9 +50,7 @@ impl ForLoop {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut libraries = self.initializer.get_missing_libraries();
libraries.extend(self.condition.get_missing_libraries());
@@ -1,6 +1,4 @@
//!
//! The function definition statement.
//!
use std::collections::BTreeSet;
use std::collections::HashSet;
@@ -20,13 +18,10 @@ use crate::yul::parser::identifier::Identifier;
use crate::yul::parser::statement::block::Block;
use crate::yul::parser::statement::expression::function_call::name::Name as FunctionName;
///
/// The function definition statement.
///
/// All functions are translated in two steps:
/// 1. The hoisted declaration
/// 2. The definition, which now has the access to all function signatures
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct FunctionDefinition {
/// The location.
@@ -50,9 +45,7 @@ impl FunctionDefinition {
/// The LLVM attribute section suffix.
pub const LLVM_ATTRIBUTE_SUFFIX: &'static str = "_llvm$";
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -180,16 +173,12 @@ impl FunctionDefinition {
})
}
///
/// Gets the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
self.body.get_missing_libraries()
}
///
/// Gets the list of LLVM attributes provided in the function name.
///
pub fn get_llvm_attributes(
identifier: &Identifier,
) -> Result<BTreeSet<revive_llvm_context::EraVMAttribute>, Error> {
@@ -1,6 +1,4 @@
//!
//! The if-conditional statement.
//!
use std::collections::HashSet;
@@ -14,9 +12,7 @@ use crate::yul::lexer::Lexer;
use crate::yul::parser::statement::block::Block;
use crate::yul::parser::statement::expression::Expression;
///
/// The Yul if-conditional statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct IfConditional {
/// The location.
@@ -28,9 +24,7 @@ pub struct IfConditional {
}
impl IfConditional {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
let location = token.location;
@@ -46,9 +40,7 @@ impl IfConditional {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut libraries = self.condition.get_missing_libraries();
libraries.extend(self.block.get_missing_libraries());
@@ -1,6 +1,4 @@
//!
//! The block statement.
//!
pub mod assignment;
pub mod block;
@@ -37,9 +35,7 @@ use self::object::Object;
use self::switch::Switch;
use self::variable_declaration::VariableDeclaration;
///
/// The Yul block statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Statement {
/// The object element.
@@ -71,9 +67,7 @@ pub enum Statement {
}
impl Statement {
///
/// The element parser.
///
pub fn parse(
lexer: &mut Lexer,
initial: Option<Token>,
@@ -145,9 +139,7 @@ impl Statement {
}
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
match self {
Self::Object(inner) => inner.get_missing_libraries(),
@@ -166,9 +158,7 @@ impl Statement {
}
}
///
/// Returns the statement location.
///
pub fn location(&self) -> Location {
match self {
Self::Object(inner) => inner.location,
@@ -1,6 +1,4 @@
//!
//! The YUL object.
//!
use std::collections::HashSet;
@@ -18,9 +16,7 @@ use crate::yul::lexer::Lexer;
use crate::yul::parser::error::Error as ParserError;
use crate::yul::parser::statement::code::Code;
///
/// The upper-level YUL object, representing the deploy code.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Object {
/// The location.
@@ -38,9 +34,7 @@ pub struct Object {
}
impl Object {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -171,9 +165,7 @@ impl Object {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut missing_libraries = self.code.get_missing_libraries();
if let Some(inner_object) = &self.inner_object {
@@ -1,6 +1,4 @@
//!
//! The switch statement case.
//!
use std::collections::HashSet;
@@ -16,9 +14,7 @@ use crate::yul::parser::error::Error as ParserError;
use crate::yul::parser::statement::block::Block;
use crate::yul::parser::statement::expression::literal::Literal;
///
/// The Yul switch statement case.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Case {
/// The location.
@@ -30,9 +26,7 @@ pub struct Case {
}
impl Case {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -61,9 +55,7 @@ impl Case {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
self.block.get_missing_libraries()
}
@@ -1,6 +1,4 @@
//!
//! The switch statement.
//!
pub mod case;
@@ -21,9 +19,7 @@ use crate::yul::parser::statement::expression::Expression;
use self::case::Case;
///
/// The Yul switch statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Switch {
/// The location.
@@ -36,9 +32,7 @@ pub struct Switch {
pub default: Option<Block>,
}
///
/// The parsing state.
///
pub enum State {
/// After match expression.
CaseOrDefaultKeyword,
@@ -49,9 +43,7 @@ pub enum State {
}
impl Switch {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let mut token = crate::yul::parser::take_or_next(initial, lexer)?;
let location = token.location;
@@ -113,9 +105,7 @@ impl Switch {
})
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
let mut libraries = HashSet::new();
for case in self.cases.iter() {
@@ -1,6 +1,4 @@
//!
//! The variable declaration statement.
//!
use std::collections::HashSet;
@@ -20,9 +18,7 @@ use crate::yul::parser::identifier::Identifier;
use crate::yul::parser::statement::expression::function_call::name::Name as FunctionName;
use crate::yul::parser::statement::expression::Expression;
///
/// The Yul variable declaration statement.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct VariableDeclaration {
/// The location.
@@ -34,9 +30,7 @@ pub struct VariableDeclaration {
}
impl VariableDeclaration {
///
/// The element parser.
///
pub fn parse(
lexer: &mut Lexer,
initial: Option<Token>,
@@ -87,9 +81,7 @@ impl VariableDeclaration {
))
}
///
/// Get the list of missing deployable libraries.
///
pub fn get_missing_libraries(&self) -> HashSet<String> {
self.expression
.as_ref()
-9
View File
@@ -1,6 +1,4 @@
//!
//! The YUL source code type.
//!
use serde::Deserialize;
use serde::Serialize;
@@ -12,11 +10,8 @@ use crate::yul::lexer::token::Token;
use crate::yul::lexer::Lexer;
use crate::yul::parser::error::Error as ParserError;
///
/// The YUL source code type.
///
/// The type is not currently in use, so all values have the `uint256` type by default.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Type {
/// The `bool` type.
@@ -36,9 +31,7 @@ impl Default for Type {
}
impl Type {
///
/// The element parser.
///
pub fn parse(lexer: &mut Lexer, initial: Option<Token>) -> Result<Self, Error> {
let token = crate::yul::parser::take_or_next(initial, lexer)?;
@@ -68,9 +61,7 @@ impl Type {
}
}
///
/// Converts the type into its LLVM.
///
pub fn into_llvm<'ctx, D>(
self,
context: &revive_llvm_context::EraVMContext<'ctx, D>,