From 33bb265d279a68526c7c4c5e3e1205d083b12a15 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Fri, 28 Sep 2018 14:11:58 -0400 Subject: [PATCH] Replaced ints with uints and added comments indicating where I'll want delete statements in the future. --- src/main.cpp | 3 ++- src/operations/node.cpp | 7 ++++--- src/operations/node.hpp | 8 +++++--- src/shell.cpp | 1 + src/variables/environment.hpp | 6 ++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4d10960..1cd5110 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,7 @@ void interpret_file(char* fileName) { struct Environment* env = new Environment(); eval_statement(result, env); delete_environment(env); - + // delete env; + delete result; } \ No newline at end of file diff --git a/src/operations/node.cpp b/src/operations/node.cpp index 4d4e0f9..b1188f5 100644 --- a/src/operations/node.cpp +++ b/src/operations/node.cpp @@ -15,14 +15,14 @@ void attach_node(struct Node* parent, struct Node* child) { if (parent->num_children > MAX_CHILDREN) { std::cerr << "Error, max children attached to a node" << std::endl; } } -void check_num_nodes(struct Node* node, int num_children, std::string error) { +void check_num_nodes(struct Node* node, uint num_children, std::string error) { if (node && node->num_children != num_children) { std::cerr << "Error, " << error << std::endl; } } -void print_tree(struct Node* node, int tabs) { - int i; +void print_tree(struct Node* node, uint tabs) { + uint i; /* base case */ if(!node) { std::cerr << "NO TREE STRUCTURE" << std::endl; @@ -113,6 +113,7 @@ struct Value* eval_expression(struct Node* node, struct Environment* env) { eval_expression(node->children[1], env))); tempVal = eval_expression(tempNode->children[1], local_env); delete_environment(local_env); + // delete local_env; return tempVal; break; case PLUS: diff --git a/src/operations/node.hpp b/src/operations/node.hpp index 257b206..64d18e1 100644 --- a/src/operations/node.hpp +++ b/src/operations/node.hpp @@ -17,19 +17,21 @@ struct Node { std::string id; /* at most three children nodes */ - int num_children; + uint num_children; std::array children; Node(int t, struct Value* v, std::string s) { type = t; value = v; id = s; - for (int i = 0; i < MAX_CHILDREN; i++) { + for (uint i = 0; i < MAX_CHILDREN; i++) { children[i] = nullptr; } } ~Node() { - for (int i = 0; i < num_children; i++) { + if (value) { delete value; } + // delete value; + for (uint i = 0; i < num_children; i++) { delete children[i]; } } diff --git a/src/shell.cpp b/src/shell.cpp index 342bc24..551509e 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -70,5 +70,6 @@ void start_shell() { } delete_environment(env); + // delete env; delete result; } \ No newline at end of file diff --git a/src/variables/environment.hpp b/src/variables/environment.hpp index c06a5f6..8650d19 100644 --- a/src/variables/environment.hpp +++ b/src/variables/environment.hpp @@ -1,12 +1,18 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H +#include "variable.hpp" #include #include struct Environment { std::vector vars; Environment() { } + // ~Environment() { + // for (uint i = 0; i < size(vars); i++) { + // delete vars[i]; + // } + // } }; // Variable Lookup Functions