void CFlownetController::CreatePointAndInsertSymbol(int iX, int iY, int iXOffSet, int iYOffSet, int iScale)
{
	CRect l_CRect = m_pInsert->GetBounds();
	CPoint l_Point(	(iX + iXOffSet) * iScale,
							(iY + iYOffSet) * iScale );
	InsertSymbol(0,l_Point);
}
// Called when the user clicks in the pane to start the drawing of a link
// by either clicking on the source node's port, or simply in empty space.
// When clicking in empty space, create a source node 
// if Tools|Customize|"Auto node creation in vacant space" is checked.
void CFlownetController::LinkReady(UINT nFlags, CPoint ptDev)
{
	CODLinkComponent* pLinkComp = (CODLinkComponent*)m_pInsert;
	ASSERT_VALID(pLinkComp);
	if (pLinkComp == NULL)
		return;

	CPoint ptLog = ptDev;
	VpDPtoLP(&ptLog);
	CODPortComponent* pPortHit = GetCanvasVp()->PortHitTest(ptLog, m_nPortHitTestSlop);

	// Link is being inserted into empty space. If auto node creation option is checked in Tools|Customize
	// then automatically create a node and attach the link to it
	if (pPortHit == 0)
	{
		if (m_pMainFrm->GetGUIPreferences().m_bAutoNodeCreation == TRUE)
		{
			m_pInsert = NULL;  // ensure that the operation to insert a node does not delete the link component
			InsertNodeComponent(IDR_NODE);
			InsertSymbol(0,ptDev);
			m_pInsert = pLinkComp; // restore the process of inserting the link component
		}
	}

	CODController::LinkReady(nFlags, ptDev);
}
Пример #3
0
static SYMBOL segDefineLabel(   // DEFINE LABEL FOR SEGMENT, IF REQ'D
    PC_SEGMENT *seg )           // - current segment
{
    SYMBOL label;               // - reference symbol
    char *name;                 // - label's name
    SYMBOL func;                // - function being compiled

    label = seg->label;
    if( label == NULL ) {
        func = ScopeFunctionInProgress();
        if( ( func != NULL ) && ( func->segid == seg->seg_id ) ) {
            label = func;
        }
    }
    if( label == NULL ) {
        label = SymMakeDummy( GetBasicType( TYP_CHAR ), &name );
        label->segid = seg->seg_id;
        if( label->segid == SEG_STACK ) {
            label->id = SC_AUTO;
        } else {
            label->id = SC_STATIC;
            InsertSymbol( GetFileScope(), label, name );
        }
        seg->label = label;
        _markUsed( seg, TRUE );
    }
    return label;
}
Пример #4
0
EXPRESSION *anonymousVar(enum e_sc storage_class, TYPE *tp)
{
    static int anonct = 1;
    char buf[256];
    SYMBOL *rv = (SYMBOL *)Alloc(sizeof(SYMBOL));
//    if ((storage_class == sc_localstatic || storage_class == sc_auto) && !theCurrentFunc)
//    {
//        storage_class = sc_static;
//        insertInitSym(rv);
//    }
    if (tp->size == 0 && isstructured(tp))
        tp = basetype(tp)->sp->tp;
    rv->storage_class = storage_class;
    rv->tp = tp;
    rv->anonymous = TRUE;
    rv->allocate = !anonymousNotAlloc;
    rv->assigned = TRUE;
    rv->used = TRUE;
    if (theCurrentFunc)
        rv->value.i = theCurrentFunc->value.i;
    sprintf(buf,"$anontemp%d", anonct++);
    rv->name = litlate(buf);
    tp->size = basetype(tp)->size;
    if (theCurrentFunc && !inDefaultParam)
        InsertSymbol(rv, storage_class, FALSE, FALSE);
    SetLinkerNames(rv, lk_none);
    return varNode(storage_class == sc_auto || storage_class == sc_parameter ? en_auto : storage_class == sc_localstatic ? en_label : en_global, rv);
}
Пример #5
0
/* Insert element */
void Insert(char *name, char *path, TreeNode *node){
	SymbolTable *p = SymTab;
	while (p){
		if (!strcmp(p->path, path)){
			InsertSymbol(name, node, p);
		}
		p = p->sibling;
	}
}
Пример #6
0
void CTokenizer::SetSymbols(keywordArray_t* theSymbols)
{
	m_symbols = theSymbols;
	if (m_symbolLookup != NULL)
	{
		m_symbolLookup->Delete();
		m_symbolLookup = NULL;
	}
	int i = 0;
	if (theSymbols == NULL)
	{
		return;
	}
	while(theSymbols[i].m_tokenvalue != TK_EOF)
	{
		InsertSymbol(theSymbols[i].m_keyword, theSymbols[i].m_tokenvalue);
		i++;
	}
}
void CFlownetController::EndLink(UINT nFlags, CPoint ptDev)
{
	if (m_pInsert == 0)
	{
		ASSERT(FALSE); // TODO make sure this is never entered
		return;
	}
	
	CODLinkComponent* pLinkComp = (CODLinkComponent*)m_pInsert;
	ASSERT_VALID(pLinkComp);

	// get the source component and type
	CFlownetComponent* pSrcComp = (CFlownetComponent*) m_pSourcePort->GetOwner();
	CString sSrcType = (pSrcComp != 0)? pSrcComp->GetType() : _T("");


	// If link is being ended in space and auto-node creation is on, then create an endnode
	// the source node is at this stage already created, either by clicking in the component bar 
	// - see CFlownetController::InsertNodeComponent()
	// or on the fly when the pipe was clicked in empty space - see CFlownetController::LinkReady()
	if ( m_pTargetPort == 0 && m_pMainFrm->GetGUIPreferences().m_bAutoNodeCreation == TRUE)
	{ 
		if (sSrcType == _T("Node"))
		{
			AfxMessageBox(_T("Cannot connect two nodes!\nThis action will be cancelled."));
			CancelLink(nFlags, ptDev);
			CreateFlownetLink();
			return;
		}
		CPoint ptLog = ptDev;
		VpDPtoLP(&ptLog);
		m_pInsert = NULL;  // ensure that the operation to insert a node does not delete the link component
		InsertNodeComponent(IDR_NODE);
		m_pTargetPort = ((CODSymbolComponent*)m_pInsert)->GetCenterPort();
		InsertSymbol(0,ptDev);
		m_pInsert = pLinkComp; // restore the process of inserting the link component
	}
	else if (m_pTargetPort == 0 && m_pMainFrm->GetGUIPreferences().m_bAutoNodeCreation == FALSE)
	{
		CancelLink(nFlags, ptDev); // cannot end a link in empty space
	}
	// if auto-node creation was not on, cancel the action and return
	if (m_pTargetPort == 0)
	{
		CODController::EndLink(nFlags, ptDev);
		CreateFlownetLink();
		return;
	}

	// get the target component and type
	CFlownetComponent* pTgtComp = (CFlownetComponent*) m_pTargetPort->GetOwner();
	CString sTgtType = (pTgtComp != 0)? pTgtComp->GetType() : _T("");

	if (sSrcType == _T("SpecialConductiveHeatTransfer") ||
	    sTgtType == _T("SpecialConductiveHeatTransfer"))
	{
		SetPropertiesCHTLink(pLinkComp);
		CODController::EndLink(nFlags, ptDev);
		/*bool bRes = ConnectCHTorCNTLink(pLinkComp, pSrcComp, pTgtComp, CString("SpecialConductiveHeatTransfer") );

		if (!bRes)
		{
			AfxMessageBox(_T("You must insert a CHT link between a CHT element\nand a node, a pipe or another element's center port"));
			CancelLink(nFlags, ptDev);
			return;
		}*/
	}
	// for CNT element links...the link must connect to a CNT element on the one end
	// and the center port of any flow element on the other end
	else if (sSrcType == _T("SpecialPIDController") ||
	         sTgtType == _T("SpecialPIDController"))
	{
		SetPropertiesCNTLink(pLinkComp);
		CODController::EndLink(nFlags, ptDev);
		/*bool bRes = ConnectCHTorCNTLink(pLinkComp, pSrcComp, pTgtComp, CString("SpecialPIDController") );

		if (!bRes)
		{
			AfxMessageBox(_T("You must insert a CNT link between a CNT element\nand a node, a pipe or another element's center port"));
			CancelLink(nFlags, ptDev);
			return;
		}*/
	}
	// for CNT element links...the link must connect to a CNT element on the one end
	// and the center port of any flow element on the other end
	else if ( (sSrcType == _T("HeatExchanger") ||
				  sSrcType == _T("HeatExchangerGasLiquid") ||
				  sSrcType == _T("HeatExchangerRecuperator") ||
				  sSrcType == _T("HeatExchangerShellAndTube") )
			   && sTgtType == _T("HeatExchangerSecondaryElement")
			  )
	{
		SetPropertiesCHTLink(pLinkComp);
		CODController::EndLink(nFlags, ptDev);
	}

	// cannot connect two nodes!
	else if (sSrcType == _T("Node") && sTgtType == _T("Node"))
	{
		AfxMessageBox(_T("Illegal connection!\nThis action will be cancelled."));
		CancelLink(nFlags, ptDev);
	}
	else if ((sSrcType == "Node" && sTgtType == "Phantom")||
			(sSrcType == "Phantom" && sTgtType == "Node"))
	{
		// Color the node points
		SetPropertiesPhantomLink(pLinkComp);
		CODController::EndLink(nFlags, ptDev);
	}

	// for ordinary links...the link must connect to the port of an element 
	// on the one end and a node on the other
	else if(sSrcType == _T("Node") &&
	        pTgtComp->IsKindOf(RUNTIME_CLASS(CODSymbolComponent)) 
			  //&& m_pTargetPort != pTgtComp->GetCenterPort()
			  ||
	        sTgtType == _T("Node") &&
	        pSrcComp->IsKindOf(RUNTIME_CLASS(CODSymbolComponent)) 
			  //&& m_pSourcePort != pSrcComp->GetCenterPort() 
			  )
	{
		SetPropertiesNormalLink(pLinkComp);
		CODController::EndLink(nFlags, ptDev);
		/*bool bRes = ConnectNormalLink(pLinkComp, pSrcComp, pTgtComp);

		if (!bRes)
		{
			AfxMessageBox(_T("You must insert a link between an element and a node"));
			CancelLink(nFlags, ptDev);
			return;
		}*/
	}
	else
	{
		AfxMessageBox(_T("Illegal connection!\nThis action will be cancelled."));
		CancelLink(nFlags, ptDev);
	}

	CreateFlownetLink();
}
Пример #8
0
void SymtabTraverseTree(TreeNode *p, char *path, int nestLevel, SymbolTable *symtab){
	char local_path[256];
	if (!p) return ;
	// printf("path:%s\n", path);
	switch (p->node){
		case routine_kind: {
			SymtabTraverseTree(p->children[0], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[1], path, nestLevel, symtab);
			break;
		}
		case const_kind: {
			if (DuplicateIdentifier(p->name, path))
				throw_error("duplicate identifier", p);
			InsertSymbol(p->name, p, symtab);
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		} 
		case type_kind: {
			switch (p->type){
				case decl_type:{
					if (DuplicateIdentifier(p->name, path))
						throw_error("duplicate identifier", p);
					InsertSymbol(p->name, p, symtab);
					if(p->dtype->type!=record_type){
						SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
					} else {
						sprintf(local_path, "%s/%s", path, p->name);
						SymbolTable *new_symtab = CreateSymbolTable(local_path, nestLevel+1);
						ConnectSymtabs(symtab, new_symtab);
						SymtabTraverseTree(p->dtype, local_path, nestLevel+1, new_symtab);
						SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
					}
					break;
				}
				case record_type:{
					SymtabTraverseTree(p->children[0], path, nestLevel, symtab);
					break;
				}
				default:{ break; }
			}
			break;
		}
		case var_kind:{
			TreeNode *q;
			q = p->children[0];
			while (q){
				if (DuplicateIdentifier(q->name, path))
					throw_error("duplicate identifier", q);
				InsertSymbol(q->name, p, symtab);
				q = q->sibling;
			}
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		} 
		case sub_kind: {
			switch(p->sub){
				case func_kind:{
					// printf("enter function %s decl:\n", p->name);
					InsertSymbol(p->name, p, symtab);
					sprintf(local_path, "%s/%s", path, p->name);
					SymbolTable * new_symtab = CreateSymbolTable(local_path, nestLevel+1);
					ConnectSymtabs(symtab, new_symtab);
					SymtabTraverseTree(p->children[0], local_path, nestLevel+1, new_symtab);
					SymtabTraverseTree(p->children[1], local_path, nestLevel+1, new_symtab);
					SymtabTraverseTree(p->children[2], local_path, nestLevel+1, new_symtab);
					break;
				}
				case proc_kind:{
					// printf("enter procedure %s decl:\n", p->name);
					InsertSymbol(p->name, p, symtab);
					sprintf(local_path, "%s/%s", path, p->name);
					SymbolTable * new_symtab = CreateSymbolTable(local_path, nestLevel+1);
					ConnectSymtabs(symtab, new_symtab);
					SymtabTraverseTree(p->children[0], local_path, nestLevel+1, new_symtab);
					SymtabTraverseTree(p->children[1], local_path, nestLevel+1, new_symtab);
					SymtabTraverseTree(p->children[2], local_path, nestLevel+1, new_symtab);
					break;
				}
				case param_var_kind:{
					TreeNode *q;
					q = p->children[0];
					while (q){
						if (DuplicateIdentifier(q->name, path))
							throw_error("duplicate identifier", q);
						InsertSymbol(q->name, p, symtab);
						q = q->sibling;
					}
					break;
				}
				case param_val_kind:{
					TreeNode *q;
					q = p->children[0];
					while (q){
						if (DuplicateIdentifier(q->name, path))
							throw_error("duplicate identifier", q);
						InsertSymbol(q->name, p, symtab);
						q = q->sibling;
					}
					break;
				}
			}
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		};
		case expr_kind:{
			switch (p->expr){
				case id_kind:{
					// printf("look for identifier: %s\n", p->name);
					if (!Lookup(p->name, path))
						throw_error("unknown identifier", p);
					break;
				}
				case fn_kind:{
					// printf("look for function: %s\n", p->name);
					if (!Lookup(p->name, path) && !p->system)
						throw_error("unknown identifier", p);
				}
				default: break;
			}
			SymtabTraverseTree(p->children[0], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[1], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[2], path, nestLevel, symtab);
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		}
		case stmt_kind:{
			switch (p->stmt){
				case for_stmt:{
					if (!Lookup(p->name, path))
						throw_error("unknown identifier", p);
				}
				case proc_stmt:{
					if (!Lookup(p->name, path) && !p->system)
						throw_error("unknown identifier", p);
				}
			}
			SymtabTraverseTree(p->children[0], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[1], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[2], path, nestLevel, symtab);
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		}
		default: {
			SymtabTraverseTree(p->children[0], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[1], path, nestLevel, symtab);
			SymtabTraverseTree(p->children[2], path, nestLevel, symtab);
			SymtabTraverseTree(p->sibling, path, nestLevel, symtab);
			break;
		}
	}
}