// idDescTab.cpp #include #include "idDescTab.h" #include "pmglobs.h" void attributes::seeAttributes() { cout << level; cout.width(7); cout << ramAddr; cout.width(7); cout << type; cout << " "; if (func) cout << "func = TRUE"; else cout << "func = FALSE"; } attributeNode::attributeNode() { anAttributes.level = -1; anAttributes.ramAddr = -2000; anAttributes.type = -1; anAttributes.func = false; next = NULL; } idDescTabSegment::idDescTabSegment() { for (int i = 0; i < SEGSIZE; i++) { idSegment[i] = NULL; } next = NULL; } bool idDescTable::createEntry(int idx, int aLevel) { // level sent in just to check duplicates at earliest time. bool dup; int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; idDescTabSegment* bIdDescTabSegment = NULL; // copy anIdDescTabSegment to bIdDescTabSegment for (int i = 0; i <= segment; i++) { if ( anIdDescTabSegment != NULL) { bIdDescTabSegment = anIdDescTabSegment; anIdDescTabSegment = anIdDescTabSegment->next; } else { anIdDescTabSegment = new idDescTabSegment; if (bIdDescTabSegment == NULL) { idts = anIdDescTabSegment; } else { bIdDescTabSegment->next = anIdDescTabSegment; } bIdDescTabSegment = anIdDescTabSegment; anIdDescTabSegment = anIdDescTabSegment->next; } // end of if-else. } // end of for loop. if ( (bIdDescTabSegment->idSegment[offset] != NULL) && ((bIdDescTabSegment->idSegment[offset])->anAttributes.level == aLevel)) { dup = true; } else { dup = false; attributeNode* anAttributeNode = new attributeNode; anAttributeNode->next = bIdDescTabSegment->idSegment[offset]; bIdDescTabSegment->idSegment[offset] = anAttributeNode; } return dup; } void idDescTable::saveLevel(int idx, int aLevel) { int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; for (int i = 1; i <= segment; i++) { anIdDescTabSegment = anIdDescTabSegment->next; } anIdDescTabSegment->idSegment[offset]->anAttributes.level = aLevel; } void idDescTable::saveAddr(int idx, int anAddr) { int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; for (int i = 1; i <= segment; i++) { anIdDescTabSegment = anIdDescTabSegment->next; } anIdDescTabSegment->idSegment[offset]->anAttributes.ramAddr = anAddr; } void idDescTable::saveType(int idx, int aType) { int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; for (int i = 1; i <= segment; i++) { anIdDescTabSegment = anIdDescTabSegment->next; } anIdDescTabSegment->idSegment[offset]->anAttributes.type = aType; } void idDescTable::saveKind(int idx, bool aFunc) { int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; for (int i = 1; i <= segment; i++) { anIdDescTabSegment = anIdDescTabSegment->next; } anIdDescTabSegment->idSegment[offset]->anAttributes.func = aFunc; } bool idDescTable::retriveAttributes(int idx, attributes& anAttributes) { // Retrieve the memory. int segment = idx / SEGSIZE; int offset = idx % SEGSIZE; idDescTabSegment* anIdDescTabSegment = idts; int i = 1; bool declared; while ( (anIdDescTabSegment != NULL) && (i < segment) ) { anIdDescTabSegment = anIdDescTabSegment->next; i++; } // end of while loop. if ( (anIdDescTabSegment != NULL) && (anIdDescTabSegment->idSegment[offset] != NULL) ) { declared = true; anAttributes.level = (anIdDescTabSegment->idSegment[offset])->anAttributes.level; anAttributes.ramAddr = (anIdDescTabSegment->idSegment[offset])->anAttributes.ramAddr; anAttributes.type = (anIdDescTabSegment->idSegment[offset])->anAttributes.type; anAttributes.func = (anIdDescTabSegment->idSegment[offset])->anAttributes.func; } else { declared = false; } return declared; } void idDescTable::clearLevel1Entries() { idDescTabSegment* anIdDescTabSegment = idts; attributeNode* anAttributeNode; while (anIdDescTabSegment != NULL) { for (int offset = 0; offset < SEGSIZE; offset++) { anAttributeNode = anIdDescTabSegment->idSegment[offset]; if ( (anAttributeNode != NULL) && ( (anAttributeNode->anAttributes).level == 1) ) { anIdDescTabSegment->idSegment[offset] = anAttributeNode->next; delete anAttributeNode; } // end of if. } // end of for loop. anIdDescTabSegment = anIdDescTabSegment->next; } // end of while loop. } // end of method clearLevel1Entries(). void idDescTable::seeIdDescTable() { idDescTabSegment* anIdDescTabSegment = idts; int k = 0; cout << endl; while ( anIdDescTabSegment != NULL) { cout << "segment = " << endl; for (int i = 0; i < SEGSIZE; i++) { cout << " offset = " << i; cout.width(7); anIdDescTabSegment->idSegment[i]->anAttributes.seeAttributes(); if (anIdDescTabSegment->idSegment[i]->next != NULL) { cout << " --> "; anIdDescTabSegment->idSegment[i]->anAttributes.seeAttributes(); } // end of if. cout << endl; } // end of for loop. anIdDescTabSegment = anIdDescTabSegment->next; k++; } // end of while loop. }