Exemple #1
0
	void ZombieGame::loadTerrain() {
		auto entry = ZombieEntry(zombieEntry_.getDeepChildEntry("settings map").getString());
		entry = entry.getDeepChildEntry("map objects object");
		while (entry.hasData()) {
			std::string geom(entry.getChildEntry("geom").getString());
			if (entry.isAttributeEqual("type", "building")) {
				auto v = loadPolygon(geom);
				Building* b = buildings_.emplaceBack(v[0], v[1], v[2], v[3], wall_, wall_, wall_);
				engine_.add(b);
				b->setActive(true);
				b->setAwake(true);
			} else if (entry.isAttributeEqual("type", "water")) {
				auto triangle = loadPolygon(geom);
				water_.addTriangle(triangle[0], triangle[1], triangle[2]);
			} else if (entry.isAttributeEqual("type", "grass")) {
				auto triangle = loadPolygon(geom);
				terrain_.addGrass(triangle[0], triangle[1], triangle[2]);
			} else if (entry.isAttributeEqual("type", "tilepoint")) {
				terrain_.addRoad(entry);
			} else if (entry.isAttributeEqual("type", "tree")) {
				engine_.add(new Tree2D(loadPoint(geom), tree_));
			} else if (entry.isAttributeEqual("type", "spawningpoint")) {
				spawningPoints_.push_back(loadPoint(geom));
			} else if (entry.isAttributeEqual("type", "carSpawningpoint")) {
				//carSpawningPoints_.push_back(loadPoint(geom));
			}
			entry = entry.getSibling("object");
		}
	}
