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,13 +1,9 @@
//!
//! The Yul IR error.
//!
use crate::yul::lexer::error::Error as LexerError;
use crate::yul::parser::error::Error as ParserError;
///
/// The Yul IR error.
///
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
/// The lexer error.
-4
View File
@@ -1,12 +1,8 @@
//!
//! The Yul IR lexer error.
//!
use crate::yul::lexer::token::location::Location;
///
/// The Yul IR lexer error.
///
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
/// The invalid lexeme error.
-10
View File
@@ -1,6 +1,4 @@
//!
//! The compiler lexer.
//!
pub mod error;
pub mod token;
@@ -18,9 +16,7 @@ use self::token::lexeme::Lexeme;
use self::token::location::Location;
use self::token::Token;
///
/// The compiler lexer.
///
pub struct Lexer {
/// The input source code.
input: String,
@@ -33,9 +29,7 @@ pub struct Lexer {
}
impl Lexer {
///
/// A shortcut constructor.
///
pub fn new(mut input: String) -> Self {
input.push('\n');
@@ -47,9 +41,7 @@ impl Lexer {
}
}
///
/// Advances the lexer, returning the next lexeme.
///
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Result<Token, Error> {
if let Some(peeked) = self.peeked.take() {
@@ -121,9 +113,7 @@ impl Lexer {
Ok(Token::new(self.location, Lexeme::EndOfFile, 0))
}
///
/// Peeks the next lexeme without advancing the iterator.
///
pub fn peek(&mut self) -> Result<Token, Error> {
match self.peeked {
Some(ref peeked) => Ok(peeked.clone()),
-2
View File
@@ -1,6 +1,4 @@
//!
//! The Yul IR lexer tests.
//!
use crate::yul::lexer::error::Error;
use crate::yul::lexer::token::lexeme::Lexeme;
@@ -1,6 +1,4 @@
//!
//! The comment lexeme.
//!
pub mod multi_line;
pub mod single_line;
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::Token;
use self::multi_line::Comment as MultiLineComment;
use self::single_line::Comment as SingleLineComment;
///
/// The comment lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(dead_code)]
pub enum Comment {
@@ -23,9 +19,7 @@ pub enum Comment {
}
impl Comment {
///
/// Returns the comment's length, including the trimmed whitespace around it.
///
pub fn parse(input: &str) -> Option<Token> {
if input.starts_with(SingleLineComment::START) {
Some(SingleLineComment::parse(input))
@@ -1,14 +1,10 @@
//!
//! The multi-line comment lexeme.
//!
use crate::yul::lexer::token::lexeme::Lexeme;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The multi-line comment lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Comment {}
@@ -18,9 +14,7 @@ impl Comment {
/// The end symbol.
pub const END: &'static str = "*/";
///
/// Returns the comment, including its length and number of lines.
///
pub fn parse(input: &str) -> Token {
let end_position = input.find(Self::END).unwrap_or(input.len());
let input = &input[..end_position];
@@ -1,14 +1,10 @@
//!
//! The single-line comment lexeme.
//!
use crate::yul::lexer::token::lexeme::Lexeme;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The single-line comment lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Comment {}
@@ -18,9 +14,7 @@ impl Comment {
/// The end symbol.
pub const END: &'static str = "\n";
///
/// Returns the comment's length, including the trimmed whitespace around it.
///
pub fn parse(input: &str) -> Token {
let end_position = input.find(Self::END).unwrap_or(input.len());
let length = end_position + Self::END.len();
@@ -1,15 +1,11 @@
//!
//! The identifier lexeme.
//!
use crate::yul::lexer::token::lexeme::keyword::Keyword;
use crate::yul::lexer::token::lexeme::Lexeme;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The identifier lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Identifier {
/// The inner string.
@@ -17,16 +13,12 @@ pub struct Identifier {
}
impl Identifier {
///
/// A shortcut constructor.
///
pub fn new(inner: String) -> Self {
Self { inner }
}
///
/// Parses the identifier, returning it as a token.
///
pub fn parse(input: &str) -> Option<Token> {
if !input.starts_with(Self::can_begin) {
return None;
@@ -47,16 +39,12 @@ impl Identifier {
))
}
///
/// Checks whether the character can begin an identifier.
///
pub fn can_begin(character: char) -> bool {
character.is_alphabetic() || character == '_' || character == '$'
}
///
/// Checks whether the character can continue an identifier.
///
pub fn can_continue(character: char) -> bool {
Self::can_begin(character)
|| character.is_numeric()
@@ -65,9 +53,7 @@ impl Identifier {
|| character == '.'
}
///
/// Checks whether the character cannot continue an identifier.
///
pub fn cannot_continue(character: char) -> bool {
!Self::can_continue(character)
}
@@ -1,6 +1,4 @@
//!
//! The keyword lexeme.
//!
use crate::yul::lexer::token::lexeme::literal::boolean::Boolean as BooleanLiteral;
use crate::yul::lexer::token::lexeme::literal::Literal;
@@ -8,9 +6,7 @@ use crate::yul::lexer::token::lexeme::Lexeme;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The keyword lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Keyword {
/// The `object` keyword.
@@ -50,9 +46,7 @@ pub enum Keyword {
}
impl Keyword {
///
/// Parses the keyword, returning it as a token.
///
pub fn parse(input: &str) -> Option<Token> {
let keyword = Self::parse_keyword(input)?;
let lexeme = match BooleanLiteral::try_from(keyword) {
@@ -68,9 +62,7 @@ impl Keyword {
Some(Token::new(Location::new(0, length), lexeme, length))
}
///
/// Parses the keyword itself.
///
fn parse_keyword(input: &str) -> Option<Self> {
if !input.starts_with(Self::can_begin) {
return None;
@@ -111,23 +103,17 @@ impl Keyword {
})
}
///
/// Checks whether the character can begin a keyword.
///
pub fn can_begin(character: char) -> bool {
character.is_alphabetic()
}
///
/// Checks whether the character can continue a keyword.
///
pub fn can_continue(character: char) -> bool {
Self::can_begin(character) || character.is_numeric()
}
///
/// Checks whether the character cannot continue a keyword.
///
pub fn cannot_continue(character: char) -> bool {
!Self::can_continue(character)
}
@@ -1,15 +1,11 @@
//!
//! The boolean literal lexeme.
//!
use serde::Deserialize;
use serde::Serialize;
use crate::yul::lexer::token::lexeme::keyword::Keyword;
///
/// The boolean literal lexeme.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Boolean {
/// Created from the `false` keyword.
@@ -19,16 +15,12 @@ pub enum Boolean {
}
impl Boolean {
///
/// Creates a `false` value.
///
pub fn r#false() -> Self {
Self::False
}
///
/// Creates a `true` value.
///
pub fn r#true() -> Self {
Self::True
}
@@ -1,6 +1,4 @@
//!
//! The integer literal lexeme.
//!
use serde::Deserialize;
use serde::Serialize;
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::lexeme::Literal;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The integer literal lexeme.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Integer {
/// An integer literal, like `42`.
@@ -28,23 +24,17 @@ pub enum Integer {
}
impl Integer {
///
/// Creates a decimal value.
///
pub fn new_decimal(inner: String) -> Self {
Self::Decimal { inner }
}
///
/// Creates a hexadecimal value.
///
pub fn new_hexadecimal(inner: String) -> Self {
Self::Hexadecimal { inner }
}
///
/// Parses the value from the source code slice.
///
pub fn parse(input: &str) -> Option<Token> {
let (value, length) = if let Some(body) = input.strip_prefix("0x") {
let end = body
@@ -72,37 +62,27 @@ impl Integer {
Some(token)
}
///
/// Checks whether the character can begin a decimal number.
///
pub fn can_begin_decimal(character: char) -> bool {
Self::can_continue_decimal(character)
}
///
/// Checks whether the character can continue a decimal number.
///
pub fn can_continue_decimal(character: char) -> bool {
character.is_digit(revive_common::BASE_DECIMAL)
}
///
/// Checks whether the character cannot continue a decimal number.
///
pub fn cannot_continue_decimal(character: char) -> bool {
!Self::can_continue_decimal(character)
}
///
/// Checks whether the character can continue a hexadecimal number.
///
pub fn can_continue_hexadecimal(character: char) -> bool {
character.is_digit(revive_common::BASE_HEXADECIMAL)
}
///
/// Checks whether the character cannot continue a hexadecimal number.
///
pub fn cannot_continue_hexadecimal(character: char) -> bool {
!Self::can_continue_hexadecimal(character)
}
@@ -1,6 +1,4 @@
//!
//! The literal lexeme.
//!
pub mod boolean;
pub mod integer;
@@ -13,9 +11,7 @@ use self::boolean::Boolean;
use self::integer::Integer;
use self::string::String;
///
/// The literal lexeme.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Literal {
/// A boolean literal, like `true`, or `false`.
@@ -1,6 +1,4 @@
//!
//! The string literal lexeme.
//!
use serde::Deserialize;
use serde::Serialize;
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::lexeme::Literal;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The string literal lexeme.
///
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct String {
/// The inner string contents.
@@ -22,9 +18,7 @@ pub struct String {
}
impl String {
///
/// Creates a string literal value.
///
pub fn new(inner: ::std::string::String, is_hexadecimal: bool) -> Self {
Self {
inner,
@@ -32,9 +26,7 @@ impl String {
}
}
///
/// Parses the value from the source code slice.
///
pub fn parse(input: &str) -> Option<Token> {
let mut length = 0;
@@ -1,6 +1,4 @@
//!
//! The lexeme.
//!
pub mod comment;
pub mod identifier;
@@ -13,9 +11,7 @@ use self::keyword::Keyword;
use self::literal::Literal;
use self::symbol::Symbol;
///
/// The lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Lexeme {
/// The keyword lexeme.
@@ -1,14 +1,10 @@
//!
//! The symbol lexeme.
//!
use crate::yul::lexer::token::lexeme::Lexeme;
use crate::yul::lexer::token::location::Location;
use crate::yul::lexer::token::Token;
///
/// The symbol lexeme.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Symbol {
/// The `:=` symbol.
@@ -30,9 +26,7 @@ pub enum Symbol {
}
impl Symbol {
///
/// Parses the symbol, returning it as a token.
///
pub fn parse(input: &str) -> Option<Token> {
let (symbol, length) = match &input[..2] {
":=" => (Self::Assignment, 2),
@@ -1,13 +1,9 @@
//!
//! The lexical token location.
//!
use serde::Deserialize;
use serde::Serialize;
///
/// The token location in the source code file.
///
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Eq)]
pub struct Location {
/// The line number, starting from 1.
@@ -23,17 +19,13 @@ impl Default for Location {
}
impl Location {
///
/// Creates a default location.
///
pub fn new(line: usize, column: usize) -> Self {
Self { line, column }
}
///
/// Mutates the location by shifting the original one down by `lines` and
/// setting the column to `column`.
///
pub fn shift_down(&mut self, lines: usize, column: usize) {
if lines == 0 {
self.shift_right(column);
@@ -44,9 +36,7 @@ impl Location {
self.column = column;
}
///
/// Mutates the location by shifting the original one rightward by `columns`.
///
pub fn shift_right(&mut self, columns: usize) {
self.column += columns;
}
@@ -1,6 +1,4 @@
//!
//! The token.
//!
pub mod lexeme;
pub mod location;
@@ -8,11 +6,8 @@ pub mod location;
use self::lexeme::Lexeme;
use self::location::Location;
///
/// The token.
///
/// Contains a lexeme and its location.
///
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
/// The token location.
@@ -24,9 +19,7 @@ pub struct Token {
}
impl Token {
///
/// A shortcut constructor.
///
pub fn new(location: Location, lexeme: Lexeme, length: usize) -> Self {
Self {
location,
-2
View File
@@ -1,6 +1,4 @@
//!
//! The Yul IR compiling tools.
//!
pub mod error;
pub mod lexer;
-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>,