Skip to content

Commit

Permalink
Add support for transient storage variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Nov 13, 2024
1 parent e0ed5da commit 305ae73
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ASTBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export class ASTBuilder
isImmutable = true
}

let isTransient = false
if (ctx.TransientKeyword_list().length > 0) {
isTransient = true
}

const decl: AST.StateVariableDeclarationVariable = {
type: 'VariableDeclaration',
typeName: type,
Expand All @@ -120,6 +125,7 @@ export class ASTBuilder
isDeclaredConst,
isIndexed: false,
isImmutable,
isTransient,
override,
storageLocation: null,
}
Expand Down
1 change: 1 addition & 0 deletions src/ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export interface VariableDeclaration extends BaseASTNode {
export interface StateVariableDeclarationVariable extends VariableDeclaration {
override: null | UserDefinedTypeName[]
isImmutable: boolean
isTransient: boolean
}
export interface ArrayTypeName extends BaseASTNode {
type: 'ArrayTypeName'
Expand Down
38 changes: 38 additions & 0 deletions test/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ describe('AST', () => {
isDeclaredConst: false,
isIndexed: false,
isImmutable: false,
isTransient: false,
storageLocation: null,
},
],
Expand Down Expand Up @@ -769,6 +770,39 @@ describe('AST', () => {
isDeclaredConst: false,
isIndexed: false,
isImmutable: true,
isTransient: false,
storageLocation: null,
},
],
initialValue: null,
})
})

it('StateVariableDeclaration with transient', () => {
const ast: any = parseNode('bool transient locked;')
assert.deepEqual(ast, {
type: 'StateVariableDeclaration',
variables: [
{
type: 'VariableDeclaration',
typeName: {
type: 'ElementaryTypeName',
name: 'bool',
stateMutability: null,
},
name: 'locked',
identifier: {
type: 'Identifier',
name: 'locked',
},
expression: null,
visibility: 'default',
override: null,
isStateVar: true,
isDeclaredConst: false,
isIndexed: false,
isImmutable: false,
isTransient: true,
storageLocation: null,
},
],
Expand Down Expand Up @@ -832,6 +866,7 @@ describe('AST', () => {
isDeclaredConst: false,
isIndexed: false,
isImmutable: false,
isTransient: false,
storageLocation: null,
},
],
Expand Down Expand Up @@ -905,6 +940,7 @@ describe('AST', () => {
isDeclaredConst: false,
isIndexed: false,
isImmutable: false,
isTransient: false,
storageLocation: null,
},
],
Expand Down Expand Up @@ -1490,6 +1526,7 @@ describe('AST', () => {
isIndexed: false,
override: null,
isImmutable: false,
isTransient: false,
storageLocation: null,
})
})
Expand Down Expand Up @@ -2751,6 +2788,7 @@ describe('AST', () => {
isDeclaredConst: false,
isIndexed: false,
isImmutable: false,
isTransient: false,
storageLocation: null,
},
],
Expand Down

0 comments on commit 305ae73

Please sign in to comment.