コード例 #1
0
	void ActionListSwitch::GenerateCaseMap()
	{
		Datum& cases = Actions();
		Datum::DatumType switchType = Datum::DatumType::UNKNOWN;
		if (cases.Size() > 0)
		{
			delete mCaseMap;
			mCaseMap = new Hashmap<Datum, ActionListSwitchCase*>(cases.Size());
			Datum* conditionDatum = Search((*this)[ATTRIBUTE_SWITCH_VALUE].Get<std::string>());
			if (conditionDatum == nullptr)
			{
				std::stringstream str;
				str << "Undefined variable: " << (*this)[ATTRIBUTE_SWITCH_VALUE].Get<std::string>();
				throw std::exception(str.str().c_str());
			}
			switchType = conditionDatum->Type();
		}
		for (uint32_t i = 0; i < cases.Size(); i++)
		{
			ActionListSwitchCase* switchCase = cases.Get<Scope>(i).As<ActionListSwitchCase>();
			if (switchCase == nullptr)
				continue;
			if (switchCase->DefaultCase)
			{
				Adopt(ActionListSwitchCase::ATTRIBUTE_DEFAULT, *switchCase);
			}
			else
			{
				Datum d;
				d.SetType(switchType);
				d.SetFromString(switchCase->operator[](ActionListSwitchCase::ATTRIBUTE_CASE_VALUE).Get<std::string>());
				mCaseMap->Insert(d, switchCase);
			}
		}
	}
コード例 #2
0
ファイル: ForStmt.cpp プロジェクト: jverne/nqc
ForStmt::ForStmt(Stmt *init, Expr *c, Stmt *iterate, Stmt *body) :
    fInit(init),        ///< Optional; can be NULL
    fCondition(c),      ///< Optional; can be NULL
    fIterate(iterate),  ///< Optional; can be NULL
    fBody(body)
{
    // we need to keep child statements in a list
    fChildren.InsertHead(fBody);
    if (fIterate)
        fChildren.InsertHead(fIterate);
    if (fInit)
        fChildren.InsertHead(fInit);

    Adopt(init);
    Adopt(iterate);
    Adopt(body);
}
コード例 #3
0
	void Attributed::AddNestedScope(const std::string& name, Scope& initialValue, std::uint32_t size)
	{
		AddEmptyInternalSignature(name, Datum::DatumType::TABLE, 0);
		for (std::uint32_t j = 0; j < size; j++)
		{
			Scope* scope = new Scope(initialValue);
			Adopt(name, *scope);
		}
	}
コード例 #4
0
ファイル: vField.c プロジェクト: lolmid/2015-2016
Field::Field(int n) : d_impl_p(0) {
  if(!s_currentRep_p)  {
    if(s_inInitialize) {
      s_currentRep_p = CreateNumber(n,1);
    } else {
      cerr << "Error with field setting\n";
    };
  };
  RECORDHERE(d_impl_p = new FieldImplementation(s_currentRep_p->make(n),Adopt());)
};
コード例 #5
0
ファイル: control.c プロジェクト: mingpen/OpenNT
//---------------------------------------------------------------------------
// ELSEIF
//
// This routine recognizes and compiles the ELSEIF statement.  The pcode
// generated is as follows:
//
//  STATEMENT:      ELSEIF <intexp> THEN
//
//  PCODE:              JMP     CSF_ENDBLOCK
//                  CSF_ELSEBLOCK:
//                      <intexp>
//                      POPA
//                      JE      0, CSF_ELSEBLOCK        ; (new ELSE block)
//
// RETURNS:     Root node of ELSEIF compilation tree
//---------------------------------------------------------------------------
INT ELSEIF (INT op)
{
    INT     curCS, n, n2, v;

    // Ensure that the current CS is an IF...
    //-----------------------------------------------------------------------
    curCS = AssertCSType (CS_IF);
    if (curCS == -1)
        return (-1);

    // The IF control struct was found.  First thing to do is check to see if
    // the ENDBLOCK label is the same as the ELSEBLOCK label.  This indicates
    // that no ELSEx block has been encountered.  If so, we set a new
    // ENDBLOCK label for the next jump.
    //-----------------------------------------------------------------------
    ADVANCE;
    v = GetCSField (curCS, CSF_ELSEBLOCK);
    if (GetCSField(curCS, CSF_ENDBLOCK) == v)
        SetCSField (curCS, CSF_ENDBLOCK, TempLabel());

    // Generate the code trees that jump to the ENDIF (ENDBLOCK), and make a
    // new ELSEBLOCK label
    //-----------------------------------------------------------------------
    n = Siblingize (MakeNode (opJMP, GetCSField (curCS, CSF_ENDBLOCK)),
                    MakeNode (opFIXUP, v), -1);
    SetCSField (curCS, CSF_ELSEBLOCK, v = TempLabel());

    // Generate another IF tree
    //-----------------------------------------------------------------------
    n2 = MakeParentNode (IntExpression(), opPOPA);
    n2 = MakeParentNode (n2, opJE, 0L, v);
    n = Adopt (MakeNode (opNOP), n, n2, -1);

    // Insist on the THEN keyword, and we're done!
    //-----------------------------------------------------------------------
    ReadKT (ST_THEN, PRS_SYNTAX);
    return (n);
    (op);
}
コード例 #6
0
	void Attributed::CopyAuxiliaryAttributesFromAnotherAttributed(const Attributed& anotherAttributed)
	{
		std::uint32_t i;
		for (i = anotherAttributed.AuxiliaryBegin(); i < anotherAttributed.Size(); i++)
		{
			const SymbolPair& pair = anotherAttributed.GetPair(i);
			Remove(pair.first);
			if (pair.second.Type() == Datum::DatumType::TABLE)
			{
				const Datum& nestedScopeDatum = pair.second;
				std::uint32_t j;
				for (j = 0; j < nestedScopeDatum.Size(); j++)
				{
					Scope* nestedScopeAttribute = new Scope(nestedScopeDatum.Get<Scope>(j));
					Adopt(pair.first, *nestedScopeAttribute);
				}
			}
			else
			{
				AppendAuxiliaryAttribute(pair.first) = pair.second;
			}
		}
	}
