Пример #1
0
 MQ2BazaarItemType():MQ2Type("bazaaritem") {
     TypeMember(Price);
     TypeMember(Quantity);
     TypeMember(ItemID);
     TypeMember(Trader);
     TypeMember(Name);
 }
Пример #2
0
 MQ2BazaarType():MQ2Type("bazaar") {
     TypeMember(Count);
     TypeMember(Done);
     TypeMember(Item);
     TypeMember(Pricecheckdone);
     TypeMember(Pricecheck);
 }
Пример #3
0
void Parser::constructor(string const& name, IntrusiveRefCntPtr<TypeDef> type, TypePtr const& typeRef)
{
	IntrusiveRefCntPtr<TypeConstructor> ctor(new TypeConstructor(name));
	type->constructors.push_back(ctor);
	ctor->type = typeRef;

	expect(TLParen);

	if(token != TRParen)
	{
		do
		{
			bool isLet = test(TLet);

			string name;

			// TODO: Common pattern?
			TypePtr type = maybeType(false);
			if(! type)
			{
				name = expectIdent();
				type = typeName(false);
			}

			ctor->members.push_back(TypeMember(name, type));
			++ctor->ctorParams;
		}
		while(test(TComma));
	}

	{
		string const& ctorName = name;
		// Constructor function
		IntrusiveRefCntPtr<FuncDef> ctorFunc(new FuncDef(ctorName));

		enterFunction(ctorFunc);
		enterScope(new Scope);

		// Constructor function has the same type parameters
		for(auto& p : type->typeParams)
			ctorFunc->typeParams.push_back(p);

		int dummy = 0;

		IntrusiveRefCntPtr<CreateExpr> body(new CreateExpr());

		body->ctor = ctor;

		for(int i = 0; i < ctor->ctorParams; ++i)
		{
			auto& member = ctor->members[i];
			auto p = declParam(ctorFunc, member.name, member.type->fresh(), &dummy);
			body->parameters.push_back(ExprPtr(new VarRef(p)));
		}

		ctorFunc->body = exitScope<Expr>(body);
		ctorFunc->returnType = typeRef;

		// TODO: Check for name collision
		mod->functions[ctorName] = ctorFunc;
		mod->constructorDefs[ctorName] = ctor;
		exitFunction();
	}

	expect(TRParen, true);
}