void CNetworkMenu::ItemActivated( int a_iItemCode, CMenuItem* a_poMenuItem ) { switch ( a_iItemCode ) { case MENU_SERVER: { CEnumMenuItem* poItem = (CEnumMenuItem*) a_poMenuItem; if ( m_bServer ) { poItem->Decrement(); } else { poItem->Increment(); } break; } case MENU_CONNECT: strcpy( g_oState.m_acNick, m_sNick.c_str() ); Connect(); break; case MENU_CANCEL: m_bOK = false; m_bDone = true; m_iReturnCode = -1; break; case MENU_HOSTNAME: EnterName( "Server name: ", m_sHostname, m_poServerMenuItem,128 ); break; case MENU_NICK: EnterName( "Nickname: ", m_sNick, m_poNickMenuItem, 12 ); strcpy( g_oState.m_acNick, m_sNick.c_str() ); break; case MENU_MORTALNET: g_oState.m_enGameMode = SState::IN_CHAT; m_bOK = false; m_bDone = true; m_iReturnCode = 100; break; } }
void IntDec(char * VarName){ struct Vtype * vtype = malloc(sizeof(struct Vtype )); struct SymEntry * e; vtype->Type = TYPE_INT; vtype->Size = 1; vtype->StackIndex = StackPointer; StackPointer = StackPointer + 4; if( global){ EnterName(locTable, VarName, &e); vtype->Local = 1; } else { EnterName(table, VarName, &e); vtype->Local = 0; } SetAttr(e,(void*)vtype); }
void BoolArrDec(char * VarName, char * Size){ int ArraySize = atoi(Size); struct SymEntry *e; struct Vtype * vtype = malloc(sizeof(struct Vtype)); vtype->Type = TYPE_BOOLARR; vtype->Size = ArraySize; vtype->StackIndex = StackPointer; StackPointer = StackPointer + ArraySize * 4; if(global ){ EnterName(locTable, VarName, &e); vtype->Local = 1; } else { EnterName(table, VarName, &e); vtype->Local = 0; } SetAttr(e, (void*)vtype); }
extern void FuncInit(char *name, int type) { global = 1; StackPointer = 0; struct SymEntry *e; locTable = CreateSymTab(33); EnterName(ProcSymTab, name, &e); struct Vtype *t = malloc(sizeof(struct Vtype)); t->Type = type; SetAttr(e, (void *)t); }
bool ParameterList::DoInfix(Infix *what) // ---------------------------------------------------------------------------- // Check if we match an infix operator // ---------------------------------------------------------------------------- { // Check if we match a type, e.g. 2 vs. 'K : integer' if (what->name == ":") { // Check the variable name, e.g. K in example above if (Name *varName = what->left->AsName()) { // Enter a name in the parameter list with adequate machine type llvm_type mtype = unit->MachineType(what->right); llvm_type ntype = unit->ExpressionMachineType(varName); if (mtype != ntype) { Ooops("Conflicting machine type for declaration $1", what); return false; } return EnterName(varName, false); } else { // We ar specifying the type of the expression, e.g. (X+Y):integer if (returned || defined) { Ooops("Cannot specify type of $1", what->left); return false; } // Remember the specified returned value returned = unit->ExpressionMachineType(what); // Keep going with the left-hand side return what->left->Do(this); } } // If this is the first one, this is what we define if (!defined) { defined = what; name = what->name; } // Otherwise, test left and right if (!what->left->Do(this)) return false; if (!what->right->Do(this)) return false; return true; }
bool ParameterList::DoName(Name *what) // ---------------------------------------------------------------------------- // Identify the named parameters being defined in the shape // ---------------------------------------------------------------------------- { if (!defined) { // The first name we see must match exactly, e.g. 'sin' in 'sin X' defined = what; name = what->value; return true; } // We need to record a new parameter, type is Tree * by default return EnterName(what, true); }
struct SymTab * CopyTable(struct SymTab * table, int newSize) { struct SymTab * copyTable; if (!(copyTable = CreateSymTab(newSize))) ErrorExit("Failed to alloc copy table.\n"); struct SymEntry * anEntry = FirstEntry(table); while (anEntry) { struct SymEntry * copyEntry; EnterName(copyTable,GetName(anEntry),©Entry); SetAttr(copyEntry,GetAttr(anEntry)); anEntry = NextEntry(table, anEntry); } return copyTable; }
int main(int argc, char * argv[]) { char *testFileName; FILE *fd; struct SymTab *theTable, *firstCopy, *secondCopy; struct SymEntry *anEntry; struct Attributes *anAttr; char buffer[16]; int val1, val2; if (argc != 2) { fprintf(stderr,"usage: SymTabDriver test-data-file\n"); exit(1); } testFileName = argv[1]; fd = fopen(testFileName,"r"); if (!fd) ErrorExit("Can't open input file.\n"); if (!(theTable = CreateSymTab(5))) ErrorExit("Failed to alloc first table.\n"); /* Read lines consisting of a name string and an integer from std input. If name already present increment value2, if new allocate storage for attribute structure and fill in fields. */ while (fscanf(fd,"%15s %d",buffer,&val1) != EOF) { printf("Find: %15s ",buffer); (FindName(theTable,buffer)) ? fprintf(stdout," Present -") : fprintf(stdout," Not Present -"); if (EnterName(theTable,buffer,&anEntry)) { fprintf(stdout," Enter: Present: %15s\n",GetName(anEntry)); anAttr = (struct Attributes *) GetAttr(anEntry); anAttr->value2++; anAttr->value1 = MAX(((struct Attributes *) GetAttr(anEntry))->value1,val1); } else { fprintf(stdout," Enter: Entered: %15s\n",GetName(anEntry)); anAttr = malloc(sizeof(struct Attributes)); anAttr->value1 = val1; anAttr->value2 = 1; SetAttr(anEntry,anAttr); } } fprintf(stdout,"\nContents of Original Table\n"); DisplayTable(theTable); DisplayStatistics(theTable); if (!(firstCopy = CopyTable(theTable,1))) ErrorExit("Failed to alloc first copy table.\n"); DestroySymTab(theTable); fprintf(stdout,"\nContents of First Copy Table\n"); DisplayTable(firstCopy); DisplayStatistics(firstCopy); if (!(secondCopy = CopyTable(firstCopy,100))) ErrorExit("Failed to alloc first copy table.\n"); DestroySymTab(firstCopy); fprintf(stdout,"\nContents of Second Copy Table\n"); DisplayTable(secondCopy); DisplayStatistics(secondCopy); VerifyCounts(secondCopy); FreeAllAttr(secondCopy); DestroySymTab(secondCopy); return 0; }