コード例 #7
0
ファイル: bidirectional-ibfs.cpp プロジェクト: caomw/sospd
void BidirectionalIBFS::IBFS() {
    auto start = Clock::now();
    m_forward_search = false;
    m_source_tree_d = 1;
    m_sink_tree_d = 0;

    IBFSInit();

    // Set up initial current_q and search nodes to make it look like
    // we just finished scanning the sink node
    NodeQueue* current_q = &(m_sink_layers[0]);
    m_search_node_iter = current_q->end();
    m_search_node_end = current_q->end();

    while (!current_q->empty()) {
        if (m_search_node_iter == m_search_node_end) {
            // Swap queues and continue
            if (m_forward_search) {
                m_source_tree_d++;
                current_q = &(m_sink_layers[m_sink_tree_d]);
            } else {
                m_sink_tree_d++;
                current_q = &(m_source_layers[m_source_tree_d]);
            }
            m_search_node_iter = current_q->begin();
            m_search_node_end = current_q->end();
            m_forward_search = !m_forward_search;
            if (!current_q->empty()) {
                Node& n = *m_search_node_iter;
                NodeId nodeIdx = n.id;
                if (m_forward_search) {
                    ASSERT(n.state == NodeState::S || n.state == NodeState::S_orphan);
                    m_search_arc = m_graph->ArcsBegin(nodeIdx);
                    m_search_arc_end = m_graph->ArcsEnd(nodeIdx);
                } else {
                    ASSERT(n.state == NodeState::T || n.state == NodeState::T_orphan);
                    m_search_arc = m_graph->ArcsBegin(nodeIdx);
                    m_search_arc_end = m_graph->ArcsEnd(nodeIdx);
                }
            }
            continue;
        }
        Node& n = *m_search_node_iter;
        NodeId search_node = n.id;
        int distance;
        if (m_forward_search) {
            distance = m_source_tree_d;
        } else {
            distance = m_sink_tree_d;
        }
        ASSERT(n.dis == distance);
        // Advance m_search_arc until we find a residual arc
        while (m_search_arc != m_search_arc_end && !m_graph->NonzeroCap(m_search_arc, m_forward_search))
            ++m_search_arc;

        if (m_search_arc != m_search_arc_end) {
            NodeId neighbor = m_search_arc.Target();
            NodeState neighbor_state = m_graph->node(neighbor).state;
            if (neighbor_state == n.state) {
                ASSERT(m_graph->node(neighbor).dis <= n.dis + 1);
                if (m_graph->node(neighbor).dis == n.dis+1) {
                    auto reverseArc = m_search_arc.Reverse();
                    if (reverseArc < m_graph->node(neighbor).parent_arc) {
                        m_graph->node(neighbor).parent_arc = reverseArc;
                        m_graph->node(neighbor).parent = search_node;
                    }
                }
                ++m_search_arc;
            } else if (neighbor_state == NodeState::N) {
                // Then we found an unlabeled node, add it to the tree
                m_graph->node(neighbor).state = n.state;
                m_graph->node(neighbor).dis = n.dis + 1;
                AddToLayer(neighbor);
                auto reverseArc = m_search_arc.Reverse();
                m_graph->node(neighbor).parent_arc = reverseArc;
                ASSERT(m_graph->NonzeroCap(m_graph->node(neighbor).parent_arc, !m_forward_search));
                m_graph->node(neighbor).parent = search_node;
                ++m_search_arc;
            } else {
                // Then we found an arc to the other tree
                ASSERT(neighbor_state != NodeState::S_orphan && neighbor_state != NodeState::T_orphan);
                ASSERT(m_graph->NonzeroCap(m_search_arc, m_forward_search));
                Augment(m_search_arc);
                Adopt();
            }
        } else {
            // No more arcs to scan from this node, so remove from queue
            AdvanceSearchNode();
        }
    } // End while
    m_totalTime += Duration{ Clock::now() - start }.count();

    //std::cout << "Total time:      " << m_totalTime << "\n";
    //std::cout << "Init time:       " << m_initTime << "\n";
    //std::cout << "Augment time:    " << m_augmentTime << "\n";
    //std::cout << "Adopt time:      " << m_adoptTime << "\n";
}
コード例 #8
0
BString&
BString::AdoptChars(BString& string, int32 charCount)
{
	return Adopt(string, UTF8CountBytes(string.String(), charCount));
}
コード例 #9
0
ファイル: vField.c プロジェクト: lolmid/2015-2016
Field::Field() : d_impl_p(0) {
  RECORDHERE(d_impl_p = new FieldImplementation(s_currentRep_p->make(0),Adopt());)
};