Ejemplo n.º 1
0
static AstExpression CheckConditionalExpression(AstExpression expr)
{
	int qual;
	Type ty1, ty2;

	expr->kids[0] = Adjust(CheckExpression(expr->kids[0]), 1);

	if (! IsScalarType(expr->kids[0]->ty))
	{
		Error(&expr->coord, "The first expression shall be scalar type.");
	}
	expr->kids[1]->kids[0] = Adjust(CheckExpression(expr->kids[1]->kids[0]), 1);
	expr->kids[1]->kids[1] = Adjust(CheckExpression(expr->kids[1]->kids[1]), 1);

	ty1 = expr->kids[1]->kids[0]->ty;
	ty2 = expr->kids[1]->kids[1]->ty;
	if (BothArithType(ty1, ty2))
	{
		expr->ty = CommonRealType(ty1, ty2);
		expr->kids[1]->kids[0] = Cast(expr->ty, expr->kids[1]->kids[0]);
		expr->kids[1]->kids[1] = Cast(expr->ty, expr->kids[1]->kids[1]);

		return FoldConstant(expr);
	}
	else if (IsRecordType(ty1) && ty1 == ty2)
	{
		expr->ty = ty1;
	}
	else if (ty1->categ == VOID && ty2->categ == VOID)
	{
		expr->ty = T(VOID);
	}
	else if (IsCompatiblePtr(ty1, ty2))
	{
		qual = ty1->bty->qual | ty2->bty->qual;
		expr->ty  = PointerTo(Qualify(qual, CompositeType(Unqual(ty1->bty), Unqual(ty2->bty))));
	}
	else if (IsPtrType(ty1) && IsNullConstant(expr->kids[1]->kids[1]))
	{
		expr->ty = ty1;
	}
	else if (IsPtrType(ty2) && IsNullConstant(expr->kids[1]->kids[0]))
	{
		expr->ty = ty2;
	}
	else if (NotFunctionPtr(ty1) && IsVoidPtr(ty2) ||
	         NotFunctionPtr(ty2) && IsVoidPtr(ty1))
	{
		qual = ty1->bty->qual | ty2->bty->qual;
		expr->ty = PointerTo(Qualify(qual, T(VOID)));
	}
	else
	{
		Error(&expr->coord, "invalid operand for ? operator.");
		expr->ty = T(INT);
	}

	return expr;
}
Ejemplo n.º 2
0
void Test(const char *path)
{
	DDUMP(sizeof(CppItem));
	Cpp cpp;
	cpp.WhenError = callback(AddError);
	cpp.path = path;
	cpp.filedir = GetFileFolder(path);
//	cpp.include_path = cpp.filedir;//"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include";
//	cpp.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include";
	cpp.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\Include;C:\\u\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\Program Files (x86)\\MySQL\\MySQL Connector C 6.1\\include";
	cpp.include_path << ";c:/u/upp.src/uppsrc";
	FileIn in(path);
	Index<String> inc;
	cpp.DoCpp(in, inc);
//	StringStream ss(pp);
//	Parse(ss, Vector<String>() << "__cdecl", base, path, callback(AddError));
	DLOG("=======================");
	DUMPC(inc);
	DLOG("=======================");
	DUMPC(errs);
	DLOG("=======================");
	Qualify(cpp.base);
	String out;
	for(int i = 0; i < cpp.base.GetCount(); i++) {
		out << Nvl(cpp.base.GetKey(i), "<globals>") << " {\n";
		const Array<CppItem>& ma = cpp.base[i];
		for(int j = 0; j < ma.GetCount(); j++) {
			const CppItem& m = ma[j];
			out << '\t' << CppItemKindAsString(m.kind) << ' ' << m.qitem << ' ' << m.line << "\n";
			// DDUMP(StoreAsString(const_cast<CppItem&>(m)).GetCount());
		}
		out << "}\n";
	}
	LOG(out);
}
Ejemplo n.º 3
0
static Type DeriveType(TypeDerivList tyDrvList, Type ty)
{
	while (tyDrvList != NULL)
	{
		if (tyDrvList->ctor == POINTER_TO)
		{
			ty = Qualify(tyDrvList->qual, PointerTo(ty));
		}
		else if (tyDrvList->ctor == ARRAY_OF)
		{
			if (ty->categ == FUNCTION || ty->size == 0 || (IsRecordType(ty) && ((RecordType)ty)->hasFlexArray))
				return NULL;
			
			ty = ArrayOf(tyDrvList->len, ty);
		}
		else
		{
			if (ty->categ == ARRAY || ty->categ == FUNCTION)
				return NULL;

			ty = FunctionReturn(ty, tyDrvList->sig);
		}

		tyDrvList = tyDrvList->next;
	}

	return ty;
}
Ejemplo n.º 4
0
String QualifyIds(ScopeInfo& nf, const String& k, const String& usings, bool all)
{
	LTIMING("QualifyIds");
	String r;
	const char *s = k;
	Vector<String> empty;
	while(*s) {
		int c = *s;
		if(c == ':') {
			const char *b = s++;
			while(*s == ':' || iscid(*s)) s++;
/*			if(all) {
				if(iscid(*r.Last()))
					r << ' ';
				ScopeInfo nnf(nf.GetScope(), nf.base);
				Qualify(r, nnf, b, s, usings);
			}
			else*/
				r.Cat(b, s);
		}
		else
		if(iscid(c)) {
			if(iscid(*r.Last()))
				r << ' ';
			if(s[0] == 'c' && s[1] == 'o' && s[2] == 'n' && s[3] == 's' && s[4] == 't' && !iscid(s[5])) {
				r << s_const;
				s += 5;
			}
			else
			if(s[0] == 'm' && s[1] == 'u' && s[2] == 't' && s[3] == 'a' && s[4] == 'b' && s[5] == 'l' && s[6] == 'e' && !iscid(s[7])) {
				r << "mutable";
				s += 7;
			}
			else
			if(s[0] == 'v' && s[1] == 'o' && s[2] == 'l' && s[3] == 'a' && s[4] == 't' && s[5] == 'i' && s[6] == 'l' && s[7] == 'e' && !iscid(s[8])) {
				r << "volatile";
				s += 8;
			}
			else {
				const char *b = s++;
				while(*s == ':' || iscid(*s)) s++;
				if(all)
					Qualify(r, nf, b, s, usings);
				else
					r.Cat(b, s);
			}
		}
		else {
			if(c == '(')
				all = true;
			if(c != ' ')
				r.Cat(c);
			s++;
		}
	}
	return r;
}
Ejemplo n.º 5
0
	bool Pipe::Open(const std::string&strName_)
	{
		Close();
		hPipe = CreateFile(Qualify(strName_).c_str(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
		if (hPipe != INVALID_HANDLE_VALUE)
		{
			strName = strName_;
			bServer=false;
			bConnected=true;
			return true;
		}
		return false;
	}
Ejemplo n.º 6
0
	bool Pipe::Create(const std::string&strName_,DWORD dwBufferSize)
	{
		Close();
		hPipe = CreateNamedPipe(Qualify(strName_).c_str(),
					PIPE_ACCESS_DUPLEX,
					PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT,
					1,
					dwBufferSize,
					dwBufferSize,
					0,
					NULL);
		if (hPipe != INVALID_HANDLE_VALUE)
		{
			strName = strName_;
			bServer=true;
			bConnected=false;
			return true;
		}
		return false;
	}
Ejemplo n.º 7
0
static AstExpression CheckMemberAccess(AstExpression expr)
{
	Type ty;
	Field fld;

	expr->kids[0] = CheckExpression(expr->kids[0]);
	if (expr->op == OP_MEMBER)
	{
		expr->kids[0] = Adjust(expr->kids[0], 0);
		ty = expr->kids[0]->ty;
		if (! IsRecordType(ty))
		{
			REPORT_OP_ERROR;
		}
		expr->lvalue = expr->kids[0]->lvalue;
	}
	else
	{
		expr->kids[0] = Adjust(expr->kids[0], 1);
		ty = expr->kids[0]->ty;
		if (! (IsPtrType(ty) && IsRecordType(ty->bty)))
		{
			REPORT_OP_ERROR;
		}
		ty = ty->bty;
		expr->lvalue = 1;
	}
	
	fld = LookupField(Unqual(ty), expr->val.p);
	if (fld == NULL)
	{
		Error(&expr->coord, "struct or union member %s doesn't exsist", expr->val.p);
		expr->ty = T(INT);
		return expr;
	}
	expr->ty = Qualify(ty->qual, fld->ty);
	expr->val.p = fld;
	expr->bitfld = fld->bits != 0;
	return expr;
}
Ejemplo n.º 8
0
	bool Pipe::WaitForServer(const std::string&strName,bool bForever)
	{
		if (WaitNamedPipe(Qualify(strName).c_str(),(bForever?NMPWAIT_WAIT_FOREVER:NMPWAIT_USE_DEFAULT_WAIT)))
			return true;
		return false;
	}