예제 #1
0
bool Parser::GetCmdLineIncludeFiles(const CC_ARRAY<CC_STRING>& ifiles, size_t np)
{
	if( ifiles.size() == 0)
		return true;

	CC_STRING path;
	bool in_compiler_dir;
	for(size_t i = 0; i < ifiles.size(); i++) {
		if(!rtc->get_include_file_path(ifiles[i], CC_STRING(""), true, false, path, &in_compiler_dir)) {
			errmsg.Format("Can not find include file \"%s\"", ifiles[i].c_str());
			return false;
		}
		RealFile *file;
		file = new RealFile;
		file->SetFileName(path);

		if( ! file->Open() ) {
			errmsg.Format("Can not open include file \"%s\"", ifiles[i].c_str());
			return false;
		}
		PushIncludedFile(file, NULL, np, in_compiler_dir, conditionals.size());
		if( ! RunEngine(1) )
			return false;

		if(has_dep_file() && ! in_compiler_dir)
			AddDependency("  ",  path.c_str());
	}
	return true;
}
예제 #2
0
파일: macro.cpp 프로젝트: yodamaster/ycpp
static int find(sym_t id, const CC_ARRAY<sym_t>& list)
{
	size_t i;
	for(i = 0; i < list.size(); i++)
		if( list[i] == id )
			return (int) i;
	return -1;
}
예제 #3
0
파일: macro.cpp 프로젝트: yodamaster/ycpp
CC_STRING CMaExpander::Expand_FLM(CMacro *ma)
{
	CC_STRING outs;
	CC_ARRAY<CC_STRING> margs;
	CC_STRING carg;
	const char *p = pos;
	int level;

	skip_blanks(p);
	if( iseol(*p) ) {
		gex.format("Macro \"%s\" expects arguments", TR(tc,ma->id));
		throw &gex;
	}
	if( *p != '(' ) {
		gex = "Macro expects '('";
		throw &gex;
	}

	p++;
	skip_blanks(p);
	level = 1;
	while( 1 ) {
		if( iseol(*p) )
			break;

		if( *p == ','  ) {
			if( level == 1 && ( ! ma->va_args || (margs.size() + 1 < ma->nr_args) ) ) {
				Trim(carg);
				margs.push_back(carg);
				carg.clear();
			} else {
				carg += ',';
				skip_blanks(p);
			}
		} else if(*p == '(') {
			level ++;
			carg += '(';
		} else if(*p == ')') {
			level --;
			if(level == 0) {
				p++;
				Trim(carg);
				margs.push_back(carg);
				carg.clear();
				break;
			} else
				carg += ')';
		} else {
			carg += *p;
		}
		p++;
	}
	pos = p;

	XCHAR *xc;
	CC_STRING s;
	size_t n;

	n = ma->nr_args;
	assert(n != CMacro::OL_M);
	if(n != margs.size()) {
		if( ma->va_args && margs.size() + 1 == n ) {
			margs.push_back(CC_STRING(""));
		} else {
			gex.format("Macro \"%s\" requires %u arguments, but %u given",
				TR(tc,ma->id), n, margs.size() );
			throw &gex;
		}
	}

	for(xc = ma->parsed; *xc != 0; xc++) {
		if(IS_MA_PAR2(*xc) || IS_MA_PAR0(*xc)) {
			const CC_STRING& carg = margs[(uint8_t)*xc];
			CMaExpander expander2(tc, carg.c_str(), for_include);
			CC_STRING tmp;
			tmp = expander2.TryExpand();
			s += tmp;
		} else if(IS_MA_PAR1(*xc)) {
			const CC_STRING& carg = margs[(uint8_t)*xc];
			s += '"';
			s += carg;
			s += '"';
		} else {
			s += (char) *xc;
		}
	}
	outs += s;

	return outs;
}