Exemple #2
0
void
UavcanNode::print_info()
{
	if (!_instance) {
		warnx("not running, start first");
	}

	(void)pthread_mutex_lock(&_node_mutex);

	// ESC mixer status
	printf("ESC actuators control groups: sub: %u / req: %u / fds: %u\n",
	       (unsigned)_groups_subscribed, (unsigned)_groups_required, _poll_fds_num);
	printf("ESC mixer: %s\n", (_mixers == nullptr) ? "NONE" : "OK");

	if (_outputs.noutputs != 0) {
		printf("ESC output: ");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			printf("%d ", (int)(_outputs.output[i] * 1000));
		}

		printf("\n");

		// ESC status
		int esc_sub = orb_subscribe(ORB_ID(esc_status));
		struct esc_status_s esc;
		memset(&esc, 0, sizeof(esc));
		orb_copy(ORB_ID(esc_status), esc_sub, &esc);

		printf("ESC Status:\n");
		printf("Addr\tV\tA\tTemp\tSetpt\tRPM\tErr\n");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			printf("%d\t",    esc.esc[i].esc_address);
			printf("%3.2f\t", (double)esc.esc[i].esc_voltage);
			printf("%3.2f\t", (double)esc.esc[i].esc_current);
			printf("%3.2f\t", (double)esc.esc[i].esc_temperature);
			printf("%3.2f\t", (double)esc.esc[i].esc_setpoint);
			printf("%d\t",    esc.esc[i].esc_rpm);
			printf("%d",      esc.esc[i].esc_errorcount);
			printf("\n");
		}

		orb_unsubscribe(esc_sub);
	}

	// Sensor bridges
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		printf("Sensor '%s':\n", br->get_name());
		br->print_status();
		printf("\n");
		br = br->getSibling();
	}

	(void)pthread_mutex_unlock(&_node_mutex);
}
Exemple #3
0
int UavcanNode::init(uavcan::NodeID node_id)
{
	int ret = -1;

	// Do regular cdev init
	ret = CDev::init();

	if (ret != OK) {
		return ret;
	}

	_node.setName("org.pixhawk.pixhawk");

	_node.setNodeID(node_id);

	fill_node_info();

	// Actuators
	ret = _esc_controller.init();

	if (ret < 0) {
		return ret;
	}

	{
		std::int32_t idle_throttle_when_armed = 0;
		(void) param_get(param_find("UAVCAN_ESC_IDLT"), &idle_throttle_when_armed);
		_esc_controller.enable_idle_throttle_when_armed(idle_throttle_when_armed > 0);
	}

	ret = _hardpoint_controller.init();

	if (ret < 0) {
		return ret;
	}

	// Sensor bridges
	IUavcanSensorBridge::make_all(_node, _sensor_bridges);
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		ret = br->init();

		if (ret < 0) {
			warnx("cannot init sensor bridge '%s' (%d)", br->get_name(), ret);
			return ret;
		}

		warnx("sensor bridge '%s' init ok", br->get_name());
		br = br->getSibling();
	}


	/*  Start the Node   */

	return _node.start();
}
Exemple #4
0
UavcanNode::~UavcanNode()
{

	fw_server(Stop);

	if (_task != -1) {

		/* tell the task we want it to go away */
		_task_should_exit = true;

		unsigned i = 10;

		do {
			/* wait 5ms - it should wake every 10ms or so worst-case */
			usleep(5000);

			/* if we have given up, kill it */
			if (--i == 0) {
				task_delete(_task);
				break;
			}

		} while (_task != -1);
	}

	(void)::close(_armed_sub);
	(void)::close(_test_motor_sub);
	(void)::close(_actuator_direct_sub);

	// Removing the sensor bridges
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		auto next = br->getSibling();
		delete br;
		br = next;
	}

	_instance = nullptr;

	perf_free(_perfcnt_node_spin_elapsed);
	perf_free(_perfcnt_esc_mixer_output_elapsed);
	perf_free(_perfcnt_esc_mixer_total_elapsed);
	pthread_mutex_destroy(&_node_mutex);
	px4_sem_destroy(&_server_command_sem);

	// Is it allowed to delete it like that?
	if (_mixers != nullptr) {
		delete _mixers;
	}
}
Exemple #5
0
int UavcanNode::init(uavcan::NodeID node_id)
{
	int ret = -1;

	// Do regular cdev init
	ret = CDev::init();

	if (ret != OK) {
		return ret;
	}

	_node.setName("org.pixhawk.pixhawk");

	_node.setNodeID(node_id);

	fill_node_info();

	// Actuators
	ret = _esc_controller.init();

	if (ret < 0) {
		return ret;
	}

	ret = _hardpoint_controller.init();

	if (ret < 0) {
		return ret;
	}

	// Sensor bridges
	IUavcanSensorBridge::make_all(_node, _sensor_bridges);
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		ret = br->init();

		if (ret < 0) {
			warnx("cannot init sensor bridge '%s' (%d)", br->get_name(), ret);
			return ret;
		}

		warnx("sensor bridge '%s' init ok", br->get_name());
		br = br->getSibling();
	}


	/*  Start the Node   */

	return _node.start();
}
Exemple #6
0
void DwarfVariableFinder::findVariables(const DWARFDie &die) {

  for (auto child = die.getFirstChild(); child; child = child.getSibling()) {
    switch(child.getTag()) {
      case dwarf::DW_TAG_variable:
      case dwarf::DW_TAG_formal_parameter:
      case dwarf::DW_TAG_constant:
        handleVariable(child);
        break;
      default:
        if (child.hasChildren())
          findVariables(child);
    }
  }
}
Exemple #7
0
UavcanNode::~UavcanNode()
{

	fw_server(Stop);

	if (_task != -1) {

		/* tell the task we want it to go away */
		_task_should_exit = true;

		unsigned i = 10;

		do {
			/* wait 5ms - it should wake every 10ms or so worst-case */
			usleep(5000);

			/* if we have given up, kill it */
			if (--i == 0) {
				task_delete(_task);
				break;
			}

		} while (_task != -1);
	}

	/* clean up the alternate device node */
	// unregister_driver(PWM_OUTPUT_DEVICE_PATH);

	::close(_armed_sub);

	// Removing the sensor bridges
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		auto next = br->getSibling();
		delete br;
		br = next;
	}

	_instance = nullptr;

	perf_free(_perfcnt_node_spin_elapsed);
	perf_free(_perfcnt_esc_mixer_output_elapsed);
	perf_free(_perfcnt_esc_mixer_total_elapsed);
	pthread_mutex_destroy(&_node_mutex);
	sem_destroy(&_server_command_sem);

}
Exemple #8
0
DwarfVariableFinder::DwarfVariableFinder(const DWARFDie &die, raw_ostream &os) : OS(os) {
  if(!die.hasChildren()) {
    outs() << "No child \n\n";
    return;
  }

  for (auto child = die.getFirstChild(); child; child = child.getSibling()) {
    //Go over all the top level sub_programs
    if(child.isSubprogramDIE() || child.isSubroutineDIE()) {
      getInfo(child);

      //Look for variables among children of sub_program die
      if(!child.hasChildren()) {
        continue;
      }
      findVariables(child);
    }
  }
}
Exemple #9
0
	INode::node_t::SP Node::_rewindRange(Size& size) const {
		const auto cs = _getCachedSize();
		if(isExpanded()) {
			if(size <= cs) {
				// このノードを精査
				auto cur = getChild();
				while(auto next = cur->getSibling())
					cur = next;
				for(;;) {
					if(auto ret = cur->rewindRange(size))
						return ret;
					if(auto next = cur->getPrevSibling())
						cur = next;
					else
						break;
				}
				AssertP(Trap, size <= _getThisSize())
				return const_cast<Node*>(this)->shared_from_this();
			}
			size -= cs;
		} else {
Exemple #10
0
void
UavcanNode::print_info()
{
	if (!_instance) {
		warnx("not running, start first");
	}

	(void)pthread_mutex_lock(&_node_mutex);

	// Memory status
	printf("Pool allocator status:\n");
	printf("\tCapacity hard/soft: %u/%u blocks\n",
		_pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
	printf("\tReserved:  %u blocks\n", _pool_allocator.getNumReservedBlocks());
	printf("\tAllocated: %u blocks\n", _pool_allocator.getNumAllocatedBlocks());

	// UAVCAN node perfcounters
	printf("UAVCAN node status:\n");
	printf("\tInternal failures: %llu\n", _node.getInternalFailureCount());
	printf("\tTransfer errors:   %llu\n", _node.getDispatcher().getTransferPerfCounter().getErrorCount());
	printf("\tRX transfers:      %llu\n", _node.getDispatcher().getTransferPerfCounter().getRxTransferCount());
	printf("\tTX transfers:      %llu\n", _node.getDispatcher().getTransferPerfCounter().getTxTransferCount());

	// CAN driver status
	for (unsigned i = 0; i < _node.getDispatcher().getCanIOManager().getCanDriver().getNumIfaces(); i++) {
		printf("CAN%u status:\n", unsigned(i + 1));

		auto iface = _node.getDispatcher().getCanIOManager().getCanDriver().getIface(i);
		printf("\tHW errors: %llu\n", iface->getErrorCount());

		auto iface_perf_cnt = _node.getDispatcher().getCanIOManager().getIfacePerfCounters(i);
		printf("\tIO errors: %llu\n", iface_perf_cnt.errors);
		printf("\tRX frames: %llu\n", iface_perf_cnt.frames_rx);
		printf("\tTX frames: %llu\n", iface_perf_cnt.frames_tx);
	}

	// ESC mixer status
	printf("ESC actuators control groups: sub: %u / req: %u / fds: %u\n",
	       (unsigned)_groups_subscribed, (unsigned)_groups_required, _poll_fds_num);
	printf("ESC mixer: %s\n", (_mixers == nullptr) ? "NONE" : "OK");

	if (_outputs.noutputs != 0) {
		printf("ESC output: ");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			printf("%d ", (int)(_outputs.output[i] * 1000));
		}

		printf("\n");

		// ESC status
		int esc_sub = orb_subscribe(ORB_ID(esc_status));
		struct esc_status_s esc;
		memset(&esc, 0, sizeof(esc));
		orb_copy(ORB_ID(esc_status), esc_sub, &esc);

		printf("ESC Status:\n");
		printf("Addr\tV\tA\tTemp\tSetpt\tRPM\tErr\n");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			printf("%d\t",    esc.esc[i].esc_address);
			printf("%3.2f\t", (double)esc.esc[i].esc_voltage);
			printf("%3.2f\t", (double)esc.esc[i].esc_current);
			printf("%3.2f\t", (double)esc.esc[i].esc_temperature);
			printf("%3.2f\t", (double)esc.esc[i].esc_setpoint);
			printf("%d\t",    esc.esc[i].esc_rpm);
			printf("%d",      esc.esc[i].esc_errorcount);
			printf("\n");
		}

		orb_unsubscribe(esc_sub);
	}

	// Sensor bridges
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		printf("Sensor '%s':\n", br->get_name());
		br->print_status();
		printf("\n");
		br = br->getSibling();
	}

	(void)pthread_mutex_unlock(&_node_mutex);
}
RBNode* RedBlackTree::getUncle(RBNode* node)
{
	return getSibling(node->parent);
}
Exemple #12
0
std::shared_ptr<TypeInfo> DwarfVariableFinder::makeType(const DWARFDie &die) {

  if (!die.isValid()) {
    return std::make_shared<TypeInfo>("", ~0u);
  }
  auto opSize = die.find(dwarf::DW_AT_byte_size);
  unsigned size = 1;
  if(opSize.hasValue()) {
    size = opSize.getValue().getAsUnsignedConstant().getValue();  
  }

  std::string type_encoding = "";
  raw_string_ostream SS(type_encoding);

  switch (die.getTag()) {
    case dwarf::DW_TAG_base_type: {  
                                    auto opForm = die.find(dwarf::DW_AT_encoding);
                                    auto opEnc = opForm->getAsUnsignedConstant();
                                    assert(opEnc < HANDLE_DW_ATE_SIZE);
                                    SS << HANDLE_DW_ATE[*opEnc];
                                    opForm = die.find(dwarf::DW_AT_name);
                                    opForm->dump(SS);
                                    return std::make_shared<TypeInfo>(SS.str(), size);
                                  }
    case dwarf::DW_TAG_reference_type:
    case dwarf::DW_TAG_rvalue_reference_type:
    case dwarf::DW_TAG_pointer_type: {
                                       auto baseType = getType(die.getAttributeValueAsReferencedDie(dwarf::DW_AT_type));
                                       SS <<  "*" << baseType->getName();
                                       return std::make_shared<TypeInfo>(SS.str(), size);
                                     }
    case dwarf::DW_TAG_array_type: {
                                     auto baseType = getType(die.getAttributeValueAsReferencedDie(dwarf::DW_AT_type));
                                     SS << baseType->getName();
                                     size *= baseType->getSize();

                                     for (auto childDie = die.getFirstChild(); childDie && childDie.getTag(); 
                                         childDie = childDie.getSibling()) {
                                       std::shared_ptr<TypeInfo> rangeInfo = makeType(childDie);
                                       SS << "[";
                                       SS <<  rangeInfo->getName();
                                       SS << "]";
                                       size *= rangeInfo->getSize();
                                     }
                                     return std::make_shared<TypeInfo>(SS.str(), size);
                                   }
    case dwarf::DW_TAG_subrange_type: {
                                        uint64_t count = 0;
                                        auto opCount = die.find(dwarf::DW_AT_count);
                                        if(opCount.hasValue()) {
                                          count = opCount.getValue().getAsUnsignedConstant().getValue();
                                        } else {
                                          opCount = die.find(dwarf::DW_AT_upper_bound);
                                          assert(opCount.hasValue());
                                          count = opCount.getValue().getAsUnsignedConstant().getValue()  +1;
                                        }
                                        return std::make_shared<TypeInfo>(std::to_string(count), count);
                                      }
    case dwarf::DW_TAG_typedef: {
                                  return getType(die.getAttributeValueAsReferencedDie(dwarf::DW_AT_type));
                                }

    case dwarf::DW_TAG_structure_type:
    case dwarf::DW_TAG_class_type:
    case dwarf::DW_TAG_union_type: {
                                     SS << "struct" << dwarf::toString(die.find(dwarf::DW_AT_name), "None");
                                     auto structType = std::make_shared<TypeInfo>(SS.str(), size);

                                     // Add subentries for various pieces of the struct.
                                     for (auto childDie = die.getFirstChild(); childDie && childDie.getTag(); childDie = childDie.getSibling()) {
                                       if (childDie.getTag() != dwarf::DW_TAG_inheritance &&
                                           childDie.getTag() != dwarf::DW_TAG_member) {
                                         continue;
                                       }
                                       uint64_t dataMemOffset = dwarf::toUnsigned(childDie.find(dwarf::DW_AT_data_member_location), ~0U);
                                       structType->getFields().emplace_back(makeType(childDie), dataMemOffset);
                                     }
                                     return structType;
                                   }

    case dwarf::DW_TAG_inheritance:
    case dwarf::DW_TAG_member: {
                                 return getType(die.getAttributeValueAsReferencedDie(dwarf::DW_AT_type));
                               }        

    default: {
               auto tagString = TagString(die.getTag());
               if (tagString.empty()) {
                 llvm::errs() << format("DW_TAG_Unknown_%x", die.getTag());
               }
               die.dump(llvm::errs(), 10);
               return std::make_shared<TypeInfo>("", ~0u);
             }
  }
}
void RedBlackTree::removeFixup(TreeNode * pNode)
{
    TreeNode * pSibling = NULL;   
    while ((pNode != m_pRoot) && (pNode->color == black))   
    {   
        pSibling = getSibling(pNode);   
        if (pNode == pNode->parent->left) // left child node   
        {   
            if (pSibling->color == red)   
            {   
                // case 1, can change to case 2, 3, 4   
                pNode->parent->color = red;   
                pSibling->color = black;   
                rotateLeft(pNode->parent);   
                // change to new sibling,    
                pSibling = pNode->parent->right;   
            }   
            // case 2;   
            if ((black == pSibling->left->color) && (black == pSibling->right->color))    
            {    
                pSibling->color = red;    
                pNode = pNode->parent;    
            }   
            else  
            {   
                if (black == pSibling->right->color)    
                {    
                    pSibling->color = red;    
                    pSibling->left->color = black;    
                    rotateRight(pSibling);    
                    pSibling = pNode->parent->right;    
                }   
                pSibling->color = pNode->parent->color;   
                pNode->parent->color = black;   
                pSibling->right->color = black;   
                rotateLeft(pNode->parent);   
                break;    
            }   
        }   
        else  
        {   
            if (pSibling->color == red)   
            {   
                // case 1, can change to case 2, 3, 4   
                pNode->parent->color = red;   
                pSibling->color = black;   
                rotateRight(pNode->parent);   
                // change to new sibling,    
                pSibling = pNode->parent->left;   
            }   
            // case 2;   
            if ((black == pSibling->left->color) && (black == pSibling->right->color))    
            {    
                pSibling->color = red;    
                pNode = pNode->parent;    
            }   
            else  
            {   
                if (black == pSibling->left->color)    
                {    
                    pSibling->color = red;    
                    pSibling->right->color = black;    
                    rotateLeft(pSibling);    
                    pSibling = pNode->parent->left;    
                }   
                pSibling->color = pNode->parent->color;   
                pNode->parent->color = black;   
                pSibling->left->color = black;   
                rotateRight(pNode->parent);   
                break;    
            }   
        }   
    }   
    pNode->color = black;   
}
Exemple #14
0
void
UavcanNode::print_info()
{
	if (!_instance) {
		warnx("not running, start first");
	}

	(void)pthread_mutex_lock(&_node_mutex);

	// Memory status
	printf("Pool allocator status:\n");
	printf("\tCapacity hard/soft: %u/%u blocks\n",
	       _pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
	printf("\tReserved:  %u blocks\n", _pool_allocator.getNumReservedBlocks());
	printf("\tAllocated: %u blocks\n", _pool_allocator.getNumAllocatedBlocks());

	// UAVCAN node perfcounters
	printf("UAVCAN node status:\n");
	printf("\tInternal failures: %llu\n", _node.getInternalFailureCount());
	printf("\tTransfer errors:   %llu\n", _node.getDispatcher().getTransferPerfCounter().getErrorCount());
	printf("\tRX transfers:      %llu\n", _node.getDispatcher().getTransferPerfCounter().getRxTransferCount());
	printf("\tTX transfers:      %llu\n", _node.getDispatcher().getTransferPerfCounter().getTxTransferCount());

	// CAN driver status
	for (unsigned i = 0; i < _node.getDispatcher().getCanIOManager().getCanDriver().getNumIfaces(); i++) {
		printf("CAN%u status:\n", unsigned(i + 1));

		auto iface = _node.getDispatcher().getCanIOManager().getCanDriver().getIface(i);
		printf("\tHW errors: %llu\n", iface->getErrorCount());

		auto iface_perf_cnt = _node.getDispatcher().getCanIOManager().getIfacePerfCounters(i);
		printf("\tIO errors: %llu\n", iface_perf_cnt.errors);
		printf("\tRX frames: %llu\n", iface_perf_cnt.frames_rx);
		printf("\tTX frames: %llu\n", iface_perf_cnt.frames_tx);
	}

	// ESC mixer status
	printf("ESC actuators control groups: sub: %u / req: %u / fds: %u\n",
	       (unsigned)_groups_subscribed, (unsigned)_groups_required, _poll_fds_num);
	printf("ESC mixer: %s\n", (_mixers == nullptr) ? "NONE" : "OK");

	if (_outputs.noutputs != 0) {
		printf("ESC output: ");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			printf("%d ", (int)(_outputs.output[i] * 1000));
		}

		printf("\n");

		// ESC status
		int esc_sub = orb_subscribe(ORB_ID(esc_status));
		struct esc_status_s esc;
		memset(&esc, 0, sizeof(esc));
		orb_copy(ORB_ID(esc_status), esc_sub, &esc);

		printf("ESC Status:\n");
		printf("Addr\tV\tA\tTemp\tSetpt\tRPM\tErr\n");

		for (uint8_t i = 0; i < _outputs.noutputs; i++) {
			const float temp_celsius = (esc.esc[i].esc_temperature > 0) ?
				(esc.esc[i].esc_temperature - 273.15F) : 0.0F;

			printf("%d\t",    esc.esc[i].esc_address);
			printf("%3.2f\t", (double)esc.esc[i].esc_voltage);
			printf("%3.2f\t", (double)esc.esc[i].esc_current);
			printf("%3.2f\t", (double)temp_celsius);
			printf("%3.2f\t", (double)esc.esc[i].esc_setpoint);
			printf("%d\t",    esc.esc[i].esc_rpm);
			printf("%d",      esc.esc[i].esc_errorcount);
			printf("\n");
		}

		orb_unsubscribe(esc_sub);
	}

	// Sensor bridges
	auto br = _sensor_bridges.getHead();

	while (br != nullptr) {
		printf("Sensor '%s':\n", br->get_name());
		br->print_status();
		printf("\n");
		br = br->getSibling();
	}

	// Printing all nodes that are online
	std::printf("Online nodes (Node ID, Health, Mode):\n");
	_node_status_monitor.forEachNode([](uavcan::NodeID nid, uavcan::NodeStatusMonitor::NodeStatus ns) {
		static constexpr const char* HEALTH[] = {
			"OK", "WARN", "ERR", "CRIT"
		};
		static constexpr const char* MODES[] = {
			"OPERAT", "INIT", "MAINT", "SW_UPD", "?", "?", "?", "OFFLN"
		};
		std::printf("\t% 3d %-10s %-10s\n", int(nid.get()), HEALTH[ns.health], MODES[ns.mode]);
	});

	(void)pthread_mutex_unlock(&_node_mutex);
}
Exemple #15
0
/*
 * Builds the symbol table, creating scopes as needed, and linking them together.
 * Adds variable and function identifiers to scopes appropriately.
 */
