Exemple #1
0
pHTable createHTable(int size, pHashFunc hashFunc, pHashElemCmp compareFunc) {
    pHTable table;
    table = wicMalloc(sizeof *table);
    table->tbl = wicMalloc(sizeof table[0] * size);
    memset(table->tbl, 0, sizeof table[0] * size);
    table->size = size;
    table->hashFunc = hashFunc;
    table->compareFunc = compareFunc;
    table->stats.numElems = 0;
    table->stats.longestChainLen = 0;
    return table;
}
Exemple #2
0
static WicErrors scanStr(pTokData tokData)
{
    char charVal;
    WicErrors retVal = ERR_NONE;

    for( ;; ) {
        if (NEXT_CHAR == '\n' || NEXT_CHAR == (char) EOF) {
            retVal = RERR_INV_STRING_CONST;
            break;
        }
        if( NEXT_CHAR == '\"' ) {
            getNextChar();
            break;
        }

        if( NEXT_CHAR == '\\' ) {
            getNextChar();
            charVal = scanESCChar();
        } else {
            charVal = NEXT_CHAR;
            getNextChar();
        }
        pushChar(charVal);
    }

    if (retVal == ERR_NONE) {
        tokData->code = Y_STRING;
        tokData->repr.s.s = wicMalloc(currTokLen);
        memcpy(tokData->repr.s.s, currTok, currTokLen);
        tokData->repr.s.strLen = currTokLen;
    }
    return( retVal );
}
Exemple #3
0
pToken createToken(pTokData data, pTokPos pos) {
    pToken tok;
    tok = wicMalloc(sizeof *tok);
    tok->data = data;
    tok->pos = pos;
    return tok;
}
Exemple #4
0
int addHTableElem(pHTable table, void *elem) {
    unsigned key;
    int chainLen = 0;
    _pHTElem tblElem;
    pHashElemCmp cmp = table->compareFunc;

    assert(elem != NULL);
    key = table->hashFunc(elem, table->size);
    if (key >= table->size) {
        printf("ERROR: in hashFunc = %p, key = %u\n", table->hashFunc, key);
        return 0;
    }

    for (tblElem = table->tbl[key]; tblElem != NULL; tblElem = tblElem->next) {
        chainLen++;
        if (!cmp(elem, tblElem->userData)) {
            return 0;
        }
    }
    tblElem = wicMalloc(sizeof *tblElem);
    tblElem->userData = elem;
    tblElem->next = table->tbl[key];
    table->tbl[key] = tblElem;
    chainLen++;

    table->stats.numElems++;
    table->stats.longestChainLen = max(table->stats.longestChainLen, chainLen);
    return 1;
}
Exemple #5
0
pSymTabEntry createTabEntry(char *name, SymType type, void *data) {
    pSymTabEntry newEntry;

    newEntry = wicMalloc(sizeof(SymTabEntry));
    newEntry->name = wicStrdup(name);
    if (newEntry->name == NULL) {
        outOfMemory();
    }
    newEntry->type = type;
    newEntry->repr.data = data;

    return newEntry;
}
Exemple #6
0
static pOUnit _createOUnit(OUnitType type, pTokPos pos, char *string) {
    pOUnit newUnit = wicMalloc(sizeof *newUnit);
    newUnit->type = type;
    if (pos != NULL) {
        memcpy(&(newUnit->pos), pos, sizeof *pos);
        newUnit->posPresent = 1;
    } else {
        newUnit->posPresent = 0;
    }

    newUnit->fileNum = MAIN_FILE;
    newUnit->preStackLevel = 0;
    newUnit->postStackLevel = 0;
    if (string != NULL) {
        strncpy(newUnit->string, string, MAX_TOKEN_SIZE);
    } else {
        newUnit->string[0] = 0;
    }
    newUnit->stringIsId = 0;
    return newUnit;
}
Exemple #7
0
pTokData createTokData(void) {
    pTokData newData = wicMalloc(sizeof *newData);
    memset(newData, 0, sizeof *newData);
    newData->repr.string = NULL;
    return newData;
}
Exemple #8
0
pTokPos createTokPos(void) {
    pTokPos newPos = wicMalloc(sizeof *newPos);
    memset(newPos, 0, sizeof *newPos);
    return newPos;
}
Exemple #9
0
pFDReadInd createFDReadInd(char *name, int readOnly) {
    pFDReadInd entry = wicMalloc(sizeof *entry);
    assert(name != NULL);
    initFDReadInd(entry, name, readOnly);
    return entry;
}