示例#1
0
std::string OSCompat::DirectoryLister::NextEntry()
{
    if(!private_data){
        DIR *pDirectory = opendir(path.c_str());
        if(!pDirectory){
            LOG(Logger::LOG_WARNING, "opendir(%s) failed", path.c_str());
            return "";
        }
        private_data=pDirectory;
        return NextEntry();
    }else{
        DIR *pDirectory = (DIR*)private_data;
        struct dirent *pEntry = readdir( pDirectory );
        if(!pEntry)return "";

        std::string filename=path;
        filename+="/";
        filename+=pEntry->d_name;
		struct stat st;
		if(stat(filename.c_str(), &st)==0 && S_ISREG(st.st_mode)){
            if((flags & FLAG_LIST_FILES)!=0)return pEntry->d_name;
        }else{
            if((flags & FLAG_LIST_DIRS)!=0)return pEntry->d_name;
        }
        return NextEntry();
    }
}
示例#2
0
bool
TracingMetaData::_FreeFirstEntry()
{
	TRACE(("  skip start %p, %lu*4 bytes\n", fFirstEntry, fFirstEntry->size));

	trace_entry* newFirst = NextEntry(fFirstEntry);

	if (fFirstEntry->flags & BUFFER_ENTRY) {
		// a buffer entry -- just skip it
	} else if (fFirstEntry->flags & ENTRY_INITIALIZED) {
		// Fully initialized TraceEntry: We could destroy it, but don't do so
		// for sake of robustness. The destructors of tracing entry classes
		// should be empty anyway.
		fEntries--;
	} else {
		// Not fully initialized TraceEntry. We can't free it, since
		// then it's constructor might still write into the memory and
		// overwrite data of the entry we're going to allocate.
		// We can't do anything until this entry can be discarded.
		return false;
	}

	if (newFirst == NULL) {
		// everything is freed -- practically this can't happen, if
		// the buffer is large enough to hold three max-sized entries
		fFirstEntry = fAfterLastEntry = fBuffer;
		TRACE(("_FreeFirstEntry(): all entries freed!\n"));
	} else
		fFirstEntry = newFirst;

	return true;
}
示例#3
0
bool glfHandler::NextSection()
{
    if (isStub)
    {
        endOfSection = true;
        data.recordType = 0;
        maxPosition = 1999999999;
        position = maxPosition + 1;
        return true;
    }

    while (!endOfSection && !ifeof(handle))
        NextEntry();

    endOfSection = false;

    int labelLength = 0;

    currentSection++;
    position = 0;
    if (ifread(handle, &labelLength, sizeof(int)) == sizeof(int))
    {
        ifread(handle, label.LockBuffer(labelLength+1), labelLength * sizeof(char));
        label.UnlockBuffer();

        maxPosition = 0;
        ifread(handle, &maxPosition, sizeof(int));

        return ((maxPosition > 0) && !ifeof(handle));
    }

    return false;
}
示例#4
0
void
FreeAllAttr(struct SymTab * table)
{
  struct SymEntry * anEntry = FirstEntry(table);
  while (anEntry) {
    free(GetAttr(anEntry));
    anEntry = NextEntry(table, anEntry);
  }
}
示例#5
0
bool glfHandler::NextBaseEntry()
   {
   bool result = true;

   do
      { result = NextEntry(); }
   while (result && data.recordType == 2);

   return result;
   }
