Skip to content

Commit

Permalink
Add debug implementations required to print Namespace (hyperledger#1446)
Browse files Browse the repository at this point in the history
Derive `Debug` implementations for structs and enums required to print
`struct Namespace`. This is of use when one needs to print `Namespace`
struct for debugging purposes.

Signed-off-by: Govardhan G D <chioni1620@gmail.com>
  • Loading branch information
chioni16 committed Jul 19, 2023
1 parent a12d803 commit 7adce9b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/codegen/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{fmt, fmt::Write};
// IndexMap <ArrayVariable res , res of temp variable>
pub type ArrayLengthVars = IndexMap<usize, usize>;

#[derive(Clone)]
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum Instr {
/// Set variable
Expand Down Expand Up @@ -392,7 +392,7 @@ impl fmt::Display for HashTy {
}
}

#[derive(Clone, Default)]
#[derive(Debug, Clone, Default)]
pub struct BasicBlock {
pub phis: Option<BTreeSet<usize>>,
pub name: String,
Expand All @@ -402,7 +402,7 @@ pub struct BasicBlock {
pub transfers: Vec<Vec<reaching_definitions::Transfer>>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct ControlFlowGraph {
pub name: String,
pub function_no: ASTFunction,
Expand All @@ -419,7 +419,7 @@ pub struct ControlFlowGraph {
pub array_lengths_temps: ArrayLengthVars,
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ASTFunction {
SolidityFunction(usize),
YulFunction(usize),
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/reaching_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Def {
pub assignment_no: usize,
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Transfer {
Gen { def: Def, var_no: usize },
Mod { var_no: usize },
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/vartable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use num_bigint::BigInt;
use solang_parser::pt;
use std::collections::BTreeSet;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Variable {
pub id: pt::Identifier,
pub ty: Type,
Expand All @@ -29,7 +29,7 @@ pub struct DirtyTracker {
set: BTreeSet<usize>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum Storage {
Constant(usize),
Contract(BigInt),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use solang_parser::pt;
use std::{ffi::OsStr, fmt};

/// The target chain you want to compile Solidity for.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum Target {
/// Solana, see <https://solana.com/>
Solana,
Expand Down
13 changes: 12 additions & 1 deletion src/sema/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ impl fmt::Display for StructDecl {
}
}

#[derive(Debug)]
pub struct EnumDecl {
pub tags: Vec<Tag>,
pub name: String,
Expand Down Expand Up @@ -298,6 +299,7 @@ impl fmt::Display for Mutability {
}
}

#[derive(Debug)]
pub struct Function {
pub tags: Vec<Tag>,
/// The location of the prototype (not body)
Expand Down Expand Up @@ -349,6 +351,7 @@ pub struct SolanaAccount {
pub generated: bool,
}

#[derive(Debug)]
pub enum ConstructorAnnotation {
Seed(Expression),
Payer(pt::Loc, String),
Expand Down Expand Up @@ -577,6 +580,7 @@ impl fmt::Display for UserTypeDecl {
}
}

#[derive(Debug)]
pub struct Variable {
pub tags: Vec<Tag>,
pub name: String,
Expand All @@ -590,7 +594,7 @@ pub struct Variable {
pub read: bool,
}

#[derive(Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Symbol {
Enum(pt::Loc, usize),
Function(Vec<(pt::Loc, usize)>),
Expand Down Expand Up @@ -664,6 +668,7 @@ pub struct File {
}

/// When resolving a Solidity file, this holds all the resolved items
#[derive(Debug)]
pub struct Namespace {
pub target: Target,
pub files: Vec<File>,
Expand Down Expand Up @@ -700,37 +705,43 @@ pub struct Namespace {
pub hover_overrides: HashMap<pt::Loc, String>,
}

#[derive(Debug)]
pub struct Layout {
pub slot: BigInt,
pub contract_no: usize,
pub var_no: usize,
pub ty: Type,
}

#[derive(Debug)]
pub struct Base {
pub loc: pt::Loc,
pub contract_no: usize,
pub constructor: Option<(usize, Vec<Expression>)>,
}

#[derive(Debug)]
pub struct Using {
pub list: UsingList,
pub ty: Option<Type>,
pub file_no: Option<usize>,
}

#[derive(Debug)]
pub enum UsingList {
Library(usize),
Functions(Vec<UsingFunction>),
}

/// Using binding for a function, optionally for an operator
#[derive(Debug)]
pub struct UsingFunction {
pub loc: pt::Loc,
pub function_no: usize,
pub oper: Option<pt::UserDefinedOperator>,
}

#[derive(Debug)]
pub struct Contract {
pub tags: Vec<Tag>,
pub loc: pt::Loc,
Expand Down

0 comments on commit 7adce9b

Please sign in to comment.