Ejemplo n.º 1
0
static void skipOverRequired(struct tokenizer *tkz, char *expecting)
/* Make sure that next token is tok, and skip over it. */
{
tokenizerMustHaveNext(tkz);
if (!sameString(tkz->string, expecting))
    expectingGot(tkz, expecting, tkz->string);
}
Ejemplo n.º 2
0
static void rTokInto(struct pfCompile *pfc, char *baseDir, char *modName,
    boolean lookForPfh)
/* Tokenize module, and recursively any thing it goes into. */
{
char *pfPath = findSourcePath(baseDir, pfc->paraLibPath, modName, ".pf");
char *pfhPath = replaceSuffix(pfPath, ".pf", ".pfh");
char *oPath = replaceSuffix(pfPath, ".pf", ".o");
char *cPath = replaceSuffix(pfPath, ".pf", ".c");
char *fileName = NULL;
struct pfModule *module;
boolean isPfh = FALSE;
struct pfToken *tok;


/* Look too see if can use just module header.
 * We can if it exists and is newer than module. */
if (lookForPfh)
    {
    if (fileExists(pfhPath) && fileExists(cPath) && fileExists(oPath))
	{
	unsigned long pfTime = fileModTime(pfPath);
	unsigned long pfhTime = fileModTime(pfhPath);
	unsigned long cTime = fileModTime(cPath);
	unsigned long oTime = fileModTime(oPath);
	if (pfTime < pfhTime && pfhTime <= cTime && cTime <= oTime)
	    {
	    fileName = pfhPath;
	    isPfh = TRUE;
	    }
	}
    }
if (fileName == NULL)
    fileName = pfPath;

/* Tokenize file and add module to hash. */
module = tokenizeFile(pfc->tkz, fileName, modName);
module->isPfh = isPfh;
hashAdd(pfc->moduleHash, modName, module);

/* Look and see if there are any 'include' or 'import' to follow. */
for (tok = module->tokList; tok != NULL; tok = tok->next)
    {
    if (tok->type == pftInclude || tok->type == pftImport)
        {
	struct pfToken *modTok = tok->next;
	if (modTok->type != pftString)
	   expectingGot("module name in single quotes", modTok); 
	if (sameString(modTok->val.s, modName))
	    errAt(modTok, "A module can't include/import itself.");
	if (!hashLookup(pfc->moduleHash, modTok->val.s))
	    rTokInto(pfc, baseDir, modTok->val.s, TRUE);
	}
    }

/* Add module to list */
slAddHead(&pfc->moduleList, module);

/* Clean up and go home. */
freeMem(pfPath);
freeMem(pfhPath);
freeMem(oPath);
freeMem(cPath);
}