示例#6
0
void
VerifyCounts(struct SymTab * table)
{
  struct SymEntry * anEntry = FirstEntry(table);
  while (anEntry) {
    struct Attributes * attr = GetAttr(anEntry);
    if (attr->value1 != attr->value2) {
      fprintf(stdout,"count for %s not correct\n",GetName(anEntry));
    }
    anEntry = NextEntry(table, anEntry);
  }
}
示例#7
0
OAHashTable::Iterator &OAHashTable::Iterator::operator++() {
  if (kvl_ != nullptr && ++kvl_pos_ < kvl_->size) {
    // We're in KVL, move the position
    return *this;
  }

  curr_bucket_++;
  curr_ = reinterpret_cast<HashEntry *>(reinterpret_cast<uint64_t>(curr_) +
                                        table_.entry_size_);
  NextEntry();

  return *this;
}
示例#8
0
void DestroySymTab(struct SymTab *aTable){
    struct SymEntry* entry=FirstEntry(aTable);
    struct SymEntry* mid;
    while (entry) {
        mid=entry;
        entry=NextEntry(aTable, entry);
        //free(mid->attributes);
        free(mid->name);
        free(mid);
    }
    free(aTable->contents);
    free(aTable);
}
示例#9
0
void							 
Finish(struct InstrSeq *Code)
{ struct InstrSeq *code;
  struct SymEntry *entry;
  struct Attr * attr;
  struct StrLabels * strlabel;

  code = GenInstr(NULL,".text",NULL,NULL,NULL);
  AppendSeq(code,GenInstr(NULL,".globl","main",NULL,NULL));
  AppendSeq(code, GenInstr("main",NULL,NULL,NULL,NULL));
  AppendSeq(code, doFuncStmt("main"));
  AppendSeq(code, GenInstr(NULL, "li", "$v0", "10", NULL)); 
  AppendSeq(code, GenInstr(NULL,"syscall",NULL,NULL,NULL));
  AppendSeq(code,Code);
  AppendSeq(code,GenInstr(NULL,".data",NULL,NULL,NULL));
  AppendSeq(code,GenInstr(NULL,".align","4",NULL,NULL));
  AppendSeq(code,GenInstr("_nl",".asciiz","\"\\n\"",NULL,NULL));
  AppendSeq(code,GenInstr("_tru",".asciiz","\"true\"",NULL,NULL));
  AppendSeq(code,GenInstr("_fal",".asciiz","\"false\"",NULL,NULL));
  AppendSeq(code,GenInstr("_sp", ".asciiz","\" \"",NULL,NULL));

 entry = FirstEntry(table);
 while (entry) {
	 struct Vtype *  vtype = ((struct Vtype *)entry->Attributes);
     
     AppendSeq(code, GenInstr(NULL, ".align", "4", NULL, NULL));

     if(vtype->Type == TYPE_INTARR || vtype->Type == TYPE_BOOLARR){
        char * buffer;
        buffer = Imm(4 * vtype->Size);
        AppendSeq(code, GenInstr( (char*)GetName(entry), ".space", buffer, NULL, NULL));

     }
     else {
         AppendSeq(code,GenInstr((char *) GetName(entry),".word","0",NULL,NULL));
     }
    
    entry = NextEntry(table, entry);
 }
 strlabel = slabels;
 
 while( strlabel ){
     AppendSeq(code, GenInstr(NULL, ".align", "4", NULL, NULL));
     AppendSeq(code, GenInstr(strlabel->SLabel, ".asciiz", strlabel->Str, NULL, NULL));
     strlabel = strlabel->next;
 }

  WriteSeq(code);
  
  return;
}
示例#10
0
void
DisplayTable(struct SymTab * table)
{
  struct SymEntry * anEntry = FirstEntry(table);
  int i = 1;
  while (anEntry) {
    fprintf(stdout,"%3d %20s %5d %5d\n", i,
            GetName(anEntry),
            ((struct Attributes *) GetAttr(anEntry))->value1,
            ((struct Attributes *) GetAttr(anEntry))->value2);
    i++;
    anEntry = NextEntry(table, anEntry);
  }
}
示例#11
0
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),&copyEntry);
    SetAttr(copyEntry,GetAttr(anEntry));
    anEntry = NextEntry(table, anEntry);
  }
  return copyTable;
}
示例#12
0
OAHashTable::Iterator::Iterator(OAHashTable &table, bool begin)
    : table_(table) {
  // If we're not creating an Iterator that starts at the beginning, don't
  // initialize anything
  if (!begin) {
    curr_bucket_ = table_.NumBuckets();
    curr_ = nullptr;
    return;
  }

  // Find first entry
  curr_bucket_ = 0;
  curr_ = table_.buckets_;

  NextEntry();
}