Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Have recognition of user type defintions use a separate action, DEFIN…
Browse files Browse the repository at this point in the history
…E_TYPE, and not DECLARE, which in addition to not being appropriate, also didn't work. Also, various fixes.
  • Loading branch information
haltman-at committed Dec 19, 2018
1 parent 7752947 commit 70354dd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
5 changes: 5 additions & 0 deletions packages/truffle-debugger/lib/ast/sagas/index.js
Expand Up @@ -47,6 +47,11 @@ function *handleEnter(sourceId, node, pointer, parentId) {
debug("%s recording variable %o", pointer, node);
yield *data.declare(node);
break;
case "ContractDefinition":
case "StructDefinition":
case "EnumDefinition":
yield *data.defineType(node);
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/truffle-debugger/lib/data/actions/index.js
Expand Up @@ -56,3 +56,11 @@ export function learnAddress(dummyAddress, address) {
address
};
}

export const DEFINE_TYPE = "DEFINE_TYPE";
export function defineType(node) {
return {
type: DEFINE_TYPE,
node
};
}
14 changes: 2 additions & 12 deletions packages/truffle-debugger/lib/data/reducers.js
Expand Up @@ -5,8 +5,6 @@ import { combineReducers } from "redux";

import { stableKeccak256 } from "lib/helpers";

import { Allocation } from "truffle-decode-utils";

import * as actions from "./actions";

const DEFAULT_SCOPES = {
Expand Down Expand Up @@ -70,16 +68,8 @@ function scopes(state = DEFAULT_SCOPES, action) {

function userDefinedTypes(state = [], action) {
switch (action.type) {
case actions.DECLARE:
const userDefinedNodeTypes =
["StructDefinition","NodeDefinition","ContractDefinition"];
//note that interfaces and libraries are also ContractDefinition
if(userDefinedNodeTypes.includes(action.node.nodeType)) {
return [...state, action.node.id];
}
else {
return state;
}
case actions.DEFINE_TYPE:
return [...state, action.node.id];
default:
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/truffle-debugger/lib/data/sagas/index.js
Expand Up @@ -92,6 +92,7 @@ function* tickSaga() {
let allocation = allocations[node.id];

debug("Contract definition case");
debug("allocations %O", allocations);
debug("allocation %O", allocation);
assignments = { byId: {} };
for (let id in allocation.children) {
Expand Down Expand Up @@ -222,6 +223,10 @@ export function* reset() {
yield put(actions.reset());
}

export function* defineType(node) {
yield put(actions.defineType(node));
}

export function* learnAddressSaga(dummyAddress, address) {
debug("about to learn an address");
yield put(actions.learnAddress(dummyAddress, address));
Expand Down
9 changes: 6 additions & 3 deletions packages/truffle-debugger/lib/data/selectors/index.js
Expand Up @@ -270,10 +270,13 @@ const data = createSelectorTree({
_: createLeaf(["../userDefinedTypes/containers/ordered",
"/views/scopes/inlined"], (types, scopes) => {
let allocations = {};
for(id of types) {
debug("types %o", types);
for(let id of types) {
debug("in the allocation loop");
debug("id %d", id);
let variables = scopes[id].variables;
let allocation = Allocation.allocateDeclarations(variables, scopes,
allocations);
let allocation = TruffleDecodeUtils.Allocation.allocateDeclarations(
variables, scopes, allocations);
allocations[id] = allocation;
}
return allocations;
Expand Down

0 comments on commit 70354dd

Please sign in to comment.