Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/solidity-v2/outputs/cargo/ir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod ir;

#[cfg(test)]
pub mod tests;
mod tests;
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub enum Definition {
#[derive(Debug)]
pub struct ConstantDefinition {
pub ir_node: ir::ConstantDefinition,
pub scope_id: ScopeId,
pub(crate) scope_id: ScopeId,
}

#[derive(Debug)]
pub struct ContractDefinition {
pub ir_node: ir::ContractDefinition,
pub bases: Option<Vec<NodeId>>,
pub constructor_parameters_scope_id: Option<ScopeId>,
pub(crate) constructor_parameters_scope_id: Option<ScopeId>,
pub base_slot: Option<usize>,
}

Expand All @@ -63,19 +63,19 @@ pub struct EnumMemberDefinition {
#[derive(Debug)]
pub struct ErrorDefinition {
pub ir_node: ir::ErrorDefinition,
pub parameters_scope_id: ScopeId,
pub(crate) parameters_scope_id: ScopeId,
}

#[derive(Debug)]
pub struct EventDefinition {
pub ir_node: ir::EventDefinition,
pub parameters_scope_id: ScopeId,
pub(crate) parameters_scope_id: ScopeId,
}

#[derive(Debug)]
pub struct FunctionDefinition {
pub ir_node: ir::FunctionDefinition,
pub parameters_scope_id: ScopeId,
pub(crate) parameters_scope_id: ScopeId,
pub visibility: ir::FunctionVisibility,
}

Expand Down
5 changes: 3 additions & 2 deletions crates/solidity-v2/outputs/cargo/semantic/src/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use scopes::ContractScope;
pub(crate) use scopes::{FileScope, ParameterDefinition, ParametersScope, Scope, UsingDirective};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ScopeId(usize);
pub(crate) struct ScopeId(usize);

//////////////////////////////////////////////////////////////////////////////
// Binder
Expand Down Expand Up @@ -221,7 +221,8 @@ impl Binder {
self.linearisations.get(&node_id)
}

pub fn linearisations(&self) -> &HashMap<NodeId, Vec<NodeId>> {
#[cfg(test)]
pub(crate) fn linearisations(&self) -> &HashMap<NodeId, Vec<NodeId>> {
Comment thread
OmarTawfik marked this conversation as resolved.
&self.linearisations
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Reference {
}

impl Resolution {
pub fn as_definition_id(&self) -> Option<NodeId> {
pub(crate) fn as_definition_id(&self) -> Option<NodeId> {
if let Resolution::Definition(definition_id) = self {
Some(*definition_id)
} else {
Expand All @@ -64,16 +64,7 @@ impl Resolution {
}

#[must_use]
pub fn non_ambiguous(self) -> Self {
if matches!(self, Self::Ambiguous(_)) {
Self::Unresolved
} else {
self
}
}

#[must_use]
pub fn or_else<F>(self, f: F) -> Self
pub(crate) fn or_else<F>(self, f: F) -> Self
where
F: FnOnce() -> Self,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl SemanticContext {
reference.resolution.as_definition_id()
}

pub fn definition_canonical_name(&self, definition_id: NodeId) -> String {
pub(crate) fn definition_canonical_name(&self, definition_id: NodeId) -> String {
self.binder
.find_definition_by_id(definition_id)
.unwrap()
Expand Down Expand Up @@ -276,8 +276,8 @@ impl SemanticContext {
}

pub const SLOT_SIZE: usize = 32;
pub const ADDRESS_BYTE_SIZE: usize = 20;
pub const SELECTOR_SIZE: usize = 4;
pub(crate) const ADDRESS_BYTE_SIZE: usize = 20;
pub(crate) const SELECTOR_SIZE: usize = 4;

pub fn storage_size_of_type_id(&self, type_id: TypeId) -> Option<usize> {
self.storage_size_of_type_id_impl(type_id, &mut HashSet::new())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl FunctionType {
}
}

pub trait ImplicitlyConvertible<T> {
pub(crate) trait ImplicitlyConvertible<T> {
fn implicitly_convertible_to(&self, target: T) -> bool;
}

Expand Down
56 changes: 32 additions & 24 deletions crates/solidity-v2/outputs/cargo/semantic/src/types/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ impl Default for TypeRegistry {
}

impl TypeRegistry {
pub fn find_type(&self, type_: &Type) -> Option<TypeId> {
pub(crate) fn find_type(&self, type_: &Type) -> Option<TypeId> {
self.types.get_index_of(type_).map(TypeId)
}

pub fn register_type(&mut self, type_: Type) -> TypeId {
pub(crate) fn register_type(&mut self, type_: Type) -> TypeId {
let (index, _) = self.types.insert_full(type_);
TypeId(index)
}

pub fn register_super_types(&mut self, type_id: TypeId, super_types: Vec<TypeId>) {
pub(crate) fn register_super_types(&mut self, type_id: TypeId, super_types: Vec<TypeId>) {
self.super_types.insert(type_id, super_types);
}

Expand All @@ -107,7 +107,11 @@ impl TypeRegistry {
}

#[allow(clippy::too_many_lines)]
pub fn implicitly_convertible_to(&self, from_type_id: TypeId, to_type_id: TypeId) -> bool {
pub(crate) fn implicitly_convertible_to(
&self,
from_type_id: TypeId,
to_type_id: TypeId,
) -> bool {
if from_type_id == to_type_id {
return true;
}
Expand Down Expand Up @@ -288,7 +292,7 @@ impl TypeRegistry {

// Similar to `implicitly_convertible_to` above, but with relaxed rules for
// data location
pub fn implicitly_convertible_to_for_external_call(
pub(crate) fn implicitly_convertible_to_for_external_call(
&self,
from_type_id: TypeId,
to_type_id: TypeId,
Expand Down Expand Up @@ -349,7 +353,10 @@ impl TypeRegistry {

// Changes a function type to have external visibility and any parameters
// normalized for that (ie. `calldata` location is changed to `memory`)
pub fn externalize_function_type(&mut self, function_type: FunctionType) -> FunctionType {
pub(crate) fn externalize_function_type(
&mut self,
function_type: FunctionType,
) -> FunctionType {
FunctionType {
visibility: ir::FunctionVisibility::External,
parameter_types: function_type
Expand All @@ -374,7 +381,7 @@ impl TypeRegistry {
}
}

pub fn find_canonical_type_id(&self, type_id: TypeId) -> Option<TypeId> {
pub(crate) fn find_canonical_type_id(&self, type_id: TypeId) -> Option<TypeId> {
let canonical_type = match self.get_type_by_id(type_id) {
Type::Array { element_type, .. } => {
let element_type = self.find_canonical_type_id(*element_type)?;
Expand Down Expand Up @@ -444,7 +451,7 @@ impl TypeRegistry {
self.register_type_with_data_location(type_, location)
}

pub fn register_type_with_data_location(
pub(crate) fn register_type_with_data_location(
&mut self,
type_: Type,
location: DataLocation,
Expand Down Expand Up @@ -495,7 +502,7 @@ impl TypeRegistry {

// Return a type that can be stored in the EVM. In short, convert literal
// types into the appropriate "real" type
pub fn reified_type(&mut self, type_id: TypeId) -> TypeId {
pub(crate) fn reified_type(&mut self, type_id: TypeId) -> TypeId {
let Type::Literal(kind) = self.get_type_by_id(type_id) else {
return type_id;
};
Expand Down Expand Up @@ -654,52 +661,53 @@ impl TypeRegistry {

// Convenience accessors for pre-defined types
impl TypeRegistry {
pub fn address(&self) -> TypeId {
pub(crate) fn address(&self) -> TypeId {
self.address_type_id
}
pub fn address_payable(&self) -> TypeId {
pub(crate) fn address_payable(&self) -> TypeId {
self.address_payable_type_id
}
pub fn boolean(&self) -> TypeId {
pub(crate) fn boolean(&self) -> TypeId {
self.boolean_type_id
}
pub fn boolean_bytes_tuple(&self) -> TypeId {
pub(crate) fn boolean_bytes_tuple(&self) -> TypeId {
self.boolean_bytes_tuple_type_id
}
pub fn bytes_calldata(&self) -> TypeId {
pub(crate) fn bytes_calldata(&self) -> TypeId {
self.bytes_calldata_type_id
}
pub fn bytes_memory(&self) -> TypeId {
pub(crate) fn bytes_memory(&self) -> TypeId {
self.bytes_memory_type_id
}
pub fn bytes1(&self) -> TypeId {
pub(crate) fn bytes1(&self) -> TypeId {
self.bytes1_type_id
}
pub fn bytes20(&self) -> TypeId {
pub(crate) fn bytes20(&self) -> TypeId {
self.bytes20_type_id
}
pub fn bytes32(&self) -> TypeId {
pub(crate) fn bytes32(&self) -> TypeId {
self.bytes32_type_id
}
pub fn bytes4(&self) -> TypeId {
pub(crate) fn bytes4(&self) -> TypeId {
self.bytes4_type_id
}
pub fn string(&self) -> TypeId {
pub(crate) fn string(&self) -> TypeId {
self.string_type_id
}
pub fn uint256(&self) -> TypeId {
pub(crate) fn uint256(&self) -> TypeId {
self.uint256_type_id
}
pub fn uint8(&self) -> TypeId {
pub(crate) fn uint8(&self) -> TypeId {
self.uint8_type_id
}
pub fn void(&self) -> TypeId {
pub(crate) fn void(&self) -> TypeId {
self.void_type_id
}
}

#[cfg(test)]
impl TypeRegistry {
pub fn iter_types(&self) -> impl Iterator<Item = (TypeId, &Type)> {
pub(crate) fn iter_types(&self) -> impl Iterator<Item = (TypeId, &Type)> {
(0usize..).map(TypeId).zip(self.types.iter())
}
}
3 changes: 3 additions & 0 deletions crates/solidity-v2/outputs/cargo/slang_solidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license = "MIT"
keywords = ["utilities"]
categories = ["compilers", "utilities"]

[features]
__private_testing_utils = []

[dependencies]
slang_solidity_v2_ast = { workspace = true }
slang_solidity_v2_common = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use slang_solidity_v2_ast::abi::*;
4 changes: 4 additions & 0 deletions crates/solidity-v2/outputs/cargo/slang_solidity/src/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub use slang_solidity_v2_ast::ast::*;
pub use slang_solidity_v2_common::built_ins::BuiltIn;
pub use slang_solidity_v2_common::nodes::NodeId;
pub use slang_solidity_v2_semantic::types::{DataLocation, TypeId};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
pub mod builder;
pub mod file;
mod builder;
mod file;
mod internal_builder;
pub mod unit;
mod unit;

pub use builder::{CompilationBuilder, CompilationBuilderConfig, CompilationBuilderError};
Comment thread
OmarTawfik marked this conversation as resolved.
pub use slang_solidity_v2_parser::ParserError;
pub use unit::CompilationUnit;
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ impl CompilationUnit {
self.language_version
}

/// Returns a list of all files in the compilation unit.
pub fn files(&self) -> Vec<Rc<File>> {
self.files.values().cloned().collect()
/// Returns a list of all file IDs in the compilation unit.
pub fn file_ids(&self) -> Vec<String> {
Comment thread
OmarTawfik marked this conversation as resolved.
self.files.keys().cloned().collect()
}

/// Returns the file with the specified ID, if it exists.
pub fn file(&self, id: &str) -> Option<Rc<File>> {
self.files.get(id).cloned()
}

// TODO: this should be semi-public
#[cfg(feature = "__private_testing_utils")]
#[doc(hidden)]
Comment thread
OmarTawfik marked this conversation as resolved.
pub fn semantic(&self) -> &Rc<SemanticContext> {
&self.semantic
}
Expand All @@ -56,6 +52,14 @@ impl CompilationUnit {
.map(|file| ast::create_source_unit(file.ir_root(), &self.semantic))
}

#[cfg(feature = "__private_testing_utils")]
#[doc(hidden)]
pub fn get_file_ir_root(&self, file_id: &str) -> Option<slang_solidity_v2_ir::ir::SourceUnit> {
self.files
.get(file_id)
.map(|file| Rc::clone(file.ir_root()))
}

pub fn all_definitions(&self) -> impl Iterator<Item = ast::Definition> + use<'_> {
self.semantic.all_definitions().map(|definition| {
ast::Definition::try_create(definition.node_id(), &self.semantic).unwrap()
Expand Down
3 changes: 3 additions & 0 deletions crates/solidity-v2/outputs/cargo/slang_solidity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub mod abi;
pub mod ast;
pub mod compilation;
pub mod utils;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use slang_solidity_v2_ast::abi::AbiEntry;

use super::fixtures;
use crate::abi::AbiEntry;

/// Convenience macro to test equality of tuple components for input/output parameters.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Result;
use slang_solidity_v2_ast::ast::{self, ContractBase, ContractMember, Definition, FunctionKind};
use slang_solidity_v2_common::built_ins::BuiltIn;

use super::fixtures;
use crate::ast::{self, BuiltIn, ContractBase, ContractMember, Definition, FunctionKind};

#[derive(Default)]
struct IdentifierCounter {
Expand Down
Loading
Loading