void build_symbol_table(ast_node root, int level, int sibno, symboltable_t *symtab) {
  //calculate the scope for the variable/func declaration
  //calculate the parent for that variable/func declaration
  //need function to take as input
  //printf("here \n");
  symhashtable_t *hash;

  /* Depending on node types, go deeper, create sibling scopes, add to hashtable,
   * or take other appropriate action.
   */
  switch (root->node_type) {
    ast_node param;
    int param_offset = 4;
    int param_count = 0;

    case SEQ_N:     // change main level when see a new sequence
      level++;
      break;

    case FORMAL_PARAMS_N:
      level++;
      param_count = 0;
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
    //   for(param = root->left_child; param != NULL; param = param->right_sibling){
    //     if(param->node_type == ARRAY_TYPE_N || param->return_type == ARRAY_TYPE_N){
    //      param_count += DEFAULT_ARRAY_PARAM_SIZE;
    //    }
    //    else{
    //      param_count++;
    //    }
    //  }
    //  printf("PARAM COUNT!!!!! = %d\n", param_count);
    //
    //  for(param = root->left_child; param != NULL; param = param->right_sibling){
    //    if(param->node_type == ARRAY_TYPE_N || param->return_type == ARRAY_TYPE_N){
    //      param->snode->offset = param_count * 4;
    //      param->snode->offset -= DEFAULT_ARRAY_PARAM_SIZE;
    //    }
    //    else{
    //     param->snode->offset = param_count-- * 4;
    //    }
    // }


      break;

    case FUNC_DECLARATION_N: // function declaraions
      //does hashtable exist with given lvl, siblvl (use find_hashtable)
      check_if_redef(root, symtab ,level, sibno);
      hash = find_hashtable(symtab->root, level, sibno);
      if(hash == NULL) {
        hash = make_insert_hashtable(symtab->root, level, sibno, MAX(level - 1, 0), getSibling(level) );

      }
      insert_into_symhashtable(hash, root); // will only insert if it is empty.
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      break;

    case FUNCTION_N:
      check_if_declared(root, symtab ,level, sibno);
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      break;

    case ID_N:      /* print the id */

        check_if_redef(root, symtab ,level, sibno);

      //if(root->return_type != 0) {  // a non-zero value means that it is a declaration, since only declarations
                                    // are assigned a return type when building the abstract syntax tree.
      if(root->isDecl){

        hash = find_hashtable(symtab->root, level, sibno);
        if(hash == NULL) {
          hash = make_insert_hashtable(symtab->root, level, sibno, MAX(level - 1, 0), getSibling(level) );
        }
        insert_into_symhashtable(hash, root);
      }
      else {  // don't know if previously declared
        check_if_declared(root, symtab , level, sibno);
      }
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      break;

    case ARRAY_TYPE_N:             // check for return types!

        check_if_redef(root, symtab ,level, sibno);

      //cif(root->return_type != 0) {
      if(root->isDecl){
        hash = find_hashtable(symtab->root, level, sibno);
        if(hash == NULL) {
          hash = make_insert_hashtable(symtab->root, level, sibno, MAX(level - 1, 0), getSibling(level) );
          }
        insert_into_symhashtable(hash, root);
      }
      else {
        check_if_declared(root, symtab , level, sibno);
      }
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      break;

    case RETURN_N:
      insert_scope_info(root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      break;

    default:
      // printf("at default of switch\n");
      assert(symtab->root != NULL);
      hash = find_hashtable(symtab->root, level, sibno);
      if(hash == NULL) {
        hash = make_insert_hashtable(symtab->root, level, sibno, MAX(level - 1, 0), getSibling(level) );
      }
      //note: cannot use insert_scope_info here because siblings[level - 1] causes invalid read as level-1 can go negative
      break;
  }

  if(arraylen == level) {
    arraylen = arraylen + DELTA;
    siblings = realloc(siblings, sizeof(int) * arraylen);

    assert(siblings != NULL);

    for(int k=0; k < DELTA; k++) {
      siblings[arraylen - (DELTA-k)] = 0;
    }
  }

  /* Recurse on each child of the subtree root, with a depth one
     greater than the root's depth. */
  ast_node child;
  for (child = root->left_child; child != NULL; child = child->right_sibling)
    build_symbol_table(child, level, siblings[level], symtab);

  if(root->node_type == SEQ_N){//} || root->node_type == FORMAL_PARAMS_N){
    siblings[level]++;  // change sibling level after you're done printing all
                      // subtrees, i.e., after done recursing.
  }
}