Ejemplo n.º 1
0
TEST(FileLexer, FileLexTest)
{
	ASSERT_NO_THROW(lexFile("TestFile.txt"));
}
Ejemplo n.º 2
0
void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool inLibrary,
			   const string& errmsg) {  // "" for no error, make fake node
    string modname = V3Os::filenameNonExt(modfilename);

    UINFO(2,__FUNCTION__<<": "<<modname<<(inLibrary?" [LIB]":"")<<endl);
    m_fileline = new FileLine(fileline);
    m_inLibrary = inLibrary;

    // Set language standard up front
    if (!v3Global.opt.preprocOnly()) {
	// Leting lex parse this saves us from having to specially en/decode
	// from the V3LangCode to the various Lex BEGIN states. The language
	// of this source file is updated here, in case there have been any
	// intervening +<lang>ext+ options since it was first ecountered.
	FileLine *modfileline = new FileLine (modfilename, 0);
	modfileline->language(v3Global.opt.fileLanguage(modfilename));
	ppPushText((string)"`begin_keywords \""+modfileline->language().ascii()+"\"\n");
    }

    // Preprocess into m_ppBuffer
    bool ok = V3PreShell::preproc(fileline, modfilename, m_filterp, this, errmsg);
    if (!ok) {
	if (errmsg != "") return;  // Threw error already
	// Create fake node for later error reporting
	AstNodeModule* nodep = new AstNotFoundModule(fileline, modname);
	v3Global.rootp()->addModulep(nodep);
	return;
    }

    if (v3Global.opt.preprocOnly() || v3Global.opt.keepTempFiles()) {
	// Create output file with all the preprocessor output we buffered up
	string vppfilename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_"+modname+".vpp";
	ofstream* ofp = NULL;
	ostream* osp;
	bool noblanks = v3Global.opt.preprocOnly() && v3Global.opt.preprocNoLine();
	if (v3Global.opt.preprocOnly()) {
	    osp = &cout;
	} else {
	    osp = ofp = V3File::new_ofstream(vppfilename);
	}
	if (osp->fail()) {
	    fileline->v3error("Cannot write preprocessor output: "+vppfilename);
	    return;
	} else {
	    for (deque<string>::iterator it = m_ppBuffers.begin(); it!=m_ppBuffers.end(); ++it) {
		if (noblanks) {
		    bool blank = true;
		    for (string::iterator its = it->begin(); its != it->end(); ++its) {
			if (!isspace(*its) && *its!='\n') { blank=false; break; }
		    }
		    if (blank) continue;
		}
		*osp << *it;
	    }
	    if (ofp) {
		ofp->close();
		delete ofp; VL_DANGLING(ofp);
	    }
	}
    }

    // Parse it
    if (!v3Global.opt.preprocOnly()) {
	lexFile (modfilename);
    }
}